# Path: crowdastro/crowd/util.py
# def majority_vote(y):
#     """Computes the majority vote of a set of crowd labels.
# 
#     y: (n_annotators, n_examples) NumPy masked array of labels.
#     -> (n_examples,) NumPy array of labels.
#     """
#     _, n_samples = y.shape
#     mv = numpy.zeros((n_samples,))
#     for i in range(n_samples):
#         labels = y[:, i]
# 
#         if labels.mask is False:
#             counter = collections.Counter(labels)
#         else:
#             counter = collections.Counter(labels[~labels.mask])
# 
#         if counter:
#             mv[i] = max(counter, key=counter.get)
#         else:
#             # No labels for this data point.
#             mv[i] = numpy.random.randint(2)  # ¯\_(ツ)_/¯
#     return mv
# 
# 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 logging
import time
import numpy
import scipy.optimize
import sklearn.linear_model
from crowdastro.crowd.util import majority_vote, logistic_regression

        divisor[divisor == 0] = EPS
        return a / divisor

    def _max_beta_step(self, m, y, y_mask):
        """Computes β based on μ.

        m: μ
        y: Array of crowd labels.
        y_mask: Mask of unobserved crowd labels.
        -> β
        """
        b = numpy.zeros((y.shape[0],))
        divisor = numpy.zeros((y.shape[0],))
        for t in range(y.shape[0]):
            for i in range(y.shape[1]):
                if y_mask[t, i]:
                    continue

                b[t] += (1 - m[i]) * (1 - y[t, i])
                divisor[t] += (1 - m[i])

        divisor[divisor == 0] = EPS
        return b / divisor

    def predict(self, X):
        return self.predict_proba(X).round()

    def predict_proba(self, X):
        X = numpy.hstack([X, numpy.ones((X.shape[0], 1))])

# Path: crowdastro/crowd/util.py
# def majority_vote(y):
#     """Computes the majority vote of a set of crowd labels.
# 
#     y: (n_annotators, n_examples) NumPy masked array of labels.
#     -> (n_examples,) NumPy array of labels.
#     """
#     _, n_samples = y.shape
#     mv = numpy.zeros((n_samples,))
#     for i in range(n_samples):
#         labels = y[:, i]
# 
#         if labels.mask is False:
#             counter = collections.Counter(labels)
#         else:
#             counter = collections.Counter(labels[~labels.mask])
# 
#         if counter:
#             mv[i] = max(counter, key=counter.get)
#         else:
#             # No labels for this data point.
#             mv[i] = numpy.random.randint(2)  # ¯\_(ツ)_/¯
#     return mv
# 
# 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.py
import logging
import time
import numpy
import scipy.optimize
import sklearn.linear_model
from crowdastro.crowd.util import majority_vote, logistic_regression


        divisor[divisor == 0] = EPS
        return a / divisor

    def _max_beta_step(self, m, y, y_mask):
        """Computes β based on μ.

        m: μ
        y: Array of crowd labels.
        y_mask: Mask of unobserved crowd labels.
        -> β
        """
        b = numpy.zeros((y.shape[0],))
        divisor = numpy.zeros((y.shape[0],))
        for t in range(y.shape[0]):
            for i in range(y.shape[1]):
                if y_mask[t, i]:
                    continue

                b[t] += (1 - m[i]) * (1 - y[t, i])
                divisor[t] += (1 - m[i])

        divisor[divisor == 0] = EPS
        return b / divisor

    def predict(self, X):
        return self.predict_proba(X).round()

    def predict_proba(self, X):
        X = numpy.hstack([X, numpy.ones((X.shape[0], 1))])

        return logistic_regression(self.w_, X)