# Path: jr/gat/scorers.py
# def scorer_angle(y_true, y_pred, n_jobs=1):
#     """Scoring function dedicated to AngularRegressor"""
#     y_true, y_pred, shape = _check_y(y_true, y_pred)
#     accuracy = _parallel_scorer(y_true, y_pred, _angle_accuracy, n_jobs)
#     if (len(shape) > 1) and (np.sum(shape[1:]) > 1):
#         accuracy = np.reshape(accuracy, shape[1:])
#     else:
#         accuracy = accuracy[0]
#     return accuracy


import numpy as np
import warnings
import scipy.sparse as sp
        import copy
        import warnings
from sklearn.base import BaseEstimator
from sklearn.svm import SVC, LinearSVC, LinearSVR
from sklearn.calibration import CalibratedClassifierCV
from .scorers import scorer_angle
        from copy import deepcopy
        from sklearn.cross_validation import StratifiedShuffleSplit
        from gat.predicters import predict_OneVsOne
        from sklearn.preprocessing import StandardScaler
        from sklearn.pipeline import make_pipeline
        from jr.stats import circ_weighted_mean
        from sklearn.base import clone
        predict_angle : list | np.array, shape(n_trials)
            angle predictions in radian
        """
        if self.independent:
            predict_cos = self.clf_cos.predict(X)
            predict_sin = self.clf_sin.predict(X)
        else:
            predict_cossin = self.clf.predict(X)
            predict_cos = predict_cossin[:, 0]
            predict_sin = predict_cossin[:, 1]
        predict_angle = np.arctan2(predict_sin, predict_cos)
        predict_radius = np.sqrt(predict_sin ** 2 + predict_cos ** 2)
        y_pred = np.concatenate((predict_angle.reshape([-1, 1]),
                                 predict_radius.reshape([-1, 1])), axis=1)
        return y_pred

    @property
    def coef_(self,):
        if self.independent:
            return np.array([self.clf_cos.coef_, self.clf_sin.coef_])
        else:
            return self.clf.coef_


class AngularRegression(PolarRegression):
    def predict(self, X):
        return super(AngularRegression, self).predict(X)[:, 0]

    def score(self, X, y):
        y_pred = self.predict(X)

# Path: jr/gat/scorers.py
# def scorer_angle(y_true, y_pred, n_jobs=1):
#     """Scoring function dedicated to AngularRegressor"""
#     y_true, y_pred, shape = _check_y(y_true, y_pred)
#     accuracy = _parallel_scorer(y_true, y_pred, _angle_accuracy, n_jobs)
#     if (len(shape) > 1) and (np.sum(shape[1:]) > 1):
#         accuracy = np.reshape(accuracy, shape[1:])
#     else:
#         accuracy = accuracy[0]
#     return accuracy


# Path: jr/gat/classifiers.py
import numpy as np
import warnings
import scipy.sparse as sp
        import copy
        import warnings
from sklearn.base import BaseEstimator
from sklearn.svm import SVC, LinearSVC, LinearSVR
from sklearn.calibration import CalibratedClassifierCV
from .scorers import scorer_angle
        from copy import deepcopy
        from sklearn.cross_validation import StratifiedShuffleSplit
        from gat.predicters import predict_OneVsOne
        from sklearn.preprocessing import StandardScaler
        from sklearn.pipeline import make_pipeline
        from jr.stats import circ_weighted_mean
        from sklearn.base import clone

        predict_angle : list | np.array, shape(n_trials)
            angle predictions in radian
        """
        if self.independent:
            predict_cos = self.clf_cos.predict(X)
            predict_sin = self.clf_sin.predict(X)
        else:
            predict_cossin = self.clf.predict(X)
            predict_cos = predict_cossin[:, 0]
            predict_sin = predict_cossin[:, 1]
        predict_angle = np.arctan2(predict_sin, predict_cos)
        predict_radius = np.sqrt(predict_sin ** 2 + predict_cos ** 2)
        y_pred = np.concatenate((predict_angle.reshape([-1, 1]),
                                 predict_radius.reshape([-1, 1])), axis=1)
        return y_pred

    @property
    def coef_(self,):
        if self.independent:
            return np.array([self.clf_cos.coef_, self.clf_sin.coef_])
        else:
            return self.clf.coef_


class AngularRegression(PolarRegression):
    def predict(self, X):
        return super(AngularRegression, self).predict(X)[:, 0]

    def score(self, X, y):
        y_pred = self.predict(X)

        return scorer_angle(y, y_pred)