# Path: epistasis/models/utils.py
# class XMatrixException(Exception):
#     """Exception Subclass for X matrix errors."""
# 
# def arghandler(method):
#     """Points methods to argument handlers. Assumes each argument has a
#     corresponding method attached to the object named "_{argument}". These
#     methods given default values to arguments.
# 
#     Ignores self and kwargs
#     """
#     @wraps(method)
#     def inner(self, *args, **kwargs):
#         # Get method name
#         name = method.__name__
# 
#         # Inspect function for arguments to update.
#         out = inspect.signature(method)
# 
#         # Construct kwargs from signature.
#         kws = {key: val.default for key, val in out.parameters.items()}
#         kws.pop('self')
# 
#         # Try to remove kwargs.
#         try:
#             kws.pop('kwargs')
#         except:
#             pass
# 
#         # Update kwargs with user specified kwargs.
#         kws.update(**kwargs)
# 
#         # Handle each argument
#         for arg in kws:
#             # Get handler function.
#             handler_name = "_{}".format(arg)
#             handler = getattr(self, handler_name)
#             kws[arg] = handler(data=kws[arg], method=name)
# 
#         return method(self, **kws)
#     return inner


import numpy as np
import pandas as pd
import warnings
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.naive_bayes import BernoulliNB
from sklearn.preprocessing import binarize
from epistasis.mapping import EpistasisMap
from epistasis.models.base import BaseModel, use_sklearn
from epistasis.models.utils import (XMatrixException, arghandler)
from epistasis.models.linear import EpistasisLinearRegression
from gpmap import GenotypePhenotypeMap
from .base import EpistasisClassifierMixin
    def score(self, X=None, y=None, **kwargs):
        yclass = binarize(y.reshape(1, -1), threshold=self.threshold)[0]
        return super(self.__class__, self).score(X=X, y=yclass)

    @arghandler
    def lnlike_of_data(self, X=None, y=None, yerr=None, thetas=None):
        # Calculate Y's
        ymodel = self.hypothesis(X=X, thetas=thetas)
        ymodel_ = 1 - ymodel
        ymodel[ymodel < 0.5] = ymodel_[ymodel < 0.5]

        return np.log(ymodel)

    @arghandler
    def lnlike_transform(
        self,
        X=None,
        y=None,
        yerr=None,
        lnprior=None,
        thetas=None):
        # Update likelihood.
        ymodel = self.hypothesis(X=X, thetas=thetas)
        yclass = np.ones(len(ymodel))
        yclass[ymodel > 0.5] = 0

        lnlike = self.lnlike_of_data(X=X, y=y, yerr=yerr, thetas=thetas)
        lnprior[yclass == 0] = 0
        return lnlike + lnprior


# Path: epistasis/models/utils.py
# class XMatrixException(Exception):
#     """Exception Subclass for X matrix errors."""
# 
# def arghandler(method):
#     """Points methods to argument handlers. Assumes each argument has a
#     corresponding method attached to the object named "_{argument}". These
#     methods given default values to arguments.
# 
#     Ignores self and kwargs
#     """
#     @wraps(method)
#     def inner(self, *args, **kwargs):
#         # Get method name
#         name = method.__name__
# 
#         # Inspect function for arguments to update.
#         out = inspect.signature(method)
# 
#         # Construct kwargs from signature.
#         kws = {key: val.default for key, val in out.parameters.items()}
#         kws.pop('self')
# 
#         # Try to remove kwargs.
#         try:
#             kws.pop('kwargs')
#         except:
#             pass
# 
#         # Update kwargs with user specified kwargs.
#         kws.update(**kwargs)
# 
#         # Handle each argument
#         for arg in kws:
#             # Get handler function.
#             handler_name = "_{}".format(arg)
#             handler = getattr(self, handler_name)
#             kws[arg] = handler(data=kws[arg], method=name)
# 
#         return method(self, **kws)
#     return inner


# Path: epistasis/models/classifiers/logistic.py
import numpy as np
import pandas as pd
import warnings
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.naive_bayes import BernoulliNB
from sklearn.preprocessing import binarize
from epistasis.mapping import EpistasisMap
from epistasis.models.base import BaseModel, use_sklearn
from epistasis.models.utils import (XMatrixException, arghandler)
from epistasis.models.linear import EpistasisLinearRegression
from gpmap import GenotypePhenotypeMap
from .base import EpistasisClassifierMixin

    def score(self, X=None, y=None, **kwargs):
        yclass = binarize(y.reshape(1, -1), threshold=self.threshold)[0]
        return super(self.__class__, self).score(X=X, y=yclass)

    @arghandler
    def lnlike_of_data(self, X=None, y=None, yerr=None, thetas=None):
        # Calculate Y's
        ymodel = self.hypothesis(X=X, thetas=thetas)
        ymodel_ = 1 - ymodel
        ymodel[ymodel < 0.5] = ymodel_[ymodel < 0.5]

        return np.log(ymodel)

    @arghandler
    def lnlike_transform(
        self,
        X=None,
        y=None,
        yerr=None,
        lnprior=None,
        thetas=None):
        # Update likelihood.
        ymodel = self.hypothesis(X=X, thetas=thetas)
        yclass = np.ones(len(ymodel))
        yclass[ymodel > 0.5] = 0

        lnlike = self.lnlike_of_data(X=X, y=y, yerr=yerr, thetas=thetas)
        lnprior[yclass == 0] = 0
        return lnlike + lnprior


    @arghandler