# 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
    """Logistic regression for estimating epistatic interactions that lead to
    nonviable phenotypes. Useful for predicting viable/nonviable phenotypes.

    Parameters
    ----------
    threshold : float
        value below which phenotypes are considered nonviable.

    order : int
        order of epistasis model

    model_type : str (default="global")
        type of model matrix to use. "global" defines epistasis with respect to
        a background-averaged "genotype-phenotype". "local" defines epistasis
        with respect to the wildtype genotype.
    """
    def __init__(self, threshold, model_type="global", **kwargs):
        super(self.__class__, self).__init__(**kwargs)
        self.threshold = threshold
        self.model_type = model_type
        self.fit_intercept = False
        self.order = 1
        self.Xbuilt = {}

        # Store model specs.
        self.model_specs = dict(
            threshold=self.threshold,
            model_type=self.model_type,
            **kwargs)


# 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

    """Logistic regression for estimating epistatic interactions that lead to
    nonviable phenotypes. Useful for predicting viable/nonviable phenotypes.

    Parameters
    ----------
    threshold : float
        value below which phenotypes are considered nonviable.

    order : int
        order of epistasis model

    model_type : str (default="global")
        type of model matrix to use. "global" defines epistasis with respect to
        a background-averaged "genotype-phenotype". "local" defines epistasis
        with respect to the wildtype genotype.
    """
    def __init__(self, threshold, model_type="global", **kwargs):
        super(self.__class__, self).__init__(**kwargs)
        self.threshold = threshold
        self.model_type = model_type
        self.fit_intercept = False
        self.order = 1
        self.Xbuilt = {}

        # Store model specs.
        self.model_specs = dict(
            threshold=self.threshold,
            model_type=self.model_type,
            **kwargs)


    @arghandler