diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000000000000000000000000000000000..1578b445705b8ed08bc512dc01f93a867f24d115 --- /dev/null +++ b/VERSION @@ -0,0 +1,2 @@ +multimodal:0.0.dev0 + diff --git a/copyright.py b/copyright.py index dcf2f207908f90d42f0fa1da24b6fcee710949c3..76c97d141d501ce4fd14240e13f17ddc6d06cb3b 100644 --- a/copyright.py +++ b/copyright.py @@ -50,7 +50,7 @@ def getStamp(date, iw_version): """ Return the corrected formated stamp """ stamp = open("copyrightstamp.txt").read() stamp = stamp.replace("DATE", date) - stamp = stamp.replace("IW_VERSION", iw_version) + stamp = stamp.replace("MULTIMODAL_VERSION", multimodal_version) stamp = stamp.replace('\n', '\n# ') stamp = "# " + stamp stamp = stamp.replace("# \n", "#\n") diff --git a/copyrightstamp.txt b/copyrightstamp.txt index 64f20833f2e61b2137fa07071d6ecca0be30bd5c..b3d76ecd90464fdbb9e0950c746cc392b0057481 100644 --- a/copyrightstamp.txt +++ b/copyrightstamp.txt @@ -34,7 +34,7 @@ Version: Licence: ------- -License: LGPLv3+ +License: New BSD License ######### COPYRIGHT ######### diff --git a/examples/usecase/plot_usecase_exampleMKL.py b/examples/usecase/plot_usecase_exampleMKL.py index 27d6fbf446dd4ebbcc065836401d8cc387770b1e..600c566af889e1b113cbc290184995e024ceaa3a 100644 --- a/examples/usecase/plot_usecase_exampleMKL.py +++ b/examples/usecase/plot_usecase_exampleMKL.py @@ -19,7 +19,6 @@ from sklearn.tree import DecisionTreeClassifier from multimodal.datasets.base import load_dict, save_dict from multimodal.tests.data.get_dataset_path import get_dataset_path from multimodal.datasets.data_sample import MultiModalArray -from multimodal.kernels.mvml import MVML from multimodal.kernels.lpMKL import MKL import numpy as np @@ -50,7 +49,6 @@ if __name__ == '__main__': # file = get_dataset_path("digit_histogram.npy") file = get_dataset_path("digit_col_grad.npy") y = np.load(get_dataset_path("digit_y.npy")) - base_estimator = DecisionTreeClassifier(max_depth=4) dic_digit = load_dict(file) XX =MultiModalArray(dic_digit) X_train, X_test, y_train, y_test = train_test_split(XX, y) diff --git a/license.txt b/license.txt index 1011e466043bbe2aaabb4d2c833c31b3278897db..54ead2657576cc0d72691717c9d6aa45f08dcf70 100644 --- a/license.txt +++ b/license.txt @@ -1,6 +1,6 @@ New BSD License -Copyright (c) 2020-15-01, The scit-multimodallearn developers. +Copyright (c) 2020-15-01, The scikit-multimodallearn developers. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/multimodal/__init__.py b/multimodal/__init__.py index 1ff96798d585b234ffb18d9a3f66bff29cc04e32..e851e58bf4c7b631d2a67f501bb74c7a2b0a8217 100644 --- a/multimodal/__init__.py +++ b/multimodal/__init__.py @@ -1 +1 @@ -__version__ = '0.0.dev0' +__version__ = "0.0.dev0" diff --git a/multimodal/boosting/cumbo.py b/multimodal/boosting/cumbo.py index 158c9cacdd07753fa7c1149ef43e061e0b8c631d..175a9cfc25fb3f25145b6ed064f1270b130ee048 100644 --- a/multimodal/boosting/cumbo.py +++ b/multimodal/boosting/cumbo.py @@ -311,16 +311,16 @@ class MuCumboClassifier(BaseEnsemble, ClassifierMixin, UBoosting): zeta2 = zeta**2 def F(x=None, z=None): if x is None: - # l'algorithme fonctionne de manière itérative - # il faut choisir un x initial, c'est ce qu'on fait ici + # iteratif algo + # choice x initial return 0, matrix(1.0, (n_view*m, 1)) if min(x) < 0.0: - return None # cas impossible - # ici commence le code qui définit ce qu'est une itération - f = sum(matrix(coef * exp( matrix(zeta * x.T)) )) - Df = matrix(np.sum( zeta * coef * exp(matrix( zeta * x.T ) ), axis=0 )).T # -(x**-1).T + return None # impossible + # begin iteration + f = sum(matrix(coef * exp( matrix(zeta * x.T)))) + Df = matrix(np.sum( zeta * coef * exp(matrix( zeta * x.T)), axis=0)).T # -(x**-1).T if z is None: return f, Df - H = spdiag(z[0] * matrix(np.sum(coef * zeta2 * exp( matrix(zeta* x.T) ), axis= 0))) ## beta**(-2)) + H = spdiag(z[0] * matrix(np.sum(coef * zeta2 * exp( matrix(zeta* x.T)), axis=0))) # beta**(-2)) return f, Df, H try: solver = solvers.cp(F, A=A, b=b, G=G, h=h, dim={'l':2*n_view*m})['x'] diff --git a/multimodal/boosting/mumbo.py b/multimodal/boosting/mumbo.py index 23dacffa077ead81160b5571352e38a4c9438719..29cfe528b295578c00d4a2026957043dabca87c4 100644 --- a/multimodal/boosting/mumbo.py +++ b/multimodal/boosting/mumbo.py @@ -221,12 +221,19 @@ class MumboClassifier(BaseEnsemble, ClassifierMixin, UBoosting): def _compute_alphas(self, edges): """Compute values of confidence rate alpha given edge values.""" + dim = edges.shape[0] np.where(edges > 1.0, edges, 1.0) alphas = 0.5 * np.log((1. + edges) / (1. - edges)) if np.any(np.isinf(alphas)): - alphas[np.where(np.isinf(alphas))[0]] = 1.0 + if isinstance(alphas, float): + alphas = 1.0 + else: + alphas[np.where(np.isinf(alphas))[0]] = 1.0 if np.any(np.isnan(alphas)): - alphas[np.where(np.isnan(alphas))[0]] = 1.0 + if isinstance(alphas, float): + alphas = 1.0 + else: + alphas[np.where(np.isnan(alphas))[0]] = 1.0 return alphas def _compute_cost_global(self, label_score_global, best_predicted_classes, diff --git a/multimodal/kernels/mvml.py b/multimodal/kernels/mvml.py index d2ce3e93afc34bb94c15f5e4f79bd9451781a6f5..3365f2cb21eb9c4b0be5be2db95af4eee03ae68f 100644 --- a/multimodal/kernels/mvml.py +++ b/multimodal/kernels/mvml.py @@ -613,7 +613,7 @@ class MVML(MKernel, BaseEstimator, ClassifierMixin, RegressorMixin): return A_new - def score(self, X, y=None): + def score(self, X, y): """Return the mean accuracy on the given test data and labels. Parameters diff --git a/multimodal/tests/data/digit.py b/multimodal/tests/data/digit.py new file mode 100644 index 0000000000000000000000000000000000000000..00f69a3f592405df4642908e0c898218bb409457 --- /dev/null +++ b/multimodal/tests/data/digit.py @@ -0,0 +1,62 @@ +from sklearn import datasets +import numpy as np +import PIL +import matplotlib.pyplot as plt +import os +import matplotlib.pyplot as plt +from multimodal.datasets.base import load_dict, save_dict +from multimodal.tests.data.get_dataset_path import get_dataset_path +from multimodal.datasets.data_sample import MultiModalArray +from multimodal.kernels.mvml import MVML +#Load the digits dataset +digits = datasets.load_digits() + +#Display the first digit +plt.figure(1, figsize=(3, 3)) +plt.imshow(digits.images[-1], cmap=plt.cm.gray_r, interpolation='nearest') +plt.show() +colors = digits.data +gradiant = np.gradient(digits.images, axis=[1,2]) +print(gradiant[0].shape) +gradiant0 = gradiant[0].reshape(colors.shape[0], colors.shape[1]) +gradiant1 = gradiant[1].reshape(colors.shape[0], colors.shape[1]) +for ind in range(digits.images.shape[0]): + ima0 = digits.images[ind, :,:] + ima1 = gradiant[0][ind, :,:] + ima2 = gradiant[1][ind, :,:] + ama_pil0 = PIL.Image.fromarray(ima0, mode=None) + ama_pil1 = PIL.Image.fromarray(ima1, mode=None) + ama_pil2 = PIL.Image.fromarray(ima2, mode=None) + histo_color = np.asarray(ama_pil0.histogram()) + histo_gradiant0 = np.asarray(ama_pil1.histogram()) + histo_gradiant1 = np.asarray(ama_pil2.histogram()) + if ind==0: + list_histogram_color = histo_color + list_histogram_gradiant0 = histo_gradiant0 + list_histogram_gradiant1 = histo_gradiant1 + else: + list_histogram_color = np.vstack((list_histogram_color, histo_color)) + list_histogram_gradiant0 = np.vstack((list_histogram_gradiant0, histo_gradiant0)) + list_histogram_gradiant1 = np.vstack((list_histogram_gradiant1, histo_gradiant1)) + +dict_digit = {0: list_histogram_color, 1: list_histogram_gradiant0, 2: list_histogram_gradiant1} + + +print(list_histogram_color.shape) +print(list_histogram_gradiant0.shape) +print(list_histogram_gradiant1.shape) +file = get_dataset_path("digit_histogram.npy") +save_dict(dict_digit, file) + +d2 = load_dict(file) + +figure = plt.figure(figsize=(27, 9)) +ax = plt.subplot(2,1,1) + +ax.scatter(list_histogram_color[:,3], list_histogram_color[:,4], c=digits.target, edgecolors='k') +ax = plt.subplot(2,1,2) +ax.scatter(list_histogram_color[:,0], list_histogram_color[:,1], c=digits.target, edgecolors='k') +plt.show() + +mvml = MVML(lmbda=0.1, eta=1, nystrom_param=0.2) +mvml.fit(d2, digits.target) diff --git a/multimodal/tests/data/digit_y.npy b/multimodal/tests/data/digit_y.npy deleted file mode 100644 index b5588884574d1c89a5d34ece3993af4b532b7191..0000000000000000000000000000000000000000 Binary files a/multimodal/tests/data/digit_y.npy and /dev/null differ diff --git a/setup.py b/setup.py index 5ec883afbe4ac9c099fd9e7ba5d3be774639c22d..48193981a51ee2a5fc5b0c97aea9eb79a9ed07e7 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,111 @@ -import os +import os, re +import shutil from setuptools import setup, find_packages - +from distutils.command.clean import clean as _clean +from distutils.dir_util import remove_tree +from distutils.command.sdist import sdist import multimodal +try: + import numpy +except: + raise 'Cannot build iw without numpy' + sys.exit() + +# -------------------------------------------------------------------- +# Clean target redefinition - force clean everything supprimer de la liste '^core\.*$', +relist = ['^.*~$', '^#.*#$', '^.*\.aux$', '^.*\.pyc$', '^.*\.o$'] +reclean = [] +USE_COPYRIGHT = True +try: + from copyright import writeStamp, eraseStamp +except ImportError: + USE_COPYRIGHT = False + +################### +# Get Multimodal version +#################### +def get_version(): + v_text = open('VERSION').read().strip() + v_text_formted = '{"' + v_text.replace('\n', '","').replace(':', '":"') + v_text_formted += '"}' + v_dict = eval(v_text_formted) + return v_dict["multimodal"] + +######################## +# Set Multimodal __version__ +######################## +def set_version(multimodal_dir, version): + filename = os.path.join(multimodal_dir, '__init__.py') + buf = "" + for line in open(filename, "rb"): + if not line.decode("utf8").startswith("__version__ ="): + buf += line.decode("utf8") + f = open(filename, "wb") + f.write(buf.encode("utf8")) + f.write(('__version__ = "%s"\n' % version).encode("utf8")) + +for restring in relist: + reclean.append(re.compile(restring)) + + +def wselect(args, dirname, names): + for n in names: + for rev in reclean: + if (rev.match(n)): + os.remove("%s/%s" %(dirname, n)) + break + + +###################### +# Custom clean command +###################### +class clean(_clean): + def walkAndClean(self): + os.walk("..", wselect, []) + pass + + def run(self): + clean.run(self) + if os.path.exists('build'): + shutil.rmtree('build') + for dirpath, dirnames, filenames in os.walk('iw'): + for filename in filenames: + if (filename.endswith('.so') or + filename.endswith('.pyd') or + filename.endswith('.dll') or + filename.endswith('.pyc')): + os.unlink(os.path.join(dirpath, filename)) + for dirname in dirnames: + if dirname == '__pycache__': + shutil.rmtree(os.path.join(dirpath, dirname)) + + +############################## +# Custom sdist command +############################## +class m_sdist(sdist): + """ Build source package + + WARNING : The stamping must be done on an default utf8 machine ! + """ + + def run(self): + if USE_COPYRIGHT: + writeStamp() + sdist.run(self) + # eraseStamp() + else: + sdist.run(self) def setup_package(): """Setup function""" name = 'scikit-multimodallearn' - version = multimodal.__version__ + version = get_version() + multimodal_dir = 'multimodal' + set_version(multimodal_dir, version) description = 'A scikit-learn compatible package for multimodal Classifiers' here = os.path.abspath(os.path.dirname(__file__)) with open(os.path.join(here, 'README.rst'), encoding='utf-8') as readme: @@ -21,7 +117,7 @@ def setup_package(): 'Source': url, 'Tracker': '{}/issues'.format(url)} author = 'Dominique Benielli and Sokol Koço and Florent Jaillet and Riikka Huusari ' \ - 'and Cécile Capponi and Hachem Kadri' + 'and Baptiste Bauvin and Cécile Capponi and Hachem Kadri' author_email = 'contact.dev@lis-lab.fr' license = 'newBSD' classifiers = [