"torch_modules/git@gitlab.lis-lab.fr:franck.dary/macaon.git" did not exist on "d145be52a13ddda6a522338a2edc08ab777ea579"
Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import numpy as np
from abc import ABCMeta
from sklearn.utils import check_array, check_X_y, check_random_state
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree.tree import BaseDecisionTree
from sklearn.tree._tree import DTYPE
from sklearn.ensemble.forest import BaseForest
from multimodal.datasets.data_sample import DataSample, MultiModalArray
class UBoosting(metaclass=ABCMeta):
"""
Abstract class MuCumboClassifier and MumboClassifier should inherit from
UBoosting for methods
"""
def _validate_X_predict(self, X):
"""Ensure that X is in the proper format."""
if (self.base_estimator is None or
isinstance(self.base_estimator,
(BaseDecisionTree, BaseForest))):
check_array(X, accept_sparse='csr', dtype=DTYPE)
else:
check_array(X, accept_sparse=['csr', 'csc'])
if X.shape[1] != self.n_features_:
raise ValueError("X doesn't contain the right number of features.")
return X
def _validate_views_ind(self, views_ind, n_features):
"""Ensure proper format for views_ind and return number of views."""
views_ind = np.array(views_ind)
if np.issubdtype(views_ind.dtype, np.integer) and views_ind.ndim == 1:
if np.any(views_ind[:-1] >= views_ind[1:]):
raise ValueError("Values in views_ind must be sorted.")
if views_ind[0] < 0 or views_ind[-1] > n_features:
raise ValueError("Values in views_ind are not in a correct "
+ "range for the provided data.")
self.view_mode_ = "slices"
n_views = views_ind.shape[0]-1
else:
if views_ind.ndim == 1:
if not views_ind.dtype == np.object:
raise ValueError("The format of views_ind is not "
+ "supported.")
for ind, val in enumerate(views_ind):
views_ind[ind] = np.array(val)
if not np.issubdtype(views_ind[ind].dtype, np.integer):
raise ValueError("Values in views_ind must be "
+ "integers.")
if views_ind[ind].min() < 0 \
or views_ind[ind].max() >= n_features:
raise ValueError("Values in views_ind are not in a "
+ "correct range for the provided "
+ "data.")
elif views_ind.ndim == 2:
if not np.issubdtype(views_ind.dtype, np.integer):
raise ValueError("Values in views_ind must be integers.")
if views_ind.min() < 0 or views_ind.max() >= n_features:
raise ValueError("Values in views_ind are not in a "
+ "correct range for the provided data.")
else:
raise ValueError("The format of views_ind is not supported.")
self.view_mode_ = "indices"
n_views = views_ind.shape[0]
return (views_ind, n_views)
def _global_X_transform(self, X, views_ind=None):
X_ = None
if isinstance(X, np.ndarray) and X.ndim == 1:
X_= MultiModalArray(X, views_ind)
elif isinstance(X, dict):
X_= MultiModalArray(X)
elif isinstance(X, np.ndarray) and X.ndim > 1:
X_ = MultiModalArray(X, views_ind)
if not isinstance(X_, MultiModalArray):
raise TypeError("Input format is not reconized")
if hasattr(self, "X_"):
if not self.X_.viexs_ind == views_ind:
raise ValueError("Input format (viewd, features) for fit and predict must be the same")
return X_