Skip to content
Snippets Groups Projects
Commit 9829bc59 authored by Dominique Benielli's avatar Dominique Benielli
Browse files

copyright + bug fix compute alpha

parent 7f11136c
No related branches found
No related tags found
No related merge requests found
multimodal:0.0.dev0
......@@ -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")
......
......@@ -34,7 +34,7 @@ Version:
Licence:
-------
License: LGPLv3+
License: New BSD License
######### COPYRIGHT #########
......@@ -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)
......
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
......
__version__ = '0.0.dev0'
__version__ = "0.0.dev0"
......@@ -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
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']
......
......@@ -221,11 +221,18 @@ 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)):
if isinstance(alphas, float):
alphas = 1.0
else:
alphas[np.where(np.isinf(alphas))[0]] = 1.0
if np.any(np.isnan(alphas)):
if isinstance(alphas, float):
alphas = 1.0
else:
alphas[np.where(np.isnan(alphas))[0]] = 1.0
return alphas
......
......@@ -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
......
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)
File deleted
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 = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment