# Path: skTMVA/skTMVA.py
# def convert_bdt_sklearn_tmva(sklearn_bdt_clf, input_var_list, tmva_outfile_xml):
# 
#     # AdaBoost
#     if isinstance(sklearn_bdt_clf, AdaBoostClassifier):
#         convert_bdt__AdaBoost(sklearn_bdt_clf, input_var_list, tmva_outfile_xml)
# 
#     # Gradient Boosting (binary classification only)
#     if isinstance(sklearn_bdt_clf, GradientBoostingClassifier):
#         convert_bdt__Grad(sklearn_bdt_clf, input_var_list, tmva_outfile_xml)


from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import GradientBoostingClassifier
from skTMVA import convert_bdt_sklearn_tmva
from numpy.random import RandomState
import cPickle
import numpy as np

# Construct an example dataset for binary classification
n_vars = 2
n_events = 10000
signal = RNG.multivariate_normal(
    np.ones(n_vars), np.diag(np.ones(n_vars)), n_events)
background = RNG.multivariate_normal(
    np.ones(n_vars) * -1, np.diag(np.ones(n_vars)), n_events)
X = np.concatenate([signal, background])
y = np.ones(X.shape[0])
w = RNG.randint(1, 10, n_events * 2)
y[signal.shape[0]:] *= -1
permute = RNG.permutation(y.shape[0])
X = X[permute]
y = y[permute]

# Use all dataset for training
X_train, y_train, w_train = X, y, w

# Declare BDT - we are going to use AdaBoost Decision Tree
bdt = GradientBoostingClassifier(
    n_estimators=200, learning_rate=0.5,
    min_samples_leaf=int(0.05*len(X_train)),
    max_depth=3, random_state=0)

# Train BDT
bdt.fit(X_train, y_train)

# Save BDT to pickle file
with open('bdt_sklearn_to_tmva_example.pkl', 'wb') as fid:

# Path: skTMVA/skTMVA.py
# def convert_bdt_sklearn_tmva(sklearn_bdt_clf, input_var_list, tmva_outfile_xml):
# 
#     # AdaBoost
#     if isinstance(sklearn_bdt_clf, AdaBoostClassifier):
#         convert_bdt__AdaBoost(sklearn_bdt_clf, input_var_list, tmva_outfile_xml)
# 
#     # Gradient Boosting (binary classification only)
#     if isinstance(sklearn_bdt_clf, GradientBoostingClassifier):
#         convert_bdt__Grad(sklearn_bdt_clf, input_var_list, tmva_outfile_xml)


# Path: examples/bdt_sklearn_to_tmva_Grad.py
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import GradientBoostingClassifier
from skTMVA import convert_bdt_sklearn_tmva
from numpy.random import RandomState
import cPickle
import numpy as np


# Construct an example dataset for binary classification
n_vars = 2
n_events = 10000
signal = RNG.multivariate_normal(
    np.ones(n_vars), np.diag(np.ones(n_vars)), n_events)
background = RNG.multivariate_normal(
    np.ones(n_vars) * -1, np.diag(np.ones(n_vars)), n_events)
X = np.concatenate([signal, background])
y = np.ones(X.shape[0])
w = RNG.randint(1, 10, n_events * 2)
y[signal.shape[0]:] *= -1
permute = RNG.permutation(y.shape[0])
X = X[permute]
y = y[permute]

# Use all dataset for training
X_train, y_train, w_train = X, y, w

# Declare BDT - we are going to use AdaBoost Decision Tree
bdt = GradientBoostingClassifier(
    n_estimators=200, learning_rate=0.5,
    min_samples_leaf=int(0.05*len(X_train)),
    max_depth=3, random_state=0)

# Train BDT
bdt.fit(X_train, y_train)

# Save BDT to pickle file
with open('bdt_sklearn_to_tmva_example.pkl', 'wb') as fid:

    cPickle.dump(bdt, fid)