"""
This script was generated by the train.py script in this repository:
https://github.com/ecohealthalliance/geoname-annotator-training
"""
import numpy as np
from numpy import array, int32


HIGH_CONFIDENCE_THRESHOLD = 0.5
GEONAME_SCORE_THRESHOLD = 0.1
base_classifier =\
{'C': 1.0,
 'class_weight': None,
 'classes_': array([False,  True], dtype=bool),
 'coef_': array([[ 0.3213819 ,  0.01823242,  0.02336938,  0.29849362,  2.47665562,
         0.47210803,  0.16109926,  0.        , -0.97918471,  0.00476336,
        -0.01442839, -0.60016267, -0.23542543,  1.89213763,  0.        ,
        -1.68017007,  0.        ,  0.        ,  0.        ,  0.        ,
         0.        ]]),
 'dual': False,
 'fit_intercept': True,
 'intercept_': array([-10.3865459]),
 'intercept_scaling': 1,
 'max_iter': 100,
 'multi_class': 'ovr',
 'n_iter_': array([30], dtype=int32),
 'n_jobs': 1,
 'penalty': 'l1',
 'random_state': None,
 'solver': 'liblinear',
 'tol': 0.0001,
 'verbose': 0,
 'warm_start': False}
contextual_classifier =\
{'C': 1.0,
 'class_weight': None,
 'classes_': array([False,  True], dtype=bool),
 'coef_': array([[ 0.33234538,  0.02662401,  0.02615038,  0.2902419 ,  2.67413257,
         0.58878742,  0.15810715, -2.57352368, -2.8911252 , -0.01368534,
        -0.01187249, -1.28375178, -1.05650366,  1.52334291, -0.63130291,
        -1.85594312,  0.54173888,  0.64798624, -0.46296609,  0.10588069,
        -0.95874479]]),
 'dual': False,
 'fit_intercept': True,
 'intercept_': array([-7.96994027]),
 'intercept_scaling': 1,
 'max_iter': 100,
 'multi_class': 'ovr',
 'n_iter_': array([35], dtype=int32),
 'n_jobs': 1,
 'penalty': 'l1',
 'random_state': None,
 'solver': 'liblinear',
 'tol': 0.0001,
 'verbose': 0,
 'warm_start': False}
# Logistic regression code from scipy
def predict_proba(X, classifier):
    """Probability estimation for OvR logistic regression.
    Positive class probabilities are computed as
    1. / (1. + np.exp(-classifier.decision_function(X)));
    multiclass is handled by normalizing that over all classes.
    """
    prob = np.dot(X, classifier['coef_'].T) + classifier['intercept_']
    prob = prob.ravel() if prob.shape[1] == 1 else prob
    prob *= -1
    np.exp(prob, prob)
    prob += 1
    np.reciprocal(prob, prob)
    if prob.ndim == 1:
        return np.vstack([1 - prob, prob]).T
    else:
        # OvR normalization, like LibLinear's predict_probability
        prob /= prob.sum(axis=1).reshape((prob.shape[0], -1))
        return prob


def predict_proba_base(X):
    return predict_proba(X, base_classifier)


def predict_proba_contextual(X):
    return predict_proba(X, contextual_classifier)
