Skip to content
Snippets Groups Projects
Commit f62991d7 authored by Baptiste Bauvin's avatar Baptiste Bauvin
Browse files

Modified distrib of HPs for CQB and CQBv2

parent fcab676c
No related branches found
No related tags found
No related merge requests found
...@@ -161,7 +161,7 @@ def getHPs(classifierModule, hyperParamSearch, nIter, CL_type, X_train, y_train, ...@@ -161,7 +161,7 @@ def getHPs(classifierModule, hyperParamSearch, nIter, CL_type, X_train, y_train,
outputFileName, classifierModule, outputFileName, classifierModule,
KFolds=KFolds, nbCores=nbCores, KFolds=KFolds, nbCores=nbCores,
metric=metrics[0], nIter=nIter) metric=metrics[0], nIter=nIter)
logging.debug("Done:\t " + hyperParamSearch + "RandomSearch best settings") logging.debug("Done:\t " + hyperParamSearch + " best settings")
else: else:
clKWARGS = kwargs[CL_type + "KWARGS"] clKWARGS = kwargs[CL_type + "KWARGS"]
return clKWARGS, testFoldsPreds return clKWARGS, testFoldsPreds
......
from sklearn.model_selection import RandomizedSearchCV from sklearn.model_selection import RandomizedSearchCV
import numpy as np import numpy as np
from scipy.stats import uniform, randint
from .. import Metrics from .. import Metrics
from ..utils import HyperParameterSearch from ..utils import HyperParameterSearch
...@@ -50,6 +51,29 @@ def genTestFoldsPreds(X_train, y_train, KFolds, estimator): ...@@ -50,6 +51,29 @@ def genTestFoldsPreds(X_train, y_train, KFolds, estimator):
testFoldsPreds = np.array([testFoldPreds[:minFoldLength] for testFoldPreds in testFoldsPreds]) testFoldsPreds = np.array([testFoldPreds[:minFoldLength] for testFoldPreds in testFoldsPreds])
return testFoldsPreds return testFoldsPreds
class CustomRandint:
def __init__(self, low=0, high=0, multiplier="e-"):
self.randint = randint(low, high)
self.multiplier = multiplier
def rvs(self, random_state=None):
randinteger = self.randint.rvs(random_state=random_state)
if self.multiplier == "e-":
return 10 ** -randinteger
class CustomUniform:
def __init__(self, loc=0, state=1, multiplier="e-"):
self.uniform = uniform(loc, state)
self.multiplier = multiplier
def rvs(self, random_state=None):
unif = self.uniform.rvs(random_state=random_state)
if self.multiplier == 'e-':
return 10 ** -unif
# def isUseful(labelSupports, index, CLASS_LABELS, labelDict): # def isUseful(labelSupports, index, CLASS_LABELS, labelDict):
# if labelSupports[labelDict[CLASS_LABELS[index]]] != 0: # if labelSupports[labelDict[CLASS_LABELS[index]]] != 0:
# labelSupports[labelDict[CLASS_LABELS[index]]] -= 1 # labelSupports[labelDict[CLASS_LABELS[index]]] -= 1
......
...@@ -19,9 +19,11 @@ from sklearn.base import BaseEstimator, ClassifierMixin ...@@ -19,9 +19,11 @@ from sklearn.base import BaseEstimator, ClassifierMixin
from sklearn.pipeline import Pipeline from sklearn.pipeline import Pipeline
from sklearn.model_selection import RandomizedSearchCV from sklearn.model_selection import RandomizedSearchCV
from sklearn.tree import DecisionTreeClassifier from sklearn.tree import DecisionTreeClassifier
from scipy.stats import randint from scipy.stats import randint, uniform
import numpy as np import numpy as np
from ..Monoview.MonoviewUtils import CustomUniform, CustomRandint
class ColumnGenerationClassifier(BaseEstimator, ClassifierMixin): class ColumnGenerationClassifier(BaseEstimator, ClassifierMixin):
...@@ -293,6 +295,10 @@ class CQBoost(CqBoostClassifier): ...@@ -293,6 +295,10 @@ class CQBoost(CqBoostClassifier):
return interpretString return interpretString
def canProbas(): def canProbas():
return False return False
...@@ -311,7 +317,7 @@ def paramsToSet(nIter, randomState): ...@@ -311,7 +317,7 @@ def paramsToSet(nIter, randomState):
"""Used for weighted linear early fusion to generate random search sets""" """Used for weighted linear early fusion to generate random search sets"""
paramsSet = [] paramsSet = []
for _ in range(nIter): for _ in range(nIter):
paramsSet.append({"mu": randomState.uniform(1e-02, 10**(-0.5)), paramsSet.append({"mu": 10**-randomState.uniform(0.5, 1.5),
"epsilon": 10**-randomState.randint(1, 15), "epsilon": 10**-randomState.randint(1, 15),
"n_max_iterations": None}) "n_max_iterations": None})
return paramsSet return paramsSet
...@@ -331,8 +337,8 @@ def genPipeline(): ...@@ -331,8 +337,8 @@ def genPipeline():
def genParamsDict(randomState): def genParamsDict(randomState):
return {"classifier__mu": [0.001, 0.002], return {"classifier__mu": CustomUniform(loc=.5, state=2, multiplier='e-'),
"classifier__epsilon": [1e-08, 2e-08], "classifier__epsilon": CustomRandint(low=1, high=15, multiplier='e-'),
"classifier__n_max_iterations": [None]} "classifier__n_max_iterations": [None]}
......
...@@ -7,21 +7,23 @@ from collections import defaultdict, OrderedDict ...@@ -7,21 +7,23 @@ from collections import defaultdict, OrderedDict
import pandas as pd import pandas as pd
import sys import sys
from functools import partial from functools import partial
import numpy as np
from scipy.spatial import distance
from sklearn.base import BaseEstimator, ClassifierMixin, TransformerMixin from sklearn.base import BaseEstimator, ClassifierMixin, TransformerMixin
from sklearn.utils.validation import check_is_fitted from sklearn.utils.validation import check_is_fitted
from sklearn.preprocessing import LabelEncoder from sklearn.preprocessing import LabelEncoder
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics.pairwise import rbf_kernel, linear_kernel
import numpy as np
from sklearn.base import BaseEstimator, ClassifierMixin from sklearn.base import BaseEstimator, ClassifierMixin
from sklearn.pipeline import Pipeline from sklearn.pipeline import Pipeline
from sklearn.model_selection import RandomizedSearchCV
from sklearn.tree import DecisionTreeClassifier
from scipy.stats import randint
import numpy as np import numpy as np
# import numpy as np
# from scipy.spatial import distance
# from sklearn.tree import DecisionTreeClassifier
# from sklearn.metrics.pairwise import rbf_kernel, linear_kernel
# from sklearn.model_selection import RandomizedSearchCV
# from sklearn.tree import DecisionTreeClassifier
# from scipy.stats import randint
from ..Monoview.MonoviewUtils import CustomRandint, CustomUniform
class ColumnGenerationClassifierv2(BaseEstimator, ClassifierMixin): class ColumnGenerationClassifierv2(BaseEstimator, ClassifierMixin):
def __init__(self, epsilon=1e-06, n_max_iterations=None, estimators_generator=None, dual_constraint_rhs=0, save_iteration_as_hyperparameter_each=None): def __init__(self, epsilon=1e-06, n_max_iterations=None, estimators_generator=None, dual_constraint_rhs=0, save_iteration_as_hyperparameter_each=None):
...@@ -350,8 +352,8 @@ def genPipeline(): ...@@ -350,8 +352,8 @@ def genPipeline():
def genParamsDict(randomState): def genParamsDict(randomState):
return {"classifier__mu": [0.001, 0.002], return {"classifier__mu": CustomUniform(loc=.5, state=2, multiplier='e-'),
"classifier__epsilon": [1e-08, 2e-08], "classifier__epsilon": CustomRandint(low=1, high=15, multiplier='e-'),
"classifier__n_max_iterations": [None]} "classifier__n_max_iterations": [None]}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment