diff --git a/doc/tutorial/auto_examples/auto_examples_jupyter.zip b/doc/tutorial/auto_examples/auto_examples_jupyter.zip index a0fbdaf0bca00c7f6941fd01e4cbfac684eadd05..71cae011e4df6bcb56b719d0678e194a7fb1fbb0 100644 Binary files a/doc/tutorial/auto_examples/auto_examples_jupyter.zip and b/doc/tutorial/auto_examples/auto_examples_jupyter.zip differ diff --git a/doc/tutorial/auto_examples/auto_examples_python.zip b/doc/tutorial/auto_examples/auto_examples_python.zip index e9eb1dd58513cedc034ae8595e7d768f4a1f4ed3..e13a39541dfa82aba880d1fdda529b9a231ae61b 100644 Binary files a/doc/tutorial/auto_examples/auto_examples_python.zip and b/doc/tutorial/auto_examples/auto_examples_python.zip differ diff --git a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.ipynb b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.ipynb index 81b05f4a84a25e90794c84757ff28fcc48dcdf2e..86a0330a07caba947cce8e3e6b6954cc2a848244 100644 --- a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.ipynb +++ b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.ipynb @@ -26,7 +26,7 @@ }, "outputs": [], "source": [ - "import numpy as np\nfrom multimodal.boosting.cumbo import MuCumboClassifier\nfrom matplotlib import pyplot as plt\n\n\ndef generate_data(n_samples, lim):\n \"\"\"Generate random data in a rectangle\"\"\"\n lim = np.array(lim)\n n_features = lim.shape[0]\n data = np.random.random((n_samples, n_features))\n data = (lim[:, 1]-lim[:, 0]) * data + lim[:, 0]\n return data\n\n\nseed = 12\nnp.random.seed(seed)\n\nn_samples = 100\n\nview_0 = np.concatenate((generate_data(n_samples, [[0., 1.], [0., 1.]]),\n generate_data(n_samples, [[1., 2.], [0., 1.]]),\n generate_data(n_samples, [[0., 1.], [0., 1.]]),\n generate_data(n_samples, [[0., 1.], [1., 2.]])))\n\nview_1 = np.concatenate((generate_data(n_samples, [[1., 2.], [0., 1.]]),\n generate_data(n_samples, [[0., 1.], [0., 1.]]),\n generate_data(n_samples, [[0., 1.], [1., 2.]]),\n generate_data(n_samples, [[0., 1.], [0., 1.]])))\n\nX = np.concatenate((view_0, view_1), axis=1)\n\ny = np.zeros(4*n_samples, dtype=np.int64)\ny[2*n_samples:] = 1\n\nviews_ind = np.array([0, 2, 4])\n\nn_estimators = 3\nclf = MuCumboClassifier(n_estimators=n_estimators)\nclf.fit(X, y, views_ind)\n\nprint('\\nAfter 3 iterations, the MuCuMBo classifier reaches exact '\n 'classification for the\\nlearning samples:')\nfor ind, score in enumerate(clf.staged_score(X, y)):\n print(' - iteration {}, score: {}'.format(ind + 1, score))\n\n\nprint('\\nThe resulting MuCuMBo classifier uses three sub-classifiers that are '\n 'wheighted\\nusing the following weights:\\n'\n ' estimator weights: {}'.format(clf.estimator_weights_alpha_))\n\n# print('\\nThe two first sub-classifiers use the data of view 0 to compute '\n# 'their\\nclassification results, while the third one uses the data of '\n# 'view 1:\\n'\n# ' best views: {}'. format(clf.best_views_))\n\nprint('\\nThe first figure displays the data, splitting the representation '\n 'between the\\ntwo views.')\n\nfig = plt.figure(figsize=(10., 8.))\nfig.suptitle('Representation of the data', size=16)\nfor ind_view in range(2):\n ax = plt.subplot(2, 1, ind_view + 1)\n ax.set_title('View {}'.format(ind_view))\n ind_feature = ind_view * 2\n styles = ('.b', 'xb', '.r', 'xr')\n labels = ('non-separated', 'separated')\n for ind in range(4):\n ind_class = ind // 2\n label = labels[(ind + ind_view) % 2]\n ax.plot(X[n_samples*ind:n_samples*(ind+1), ind_feature],\n X[n_samples*ind:n_samples*(ind+1), ind_feature + 1],\n styles[ind],\n label='Class {} ({})'.format(ind_class, label))\n ax.legend()\n\nprint('\\nThe second figure displays the classification results for the '\n 'sub-classifiers\\non the learning sample data.\\n')\n\nstyles = ('.b', '.r')\n# fig = plt.figure(figsize=(12., 7.))\n# fig.suptitle('Classification results on the learning data for the '\n# 'sub-classifiers', size=16)\n# for ind_estimator in range(n_estimators):\n# best_view = clf.best_views_[ind_estimator]\n# y_pred = clf.estimators_[ind_estimator].predict(\n# X[:, 2*best_view:2*best_view+2])\n# background_color = (1.0, 1.0, 0.9)\n# for ind_view in range(2):\n# ax = plt.subplot(2, 3, ind_estimator + 3*ind_view + 1)\n# if ind_view == best_view:\n# ax.set_facecolor(background_color)\n# ax.set_title(\n# 'Sub-classifier {} - View {}'.format(ind_estimator, ind_view))\n# ind_feature = ind_view * 2\n# for ind_class in range(2):\n# ind_samples = (y_pred == ind_class)\n# ax.plot(X[ind_samples, ind_feature],\n# X[ind_samples, ind_feature + 1],\n# styles[ind_class],\n# label='Class {}'.format(ind_class))\n# ax.legend(title='Predicted class:')\n\nplt.show()" + "import numpy as np\nfrom multimodal.boosting.cumbo import MuCumboClassifier\nfrom matplotlib import pyplot as plt\n\n\ndef generate_data(n_samples, lim):\n \"\"\"Generate random data in a rectangle\"\"\"\n lim = np.array(lim)\n n_features = lim.shape[0]\n data = np.random.random((n_samples, n_features))\n data = (lim[:, 1]-lim[:, 0]) * data + lim[:, 0]\n return data\n\n\nseed = 12\nnp.random.seed(seed)\n\nn_samples = 100\n\nview_0 = np.concatenate((generate_data(n_samples, [[0., 1.], [0., 1.]]),\n generate_data(n_samples, [[1., 2.], [0., 1.]]),\n generate_data(n_samples, [[0., 1.], [0., 1.]]),\n generate_data(n_samples, [[0., 1.], [1., 2.]])))\n\nview_1 = np.concatenate((generate_data(n_samples, [[1., 2.], [0., 1.]]),\n generate_data(n_samples, [[0., 1.], [0., 1.]]),\n generate_data(n_samples, [[0., 1.], [1., 2.]]),\n generate_data(n_samples, [[0., 1.], [0., 1.]])))\n\nX = np.concatenate((view_0, view_1), axis=1)\n\ny = np.zeros(4*n_samples, dtype=np.int64)\ny[2*n_samples:] = 1\n\nviews_ind = np.array([0, 2, 4])\n\nn_estimators = 3\nclf = MuCumboClassifier(n_estimators=n_estimators)\nclf.fit(X, y, views_ind)\n\nprint('\\nAfter 3 iterations, the MuCuMBo classifier reaches exact '\n 'classification for the\\nlearning samples:')\nfor ind, score in enumerate(clf.staged_score(X, y)):\n print(' - iteration {}, score: {}'.format(ind + 1, score))\n\n\nprint('\\nThe resulting MuCuMBo classifier uses three sub-classifiers that are '\n 'wheighted\\nusing the following weights:\\n'\n ' estimator weights: {}'.format(clf.estimator_weights_alpha_))\n\n# print('\\nThe two first sub-classifiers use the data of view 0 to compute '\n# 'their\\nclassification results, while the third one uses the data of '\n# 'view 1:\\n'\n# ' best views: {}'. format(clf.best_views_))\n\nprint('\\nThe first figure displays the data, splitting the representation '\n 'between the\\ntwo views.')\n\nfig = plt.figure(figsize=(10., 8.))\nfig.suptitle('Representation of the data', size=16)\nfor ind_view in range(2):\n ax = plt.subplot(2, 1, ind_view + 1)\n ax.set_title('View {}'.format(ind_view))\n ind_feature = ind_view * 2\n styles = ('.b', 'xb', '.r', 'xr')\n labels = ('non-separated', 'separated')\n for ind in range(4):\n ind_class = ind // 2\n label = labels[(ind + ind_view) % 2]\n ax.plot(X[n_samples*ind:n_samples*(ind+1), ind_feature],\n X[n_samples*ind:n_samples*(ind+1), ind_feature + 1],\n styles[ind],\n label='Class {} ({})'.format(ind_class, label))\n ax.legend()\n\n# print('\\nThe second figure displays the classification results for the '\n# 'sub-classifiers\\non the learning sample data.\\n')\n#\n# styles = ('.b', '.r')\n# fig = plt.figure(figsize=(12., 7.))\n# fig.suptitle('Classification results on the learning data for the '\n# 'sub-classifiers', size=16)\n# for ind_estimator in range(n_estimators):\n# best_view = clf.best_views_[ind_estimator]\n# y_pred = clf.estimators_[ind_estimator].predict(\n# X[:, 2*best_view:2*best_view+2])\n# background_color = (1.0, 1.0, 0.9)\n# for ind_view in range(2):\n# ax = plt.subplot(2, 3, ind_estimator + 3*ind_view + 1)\n# if ind_view == best_view:\n# ax.set_facecolor(background_color)\n# ax.set_title(\n# 'Sub-classifier {} - View {}'.format(ind_estimator, ind_view))\n# ind_feature = ind_view * 2\n# for ind_class in range(2):\n# ind_samples = (y_pred == ind_class)\n# ax.plot(X[ind_samples, ind_feature],\n# X[ind_samples, ind_feature + 1],\n# styles[ind_class],\n# label='Class {}'.format(ind_class))\n# ax.legend(title='Predicted class:')\n\nplt.show()" ] } ], diff --git a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.py b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.py index c669f6919c71f964891940bdfa3c1276e7342992..77d0588aafa3392199880800c9ad33cba959f094 100644 --- a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.py +++ b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.py @@ -97,10 +97,10 @@ for ind_view in range(2): label='Class {} ({})'.format(ind_class, label)) ax.legend() -print('\nThe second figure displays the classification results for the ' - 'sub-classifiers\non the learning sample data.\n') - -styles = ('.b', '.r') +# print('\nThe second figure displays the classification results for the ' +# 'sub-classifiers\non the learning sample data.\n') +# +# styles = ('.b', '.r') # fig = plt.figure(figsize=(12., 7.)) # fig.suptitle('Classification results on the learning data for the ' # 'sub-classifiers', size=16) diff --git a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.py.md5 b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.py.md5 index 06630ff19708de5a1323bf19987c05ff64028b9b..0b84b4f5b63f54b8fd1e5c2418bf3e4f106c3391 100644 --- a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.py.md5 +++ b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.py.md5 @@ -1 +1 @@ -5b1bad9179e6c052ce9a8198c8443c9a \ No newline at end of file +ac125b9b4b4a1f4600b8a804ce421f11 \ No newline at end of file diff --git a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.rst b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.rst index f47b92abcb3d2794aa65b4b003ed32f1ae74773d..fd2ac2716148c6a47372b996801a4edc209fcdd7 100644 --- a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.rst +++ b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes.rst @@ -54,10 +54,8 @@ rightly classify the points. The first figure displays the data, splitting the representation between the two views. - - The second figure displays the classification results for the sub-classifiers - on the learning sample data. - + /home/dominique/projets/ANR-Lives/scikit-multimodallearn/examples/cumbo/plot_cumbo_2_views_2_classes.py:127: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. + plt.show() @@ -145,10 +143,10 @@ rightly classify the points. label='Class {} ({})'.format(ind_class, label)) ax.legend() - print('\nThe second figure displays the classification results for the ' - 'sub-classifiers\non the learning sample data.\n') - - styles = ('.b', '.r') + # print('\nThe second figure displays the classification results for the ' + # 'sub-classifiers\non the learning sample data.\n') + # + # styles = ('.b', '.r') # fig = plt.figure(figsize=(12., 7.)) # fig.suptitle('Classification results on the learning data for the ' # 'sub-classifiers', size=16) @@ -177,7 +175,7 @@ rightly classify the points. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 0.616 seconds) + **Total running time of the script:** ( 0 minutes 0.926 seconds) .. _sphx_glr_download_tutorial_auto_examples_cumbo_plot_cumbo_2_views_2_classes.py: diff --git a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes_codeobj.pickle b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes_codeobj.pickle index c952702cb6c9aef634d994d47180af94e03b0775..46f31f8bc0410beb38b60cce658754762051120c 100644 Binary files a/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes_codeobj.pickle and b/doc/tutorial/auto_examples/cumbo/plot_cumbo_2_views_2_classes_codeobj.pickle differ diff --git a/doc/tutorial/auto_examples/cumbo/sg_execution_times.rst b/doc/tutorial/auto_examples/cumbo/sg_execution_times.rst index 79796437f40a6b417cf88df0c276e77c223ffe11..8a8e3b008ff87c834e1add9029f44a4729a5b9df 100644 --- a/doc/tutorial/auto_examples/cumbo/sg_execution_times.rst +++ b/doc/tutorial/auto_examples/cumbo/sg_execution_times.rst @@ -1,10 +1,14 @@ +:orphan: + +.. _sphx_glr_tutorial_auto_examples_cumbo_sg_execution_times: + Computation times ================= -**00:01.113** total execution time for **tutorial_auto_examples_cumbo** files: +**00:00.926** total execution time for **tutorial_auto_examples_cumbo** files: +--------------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_tutorial_auto_examples_cumbo_plot_cumbo_2_views_2_classes.py` (``plot_cumbo_2_views_2_classes.py``) | 00:00.616 | 0.0 MB | +| :ref:`sphx_glr_tutorial_auto_examples_cumbo_plot_cumbo_2_views_2_classes.py` (``plot_cumbo_2_views_2_classes.py``) | 00:00.926 | 0.0 MB | +--------------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_tutorial_auto_examples_cumbo_plot_cumbo_3_views_3_classes.py` (``plot_cumbo_3_views_3_classes.py``) | 00:00.497 | 0.0 MB | +| :ref:`sphx_glr_tutorial_auto_examples_cumbo_plot_cumbo_3_views_3_classes.py` (``plot_cumbo_3_views_3_classes.py``) | 00:00.000 | 0.0 MB | +--------------------------------------------------------------------------------------------------------------------+-----------+--------+ diff --git a/doc/tutorial/auto_examples/mvml/plot_mvml_.ipynb b/doc/tutorial/auto_examples/mvml/plot_mvml_.ipynb index 211b617fe7045ab11b9cd8c229cbb6e55a0b5812..61b53bcc79b7ad83ff9b0cee2ee44cdf7a3eb625 100644 --- a/doc/tutorial/auto_examples/mvml/plot_mvml_.ipynb +++ b/doc/tutorial/auto_examples/mvml/plot_mvml_.ipynb @@ -44,7 +44,7 @@ }, "outputs": [], "source": [ - "kernel_dict = {}\ntest_kernel_dict = {}\nkernel_dict[0] = rbf_kernel(X0[0:n_tr, :])\nkernel_dict[1] = rbf_kernel(X1[0:n_tr, :])\ntest_kernel_dict[0] = rbf_kernel(X0[n_tr:n_tot, :], X0[0:n_tr, :])\ntest_kernel_dict[1] = rbf_kernel(X1[n_tr:n_tot, :], X1[0:n_tr, :])\nx_dict = {}\nx_dict[0] = X0[0:n_tr, :]\nx_dict[1] = X1[0:n_tr, :]\ntest_x_dict = {}\ntest_x_dict[0] = X0[n_tr:n_tot, :]\ntest_x_dict[1] = X1[n_tr:n_tot, :]\n# d= DataSample(kernel_dict)\n# a = d.data\n#\n# =========== use MVML in classifying the data ============\n# kernel precomputed\n# demo on how the code is intended to be used; parameters are not cross-validated, just picked some\n# # with approximation\n# # default: learn A, don't learn w (learn_A=1, learn_w=0)\nmvml = MVML(lmbda=0.1, eta=1, nystrom_param=0.2, kernel='precomputed')\nmvml.fit(kernel_dict, Y[0:n_tr])\n\n\n#\n\npred1 = np.sign(mvml.predict(test_kernel_dict) ) # take sign for classification result\n#\n# without approximation\nmvml2 = MVML(lmbda=0.1, eta=1, nystrom_param=1, kernel='precomputed') # without approximation\nmvml2.fit(kernel_dict, Y[0:n_tr])\npred2 = np.sign(mvml2.predict(test_kernel_dict))\n#\n# use MVML_Cov, don't learn w\nmvml3 = MVML(lmbda=0.1, eta=1,learn_A=3, nystrom_param=1, kernel='precomputed')\nmvml3.fit(kernel_dict, Y[0:n_tr])\npred3 = np.sign(mvml3.predict(test_kernel_dict))\n#\n# use MVML_I, don't learn w\nmvml4 = MVML(lmbda=0.1, eta=1,learn_A=4, nystrom_param=1, kernel='precomputed')\nmvml4.fit(kernel_dict, Y[0:n_tr])\npred4 = np.sign(mvml4.predict(test_kernel_dict))\n#\n# use kernel rbf equivalent to case 1\nmvml5 = MVML(lmbda=0.1, eta=1, nystrom_param=0.2, kernel='rbf')\nmvml5.fit(x_dict, Y[0:n_tr])\npred5 = np.sign(mvml5.predict(test_x_dict))\n#\n#\n# # =========== show results ============\n#\n# # accuracies\nacc1 = accuracy_score(Y[n_tr:n_tot], pred1)\nacc2 = accuracy_score(Y[n_tr:n_tot], pred2)\nacc3 = accuracy_score(Y[n_tr:n_tot], pred3)\nacc4 = accuracy_score(Y[n_tr:n_tot], pred4)\nacc5 = accuracy_score(Y[n_tr:n_tot], pred5)\n#\n# # display obtained accuracies\n#\nprint(\"MVML: \", acc1)\nprint(\"MVMLsparse: \", acc2)\nprint(\"MVML_Cov: \", acc3)\nprint(\"MVML_I: \", acc4)\nprint(\"MVML_rbf: \", acc5)\n#\n#\n# # plot data and some classification results\n#\nplt.figure(2, figsize=(10., 8.))\nplt.subplot(341)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=Y[n_tr:n_tot])\nplt.title(\"orig. view 1\")\nplt.subplot(342)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=Y[n_tr:n_tot])\nplt.title(\"orig. view 2\")\n#\npred1[np.where(pred1[:, 0] != Y[n_tr:n_tot])] = 0\npred1 = pred1.reshape((pred1.shape[0]))\nplt.subplot(343)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred1)\nplt.title(\"MVML view 1\")\nplt.subplot(344)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred1)\nplt.title(\"MVML view 2\")\n#\npred2[np.where(pred2[:, 0] != Y[n_tr:n_tot])] = 0\npred2 = pred2.reshape((pred2.shape[0]))\nplt.subplot(345)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred2)\nplt.title(\"MVMLsparse view 1\")\nplt.subplot(346)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred2)\nplt.title(\"MVMLsparse view 2\")\n#\npred3[np.where(pred3[:, 0] != Y[n_tr:n_tot])] = 0\npred3 = pred3.reshape((pred3.shape[0]))\n#\nplt.subplot(347)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred3)\nplt.title(\"MVML_Cov view 1\")\nplt.subplot(348)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred3)\nplt.title(\"MVML_Cov view 2\")\n#\npred4[np.where(pred4[:, 0] != Y[n_tr:n_tot])] = 0\npred4 = pred4.reshape((pred4.shape[0]))\nplt.subplot(349)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred4)\nplt.title(\"MVML_I view 1\")\nplt.subplot(3,4,10)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred4)\nplt.title(\"MVML_I view 2\")\n#\npred5[np.where(pred5[:, 0] != Y[n_tr:n_tot])] = 0\npred5 = pred5.reshape((pred5.shape[0]))\nplt.subplot(3,4,11)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred5)\nplt.title(\"MVML_rbf_kernel view 1\")\nplt.subplot(3,4,12)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred5)\nplt.title(\"MVML_rbf_kernel view 2\")\n#\nplt.show()" + "kernel_dict = {}\ntest_kernel_dict = {}\nkernel_dict[0] = rbf_kernel(X0[0:n_tr, :])\nkernel_dict[1] = rbf_kernel(X1[0:n_tr, :])\ntest_kernel_dict[0] = rbf_kernel(X0[n_tr:n_tot, :], X0[0:n_tr, :])\ntest_kernel_dict[1] = rbf_kernel(X1[n_tr:n_tot, :], X1[0:n_tr, :])\nx_dict = {}\nx_dict[0] = X0[0:n_tr, :]\nx_dict[1] = X1[0:n_tr, :]\ntest_x_dict = {}\ntest_x_dict[0] = X0[n_tr:n_tot, :]\ntest_x_dict[1] = X1[n_tr:n_tot, :]\n# d= DataSample(kernel_dict)\n# a = d.data\n#\n# =========== use MVML in classifying the data ============\n# kernel precomputed\n# demo on how the code is intended to be used; parameters are not cross-validated, just picked some\n# # with approximation\n# # default: learn A, don't learn w (learn_A=1, learn_w=0)\nmvml = MVML(lmbda=0.1, eta=1, nystrom_param=0.2, kernel='precomputed')\nmvml.fit(kernel_dict, Y[0:n_tr])\n\n\n#\n\npred1 = mvml.predict(test_kernel_dict)\n#\n# without approximation\nmvml2 = MVML(lmbda=0.1, eta=1, nystrom_param=1, kernel='precomputed') # without approximation\nmvml2.fit(kernel_dict, Y[0:n_tr])\npred2 = mvml2.predict(test_kernel_dict)\n#\n# use MVML_Cov, don't learn w\nmvml3 = MVML(lmbda=0.1, eta=1,learn_A=3, nystrom_param=1, kernel='precomputed')\nmvml3.fit(kernel_dict, Y[0:n_tr])\npred3 = mvml3.predict(test_kernel_dict)\n#\n# use MVML_I, don't learn w\nmvml4 = MVML(lmbda=0.1, eta=1,learn_A=4, nystrom_param=1, kernel='precomputed')\nmvml4.fit(kernel_dict, Y[0:n_tr])\npred4 = mvml4.predict(test_kernel_dict)\n#\n# use kernel rbf equivalent to case 1\nmvml5 = MVML(lmbda=0.1, eta=1, nystrom_param=0.2, kernel='rbf')\nmvml5.fit(x_dict, Y[0:n_tr])\npred5 = mvml5.predict(test_x_dict)\n#\n#\n# # =========== show results ============\n#\n# # accuracies\nacc1 = accuracy_score(Y[n_tr:n_tot], pred1)\nacc2 = accuracy_score(Y[n_tr:n_tot], pred2)\nacc3 = accuracy_score(Y[n_tr:n_tot], pred3)\nacc4 = accuracy_score(Y[n_tr:n_tot], pred4)\nacc5 = accuracy_score(Y[n_tr:n_tot], pred5)\n#\n# # display obtained accuracies\n#\nprint(\"MVML: \", acc1)\nprint(\"MVMLsparse: \", acc2)\nprint(\"MVML_Cov: \", acc3)\nprint(\"MVML_I: \", acc4)\nprint(\"MVML_rbf: \", acc5)\n#\n#\n# # plot data and some classification results\n#\nplt.figure(2, figsize=(10., 8.))\nplt.subplot(341)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=Y[n_tr:n_tot])\nplt.title(\"orig. view 1\")\nplt.subplot(342)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=Y[n_tr:n_tot])\nplt.title(\"orig. view 2\")\n#\npred1[np.where(pred1[:] != Y[n_tr:n_tot])] = 0\npred1 = pred1.reshape((pred1.shape[0]))\nplt.subplot(343)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred1)\nplt.title(\"MVML view 1\")\nplt.subplot(344)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred1)\nplt.title(\"MVML view 2\")\n#\npred2[np.where(pred2[:] != Y[n_tr:n_tot])] = 0\npred2 = pred2.reshape((pred2.shape[0]))\nplt.subplot(345)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred2)\nplt.title(\"MVMLsparse view 1\")\nplt.subplot(346)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred2)\nplt.title(\"MVMLsparse view 2\")\n#\npred3[np.where(pred3[:] != Y[n_tr:n_tot])] = 0\npred3 = pred3.reshape((pred3.shape[0]))\n#\nplt.subplot(347)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred3)\nplt.title(\"MVML_Cov view 1\")\nplt.subplot(348)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred3)\nplt.title(\"MVML_Cov view 2\")\n#\npred4[np.where(pred4[:] != Y[n_tr:n_tot])] = 0\npred4 = pred4.reshape((pred4.shape[0]))\nplt.subplot(349)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred4)\nplt.title(\"MVML_I view 1\")\nplt.subplot(3,4,10)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred4)\nplt.title(\"MVML_I view 2\")\n#\npred5[np.where(pred5[:] != Y[n_tr:n_tot])] = 0\npred5 = pred5.reshape((pred5.shape[0]))\nplt.subplot(3,4,11)\nplt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred5)\nplt.title(\"MVML_rbf_kernel view 1\")\nplt.subplot(3,4,12)\nplt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred5)\nplt.title(\"MVML_rbf_kernel view 2\")\n#\nplt.show()" ] } ], diff --git a/doc/tutorial/auto_examples/mvml/plot_mvml_.py b/doc/tutorial/auto_examples/mvml/plot_mvml_.py index a449a7c868af0b92677a8703e6ca12e2685d9e35..8989230d812287c5c4fefde4dcc9aecbfd2d8a48 100644 --- a/doc/tutorial/auto_examples/mvml/plot_mvml_.py +++ b/doc/tutorial/auto_examples/mvml/plot_mvml_.py @@ -106,27 +106,27 @@ mvml.fit(kernel_dict, Y[0:n_tr]) # -pred1 = np.sign(mvml.predict(test_kernel_dict) ) # take sign for classification result +pred1 = mvml.predict(test_kernel_dict) # # without approximation mvml2 = MVML(lmbda=0.1, eta=1, nystrom_param=1, kernel='precomputed') # without approximation mvml2.fit(kernel_dict, Y[0:n_tr]) -pred2 = np.sign(mvml2.predict(test_kernel_dict)) +pred2 = mvml2.predict(test_kernel_dict) # # use MVML_Cov, don't learn w mvml3 = MVML(lmbda=0.1, eta=1,learn_A=3, nystrom_param=1, kernel='precomputed') mvml3.fit(kernel_dict, Y[0:n_tr]) -pred3 = np.sign(mvml3.predict(test_kernel_dict)) +pred3 = mvml3.predict(test_kernel_dict) # # use MVML_I, don't learn w mvml4 = MVML(lmbda=0.1, eta=1,learn_A=4, nystrom_param=1, kernel='precomputed') mvml4.fit(kernel_dict, Y[0:n_tr]) -pred4 = np.sign(mvml4.predict(test_kernel_dict)) +pred4 = mvml4.predict(test_kernel_dict) # # use kernel rbf equivalent to case 1 mvml5 = MVML(lmbda=0.1, eta=1, nystrom_param=0.2, kernel='rbf') mvml5.fit(x_dict, Y[0:n_tr]) -pred5 = np.sign(mvml5.predict(test_x_dict)) +pred5 = mvml5.predict(test_x_dict) # # # # =========== show results ============ @@ -157,7 +157,7 @@ plt.subplot(342) plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=Y[n_tr:n_tot]) plt.title("orig. view 2") # -pred1[np.where(pred1[:, 0] != Y[n_tr:n_tot])] = 0 +pred1[np.where(pred1[:] != Y[n_tr:n_tot])] = 0 pred1 = pred1.reshape((pred1.shape[0])) plt.subplot(343) plt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred1) @@ -166,7 +166,7 @@ plt.subplot(344) plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred1) plt.title("MVML view 2") # -pred2[np.where(pred2[:, 0] != Y[n_tr:n_tot])] = 0 +pred2[np.where(pred2[:] != Y[n_tr:n_tot])] = 0 pred2 = pred2.reshape((pred2.shape[0])) plt.subplot(345) plt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred2) @@ -175,7 +175,7 @@ plt.subplot(346) plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred2) plt.title("MVMLsparse view 2") # -pred3[np.where(pred3[:, 0] != Y[n_tr:n_tot])] = 0 +pred3[np.where(pred3[:] != Y[n_tr:n_tot])] = 0 pred3 = pred3.reshape((pred3.shape[0])) # plt.subplot(347) @@ -185,7 +185,7 @@ plt.subplot(348) plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred3) plt.title("MVML_Cov view 2") # -pred4[np.where(pred4[:, 0] != Y[n_tr:n_tot])] = 0 +pred4[np.where(pred4[:] != Y[n_tr:n_tot])] = 0 pred4 = pred4.reshape((pred4.shape[0])) plt.subplot(349) plt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred4) @@ -194,7 +194,7 @@ plt.subplot(3,4,10) plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred4) plt.title("MVML_I view 2") # -pred5[np.where(pred5[:, 0] != Y[n_tr:n_tot])] = 0 +pred5[np.where(pred5[:] != Y[n_tr:n_tot])] = 0 pred5 = pred5.reshape((pred5.shape[0])) plt.subplot(3,4,11) plt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred5) diff --git a/doc/tutorial/auto_examples/mvml/plot_mvml_.py.md5 b/doc/tutorial/auto_examples/mvml/plot_mvml_.py.md5 index 4ee8d03a224fd6a5860f0384a9b9b66efff9550a..fee4ef63b30a1692b56a6f5a14fc917d91e693f9 100644 --- a/doc/tutorial/auto_examples/mvml/plot_mvml_.py.md5 +++ b/doc/tutorial/auto_examples/mvml/plot_mvml_.py.md5 @@ -1 +1 @@ -870a37ab95c98874716ccd8b360cbc36 \ No newline at end of file +78c8ab5d5b62ecaa8b639a49b4cbaea0 \ No newline at end of file diff --git a/doc/tutorial/auto_examples/mvml/plot_mvml_.rst b/doc/tutorial/auto_examples/mvml/plot_mvml_.rst index cce0d8f36c9539a07b91880169c0f5b6fd17f6b2..88f46af91d889766322e73b638c0f443cae4ad49 100644 --- a/doc/tutorial/auto_examples/mvml/plot_mvml_.rst +++ b/doc/tutorial/auto_examples/mvml/plot_mvml_.rst @@ -138,27 +138,27 @@ make kernel dictionaries # - pred1 = np.sign(mvml.predict(test_kernel_dict) ) # take sign for classification result + pred1 = mvml.predict(test_kernel_dict) # # without approximation mvml2 = MVML(lmbda=0.1, eta=1, nystrom_param=1, kernel='precomputed') # without approximation mvml2.fit(kernel_dict, Y[0:n_tr]) - pred2 = np.sign(mvml2.predict(test_kernel_dict)) + pred2 = mvml2.predict(test_kernel_dict) # # use MVML_Cov, don't learn w mvml3 = MVML(lmbda=0.1, eta=1,learn_A=3, nystrom_param=1, kernel='precomputed') mvml3.fit(kernel_dict, Y[0:n_tr]) - pred3 = np.sign(mvml3.predict(test_kernel_dict)) + pred3 = mvml3.predict(test_kernel_dict) # # use MVML_I, don't learn w mvml4 = MVML(lmbda=0.1, eta=1,learn_A=4, nystrom_param=1, kernel='precomputed') mvml4.fit(kernel_dict, Y[0:n_tr]) - pred4 = np.sign(mvml4.predict(test_kernel_dict)) + pred4 = mvml4.predict(test_kernel_dict) # # use kernel rbf equivalent to case 1 mvml5 = MVML(lmbda=0.1, eta=1, nystrom_param=0.2, kernel='rbf') mvml5.fit(x_dict, Y[0:n_tr]) - pred5 = np.sign(mvml5.predict(test_x_dict)) + pred5 = mvml5.predict(test_x_dict) # # # # =========== show results ============ @@ -189,7 +189,7 @@ make kernel dictionaries plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=Y[n_tr:n_tot]) plt.title("orig. view 2") # - pred1[np.where(pred1[:, 0] != Y[n_tr:n_tot])] = 0 + pred1[np.where(pred1[:] != Y[n_tr:n_tot])] = 0 pred1 = pred1.reshape((pred1.shape[0])) plt.subplot(343) plt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred1) @@ -198,7 +198,7 @@ make kernel dictionaries plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred1) plt.title("MVML view 2") # - pred2[np.where(pred2[:, 0] != Y[n_tr:n_tot])] = 0 + pred2[np.where(pred2[:] != Y[n_tr:n_tot])] = 0 pred2 = pred2.reshape((pred2.shape[0])) plt.subplot(345) plt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred2) @@ -207,7 +207,7 @@ make kernel dictionaries plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred2) plt.title("MVMLsparse view 2") # - pred3[np.where(pred3[:, 0] != Y[n_tr:n_tot])] = 0 + pred3[np.where(pred3[:] != Y[n_tr:n_tot])] = 0 pred3 = pred3.reshape((pred3.shape[0])) # plt.subplot(347) @@ -217,7 +217,7 @@ make kernel dictionaries plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred3) plt.title("MVML_Cov view 2") # - pred4[np.where(pred4[:, 0] != Y[n_tr:n_tot])] = 0 + pred4[np.where(pred4[:] != Y[n_tr:n_tot])] = 0 pred4 = pred4.reshape((pred4.shape[0])) plt.subplot(349) plt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred4) @@ -226,7 +226,7 @@ make kernel dictionaries plt.scatter(X1[n_tr:n_tot, 0], X1[n_tr:n_tot, 1], c=pred4) plt.title("MVML_I view 2") # - pred5[np.where(pred5[:, 0] != Y[n_tr:n_tot])] = 0 + pred5[np.where(pred5[:] != Y[n_tr:n_tot])] = 0 pred5 = pred5.reshape((pred5.shape[0])) plt.subplot(3,4,11) plt.scatter(X0[n_tr:n_tot, 0], X0[n_tr:n_tot, 1], c=pred5) @@ -268,7 +268,7 @@ make kernel dictionaries .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 5.285 seconds) + **Total running time of the script:** ( 0 minutes 4.803 seconds) .. _sphx_glr_download_tutorial_auto_examples_mvml_plot_mvml_.py: diff --git a/doc/tutorial/auto_examples/mvml/plot_mvml__codeobj.pickle b/doc/tutorial/auto_examples/mvml/plot_mvml__codeobj.pickle index 25388d951eb345c5a8f5fb3a7b5596ef70993a1f..951ac413d82c84bd33834d8ac8a159f8d182c9d4 100644 Binary files a/doc/tutorial/auto_examples/mvml/plot_mvml__codeobj.pickle and b/doc/tutorial/auto_examples/mvml/plot_mvml__codeobj.pickle differ diff --git a/doc/tutorial/auto_examples/mvml/sg_execution_times.rst b/doc/tutorial/auto_examples/mvml/sg_execution_times.rst index bca9ff828c1213ad8844db81d6ff96e69c4dc832..7b21dbef0e31716d78621d1c7f9284f713a2e4e0 100644 --- a/doc/tutorial/auto_examples/mvml/sg_execution_times.rst +++ b/doc/tutorial/auto_examples/mvml/sg_execution_times.rst @@ -5,8 +5,8 @@ Computation times ================= -**00:05.285** total execution time for **tutorial_auto_examples_mvml** files: +**00:04.803** total execution time for **tutorial_auto_examples_mvml** files: +-------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_tutorial_auto_examples_mvml_plot_mvml_.py` (``plot_mvml_.py``) | 00:05.285 | 0.0 MB | +| :ref:`sphx_glr_tutorial_auto_examples_mvml_plot_mvml_.py` (``plot_mvml_.py``) | 00:04.803 | 0.0 MB | +-------------------------------------------------------------------------------+-----------+--------+ diff --git a/multimodal/datasets/data_sample.py b/multimodal/datasets/data_sample.py index 377eea8f7662ee5612248987cc2a6733f41a76fd..c56ec4fa77ab64590565966b6cf6a9ececaeb25d 100644 --- a/multimodal/datasets/data_sample.py +++ b/multimodal/datasets/data_sample.py @@ -365,13 +365,18 @@ class MultiModalArray(np.ndarray, MultiModalData): views_ind = np.array([0, new_data.shape[1] // 2, new_data.shape[1]]) else: views_ind = np.array([0, new_data.shape[1]]) + elif not isinstance(views_ind, np.ndarray): + try: + views_ind = np.asarray(views_ind) + except Exception: + raise TypeError("format of views_ind is not list or nd array") except Exception as e: raise ValueError('Reshape your data') if new_data.ndim < 2 : raise ValueError('Reshape your data') if new_data.ndim > 1 and (new_data.shape == (1, 1) or new_data.shape == ()): raise ValueError('Reshape your data') - if views_ind.ndim < 2 and new_data.ndim <2 and views_ind[-1] > new_data.shape[1]: + if views_ind.ndim < 2 and new_data.ndim < 2 and views_ind[-1] > new_data.shape[1]: raise ValueError('Reshape your data') # views_ind_self = views_ind diff --git a/multimodal/kernels/lpMKL.py b/multimodal/kernels/lpMKL.py index ca61b8cbf283c62192c26d30ee26abed419dd192..44a15eba5e6de723515825f01c7fe6f9f616071c 100644 --- a/multimodal/kernels/lpMKL.py +++ b/multimodal/kernels/lpMKL.py @@ -133,6 +133,7 @@ class MKL(BaseEstimator, ClassifierMixin, MKernel): self.weights = weights return self + def learn_lpMKL(self): """ function of lpMKL learning diff --git a/multimodal/kernels/mvml.py b/multimodal/kernels/mvml.py index 29df9f918a41f36cdf37395b36f0cbec91bbb30e..706bc28722ffba334936331ba2d1dab6a389b62a 100644 --- a/multimodal/kernels/mvml.py +++ b/multimodal/kernels/mvml.py @@ -136,7 +136,8 @@ class MVML(MKernel, BaseEstimator, ClassifierMixin): def _more_tags(self): return {'X_types': ["2darray"], 'binary_only': True, - 'multilabel' : False} + 'multilabel' : False, + } def fit(self, X, y= None, views_ind=None): """ @@ -457,6 +458,8 @@ class MVML(MKernel, BaseEstimator, ClassifierMixin): return np.take(self.classes_, pred) + + def _predict_mvml(self, test_kernels, g, w): """