# Path: crowdastro/crowd/raykar.py
# EPS = 1E-8
#         X = numpy.hstack([X, numpy.ones((X.shape[0], 1))])
#         X = numpy.hstack([X, numpy.ones((X.shape[0], 1))])
# class RaykarClassifier(object):
#     def __init__(self, n_restarts=5, epsilon=1e-5, lr_init=True):
#     def fit(self, X, Y):
#     def _fit_params(self, x, y):
#     def _exp_m_step(self, a, b, w, x, y, y_mask):
#     def _hessian_inverse_multiply(self, x, H, g):
#     def _max_w_step(self, a, b, m, x, y_0, y_1, mv, init_w=None):
#     def _max_alpha_step(self, m, y, y_mask):
#     def _max_beta_step(self, m, y, y_mask):
#     def predict(self, X):
#     def predict_proba(self, X):
#     def score(self, X, Y):
#     def _log_likelihood(self, *args, **kwargs):
#     def _likelihood(self, w, a, b, X, Y_0, Y_1):
#     def get_params(self, deep=True):
#     def set_params(self, **parameters):
#     def serialise(self):
#     def unserialise(cls, array):
# 
# Path: crowdastro/crowd/util.py
# def logistic_regression(w, x):
#     """Logistic regression classifier model.
# 
#     w: Weights w. (n_features,) NumPy array
#     x: Data point x_i. (n_features,) NumPy array
#     -> float in [0, 1]
#     """
#     return scipy.special.expit(numpy.dot(x, w.T))


import unittest
import numpy
import scipy.optimize
import sklearn.linear_model
from crowdastro.crowd import raykar
from crowdastro.crowd.util import logistic_regression
The Australian National University
2016
"""





class TestSymmetry(unittest.TestCase):
    """Tests that the classifier is symmetric in its labels.

    i.e. Swapping 0 and 1 doesn't change the output.
    """

    def setUp(self):
        self.n_labellers = 10
        self.n_features = 1
        self.n_examples = 50
        self.noise = 0.25
        self.masked = 0.50
        self.x = numpy.arange(self.n_examples).reshape((-1, 1))
        y = (self.x.ravel() < self.n_examples // 4).astype(int)
        self.z = y
        y = numpy.tile(y, (self.n_labellers, 1))
        to_flip = numpy.random.binomial(
            1, self.noise, size=y.shape).astype(bool)
        y[to_flip] = 1 - y[to_flip]
        y_mask = numpy.random.binomial(1, self.masked, size=y.shape)
        self.y = numpy.ma.MaskedArray(y, mask=y_mask)
        numpy.random.seed(0)

# Path: crowdastro/crowd/raykar.py
# EPS = 1E-8
#         X = numpy.hstack([X, numpy.ones((X.shape[0], 1))])
#         X = numpy.hstack([X, numpy.ones((X.shape[0], 1))])
# class RaykarClassifier(object):
#     def __init__(self, n_restarts=5, epsilon=1e-5, lr_init=True):
#     def fit(self, X, Y):
#     def _fit_params(self, x, y):
#     def _exp_m_step(self, a, b, w, x, y, y_mask):
#     def _hessian_inverse_multiply(self, x, H, g):
#     def _max_w_step(self, a, b, m, x, y_0, y_1, mv, init_w=None):
#     def _max_alpha_step(self, m, y, y_mask):
#     def _max_beta_step(self, m, y, y_mask):
#     def predict(self, X):
#     def predict_proba(self, X):
#     def score(self, X, Y):
#     def _log_likelihood(self, *args, **kwargs):
#     def _likelihood(self, w, a, b, X, Y_0, Y_1):
#     def get_params(self, deep=True):
#     def set_params(self, **parameters):
#     def serialise(self):
#     def unserialise(cls, array):
# 
# Path: crowdastro/crowd/util.py
# def logistic_regression(w, x):
#     """Logistic regression classifier model.
# 
#     w: Weights w. (n_features,) NumPy array
#     x: Data point x_i. (n_features,) NumPy array
#     -> float in [0, 1]
#     """
#     return scipy.special.expit(numpy.dot(x, w.T))


# Path: crowdastro/crowd/raykar_test.py
import unittest
import numpy
import scipy.optimize
import sklearn.linear_model
from crowdastro.crowd import raykar
from crowdastro.crowd.util import logistic_regression

The Australian National University
2016
"""





class TestSymmetry(unittest.TestCase):
    """Tests that the classifier is symmetric in its labels.

    i.e. Swapping 0 and 1 doesn't change the output.
    """

    def setUp(self):
        self.n_labellers = 10
        self.n_features = 1
        self.n_examples = 50
        self.noise = 0.25
        self.masked = 0.50
        self.x = numpy.arange(self.n_examples).reshape((-1, 1))
        y = (self.x.ravel() < self.n_examples // 4).astype(int)
        self.z = y
        y = numpy.tile(y, (self.n_labellers, 1))
        to_flip = numpy.random.binomial(
            1, self.noise, size=y.shape).astype(bool)
        y[to_flip] = 1 - y[to_flip]
        y_mask = numpy.random.binomial(1, self.masked, size=y.shape)
        self.y = numpy.ma.MaskedArray(y, mask=y_mask)
        numpy.random.seed(0)

        self.rc = raykar.RaykarClassifier(