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

Added easymkl, not working

parent d3930ac2
No related branches found
No related tags found
No related merge requests found
...@@ -198,3 +198,8 @@ weighted_linear_late_fusion: ...@@ -198,3 +198,8 @@ weighted_linear_late_fusion:
max_depth: [1] max_depth: [1]
criterion: ["gini"] criterion: ["gini"]
splitter: ["best"] splitter: ["best"]
mumbo:
base_estimator: [None]
n_estimators: [10]
best_view_mode: ["edge"]
\ No newline at end of file
...@@ -24,7 +24,7 @@ Classification: ...@@ -24,7 +24,7 @@ Classification:
classes: classes:
type: ["multiview"] type: ["multiview"]
algos_monoview: ["all"] algos_monoview: ["all"]
algos_multiview: ["mumbo"] algos_multiview: ["mumbo", "easy_mkl"]
stats_iter: 2 stats_iter: 2
metrics: ["accuracy_score", "f1_score"] metrics: ["accuracy_score", "f1_score"]
metric_princ: "f1_score" metric_princ: "f1_score"
...@@ -203,3 +203,7 @@ mumbo: ...@@ -203,3 +203,7 @@ mumbo:
base_estimator: [None] base_estimator: [None]
n_estimators: [10] n_estimators: [10]
best_view_mode: ["edge"] best_view_mode: ["edge"]
easy_mkl:
degrees: [1]
lam: [0.1]
from MKLpy.algorithms import EasyMKL
from MKLpy.metrics import pairwise
import numpy as np
from ..multiview.multiview_utils import BaseMultiviewClassifier, get_examples_views_indices
from ..utils.hyper_parameter_search import CustomUniform
classifier_class_name = "EasyMKLClassifier"
class EasyMKLClassifier(BaseMultiviewClassifier, EasyMKL):
def __init__(self, random_state=None, degrees=1, lam=0.1):
super().__init__(random_state)
super(BaseMultiviewClassifier, self).__init__(lam=lam)
self.degrees = degrees
self.param_names = ["lam", "degrees"]
self.distribs = [CustomUniform(), DegreesGenerator()]
def fit(self, X, y, train_indices=None, views_indices=None ):
train_indices, views_indices = get_examples_views_indices(X,
train_indices,
views_indices)
if isinstance(self.degrees, DegreesDistribution):
self.degrees = self.degrees.draw(len(views_indices))
elif isinstance(int, self.degrees):
self.degrees = [self.degrees for _ in range(len(views_indices))]
kernels = [pairwise.homogeneous_polynomial_kernel(X.get_V(views_indices[index],
train_indices),
degree=degree)
for index, degree in enumerate(self.degrees)]
return super(EasyMKLClassifier, self).fit(kernels, y[train_indices])
def predict(self, X, example_indices=None, views_indices=None):
example_indices, views_indices = get_examples_views_indices(X,
example_indices,
views_indices)
kernels = [
pairwise.homogeneous_polynomial_kernel(X.get_V(views_indices[index],
example_indices),
degree=degree)
for index, degree in enumerate(self.degrees)]
return super(EasyMKLClassifier, self).predict(kernels,)
class DegreesGenerator:
def __init__(self):
pass
def rvs(self, random_state=None):
return DegreesDistribution(seed=random_state.randint(1))
class DegreesDistribution:
def __init__(self, seed=42):
self.random_state=np.random.RandomState(seed)
def draw(self, nb_view):
return self.random_state.randint(low=1,high=10,size=nb_view)
...@@ -3,7 +3,7 @@ import sys ...@@ -3,7 +3,7 @@ import sys
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from scipy.stats import randint from scipy.stats import randint, uniform
from sklearn.model_selection import RandomizedSearchCV from sklearn.model_selection import RandomizedSearchCV
...@@ -38,6 +38,22 @@ def grid_search(dataset, classifier_name, views_indices=None, k_folds=None, n_it ...@@ -38,6 +38,22 @@ def grid_search(dataset, classifier_name, views_indices=None, k_folds=None, n_it
"""Used to perfom gridsearch on the classifiers""" """Used to perfom gridsearch on the classifiers"""
pass pass
class CustomUniform:
"""Used as a distribution returning a float between loc and loc + scale..
It can be used with a multiplier agrument to be able to perform more complex generation
for example 10 e -(float)"""
def __init__(self, loc=0, state=1, multiplier=""):
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
else:
return unif
class CustomRandint: class CustomRandint:
"""Used as a distribution returning a integer between low and high-1. """Used as a distribution returning a integer between low and high-1.
It can be used with a multiplier agrument to be able to perform more complex generation It can be used with a multiplier agrument to be able to perform more complex generation
......
...@@ -15,3 +15,4 @@ m2r==0.2.1 ...@@ -15,3 +15,4 @@ m2r==0.2.1
docutils==0.12 docutils==0.12
pyyaml==3.12 pyyaml==3.12
cvxopt==1.2.0 cvxopt==1.2.0
-e git+https://github.com/IvanoLauriola/MKLpy.git#egg=MKLpy
\ No newline at end of file
...@@ -55,7 +55,7 @@ def setup_package(): ...@@ -55,7 +55,7 @@ def setup_package():
install_requires=['numpy>=1.16', 'scipy>=0.16','scikit-learn==0.19', install_requires=['numpy>=1.16', 'scipy>=0.16','scikit-learn==0.19',
'matplotlib', 'h5py', 'joblib', 'matplotlib', 'h5py', 'joblib',
'pandas', 'm2r', 'pyyaml', 'pyscm @ git+https://github.com/aldro61/pyscm', 'pandas', 'm2r', 'pyyaml', 'pyscm @ git+https://github.com/aldro61/pyscm',
'cvxopt'], 'cvxopt', 'MKLpy @ git+https://github.com/IvanoLauriola/MKLpy'],
# Il est d'usage de mettre quelques metadata à propos de sa lib # Il est d'usage de mettre quelques metadata à propos de sa lib
# Pour que les robots puissent facilement la classer. # Pour que les robots puissent facilement la classer.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment