├── MANIFEST ├── MANIFEST.in ├── README.txt ├── __init__.py ├── build └── lib │ ├── examples │ ├── README.txt │ ├── __pycache__ │ │ ├── cpcmv.cpython-36.pyc │ │ ├── mvmds.cpython-36.pyc │ │ ├── mvsc.cpython-36.pyc │ │ ├── mvtsne.cpython-36.pyc │ │ └── utils.cpython-36.pyc │ ├── mfeat-fac.txt │ ├── mfeat-fou.txt │ ├── mfeat-mor.txt │ ├── mfeat-pix.txt │ ├── plot_mvmds.py │ ├── plot_mvsc.py │ └── plot_mvtsne.py │ └── multiview │ ├── __init__.py │ ├── cpcmv.py │ ├── mvmds.py │ ├── mvsc.py │ ├── mvtsne.py │ ├── tests │ ├── __init__.py │ ├── mvtsne.py │ ├── test_cpcmv.py │ ├── test_mvmds.py │ ├── test_mvsc.py │ ├── test_mvtsne.py │ ├── test_utils.py │ └── utils.py │ └── utils.py ├── dist ├── multiview-1.0-py3.6.egg ├── multiview-1.0.tar.gz └── multiview-1.0.win-amd64.exe ├── doc ├── Makefile ├── build │ ├── doctrees │ │ ├── cpc.doctree │ │ ├── environment.pickle │ │ ├── index.doctree │ │ ├── mvmds.doctree │ │ ├── mvsc.doctree │ │ ├── mvtsne.doctree │ │ ├── plot_mvmds.doctree │ │ ├── plot_mvsc.doctree │ │ └── plot_mvtsne.doctree │ └── html │ │ ├── .buildinfo │ │ ├── _images │ │ ├── mvmds.png │ │ └── mvtsne-6.png │ │ ├── _sources │ │ ├── cpc.rst.txt │ │ ├── index.rst.txt │ │ ├── mvmds.rst.txt │ │ ├── mvsc.rst.txt │ │ ├── mvtsne.rst.txt │ │ ├── plot_mvmds.rst.txt │ │ ├── plot_mvsc.rst.txt │ │ └── plot_mvtsne.rst.txt │ │ ├── _static │ │ ├── ajax-loader.gif │ │ ├── alabaster.css │ │ ├── basic.css │ │ ├── classic.css │ │ ├── comment-bright.png │ │ ├── comment-close.png │ │ ├── comment.png │ │ ├── contents.png │ │ ├── custom.css │ │ ├── doctools.js │ │ ├── down-pressed.png │ │ ├── down.png │ │ ├── file.png │ │ ├── jquery-3.1.0.js │ │ ├── jquery.js │ │ ├── minus.png │ │ ├── mvmds.png │ │ ├── mvtsne-6.png │ │ ├── nature.css │ │ ├── navigation.png │ │ ├── plus.png │ │ ├── pygments.css │ │ ├── searchtools.js │ │ ├── sidebar.js │ │ ├── sphinxdoc.css │ │ ├── underscore-1.3.1.js │ │ ├── underscore.js │ │ ├── up-pressed.png │ │ ├── up.png │ │ └── websupport.js │ │ ├── cpc.html │ │ ├── genindex.html │ │ ├── index.html │ │ ├── mvmds.html │ │ ├── mvsc.html │ │ ├── mvtsne.html │ │ ├── objects.inv │ │ ├── plot_mvmds.html │ │ ├── plot_mvsc.html │ │ ├── plot_mvtsne.html │ │ ├── py-modindex.html │ │ ├── search.html │ │ └── searchindex.js ├── make.bat └── source │ ├── README.txt │ ├── conf.py │ ├── cpc.rst │ ├── cpc.rst~ │ ├── index.rst │ ├── index.rst~ │ ├── mvmds.rst │ ├── mvmds.rst~ │ ├── mvsc.rst │ ├── mvsc.rst~ │ ├── mvtsne.rst │ ├── mvtsne.rst~ │ ├── plot_mvmds.rst │ ├── plot_mvmds.rst~ │ ├── plot_mvsc.rst │ ├── plot_mvsc.rst~ │ ├── plot_mvtsne.rst │ ├── plot_mvtsne.rst~ │ └── ystatic │ ├── mvmds.png │ └── mvtsne-6.png ├── examples ├── README.txt ├── __pycache__ │ ├── cpcmv.cpython-36.pyc │ ├── mvmds.cpython-36.pyc │ ├── mvsc.cpython-36.pyc │ ├── mvtsne.cpython-36.pyc │ └── utils.cpython-36.pyc ├── mfeat-fac.txt ├── mfeat-fou.txt ├── mfeat-mor.txt ├── mfeat-pix.txt ├── plot_mvmds.py ├── plot_mvsc.py └── plot_mvtsne.py ├── multiview.egg-info ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt ├── not-zip-safe └── top_level.txt ├── multiview ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-36.pyc │ ├── cpc_mv.cpython-36.pyc │ ├── cpcmv.cpython-36.pyc │ ├── mvmds.cpython-36.pyc │ ├── mvsc.cpython-36.pyc │ ├── mvtsne.cpython-36.pyc │ └── utils.cpython-36.pyc ├── cpcmv.py ├── mvmds.py ├── mvsc.py ├── mvtsne.py ├── tests │ ├── __init__.py │ ├── __pycache__ │ │ ├── cpcmv.cpython-36.pyc │ │ ├── mvmds.cpython-36.pyc │ │ └── utils.cpython-36.pyc │ ├── test_cpcmv.py │ ├── test_mvmds.py │ ├── test_mvsc.py │ ├── test_mvtsne.py │ └── test_utils.py └── utils.py └── setup.py /MANIFEST: -------------------------------------------------------------------------------- 1 | # file GENERATED by distutils, do NOT edit 2 | README.txt 3 | setup.py 4 | doc\Makefile 5 | doc\make.bat 6 | doc\build\doctrees\cpc.doctree 7 | doc\build\doctrees\environment.pickle 8 | doc\build\doctrees\index.doctree 9 | doc\build\doctrees\mvmds.doctree 10 | doc\build\doctrees\mvsc.doctree 11 | doc\build\doctrees\mvtsne.doctree 12 | doc\build\doctrees\plot_mvmds.doctree 13 | doc\build\doctrees\plot_mvsc.doctree 14 | doc\build\doctrees\plot_mvtsne.doctree 15 | doc\build\html\.buildinfo 16 | doc\build\html\cpc.html 17 | doc\build\html\genindex.html 18 | doc\build\html\index.html 19 | doc\build\html\mvmds.html 20 | doc\build\html\mvsc.html 21 | doc\build\html\mvtsne.html 22 | doc\build\html\objects.inv 23 | doc\build\html\plot_mvmds.html 24 | doc\build\html\plot_mvsc.html 25 | doc\build\html\plot_mvtsne.html 26 | doc\build\html\py-modindex.html 27 | doc\build\html\search.html 28 | doc\build\html\searchindex.js 29 | doc\build\html\_images\mvmds.png 30 | doc\build\html\_images\mvtsne-6.png 31 | doc\build\html\_sources\cpc.rst.txt 32 | doc\build\html\_sources\index.rst.txt 33 | doc\build\html\_sources\mvmds.rst.txt 34 | doc\build\html\_sources\mvsc.rst.txt 35 | doc\build\html\_sources\mvtsne.rst.txt 36 | doc\build\html\_sources\plot_mvmds.rst.txt 37 | doc\build\html\_sources\plot_mvsc.rst.txt 38 | doc\build\html\_sources\plot_mvtsne.rst.txt 39 | doc\build\html\_static\ajax-loader.gif 40 | doc\build\html\_static\alabaster.css 41 | doc\build\html\_static\basic.css 42 | doc\build\html\_static\classic.css 43 | doc\build\html\_static\comment-bright.png 44 | doc\build\html\_static\comment-close.png 45 | doc\build\html\_static\comment.png 46 | doc\build\html\_static\contents.png 47 | doc\build\html\_static\custom.css 48 | doc\build\html\_static\doctools.js 49 | doc\build\html\_static\down-pressed.png 50 | doc\build\html\_static\down.png 51 | doc\build\html\_static\file.png 52 | doc\build\html\_static\jquery-3.1.0.js 53 | doc\build\html\_static\jquery.js 54 | doc\build\html\_static\minus.png 55 | doc\build\html\_static\mvmds.png 56 | doc\build\html\_static\mvtsne-6.png 57 | doc\build\html\_static\nature.css 58 | doc\build\html\_static\navigation.png 59 | doc\build\html\_static\plus.png 60 | doc\build\html\_static\pygments.css 61 | doc\build\html\_static\searchtools.js 62 | doc\build\html\_static\sidebar.js 63 | doc\build\html\_static\sphinxdoc.css 64 | doc\build\html\_static\underscore-1.3.1.js 65 | doc\build\html\_static\underscore.js 66 | doc\build\html\_static\up-pressed.png 67 | doc\build\html\_static\up.png 68 | doc\build\html\_static\websupport.js 69 | doc\source\README.txt 70 | doc\source\conf.py 71 | doc\source\cpc.rst 72 | doc\source\cpc.rst~ 73 | doc\source\index.rst 74 | doc\source\index.rst~ 75 | doc\source\mvmds.rst 76 | doc\source\mvmds.rst~ 77 | doc\source\mvsc.rst 78 | doc\source\mvsc.rst~ 79 | doc\source\mvtsne.rst 80 | doc\source\mvtsne.rst~ 81 | doc\source\plot_mvmds.rst 82 | doc\source\plot_mvmds.rst~ 83 | doc\source\plot_mvsc.rst 84 | doc\source\plot_mvsc.rst~ 85 | doc\source\plot_mvtsne.rst 86 | doc\source\plot_mvtsne.rst~ 87 | doc\source\ystatic\mvmds.png 88 | doc\source\ystatic\mvtsne-6.png 89 | examples\README.txt 90 | examples\mfeat-fac.txt 91 | examples\mfeat-fou.txt 92 | examples\mfeat-mor.txt 93 | examples\mfeat-pix.txt 94 | examples\plot_mvmds.py 95 | examples\plot_mvsc.py 96 | examples\plot_mvtsne.py 97 | examples\__pycache__\cpcmv.cpython-36.pyc 98 | examples\__pycache__\mvmds.cpython-36.pyc 99 | examples\__pycache__\mvsc.cpython-36.pyc 100 | examples\__pycache__\mvtsne.cpython-36.pyc 101 | examples\__pycache__\utils.cpython-36.pyc 102 | multiview\__init__.py 103 | multiview\cpcmv.py 104 | multiview\mvmds.py 105 | multiview\mvsc.py 106 | multiview\mvtsne.py 107 | multiview\utils.py 108 | multiview\tests\__init__.py 109 | multiview\tests\test_cpcmv.py 110 | multiview\tests\test_mvmds.py 111 | multiview\tests\test_mvsc.py 112 | multiview\tests\test_mvtsne.py 113 | multiview\tests\test_utils.py 114 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include doc * 2 | recursive-include examples * -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | Given a multiview dataset with ``v`` input data matrices, multiview dimensionality 5 | reduction methods produce a single, low-dimensional projection of the input data 6 | samples, trying to maintain as much of the original information as possible. 7 | 8 | Multiview learning can be thought of as an effort to adapt some of the manifold algorithms 9 | principles to algorithms whose main inputs are multiview data. These data can be understood 10 | as different views of the same data, so it is attempted to use these views to and all their 11 | information for dimensionality reduction and spectral clustering. 12 | 13 | Methods developed here are adaptions of single view algorithms to multiview data. 14 | Also, these modules are translation from the multiview package, firstly written in 15 | R. 16 | 17 | .. _mvmds: 18 | 19 | MVMDS 20 | ===== 21 | 22 | MVMDS (Multiview Multidimensional Scaling) ia one of the approaches to dimensionality reduction that offers the class 23 | :doc:`mvmds` to perform multiview dimensionality reduction in a similar way than 24 | the multidimensional scaling method does (similar to ``cmdscale`` in R language). 25 | In general, it is a technique used for analyzing similarity or dissimilarity data. 26 | 27 | .. image:: ystatic/mvmds.png 28 | :align: center 29 | :scale: 60 30 | 31 | Complexity 32 | ---------- 33 | MVMDS computes distance matrices from plain data matrices is so and preprocesses these distance 34 | matrices (centering and double square). Lastly, it extracts commom principal components 35 | of the processed data. The overall complexity is about 36 | :math:`O[k n^2 v]`. 37 | 38 | * :math:`n`: number of samples of each view 39 | * :math:`k`: components to extract 40 | * :math:`v`: number of different views 41 | 42 | .. _mvtsne: 43 | 44 | MvtSNE 45 | ====== 46 | 47 | Another dimensionality reduction function in this package is the class :doc:`mvtsne`, that 48 | extends the ``tsne`` algorithm (available in ``manifold`` module) to work with multiview data. 49 | It based on the conversion of affinities of data to probabilities. The affinities 50 | in the original space are represented by Gaussian joint probabilities and the affinities 51 | in the embedded space are represented by Student's t-distributions. 52 | 53 | .. image:: ystatic/mvtsne-6.png 54 | :align: center 55 | :scale: 60 56 | 57 | Complexity 58 | ---------- 59 | The MvtSNE algorithm comprises two steps: 60 | 61 | 1. **Opinion pooling finding**: MvtSNE computes optimal pooling of probabilities for 62 | each view from affinities of data points. It runs an optimizer to find the best set 63 | of weights. Start point at (1/v,..) using bounds to limit the weights to 0..1. Then, 64 | it computes KL between the different probabilities. The overall complexity of opinion 65 | pooling finding is 66 | :math:`O[n^2 v^2]` + :math:`O[w n^2]`. 67 | 68 | 69 | 2. **tSNE application**: this stage applies tSNE (t-distributed Stochastic Neighbor Embedding) 70 | to the multiple views of the same data. Its complexity is about :math:`O[n^2 v m]`. 71 | 72 | The overall complexity of MvtSNE is 73 | :math:`O[n^2 v^2] + O[w n^2] + O[n^2 v m]`. 74 | 75 | * :math:`n`: number of samples of each view 76 | * :math:`v`: number of different views 77 | * :math:`w`: weights dimension 78 | * :math:`m`: input maximum iteration 79 | 80 | .. _mvsc: 81 | 82 | MVSC 83 | ==== 84 | 85 | Given a multiview dataset with ``v`` input data matrices, multiview spectral clustering (MVSC) methods 86 | produce a single clustering assignment, considering the information from all the 87 | input views. 88 | Package ``multiview`` offers the class :doc:`mvsc` to perform multiview spectral 89 | clustering. It is an extension to spectral clustering (``kernlab::specc`` in R language) 90 | to multiview datasets. 91 | 92 | Complexity 93 | ---------- 94 | Multiview spectral clustering computes the diagonal matrix of the similarity matrices. 95 | Firstly, computes distance matrices if necessary. After that, calculates laplacian matrices, 96 | extracts commom principal components and apply KMeans algorithm to obtained data. 97 | Roughly, the complexity of MVSC is 98 | :math:`O[k n^2 v] + O[n \log(n)]`. 99 | 100 | * :math:`n`: number of samples of each view 101 | * :math:`v`: number of different views 102 | * :math:`k`: components to extract 103 | 104 | 105 | Alternative use 106 | =============== 107 | 108 | Although the methods in this package have been divided in dimensionality reduction 109 | and clustering, there is a close relationship between both tasks. In fact, all three 110 | methods can be used for both tasks. 111 | 112 | First, the data projection produced by dimensionality reduction methods can be 113 | fed to a standard clustering algorithm in order to obtain a multiview clustering. 114 | Second, as mvsc also returns the projection resulting from the k first common 115 | eigenvectors in matrix $evectors, this space can also be used as a low-dimensional 116 | embedding of the original multiview data, for visualization or other purposes. 117 | 118 | .. topic:: References: 119 | 120 | * Abbas, Ali E. 2009. "A Kullback-Leibler View of Linear and Log-Linear Pools." *Decision Analysis* 121 | 6 (1): 25-37. doi:`10.1287/deca.1080.0133 `_. 122 | 123 | * Carvalho, Arthur, and Kate Larson. 2012. "A Consensual Linear Opinion Pool." 124 | http://arxiv.org/abs/1204.5399. 125 | 126 | * Kruskal, J B. 1964. "Multidimensional scaling by optimizing goodness of fit to 127 | a nonmetric hypothesis." *Psychometrika* 29 (1): 1\-27. doi:`10.1007/BF02289565 `_. 128 | 129 | * Ng, Andrew Y, Michael I Jordan, and Yair Weiss. 2001. "On spectral clustering: 130 | Analysis and an algorithm." *Nips* 14 (14). MIT Press: 849-56. 131 | 132 | * Planck, Max, and Ulrike Von Luxburg. 2006. "A Tutorial on Spectral Clustering." 133 | *Statistics and Computing* 17 (March). Springer US: 395-416. doi 134 | `10.1007/s11222-007-9033-z `_. 135 | 136 | * Shi, Jianbo, and Jitendra Malik. 2005. "Normalized Cuts and Image Segmentation 137 | Normalized Cuts and Image Segmentation." *Pattern Analysis and Machine Intelligence, IEEE Transactions* 138 | on 22 (March): 888-905. doi:`10.1109/CVPR.1997.609407 `_. 139 | 140 | * Trendafilov, Nickolay T. 2010. "Stepwise estimation of common principal 141 | components." *Computational Statistics and Data Analysis* 54 (12): 3446-57. 142 | doi:`10.1016/j.csda.2010.03.010 `_. 143 | 144 | * Van Der Maaten, Laurens, Geoffrey Hinton, and Geoffrey Hinton van der Maaten. 145 | 2008. "Visualizing Data using t-SNE." doi:`10.1007/s10479-011-0841-3 `_. 146 | 147 | * Multiview features dataset. https://archive.ics.uci.edu/ml/datasets/Multiple+Features -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/__init__.py -------------------------------------------------------------------------------- /build/lib/examples/README.txt: -------------------------------------------------------------------------------- 1 | 2 | General examples 3 | ---------------- 4 | 5 | General-purpose and introductory examples for the multiview. -------------------------------------------------------------------------------- /build/lib/examples/__pycache__/cpcmv.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/build/lib/examples/__pycache__/cpcmv.cpython-36.pyc -------------------------------------------------------------------------------- /build/lib/examples/__pycache__/mvmds.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/build/lib/examples/__pycache__/mvmds.cpython-36.pyc -------------------------------------------------------------------------------- /build/lib/examples/__pycache__/mvsc.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/build/lib/examples/__pycache__/mvsc.cpython-36.pyc -------------------------------------------------------------------------------- /build/lib/examples/__pycache__/mvtsne.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/build/lib/examples/__pycache__/mvtsne.cpython-36.pyc -------------------------------------------------------------------------------- /build/lib/examples/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/build/lib/examples/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /build/lib/examples/plot_mvmds.py: -------------------------------------------------------------------------------- 1 | """ 2 | ============= 3 | Multiview MDS 4 | ============= 5 | 6 | An example plot of multiview MDS, using multiples views from same data thanks 7 | to data given in `UCI Machine Learning Repository 8 | `_. 9 | """ 10 | import numpy as np 11 | from matplotlib import pyplot as plt 12 | from multiview.mvmds import MVMDS 13 | 14 | 15 | def readData(filename, data_type=0): 16 | """ 17 | Given a txt file, returns a numpy matrix with the values, according 18 | to datatype specified in data_type parameters. 19 | 20 | Parameters 21 | ---------- 22 | filename: string 23 | Path or name of the txt file. 24 | data_type: integer, default 0 25 | Specifies the matrix datatype. If data_type is 0, data loaded will be 26 | float type. If data_type is 1, matrix datatype will be float. 27 | 28 | Returns 29 | ------- 30 | output: ndarray 31 | Matrix with data loaded. 32 | """ 33 | if data_type != 0 and data_type != 1: 34 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 35 | 'instead.' % data_type) 36 | with open(filename) as txtfile: 37 | 38 | result = [] 39 | myreader = txtfile.readlines() 40 | 41 | for row in myreader: 42 | if data_type == 0: 43 | result.append([float(x) for x in row.split()]) 44 | elif data_type == 1: 45 | result.append([int(x) for x in row.split()]) 46 | if data_type == 0: 47 | return np.array(result, dtype='float') 48 | else: 49 | return np.array(result, dtype='int') 50 | 51 | 52 | ##################################################### 53 | 54 | fourier = readData("mfeat-fou.txt", 0) 55 | profcorr = readData("mfeat-fac.txt", 1) 56 | pixels = readData("mfeat-pix.txt", 1) 57 | morpho = readData("mfeat-mor.txt", 0) 58 | 59 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 60 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 61 | 'brown', 'yellow', 'orange', 'gray', 'red'] 62 | 63 | is_distance = [False] * 4 64 | 65 | mvmds = MVMDS(k=2) 66 | projection = mvmds.fit_transform([fourier, profcorr, pixels, morpho], 67 | is_distance) 68 | # print(projection) 69 | for i in range(10): 70 | plt.scatter(projection[i * 200:200 * (i + 1), 0], 71 | projection[i * 200:200 * (1 + i), 1], 72 | c=mypalette[i], marker=markers[i]) 73 | plt.axis('off') 74 | plt.show() 75 | -------------------------------------------------------------------------------- /build/lib/examples/plot_mvsc.py: -------------------------------------------------------------------------------- 1 | """ 2 | ============================= 3 | Multiview Spectral Clustering 4 | ============================= 5 | 6 | An example plot of multiview Spectral Clustering, using multiples views from 7 | same data thanks data given in `UCI Machine Learning Repository 8 | `_. 9 | """ 10 | import numpy as np 11 | import pandas 12 | from multiview.mvsc import MVSC 13 | 14 | 15 | def readData(filename, data_type=0): 16 | """ 17 | Given a txt file, returns a numpy matrix with the values, according 18 | to datatype specified in data_type parameters. 19 | 20 | Parameters 21 | ---------- 22 | filename: string 23 | Path or name of the txt file. 24 | data_type: integer, default 0 25 | Specifies the matrix datatype. If data_type is 0, data loaded will be 26 | float type. If data_type is 1, matrix datatype will be float. 27 | 28 | Returns 29 | ------- 30 | output: ndarray 31 | Matrix with data loaded. 32 | """ 33 | if data_type != 0 and data_type != 1: 34 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 35 | 'instead.' % data_type) 36 | with open(filename) as txtfile: 37 | 38 | result = [] 39 | myreader = txtfile.readlines() 40 | 41 | for row in myreader: 42 | if data_type == 0: 43 | result.append([float(x) for x in row.split()]) 44 | elif data_type == 1: 45 | result.append([int(x) for x in row.split()]) 46 | if data_type == 0: 47 | return np.array(result, dtype='float') 48 | else: 49 | return np.array(result, dtype='int') 50 | 51 | 52 | ##################################################### 53 | 54 | fourier = readData("mfeat-fou.txt", 0) 55 | profcorr = readData("mfeat-fac.txt", 1) 56 | pixels = readData("mfeat-pix.txt", 1) 57 | morpho = readData("mfeat-mor.txt", 0) 58 | 59 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 60 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 61 | 'brown', 'yellow', 'orange', 'gray', 'red'] 62 | 63 | distance = [False] * 4 64 | 65 | # Ten clusters 66 | mvsc = MVSC(k=10) 67 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 68 | clustering = clust[0] 69 | labels_count = [np.unique( 70 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 71 | for i in range(10)] 72 | clustered = np.zeros((10, 10), dtype=int) 73 | for i in range(10): 74 | for index, j in enumerate(labels_count[i][0]): 75 | clustered[i, j] = labels_count[i][1][index] 76 | classes = np.arange(10) 77 | print("############################################") 78 | print("# TEN CLUSTERS #") 79 | print("############################################") 80 | print(pandas.DataFrame(clustered, classes, classes)) 81 | 82 | # Ten clusters and neighbours 2 83 | mvsc = MVSC(k=10, neighbours=2) 84 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 85 | clustering = clust[0] 86 | labels_count = [np.unique( 87 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 88 | for i in range(10)] 89 | clustered = np.zeros((10, 10), dtype=int) 90 | for i in range(10): 91 | for index, j in enumerate(labels_count[i][0]): 92 | clustered[i, j] = labels_count[i][1][index] 93 | classes = np.arange(10) 94 | print("############################################") 95 | print("# TEN CLUSTERS AND NEIGHBOURS 2 #") 96 | print("############################################") 97 | print(pandas.DataFrame(clustered, classes, classes)) 98 | -------------------------------------------------------------------------------- /build/lib/examples/plot_mvtsne.py: -------------------------------------------------------------------------------- 1 | """ 2 | ============== 3 | Multiview tSNE 4 | ============== 5 | 6 | An example plot of multiview tSNE, using multiples views from same data thanks 7 | to data given in `UCI Machine Learning Repository 8 | `_. 9 | """ 10 | 11 | import numpy as np 12 | from matplotlib import pyplot as plt 13 | from multiview.mvtsne import MvtSNE 14 | 15 | 16 | def readData(filename, data_type=0): 17 | """ 18 | Given a txt file, returns a numpy matrix with the values, according 19 | to datatype specified in data_type parameters. 20 | 21 | Parameters 22 | ---------- 23 | filename: string 24 | Path or name of the txt file. 25 | data_type: integer, default 0 26 | Specifies the matrix datatype. If data_type is 0, data loaded will be 27 | float type. If data_type is 1, matrix datatype will be float. 28 | 29 | Returns 30 | ------- 31 | output: ndarray 32 | Matrix with data loaded. 33 | """ 34 | if data_type != 0 and data_type != 1: 35 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 36 | 'instead.' % data_type) 37 | with open(filename) as txtfile: 38 | 39 | result = [] 40 | myreader = txtfile.readlines() 41 | 42 | for row in myreader: 43 | if data_type == 0: 44 | result.append([float(x) for x in row.split()]) 45 | elif data_type == 1: 46 | result.append([int(x) for x in row.split()]) 47 | if data_type == 0: 48 | return np.array(result, dtype='float') 49 | else: 50 | return np.array(result, dtype='int') 51 | 52 | 53 | ##################################################### 54 | 55 | fourier = readData("mfeat-fou.txt", 0) 56 | profcorr = readData("mfeat-fac.txt", 1) 57 | pixels = readData("mfeat-pix.txt", 1) 58 | morpho = readData("mfeat-mor.txt", 0) 59 | 60 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 61 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 62 | 'brown', 'yellow', 'orange', 'gray', 'red'] 63 | 64 | distance = [False] * 4 65 | 66 | mvtsne = MvtSNE(k=2) 67 | projection = mvtsne.fit_transform( 68 | [fourier, profcorr, pixels, morpho], distance) 69 | 70 | projection = projection[0] 71 | for i in range(10): 72 | plt.scatter(projection[i * 200:200 * (i + 1), 0], 73 | projection[i * 200:200 * (1 + i), 1], 74 | c=mypalette[i], marker=markers[i]) 75 | plt.axis('off') 76 | plt.show() 77 | -------------------------------------------------------------------------------- /build/lib/multiview/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | The package implements multiview data techniques. 3 | """ 4 | 5 | from .cpcmv import MVCPC 6 | from .mvmds import MVMDS 7 | from .mvsc import MVSC 8 | from .mvtsne import MvtSNE 9 | 10 | __all__ = ['MVCPC', 'MVMDS', 'MVSC', 'MvtSNE'] 11 | -------------------------------------------------------------------------------- /build/lib/multiview/cpcmv.py: -------------------------------------------------------------------------------- 1 | """ 2 | CPC computes Common principal components of a set of matrices. 3 | 4 | This file uses a variation of Trendafilov (2010) method to compute 5 | the k first common principal components of a set of matrices in an 6 | efficient way 7 | """ 8 | 9 | import numpy as np 10 | import warnings 11 | from sklearn.base import BaseEstimator 12 | import scipy.sparse.linalg as sparse 13 | 14 | 15 | def cpc(x, k=0): 16 | # Adapt parameter names to those used by Trendafilov on his code 17 | n_g = np.array([x.shape[1]] * x.shape[0]) 18 | p = x.shape[1] 19 | # Shape of matrix is consider as number of matrices, number of rows and 20 | # number of colums. 21 | mcas = x.shape[0] 22 | iterator = 15 23 | n = n_g / np.sum(n_g) 24 | D = np.zeros((k, mcas)) 25 | CPC = np.zeros((p, k)) 26 | Qw = np.eye(p) 27 | 28 | s = np.zeros((p, p)) 29 | for m in np.arange(mcas): 30 | s += (n[m] * x[m]) 31 | # end of mcas for 32 | 33 | if k == p: 34 | res_vals, res_vectors = np.linalg.eigh(s) 35 | else: 36 | res_vals, res_vectors = sparse.eigsh(s, k=k) 37 | q0 = res_vectors[:, ::-1] 38 | 39 | for ncomp in np.arange(k): 40 | q = q0[:, ncomp] 41 | q = np.array(q0[:, ncomp]).reshape(len(q), 1) 42 | d = np.zeros((1, mcas)) 43 | for m in np.arange(mcas): 44 | d[:, m] = np.dot(np.dot(q.T, x[m]), q) 45 | 46 | # Second for-loop 47 | for _ in np.arange(iterator): 48 | s = np.zeros((p, p)) 49 | for m in np.arange(mcas): 50 | s += (n_g[m] * x[m] / d[:, m]) 51 | 52 | w = np.dot(s, q) 53 | if ncomp != 0: 54 | w = np.dot(Qw, w) 55 | 56 | # Presumably, the dot function return only one value 57 | q = w / np.sqrt(np.dot(w.T, w)) 58 | for m in np.arange(mcas): 59 | d[:, m] = np.dot(np.dot(q.T, x[m]), q) 60 | # end of loop for iter 61 | 62 | D[ncomp, :] = d 63 | CPC[:, ncomp] = q[:, 0] 64 | Qw -= np.dot(q, q.T) 65 | # end of loop ncomp 66 | return (D, CPC) 67 | 68 | 69 | class MVCPC(BaseEstimator): 70 | """Compute common principal components of x. 71 | 72 | Parameters 73 | ---------- 74 | 75 | k : int, default 0 76 | Number of components to extract (0 means all p components). 77 | 78 | Attributes 79 | ---------- 80 | eigenvalues_ : ndarray 81 | Stores the eigenvalues computed in the algorithm. 82 | eigenvectors_ : ndarray 83 | Stores the eigenvectors computed in the algorithm. 84 | 85 | References 86 | ---------- 87 | 88 | Trendafilov, N. (2010). Stepwise estimation of common principal 89 | components. *Computational Statistics and Data Analysis*, 54, 90 | 3446–3457. 91 | """ 92 | 93 | def __init__(self, k=0): 94 | self.k = k 95 | 96 | def fit(self, x): 97 | """Compute k common principal components of x. 98 | 99 | Parameters 100 | ---------- 101 | 102 | x : array_like or ndarray 103 | A set of n matrices of dimension pxp given as a n x p x p matrix. 104 | 105 | """ 106 | self.fit_transform(x) 107 | return self 108 | 109 | def fit_transform(self, x): 110 | """Compute k common principal components of x, and return those 111 | components. 112 | 113 | Parameters 114 | ---------- 115 | 116 | x : array_like or ndarray 117 | A set of n matrices of dimension pxp given as a n x p x p matrix. 118 | 119 | Returns 120 | ------- 121 | values : tuple 122 | Tuple with two elements: 123 | 124 | the eigenvalues 125 | 126 | the common eigenvectors 127 | 128 | Raises 129 | ------ 130 | 131 | ValueError: Matrices are not square matrices or k value is 132 | negative. 133 | 134 | Examples 135 | -------- 136 | 137 | >>> import numpy as np 138 | >>> x = np.array([[[2, 1, 8], [4, 5, 6], [3, 7, 9]], 139 | [[1, 4, 7], [2, 5, 8], [3, 6, 9]]]) 140 | >>> mv_cpc = MVCPC(k=3) 141 | >>> mv_cpc.fit_transform(x) 142 | (array([[ 16.09601677, 16.21849616], 143 | [ -0.11903382, -0.85516505], 144 | [ 0.02301705, -0.3633311 ]]), 145 | array([[ 0.45139369, -0.88875921, 0.07969196], 146 | [ 0.55811719, 0.35088538, 0.75192065], 147 | [ 0.69623914, 0.29493478, -0.65441923]])) 148 | >>> 149 | """ 150 | 151 | if x.shape[1] != x.shape[2]: 152 | raise ValueError("matrices have different size from mx n x n. " 153 | "Size found instead is %d x %d x %d" % x.shape) 154 | if self.k == 0: 155 | # If k is 0 then retrieve all the components 156 | self.k = x.shape[1] 157 | elif self.k > x.shape[1]: 158 | self.k = x.shape[1] 159 | warnings.warn("k is greater than matrix dimension. Maximum " 160 | "possible number of components is computed instead.") 161 | elif self.k < 0: 162 | raise ValueError("k value must be between 0 and number of samples" 163 | " of data matrix.") 164 | D, CPC = cpc(x, self.k) 165 | self.eigenvalues_ = D 166 | self.eigenvectors_ = CPC 167 | return (self.eigenvalues_, self.eigenvectors_) 168 | -------------------------------------------------------------------------------- /build/lib/multiview/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/build/lib/multiview/tests/__init__.py -------------------------------------------------------------------------------- /build/lib/multiview/tests/test_cpcmv.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy.testing import assert_array_almost_equal 3 | from sklearn.utils.testing import assert_raises 4 | import multiview.cpcmv as cpcmv 5 | 6 | 7 | def test_cpc(): 8 | data = np.arange(50, dtype=float).reshape((2, 5, 5)) 9 | eigenvalues, eigenvectors = cpcmv.cpc(data, k=2) 10 | 11 | real_eigenvalues = np.array([[66.60954262, 176.89090037], 12 | [-6.60954262, 8.10909963]]) 13 | real_eigenvectors = np.array([[0.20303518, 0.74751369], 14 | [0.31154745, 0.45048661], 15 | [0.42005972, 0.15345953], 16 | [0.528572, -0.14356755], 17 | [0.63708427, -0.44059463]]) 18 | 19 | assert_array_almost_equal(eigenvalues, real_eigenvalues, decimal=4) 20 | assert_array_almost_equal(eigenvectors, real_eigenvectors, decimal=4) 21 | 22 | 23 | def test_cpc_error(): 24 | # k value cannot be negative 25 | data = np.arange(40, dtype=float).reshape((2, 5, 4)) 26 | cpc_est = cpcmv.MVCPC(k=-2) 27 | assert_raises(ValueError, cpc_est.fit, data) 28 | # Second and third dimensions must be equal 29 | cpc_est = cpcmv.MVCPC(k=2) 30 | assert_raises(ValueError, cpc_est.fit, data) 31 | 32 | 33 | def test_cpcmv(): 34 | data = np.arange(50, dtype=float).reshape((2, 5, 5)) 35 | 36 | cpc_est = cpcmv.MVCPC(k=2) 37 | cpc_est.fit(data) 38 | -------------------------------------------------------------------------------- /build/lib/multiview/tests/test_mvmds.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy.testing import assert_array_almost_equal 3 | from sklearn.utils.testing import assert_raises 4 | import multiview.mvmds as mvmds 5 | 6 | 7 | def test_preprocess_mds(): 8 | data = np.arange(25, dtype=float).reshape((5, 5)) 9 | preprocessed_data = mvmds.preprocess_mvmds(data) 10 | 11 | sim = np.array([[40., 20., 0., -20., -40.], 12 | [20., 10., 0., -10., -20.], 13 | [0., 0., 0., 0., 0.], 14 | [-20., -10., 0., 10., 20.], 15 | [-40., -20., 0., 20., 40.]]) 16 | 17 | assert_array_almost_equal(preprocessed_data, sim, decimal=3) 18 | 19 | 20 | def test_mvmds_error(): 21 | # Data and is_distane do not have the same length. 22 | one = np.arange(25, dtype=float).reshape((5, 5)) 23 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 24 | data = [one, two] 25 | is_distance = [False, False, False] 26 | 27 | mvmds_est = mvmds.MVMDS(k=2) 28 | assert_raises(ValueError, mvmds_est.fit, data, is_distance) 29 | 30 | # Sample data matrices do not have the same number of rows 31 | one = np.arange(25, dtype=float).reshape((5, 5)) 32 | two = np.arange(25, 49, dtype=float).reshape((4, 6)) 33 | data = [one, two] 34 | is_distance = [False, False] 35 | 36 | mvmds_est = mvmds.MVMDS(k=2) 37 | assert_raises(ValueError, mvmds_est.fit, data, is_distance) 38 | 39 | # k value cannot be negative 40 | one = np.arange(25, dtype=float).reshape((5, 5)) 41 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 42 | data = [one, two] 43 | is_distance = [False, False] 44 | 45 | mvmds_est = mvmds.MVMDS(k=-2) 46 | assert_raises(ValueError, mvmds_est.fit, data, is_distance) 47 | 48 | 49 | def test_mvmds(): 50 | one = np.arange(25, dtype=float).reshape((5, 5)) 51 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 52 | data = [one, two] 53 | is_distance = [False, False] 54 | 55 | mvmds_est = mvmds.MVMDS(k=2) 56 | mvmds_est.fit(data, is_distance) 57 | -------------------------------------------------------------------------------- /build/lib/multiview/tests/test_mvsc.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy.testing import assert_array_almost_equal 3 | from sklearn.utils.testing import assert_raises 4 | import multiview.mvsc as mvsc 5 | 6 | 7 | def test_laplacian_ng(): 8 | data = np.arange(25, dtype=float).reshape((5, 5)) 9 | laplacian = mvsc.laplacian_ng(data) 10 | 11 | real_laplacian = np.array([[0., 0.0534, 0.0816, 0.1028, 0.1206], 12 | [0.2672, 0.1714, 0.1527, 0.1466, 0.1450], 13 | [0.4082, 0.2400, 0.2, 0.1820, 0.1723], 14 | [0.5144, 0.2933, 0.2380, 0.2117, 0.1964], 15 | [0.6030, 0.3384, 0.2708, 0.2378, 0.2181]]) 16 | 17 | assert_array_almost_equal(laplacian, real_laplacian, decimal=4) 18 | 19 | 20 | def test_suggested_sigma(): 21 | data = np.arange(25, dtype=float).reshape((5, 5)) 22 | s_sigma = mvsc.suggested_sigma(data) 23 | 24 | real_s_sigma = 7.0 25 | 26 | assert_array_almost_equal(s_sigma, real_s_sigma, decimal=4) 27 | 28 | 29 | def test_gaussian_similarity(): 30 | data = np.arange(25, dtype=float).reshape((5, 5)) 31 | similarity = mvsc.distance_gaussian_similarity(data, 2) 32 | print(similarity) 33 | 34 | real_similarity = np.array([[1., 0.8824, 0.6065, 0.3246, 0.1353], 35 | [0.0439, 0.0110, 0.0021, 0.0003, 0.], 36 | [0., 0., 0., 0., 0.], 37 | [0., 0., 0., 0., 0.], 38 | [0., 0., 0., 0., 0.]]) 39 | 40 | assert_array_almost_equal(similarity, real_similarity, decimal=4) 41 | 42 | 43 | def test_mvsc_error(): 44 | # Data and is_distane do not have the same length. 45 | one = np.arange(25, dtype=float).reshape((5, 5)) 46 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 47 | data = [one, two] 48 | is_distance = [False, False, False] 49 | 50 | mvsc_est = mvsc.MVSC(k=2) 51 | assert_raises(ValueError, mvsc_est.fit, data, is_distance) 52 | 53 | # Sample data matrices do not have the same number of rows 54 | one = np.arange(25, dtype=float).reshape((5, 5)) 55 | two = np.arange(25, 49, dtype=float).reshape((4, 6)) 56 | data = [one, two] 57 | is_distance = [False, False] 58 | 59 | mvsc_est = mvsc.MVSC(k=2) 60 | assert_raises(ValueError, mvsc_est.fit, data, is_distance) 61 | 62 | # k value cannot be negative 63 | one = np.arange(25, dtype=float).reshape((5, 5)) 64 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 65 | data = [one, two] 66 | is_distance = [False, False] 67 | 68 | mvsc_est = mvsc.MVSC(k=-2) 69 | assert_raises(ValueError, mvsc_est.fit, data, is_distance) 70 | 71 | 72 | def test_mvsc(): 73 | one = np.arange(25, dtype=float).reshape((5, 5)) 74 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 75 | data = [one, two] 76 | is_distance = [False, False] 77 | 78 | mvsc_est = mvsc.MVSC(k=2) 79 | mvsc_est.fit(data, is_distance) 80 | -------------------------------------------------------------------------------- /build/lib/multiview/tests/test_mvtsne.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from sklearn.utils.testing import assert_raises 3 | import multiview.mvtsne as mvtsne 4 | 5 | 6 | def test_mvtsne_error(): 7 | # Data and is_distane do not have the same length. 8 | one = np.arange(25, dtype=float).reshape((5, 5)) 9 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 10 | data = [one, two] 11 | is_distance = [False, False, False] 12 | 13 | mvtsne_est = mvtsne.MvtSNE(k=2) 14 | assert_raises(ValueError, mvtsne_est.fit, data, is_distance) 15 | 16 | # Sample data matrices do not have the same number of rows 17 | one = np.arange(25, dtype=float).reshape((5, 5)) 18 | two = np.arange(25, 49, dtype=float).reshape((4, 6)) 19 | data = [one, two] 20 | is_distance = [False, False] 21 | 22 | mvtsne_est = mvtsne.MvtSNE(k=2) 23 | assert_raises(ValueError, mvtsne_est.fit, data, is_distance) 24 | 25 | # k value cannot be negative 26 | one = np.arange(25, dtype=float).reshape((5, 5)) 27 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 28 | data = [one, two] 29 | is_distance = [False, False] 30 | 31 | mvtsne_est = mvtsne.MvtSNE(k=-2) 32 | assert_raises(ValueError, mvtsne_est.fit, data, is_distance) 33 | 34 | 35 | def test_mvtsne(): 36 | one = np.arange(25, dtype=float).reshape((5, 5)) 37 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 38 | data = [one, two] 39 | is_distance = [False, False] 40 | 41 | mvtsne_est = mvtsne.MvtSNE(k=2) 42 | mvtsne_est.fit(data, is_distance) 43 | -------------------------------------------------------------------------------- /build/lib/multiview/tests/test_utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy.testing import assert_array_almost_equal 3 | import multiview.utils as utils 4 | 5 | 6 | def test_hbeta(): 7 | data = np.arange(25, dtype=float).reshape((5, 5)) 8 | H, P = utils.Hbeta(data, 2) 9 | 10 | real_H = 100.145867 11 | real_P = np.array([[8.64664717e-01, 1.17019644e-01, 1.58368867e-02, 12 | 2.14328955e-03, 2.90062698e-04], 13 | [3.92557174e-05, 5.31268363e-06, 7.18993544e-07, 14 | 9.73051950e-08, 1.31688261e-08], 15 | [1.78220681e-09, 2.41195464e-10, 3.26422564e-11, 16 | 4.41764902e-12, 5.97863781e-13], 17 | [8.09120641e-14, 1.09502571e-14, 1.48195615e-15, 18 | 2.00560955e-16, 2.71429737e-17], 19 | [3.67340203e-18, 4.97140904e-19, 6.72807051e-20, 20 | 9.10545327e-21, 1.23228910e-21]]) 21 | 22 | assert_array_almost_equal(H, real_H, decimal=4) 23 | assert_array_almost_equal(P, real_P, decimal=4) 24 | 25 | 26 | def test_x2p(): 27 | data = np.arange(25, dtype=float).reshape((5, 5)) 28 | P, beta = utils.x2p(data) 29 | 30 | real_P = np.array([[0., 0.25, 0.25, 0.25, 0.25], 31 | [0.25, 0., 0.25, 0.25, 0.25], 32 | [0.25, 0.25, 0., 0.25, 0.25], 33 | [0.25, 0.25, 0.25, 0., 0.25], 34 | [0.25, 0.25, 0.25, 0.25, 0.]]) 35 | real_beta = np.array([8.88178420e-16, 8.88178420e-16, 8.88178420e-16, 36 | 8.88178420e-16, 8.88178420e-16]) 37 | 38 | assert_array_almost_equal(P, real_P, decimal=4) 39 | assert_array_almost_equal(beta, real_beta, decimal=10) 40 | 41 | 42 | def test_whiten(): 43 | data = np.array([[1, 2, 3, 4], [4, 3, 2, 1], [2, 4, 1, 3], [1, 3, 2, 4]]) 44 | whitened = utils.whiten(data) 45 | 46 | real_whitened = np.array([[9.63475981e-01, 1.11961253e+00, 1.49011612e-08, 47 | 0.00000000e+00], 48 | [-1.55893688e+00, 6.91958598e-01, 0.00000000e+00, 49 | 0.00000000e+00], 50 | [-1.84007539e-01, -1.46559183e+00, 51 | -1.49011612e-08, 0.00000000e+00], 52 | [7.79468442e-01, -3.45979299e-01, 0.00000000e+00, 53 | 0.00000000e+00]]) 54 | 55 | assert_array_almost_equal(whitened, real_whitened, decimal=0) 56 | -------------------------------------------------------------------------------- /build/lib/multiview/tests/utils.py: -------------------------------------------------------------------------------- 1 | """ Utilities to be used in this package. 2 | 3 | There are mainly four functions to help other classes: 4 | Hbeta, x2p and whiten for the tsne algorithm and distance_between_rows to 5 | compute row distances (euclidean distance) in a matrix and return those 6 | distances.""" 7 | 8 | ___version___ = '1.0' 9 | ___author___ = 'Maria Araceli Burgueño Caballero' 10 | ___email___ = "mburgueno@uoc.edu" 11 | ___status___ = "Pre-Production" 12 | 13 | 14 | import numpy as np 15 | from scipy.spatial.distance import sqeuclidean 16 | from sklearn.metrics.pairwise import euclidean_distances 17 | from sklearn.utils import check_array 18 | 19 | 20 | def Hbeta(D, beta): 21 | """Compute H beta for matrix D, given beta. 22 | 23 | Parameters 24 | ---------- 25 | 26 | D : ndarray or nscalar. 27 | Input value. 28 | beta : numeric. 29 | Number to operate with in the exponential distribution. 30 | 31 | Returns 32 | ------- 33 | 34 | (H, P) : tuple 35 | Return a tuple with H and P values. H is a float value and P 36 | can be either an scalar or a ndarray. 37 | 38 | Examples 39 | -------- 40 | 41 | >>> import numpy as np 42 | >>> matrix = np.array([[1, 2, 3], [2, 3, 4], [5, 6, 2]]) 43 | >>> hbeta = Hbeta(matrix, 3) 44 | >>> print("H -> %g\nP-> %a" % hbeta) 45 | H -> 21.6814 46 | P-> array([[ 8.66214422e-01, 4.31262766e-02, 2.14713088e-03], 47 | [ 4.31262766e-02, 2.14713088e-03, 1.06899352e-04], 48 | [ 5.32220535e-06, 2.64977002e-07, 4.31262766e-02]]) 49 | """ 50 | P = np.exp(-D * beta) 51 | sumP = np.sum(P) 52 | if sumP == 0: 53 | H = 0 54 | P = D * 0 55 | else: 56 | H = np.log(sumP) + beta * np.sum(np.dot(D, P)) / sumP 57 | P -= sumP 58 | return (H, P) 59 | 60 | 61 | def distance_between_rows(X): 62 | """Compute euclidean distance between rows of data matrix. 63 | 64 | Parameters 65 | ---------- 66 | X : array_like or ndarray. 67 | Input data. 68 | 69 | Returns 70 | ------- 71 | dist : ndarray (2D). 72 | Simmetric matrix of computed distance between rows. 73 | 74 | Examples 75 | -------- 76 | 77 | >>> x = np.array(([2, 4, 3], [1, 5, 7], [8, 6, 9])).T 78 | >>> distance_between_rows(x) 79 | [[ 0. 4.89897949 6.164414 ] 80 | [ 4.89897949 0. 3.74165739] 81 | [ 6.164414 3.74165739 0. ]] 82 | """ 83 | X = check_array(X) 84 | dist = np.zeros((X.shape[0], X.shape[0])) 85 | for i in range(X.shape[0] - 1): 86 | for j in range(i + 1, X.shape[0]): 87 | dist[i, j] = dist[j, i] = np.sqrt(sqeuclidean(X[i], X[j])) 88 | return dist 89 | 90 | 91 | def x2p(X, perplexity=15, tol=1e-5): 92 | """ Compute a pair-wise conditional matrix given input matrix. 93 | 94 | Parameters 95 | ---------- 96 | X : ndarray. 97 | Input data. Matrix with n rows. 98 | perplexity : numeric. 99 | Target perplexity. Loosely translates into the expected number of 100 | behibours per point. 101 | tol : float 102 | Tolerance to be used in the computation. It must be a small value. 103 | 104 | Returns 105 | ------- 106 | (P, beta) : tuple 107 | P: Pair-wise conditional probability matrix. 108 | beta: array used during computation. 109 | 110 | Examples 111 | -------- 112 | 113 | >>> x = np.array(([2, 4, 3], [1, 5, 7], [8, 6, 9])).T 114 | >>> x2p(x) 115 | (array([[ 0. , 0.5, 0.5], 116 | [ 0.5, 0. , 0.5], 117 | [ 0.5, 0.5, 0. ]]), array([ 8.88178420e-16, 118 | 8.88178420e-16, 8.88178420e-16])) 119 | """ 120 | X = check_array(X) 121 | n = X.shape[0] 122 | D = euclidean_distances(X) 123 | # print(D) 124 | P = np.zeros((n, n)) 125 | beta = np.array([1] * n, dtype="float64") 126 | logU = np.log(perplexity) 127 | for i in np.arange(n): 128 | betamin = -float("inf") 129 | betamax = float("inf") 130 | Di = np.delete(D[i], i) 131 | H, this_P = Hbeta(Di, beta[i]) 132 | H_diff = H - logU 133 | tries = 0 134 | while abs(H_diff) > tol and tries < 50: 135 | if H_diff > 0: 136 | betamin = beta[i] 137 | if betamax == float("inf"): 138 | beta[i] = beta[i] * 2 139 | else: 140 | beta[i] = (beta[i] + betamax) / 2 141 | else: 142 | betamax = beta[i] 143 | if betamin == -float("inf"): 144 | beta[i] = beta[i] / 2 145 | else: 146 | beta[i] = (beta[i] + betamin) / 2 147 | H, this_P = Hbeta(Di, beta[i]) 148 | H_diff = H - logU 149 | tries += 1 150 | P[i, np.arange(n) != i] = this_P 151 | return (P, beta) 152 | 153 | 154 | def whiten(X, row_norm=False, verbose=0, n_comp=-1): 155 | """Whitening of matrix X, and return that new matrix whitened. 156 | 157 | Parameters 158 | ---------- 159 | 160 | X : ndarray 161 | Input data (2D). 162 | row_norm : int, default 0 163 | If row_norm is True, then input data is scaled as well as centered. 164 | If it is False, then no center or scale is computed. 165 | verbose : int, default 0 166 | Verbosity mode. 167 | n_comp : int, default -1 168 | Number of rows of output matrix. If n_comp is -1, the number 169 | of columns of input data is set. 170 | 171 | Returns 172 | ------- 173 | 174 | X : ndarray 175 | Whitened matrix. 176 | 177 | Examples 178 | -------- 179 | 180 | >>> x = np.array(([2, 4, 3], [1, 5, 7], [8, 6, 9])).T 181 | >>> whiten(x, row_norm=True) 182 | [[ 1.22474487e+00 7.07106781e-01 -7.26265414e-08] 183 | [ -1.22474487e+00 7.07106781e-01 -3.69804654e-08] 184 | [ 2.10705234e-16 -1.41421356e+00 -5.30203132e-09]] 185 | >>> y = np.array(([1, 2, 3], [4, 5, 6], [7, 8, 9])).T 186 | >>> whiten(y) 187 | [[ 1.22474487e+00 -2.98023224e-08 0.00000000e+00] 188 | [ 0.00000000e+00 0.00000000e+00 0.00000000e+00] 189 | [ -1.22474487e+00 2.98023224e-08 0.00000000e+00]] 190 | """ 191 | if n_comp == -1: 192 | n_comp = X.shape[1] 193 | if verbose: 194 | print("Centering") 195 | n = X.shape[0] 196 | p = X.shape[1] 197 | # Centering matrix columns 198 | mean = X.mean(axis=0) 199 | sd = np.std(X, axis=0, ddof=1) 200 | X -= mean 201 | if row_norm: 202 | X = (X / sd).T 203 | else: 204 | X = X.T 205 | if verbose: 206 | print("Whitening") 207 | V = np.dot(X, X.T) / n 208 | u, s, v = np.linalg.svd(V) 209 | D = (np.diag(1 / s**(1 / 2))) 210 | K = np.dot(D, u.T) 211 | K = np.matrix(K[:n_comp, :].reshape((n_comp, p))) 212 | X = np.dot(K, X).T 213 | return X 214 | 215 | 216 | ############################################################ 217 | # MAIN # 218 | ############################################################ 219 | # hbeta = Hbeta(np.array([[1, 2, 3], [2, 3, 4], [5, 6, 2]]), 3) 220 | # print("H -> %g\nP-> %a" % hbeta) 221 | # x = np.array(([1, 2, 3], [4, 5, 6], [7, 8, 9])).T 222 | # xx = np.array(([2, 4, 3], [1, 5, 7], [8, 6, 9])).T 223 | # whitening = whiten(x) # , row_norm=True) 224 | # print(whitening) 225 | # distance = x2p(xx) 226 | # print(distance) 227 | # print(np.var(np.array([8,6,9], dtype="float64"))) 228 | 229 | # Check wheter function is less time consuming 230 | # xx = np.random.rand(2000, 2000) 231 | # beginning1 = time.time() 232 | # function = distance_between_rows(xx) 233 | # end1 = time.time() - beginning1 234 | # print("Distance between rows finished in %g" % end1) 235 | # beginning2 = time.time() 236 | # function1 = euclidean_distances(xx) 237 | # end2 = time.time() - beginning2 238 | # print("Euclidean distances finished in %g" % end2) 239 | -------------------------------------------------------------------------------- /build/lib/multiview/utils.py: -------------------------------------------------------------------------------- 1 | """ Utilities to be used in this package. 2 | 3 | There are mainly three functions to help other classes: 4 | Hbeta, x2p and whiten for the tsne algorithm .""" 5 | 6 | ___version___ = '1.0' 7 | ___author___ = 'Maria Araceli Burgueño Caballero' 8 | ___email___ = "mburgueno@uoc.edu" 9 | ___status___ = "Pre-Production" 10 | 11 | 12 | import numpy as np 13 | from sklearn.metrics.pairwise import euclidean_distances 14 | from sklearn.utils import check_array 15 | 16 | 17 | def Hbeta(D, beta): 18 | """Compute H beta for matrix D, given beta. 19 | 20 | Parameters 21 | ---------- 22 | 23 | D : ndarray or nscalar. 24 | Input value. 25 | beta : numeric. 26 | Number to operate with in the exponential distribution. 27 | 28 | Returns 29 | ------- 30 | 31 | (H, P) : tuple 32 | Return a tuple with H and P values. H is a float value and P 33 | can be either an scalar or a ndarray. 34 | 35 | Examples 36 | -------- 37 | 38 | >>> import numpy as np 39 | >>> matrix = np.array([[1, 2, 3], [2, 3, 4], [5, 6, 2]]) 40 | >>> hbeta = Hbeta(matrix, 3) 41 | >>> print("H -> %g\nP-> %a" % hbeta) 42 | H -> 21.6814 43 | P-> array([[ 8.66214422e-01, 4.31262766e-02, 2.14713088e-03], 44 | [ 4.31262766e-02, 2.14713088e-03, 1.06899352e-04], 45 | [ 5.32220535e-06, 2.64977002e-07, 4.31262766e-02]]) 46 | """ 47 | P = np.exp(-D * beta) 48 | sumP = np.sum(P) 49 | if sumP == 0: 50 | H = 0 51 | P = D * 0 52 | else: 53 | H = np.log(sumP) + beta * np.sum(np.dot(D, P)) / sumP 54 | P -= sumP 55 | return (H, P) 56 | 57 | 58 | def x2p(X, perplexity=15, tol=1e-5): 59 | """ Compute a pair-wise conditional matrix given input matrix. 60 | 61 | Parameters 62 | ---------- 63 | X : ndarray. 64 | Input data. Matrix with n rows. 65 | perplexity : numeric. 66 | Target perplexity. Loosely translates into the expected number of 67 | behibours per point. 68 | tol : float 69 | Tolerance to be used in the computation. It must be a small value. 70 | 71 | Returns 72 | ------- 73 | (P, beta) : tuple 74 | P: Pair-wise conditional probability matrix. 75 | beta: array used during computation. 76 | 77 | Examples 78 | -------- 79 | 80 | >>> x = np.array(([2, 4, 3], [1, 5, 7], [8, 6, 9])).T 81 | >>> x2p(x) 82 | (array([[ 0. , 0.5, 0.5], 83 | [ 0.5, 0. , 0.5], 84 | [ 0.5, 0.5, 0. ]]), array([ 8.88178420e-16, 85 | 8.88178420e-16, 8.88178420e-16])) 86 | """ 87 | X = check_array(X) 88 | n = X.shape[0] 89 | D = euclidean_distances(X) 90 | # print(D) 91 | P = np.zeros((n, n)) 92 | beta = np.array([1] * n, dtype="float64") 93 | logU = np.log(perplexity) 94 | for i in np.arange(n): 95 | betamin = -float("inf") 96 | betamax = float("inf") 97 | Di = np.delete(D[i], i) 98 | H, this_P = Hbeta(Di, beta[i]) 99 | H_diff = H - logU 100 | tries = 0 101 | while abs(H_diff) > tol and tries < 50: 102 | if H_diff > 0: 103 | betamin = beta[i] 104 | if betamax == float("inf"): 105 | beta[i] = beta[i] * 2 106 | else: 107 | beta[i] = (beta[i] + betamax) / 2 108 | else: 109 | betamax = beta[i] 110 | if betamin == -float("inf"): 111 | beta[i] = beta[i] / 2 112 | else: 113 | beta[i] = (beta[i] + betamin) / 2 114 | H, this_P = Hbeta(Di, beta[i]) 115 | H_diff = H - logU 116 | tries += 1 117 | P[i, np.arange(n) != i] = this_P 118 | return (P, beta) 119 | 120 | 121 | def whiten(X, row_norm=False, verbose=0, n_comp=-1): 122 | """Whitening of matrix X, and return that new matrix whitened. 123 | 124 | Parameters 125 | ---------- 126 | 127 | X : ndarray 128 | Input data (2D). 129 | row_norm : int, default 0 130 | If row_norm is True, then input data is scaled as well as centered. 131 | If it is False, then no center or scale is computed. 132 | verbose : int, default 0 133 | Verbosity mode. 134 | n_comp : int, default -1 135 | Number of rows of output matrix. If n_comp is -1, the number 136 | of columns of input data is set. 137 | 138 | Returns 139 | ------- 140 | 141 | X : ndarray 142 | Whitened matrix. 143 | 144 | Examples 145 | -------- 146 | 147 | >>> x = np.array(([2, 4, 3], [1, 5, 7], [8, 6, 9])).T 148 | >>> whiten(x, row_norm=True) 149 | [[ 1.22474487e+00 7.07106781e-01 -7.26265414e-08] 150 | [ -1.22474487e+00 7.07106781e-01 -3.69804654e-08] 151 | [ 2.10705234e-16 -1.41421356e+00 -5.30203132e-09]] 152 | >>> y = np.array(([1, 2, 3], [4, 5, 6], [7, 8, 9])).T 153 | >>> whiten(y) 154 | [[ 1.22474487e+00 -2.98023224e-08 0.00000000e+00] 155 | [ 0.00000000e+00 0.00000000e+00 0.00000000e+00] 156 | [ -1.22474487e+00 2.98023224e-08 0.00000000e+00]] 157 | """ 158 | if n_comp == -1: 159 | n_comp = X.shape[1] 160 | if verbose: 161 | print("Centering") 162 | n = X.shape[0] 163 | p = X.shape[1] 164 | # Centering matrix columns 165 | mean = X.mean(axis=0) 166 | sd = np.std(X, axis=0, ddof=1) 167 | X -= mean 168 | if row_norm: 169 | X = (X / sd).T 170 | else: 171 | X = X.T 172 | if verbose: 173 | print("Whitening") 174 | V = np.dot(X, X.T) / n 175 | u, s, v = np.linalg.svd(V) 176 | D = (np.diag(1 / s**(1 / 2))) 177 | K = np.dot(D, u.T) 178 | K = np.matrix(K[:n_comp, :].reshape((n_comp, p))) 179 | X = np.dot(K, X).T 180 | return X 181 | -------------------------------------------------------------------------------- /dist/multiview-1.0-py3.6.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/dist/multiview-1.0-py3.6.egg -------------------------------------------------------------------------------- /dist/multiview-1.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/dist/multiview-1.0.tar.gz -------------------------------------------------------------------------------- /dist/multiview-1.0.win-amd64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/dist/multiview-1.0.win-amd64.exe -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = multiview 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /doc/build/doctrees/cpc.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/doctrees/cpc.doctree -------------------------------------------------------------------------------- /doc/build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/doctrees/environment.pickle -------------------------------------------------------------------------------- /doc/build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/doctrees/index.doctree -------------------------------------------------------------------------------- /doc/build/doctrees/mvmds.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/doctrees/mvmds.doctree -------------------------------------------------------------------------------- /doc/build/doctrees/mvsc.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/doctrees/mvsc.doctree -------------------------------------------------------------------------------- /doc/build/doctrees/mvtsne.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/doctrees/mvtsne.doctree -------------------------------------------------------------------------------- /doc/build/doctrees/plot_mvmds.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/doctrees/plot_mvmds.doctree -------------------------------------------------------------------------------- /doc/build/doctrees/plot_mvsc.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/doctrees/plot_mvsc.doctree -------------------------------------------------------------------------------- /doc/build/doctrees/plot_mvtsne.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/doctrees/plot_mvtsne.doctree -------------------------------------------------------------------------------- /doc/build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 860adb4624b108f4a78b97e67d9f9087 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /doc/build/html/_images/mvmds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_images/mvmds.png -------------------------------------------------------------------------------- /doc/build/html/_images/mvtsne-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_images/mvtsne-6.png -------------------------------------------------------------------------------- /doc/build/html/_sources/cpc.rst.txt: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | CPC 7 | === 8 | Multiview Common Principal Components 9 | ------------------------------------- 10 | 11 | 12 | .. automodule:: multiview.cpcmv 13 | 14 | .. autoclass:: MVCPC 15 | 16 | .. automethod:: fit 17 | .. automethod:: fit_transform 18 | -------------------------------------------------------------------------------- /doc/build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. multiview documentation master file, created by 2 | sphinx-quickstart on Fri Oct 20 18:41:26 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | ================== 7 | Multiview learning 8 | ================== 9 | 10 | .. toctree:: 11 | :hidden: 12 | 13 | cpc 14 | mvmds 15 | mvsc 16 | mvtsne 17 | plot_mvmds 18 | plot_mvsc 19 | plot_mvtsne 20 | 21 | 22 | 23 | Introduction 24 | ============ 25 | 26 | Given a multiview dataset with ``v`` input data matrices, multiview dimensionality 27 | reduction methods produce a single, low-dimensional projection of the input data 28 | samples, trying to maintain as much of the original information as possible. 29 | 30 | Multiview learning can be thought of as an effort to adapt some of the manifold algorithms 31 | principles to algorithms whose main inputs are multiview data. These data can be understood 32 | as different views of the same data, so it is attempted to use these views to and all their 33 | information for dimensionality reduction and spectral clustering. 34 | 35 | Methods developed here are adaptions of single view algorithms to multiview data. 36 | Also, these modules are translation from the multiview package, firstly written in 37 | R. 38 | 39 | .. _mvmds: 40 | 41 | MVMDS 42 | ===== 43 | 44 | MVMDS (Multiview Multidimensional Scaling) ia one of the approaches to dimensionality reduction that offers the class 45 | :doc:`mvmds` to perform multiview dimensionality reduction in a similar way than 46 | the multidimensional scaling method does (similar to ``cmdscale`` in R language). 47 | In general, it is a technique used for analyzing similarity or dissimilarity data. 48 | 49 | .. image:: ystatic/mvmds.png 50 | :align: center 51 | :scale: 60 52 | 53 | Complexity 54 | ---------- 55 | MVMDS computes distance matrices from plain data matrices is so and preprocesses these distance 56 | matrices (centering and double square). Lastly, it extracts commom principal components 57 | of the processed data. The overall complexity is about 58 | :math:`O[k n^2 v]`. 59 | 60 | * :math:`n`: number of samples of each view 61 | * :math:`k`: components to extract 62 | * :math:`v`: number of different views 63 | 64 | .. _mvtsne: 65 | 66 | MvtSNE 67 | ====== 68 | 69 | Another dimensionality reduction function in this package is the class :doc:`mvtsne`, that 70 | extends the ``tsne`` algorithm (available in ``manifold`` module) to work with multiview data. 71 | It based on the conversion of affinities of data to probabilities. The affinities 72 | in the original space are represented by Gaussian joint probabilities and the affinities 73 | in the embedded space are represented by Student's t-distributions. 74 | 75 | .. image:: ystatic/mvtsne-6.png 76 | :align: center 77 | :scale: 60 78 | 79 | Complexity 80 | ---------- 81 | The MvtSNE algorithm comprises two steps: 82 | 83 | 1. **Opinion pooling finding**: MvtSNE computes optimal pooling of probabilities for 84 | each view from affinities of data points. It runs an optimizer to find the best set 85 | of weights. Start point at (1/v,..) using bounds to limit the weights to 0..1. Then, 86 | it computes KL between the different probabilities. The overall complexity of opinion 87 | pooling finding is 88 | :math:`O[n^2 v^2]` + :math:`O[w n^2]`. 89 | 90 | 91 | 2. **tSNE application**: this stage applies tSNE (t-distributed Stochastic Neighbor Embedding) 92 | to the multiple views of the same data. Its complexity is about :math:`O[n^2 v m]`. 93 | 94 | The overall complexity of MvtSNE is 95 | :math:`O[n^2 v^2] + O[w n^2] + O[n^2 v m]`. 96 | 97 | * :math:`n`: number of samples of each view 98 | * :math:`v`: number of different views 99 | * :math:`w`: weights dimension 100 | * :math:`m`: input maximum iteration 101 | 102 | .. _mvsc: 103 | 104 | MVSC 105 | ==== 106 | 107 | Given a multiview dataset with ``v`` input data matrices, multiview spectral clustering (MVSC) methods 108 | produce a single clustering assignment, considering the information from all the 109 | input views. 110 | Package ``multiview`` offers the class :doc:`mvsc` to perform multiview spectral 111 | clustering. It is an extension to spectral clustering (``kernlab::specc`` in R language) 112 | to multiview datasets. 113 | 114 | Complexity 115 | ---------- 116 | Multiview spectral clustering computes the diagonal matrix of the similarity matrices. 117 | Firstly, computes distance matrices if necessary. After that, calculates laplacian matrices, 118 | extracts commom principal components and apply KMeans algorithm to obtained data. 119 | Roughly, the complexity of MVSC is 120 | :math:`O[k n^2 v] + O[n \log(n)]`. 121 | 122 | * :math:`n`: number of samples of each view 123 | * :math:`v`: number of different views 124 | * :math:`k`: components to extract 125 | 126 | 127 | Alternative use 128 | =============== 129 | 130 | Although the methods in this package have been divided in dimensionality reduction 131 | and clustering, there is a close relationship between both tasks. In fact, all three 132 | methods can be used for both tasks. 133 | 134 | First, the data projection produced by dimensionality reduction methods can be 135 | fed to a standard clustering algorithm in order to obtain a multiview clustering. 136 | Second, as mvsc also returns the projection resulting from the k first common 137 | eigenvectors in matrix $evectors, this space can also be used as a low-dimensional 138 | embedding of the original multiview data, for visualization or other purposes. 139 | 140 | .. topic:: References: 141 | 142 | * Abbas, Ali E. 2009. "A Kullback-Leibler View of Linear and Log-Linear Pools." *Decision Analysis* 143 | 6 (1): 25-37. doi:`10.1287/deca.1080.0133 `_. 144 | 145 | * Carvalho, Arthur, and Kate Larson. 2012. "A Consensual Linear Opinion Pool." 146 | http://arxiv.org/abs/1204.5399. 147 | 148 | * Kruskal, J B. 1964. "Multidimensional scaling by optimizing goodness of fit to 149 | a nonmetric hypothesis." *Psychometrika* 29 (1): 1\-27. doi:`10.1007/BF02289565 `_. 150 | 151 | * Ng, Andrew Y, Michael I Jordan, and Yair Weiss. 2001. "On spectral clustering: 152 | Analysis and an algorithm." *Nips* 14 (14). MIT Press: 849-56. 153 | 154 | * Planck, Max, and Ulrike Von Luxburg. 2006. "A Tutorial on Spectral Clustering." 155 | *Statistics and Computing* 17 (March). Springer US: 395-416. doi 156 | `10.1007/s11222-007-9033-z `_. 157 | 158 | * Shi, Jianbo, and Jitendra Malik. 2005. "Normalized Cuts and Image Segmentation 159 | Normalized Cuts and Image Segmentation." *Pattern Analysis and Machine Intelligence, IEEE Transactions* 160 | on 22 (March): 888-905. doi:`10.1109/CVPR.1997.609407 `_. 161 | 162 | * Trendafilov, Nickolay T. 2010. "Stepwise estimation of common principal 163 | components." *Computational Statistics and Data Analysis* 54 (12): 3446-57. 164 | doi:`10.1016/j.csda.2010.03.010 `_. 165 | 166 | * Van Der Maaten, Laurens, Geoffrey Hinton, and Geoffrey Hinton van der Maaten. 167 | 2008. "Visualizing Data using t-SNE." doi:`10.1007/s10479-011-0841-3 `_. 168 | 169 | * Multiview features dataset. https://archive.ics.uci.edu/ml/datasets/Multiple+Features -------------------------------------------------------------------------------- /doc/build/html/_sources/mvmds.rst.txt: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | MV-MDS 7 | ====== 8 | Multiview Multidimensional Scaling 9 | ---------------------------------- 10 | 11 | .. automodule:: multiview.mvmds 12 | 13 | .. autoclass:: MVMDS 14 | 15 | .. automethod:: fit 16 | .. automethod:: fit_transform 17 | 18 | Examples using ``MVMDS`` 19 | ------------------------ 20 | 21 | .. raw:: html 22 | 23 |
24 | 25 | .. only:: html 26 | 27 | .. figure:: ystatic/mvmds.png 28 | :width: 25% 29 | 30 | :doc:`plot_mvmds` 31 | 32 | .. raw:: html 33 | 34 |
35 | 36 | .. only:: not html 37 | 38 | * :doc:`plot_mvmds` 39 | 40 | -------------------------------------------------------------------------------- /doc/build/html/_sources/mvsc.rst.txt: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | MV-SC 7 | ====== 8 | Multiview Spectral Clustering 9 | ----------------------------- 10 | 11 | 12 | .. automodule:: multiview.mvsc 13 | 14 | .. autoclass:: MVSC 15 | 16 | .. automethod:: fit 17 | .. automethod:: fit_transform 18 | -------------------------------------------------------------------------------- /doc/build/html/_sources/mvtsne.rst.txt: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | MVtSNE 7 | ====== 8 | Multiview t-distributed Stochastic Neighbour Embedding 9 | ------------------------------------------------------ 10 | 11 | 12 | .. automodule:: multiview.mvtsne 13 | 14 | .. autoclass:: MvtSNE 15 | 16 | .. automethod:: fit 17 | .. automethod:: fit_transform 18 | 19 | Examples using ``MvtSNE`` 20 | ------------------------- 21 | 22 | .. raw:: html 23 | 24 |
25 | 26 | .. only:: html 27 | 28 | .. figure:: ystatic/mvtsne-6.png 29 | :width: 25% 30 | 31 | :doc:`plot_mvtsne` 32 | 33 | .. raw:: html 34 | 35 |
36 | 37 | .. only:: not html 38 | 39 | * :doc:`plot_mvtsne` 40 | -------------------------------------------------------------------------------- /doc/build/html/_sources/plot_mvmds.rst.txt: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | ==================================== 7 | Multiview MDS with multiple features 8 | ==================================== 9 | 10 | An illustration of the multiview multidimensional scaling with the multiple features 11 | data set. It consists on the scaling of four different views. 12 | 13 | Depending on the exact implementation, the result might be slightly different, 14 | the solution might be symmetric to the one shown here. 15 | 16 | .. image:: ystatic/mvmds.png 17 | :align: center 18 | 19 | .. code-block:: python 20 | 21 | # Author: Maria Araceli Burgueno Caballero 22 | 23 | import numpy as np 24 | from mvmds import MVMDS 25 | from matplotlib import pyplot as plt 26 | 27 | def readData(filename, data_type=0): 28 | """Given a txt file, returns a numpy matrix with the values, according 29 | to datatype specified in data_type parameters.""" 30 | if data_type != 0 and data_type != 1: 31 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 32 | 'instead.' % data_type) 33 | with open(filename) as txtfile: 34 | 35 | result = [] 36 | myreader = txtfile.readlines() 37 | 38 | for row in myreader: 39 | if data_type == 0: 40 | result.append([float(x) for x in row.split()]) 41 | elif data_type == 1: 42 | result.append([int(x) for x in row.split()]) 43 | if data_type == 0: 44 | return np.array(result, dtype='float') 45 | else: 46 | return np.array(result, dtype='int') 47 | 48 | 49 | fourier = readData("mfeat-fou.txt", 0) 50 | profcorr = readData("mfeat-fac.txt", 1) 51 | pixels = readData("mfeat-pix.txt", 1) 52 | morpho = readData("mfeat-mor.txt", 0) 53 | 54 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 55 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 56 | 'brown', 'yellow', 'orange', 'gray', 'red'] 57 | 58 | is_distance = [False] * 4 59 | 60 | mvmds = MVMDS() 61 | projection = mvmds.fit_transform([fourier, profcorr, pixels, morpho], 62 | is_distance, k=2) 63 | for i in range(10): 64 | plt.scatter(projection[i * 200:200 * (i + 1), 0], 65 | projection[i * 200:200 * (1 + i), 1], 66 | c=mypalette[i], marker=markers[i]) 67 | plt.axis('off') 68 | plt.show() 69 | 70 | **Total running time of the script:** ( 0 minutes 11.5 seconds) -------------------------------------------------------------------------------- /doc/build/html/_sources/plot_mvsc.rst.txt: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | ==================================================== 7 | Multiview Spectral Clustering with multiple features 8 | ==================================================== 9 | 10 | An illustration of the multiview spectral clustering with the multiple features 11 | data set. It consists on the clustering of four different views. 12 | 13 | Here it is shown the output result of an implementation of MV SC with 10 clusters. 14 | Dataset used in this examples is available 15 | `here `_. 16 | 17 | === === === === === === === === === === === 18 | I 1 2 3 4 5 6 7 8 9 10 19 | === === === === === === === === === === === 20 | 0 181 18 0 0 0 1 0 0 0 0 21 | 1 0 1 3 1 0 0 4 189 2 0 22 | 2 0 0 0 0 1 1 3 0 0 195 23 | 3 0 0 5 10 178 0 0 3 0 4 24 | 4 0 0 0 195 0 2 0 2 1 0 25 | 5 0 0 0 5 8 186 0 0 0 1 26 | 6 0 7 1 0 0 2 0 2 188 0 27 | 7 0 0 154 1 0 0 38 2 0 5 28 | 8 4 190 0 0 0 0 0 6 0 0 29 | 9 0 6 3 1 1 3 182 4 0 0 30 | === === === === === === === === === === === 31 | 32 | .. code-block:: python 33 | 34 | # Author: Maria Araceli Burgueno Caballero 35 | import numpy as np 36 | import pandas 37 | from multiview.mvsc import MVSC 38 | 39 | 40 | def readData(filename, data_type=0): 41 | if data_type != 0 and data_type != 1: 42 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 43 | 'instead.' % data_type) 44 | with open(filename) as txtfile: 45 | 46 | result = [] 47 | myreader = txtfile.readlines() 48 | 49 | for row in myreader: 50 | if data_type == 0: 51 | result.append([float(x) for x in row.split()]) 52 | elif data_type == 1: 53 | result.append([int(x) for x in row.split()]) 54 | if data_type == 0: 55 | return np.array(result, dtype='float') 56 | else: 57 | return np.array(result, dtype='int') 58 | 59 | fourier = readData("mfeat-fou.txt", 0) 60 | profcorr = readData("mfeat-fac.txt", 1) 61 | pixels = readData("mfeat-pix.txt", 1) 62 | morpho = readData("mfeat-mor.txt", 0) 63 | 64 | classes = np.array([[x] * 200 for x in range(10)]).ravel() 65 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 66 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 67 | 'brown', 'yellow', 'orange', 'gray', 'red'] 68 | 69 | distance = [False] * 4 70 | 71 | mvsc = MVSC(k=10) 72 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 73 | clustering = clust[0] 74 | labels_count = [np.unique( 75 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 76 | for i in range(10)] 77 | clustered = np.zeros((10, 10), dtype=int) 78 | for i in range(10): 79 | for index, j in enumerate(labels_count[i][0]): 80 | clustered[i, j] = labels_count[i][1][index] 81 | classes = np.arange(10) 82 | print("############################################") 83 | print("# TEN CLUSTERS #") 84 | print("############################################") 85 | print(pandas.DataFrame(clustered, classes, classes)) 86 | 87 | 88 | Here it is shown the output result of an implementation of MV SC with 10 clusters 89 | and 2 neighbours for each point in the clustering space. 90 | 91 | === === === === === === === === === === === 92 | I 1 2 3 4 5 6 7 8 9 10 93 | === === === === === === === === === === === 94 | 0 0 0 190 0 10 0 0 0 0 0 95 | 1 192 0 0 0 0 1 6 1 0 0 96 | 2 0 0 0 197 0 0 1 2 0 0 97 | 3 8 181 0 3 0 2 3 1 2 0 98 | 4 2 0 0 0 0 193 0 0 5 0 99 | 5 0 5 0 1 0 3 0 0 191 0 100 | 6 2 0 0 0 14 1 0 0 0 183 101 | 7 1 0 0 4 0 0 170 25 0 0 102 | 8 7 0 2 0 191 0 0 0 0 0 103 | 9 5 0 0 0 4 1 0 183 7 0 104 | === === === === === === === === === === === 105 | 106 | .. code-block:: python 107 | 108 | mvsc = MVSC(k=10, neighbours=2) 109 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 110 | clustering = clust[0] 111 | labels_count = [np.unique( 112 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 113 | for i in range(10)] 114 | clustered = np.zeros((10, 10), dtype=int) 115 | for i in range(10): 116 | for index, j in enumerate(labels_count[i][0]): 117 | clustered[i, j] = labels_count[i][1][index] 118 | classes = np.arange(10) 119 | print("############################################") 120 | print("# TEN CLUSTERS AND NEIGHBOURS 2 #") 121 | print("############################################") 122 | print(pandas.DataFrame(clustered, classes, classes)) 123 | 124 | **Total running time of the script:** ( 1 minutes 10.6 seconds) -------------------------------------------------------------------------------- /doc/build/html/_sources/plot_mvtsne.rst.txt: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | ===================================== 7 | Multiview tSNE with multiple features 8 | ===================================== 9 | 10 | An illustration of the multiview tSNE with the multiple features 11 | data set. Dataset is split into four different views. 12 | 13 | Depending on the random values or the RandomState given as a parameter, the implementation 14 | will be different each different running. 15 | 16 | 17 | .. image:: ystatic/mvtsne-6.png 18 | :align: center 19 | 20 | .. code-block:: python 21 | 22 | # Author: Maraa Araceli Burgueno Caballero 23 | 24 | import numpy as np 25 | from matplotlib import pyplot as plt 26 | from multiview.mvtsne import MvtSNE 27 | 28 | def readData(filename, data_type=0): 29 | """Given a txt file, returns a numpy matrix with the values, according 30 | to datatype specified in data_type parameters.""" 31 | if data_type != 0 and data_type != 1: 32 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 33 | 'instead.' % data_type) 34 | with open(filename) as txtfile: 35 | 36 | result = [] 37 | myreader = txtfile.readlines() 38 | 39 | for row in myreader: 40 | if data_type == 0: 41 | result.append([float(x) for x in row.split()]) 42 | elif data_type == 1: 43 | result.append([int(x) for x in row.split()]) 44 | if data_type == 0: 45 | return np.array(result, dtype='float') 46 | else: 47 | return np.array(result, dtype='int') 48 | 49 | 50 | fourier = readData("mfeat-fou.txt", 0) 51 | profcorr = readData("mfeat-fac.txt", 1) 52 | pixels = readData("mfeat-pix.txt", 1) 53 | morpho = readData("mfeat-mor.txt", 0) 54 | 55 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 56 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 57 | 'brown', 'yellow', 'orange', 'gray', 'red'] 58 | 59 | is_distance = [False] * 4 60 | 61 | mvtsne = MvtSNE() 62 | projection = mvtsne.fit_transform([fourier, profcorr, pixels, morpho], 63 | is_distance, k=2) 64 | for i in range(10): 65 | plt.scatter(projection[i * 200:200 * (i + 1), 0], 66 | projection[i * 200:200 * (1 + i), 1], 67 | c=mypalette[i], marker=markers[i]) 68 | plt.axis('off') 69 | plt.show() 70 | 71 | **Total running time of the script:** ( 3 minutes 46.4 seconds) -------------------------------------------------------------------------------- /doc/build/html/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/ajax-loader.gif -------------------------------------------------------------------------------- /doc/build/html/_static/classic.css: -------------------------------------------------------------------------------- 1 | /* 2 | * classic.css_t 3 | * ~~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- classic theme. 6 | * 7 | * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: sans-serif; 18 | font-size: 100%; 19 | background-color: #11303d; 20 | color: #000; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.document { 26 | background-color: #1c4e63; 27 | } 28 | 29 | div.documentwrapper { 30 | float: left; 31 | width: 100%; 32 | } 33 | 34 | div.bodywrapper { 35 | margin: 0 0 0 230px; 36 | } 37 | 38 | div.body { 39 | background-color: #ffffff; 40 | color: #000000; 41 | padding: 0 20px 30px 20px; 42 | } 43 | 44 | div.footer { 45 | color: #ffffff; 46 | width: 100%; 47 | padding: 9px 0 9px 0; 48 | text-align: center; 49 | font-size: 75%; 50 | } 51 | 52 | div.footer a { 53 | color: #ffffff; 54 | text-decoration: underline; 55 | } 56 | 57 | div.related { 58 | background-color: #133f52; 59 | line-height: 30px; 60 | color: #ffffff; 61 | } 62 | 63 | div.related a { 64 | color: #ffffff; 65 | } 66 | 67 | div.sphinxsidebar { 68 | } 69 | 70 | div.sphinxsidebar h3 { 71 | font-family: 'Trebuchet MS', sans-serif; 72 | color: #ffffff; 73 | font-size: 1.4em; 74 | font-weight: normal; 75 | margin: 0; 76 | padding: 0; 77 | } 78 | 79 | div.sphinxsidebar h3 a { 80 | color: #ffffff; 81 | } 82 | 83 | div.sphinxsidebar h4 { 84 | font-family: 'Trebuchet MS', sans-serif; 85 | color: #ffffff; 86 | font-size: 1.3em; 87 | font-weight: normal; 88 | margin: 5px 0 0 0; 89 | padding: 0; 90 | } 91 | 92 | div.sphinxsidebar p { 93 | color: #ffffff; 94 | } 95 | 96 | div.sphinxsidebar p.topless { 97 | margin: 5px 10px 10px 10px; 98 | } 99 | 100 | div.sphinxsidebar ul { 101 | margin: 10px; 102 | padding: 0; 103 | color: #ffffff; 104 | } 105 | 106 | div.sphinxsidebar a { 107 | color: #98dbcc; 108 | } 109 | 110 | div.sphinxsidebar input { 111 | border: 1px solid #98dbcc; 112 | font-family: sans-serif; 113 | font-size: 1em; 114 | } 115 | 116 | 117 | 118 | /* -- hyperlink styles ------------------------------------------------------ */ 119 | 120 | a { 121 | color: #355f7c; 122 | text-decoration: none; 123 | } 124 | 125 | a:visited { 126 | color: #355f7c; 127 | text-decoration: none; 128 | } 129 | 130 | a:hover { 131 | text-decoration: underline; 132 | } 133 | 134 | 135 | 136 | /* -- body styles ----------------------------------------------------------- */ 137 | 138 | div.body h1, 139 | div.body h2, 140 | div.body h3, 141 | div.body h4, 142 | div.body h5, 143 | div.body h6 { 144 | font-family: 'Trebuchet MS', sans-serif; 145 | background-color: #f2f2f2; 146 | font-weight: normal; 147 | color: #20435c; 148 | border-bottom: 1px solid #ccc; 149 | margin: 20px -20px 10px -20px; 150 | padding: 3px 0 3px 10px; 151 | } 152 | 153 | div.body h1 { margin-top: 0; font-size: 200%; } 154 | div.body h2 { font-size: 160%; } 155 | div.body h3 { font-size: 140%; } 156 | div.body h4 { font-size: 120%; } 157 | div.body h5 { font-size: 110%; } 158 | div.body h6 { font-size: 100%; } 159 | 160 | a.headerlink { 161 | color: #c60f0f; 162 | font-size: 0.8em; 163 | padding: 0 4px 0 4px; 164 | text-decoration: none; 165 | } 166 | 167 | a.headerlink:hover { 168 | background-color: #c60f0f; 169 | color: white; 170 | } 171 | 172 | div.body p, div.body dd, div.body li, div.body blockquote { 173 | text-align: justify; 174 | line-height: 130%; 175 | } 176 | 177 | div.admonition p.admonition-title + p { 178 | display: inline; 179 | } 180 | 181 | div.admonition p { 182 | margin-bottom: 5px; 183 | } 184 | 185 | div.admonition pre { 186 | margin-bottom: 5px; 187 | } 188 | 189 | div.admonition ul, div.admonition ol { 190 | margin-bottom: 5px; 191 | } 192 | 193 | div.note { 194 | background-color: #eee; 195 | border: 1px solid #ccc; 196 | } 197 | 198 | div.seealso { 199 | background-color: #ffc; 200 | border: 1px solid #ff6; 201 | } 202 | 203 | div.topic { 204 | background-color: #eee; 205 | } 206 | 207 | div.warning { 208 | background-color: #ffe4e4; 209 | border: 1px solid #f66; 210 | } 211 | 212 | p.admonition-title { 213 | display: inline; 214 | } 215 | 216 | p.admonition-title:after { 217 | content: ":"; 218 | } 219 | 220 | pre { 221 | padding: 5px; 222 | background-color: #eeffcc; 223 | color: #333333; 224 | line-height: 120%; 225 | border: 1px solid #ac9; 226 | border-left: none; 227 | border-right: none; 228 | } 229 | 230 | code { 231 | background-color: #ecf0f3; 232 | padding: 0 1px 0 1px; 233 | font-size: 0.95em; 234 | } 235 | 236 | th { 237 | background-color: #ede; 238 | } 239 | 240 | .warning code { 241 | background: #efc2c2; 242 | } 243 | 244 | .note code { 245 | background: #d6d6d6; 246 | } 247 | 248 | .viewcode-back { 249 | font-family: sans-serif; 250 | } 251 | 252 | div.viewcode-block:target { 253 | background-color: #f4debf; 254 | border-top: 1px solid #ac9; 255 | border-bottom: 1px solid #ac9; 256 | } 257 | 258 | div.code-block-caption { 259 | color: #efefef; 260 | background-color: #1c4e63; 261 | } -------------------------------------------------------------------------------- /doc/build/html/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/comment-bright.png -------------------------------------------------------------------------------- /doc/build/html/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/comment-close.png -------------------------------------------------------------------------------- /doc/build/html/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/comment.png -------------------------------------------------------------------------------- /doc/build/html/_static/contents.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/contents.png -------------------------------------------------------------------------------- /doc/build/html/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* This file intentionally left blank. */ 2 | -------------------------------------------------------------------------------- /doc/build/html/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/down-pressed.png -------------------------------------------------------------------------------- /doc/build/html/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/down.png -------------------------------------------------------------------------------- /doc/build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/file.png -------------------------------------------------------------------------------- /doc/build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/minus.png -------------------------------------------------------------------------------- /doc/build/html/_static/mvmds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/mvmds.png -------------------------------------------------------------------------------- /doc/build/html/_static/mvtsne-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/mvtsne-6.png -------------------------------------------------------------------------------- /doc/build/html/_static/nature.css: -------------------------------------------------------------------------------- 1 | /* 2 | * nature.css_t 3 | * ~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- nature theme. 6 | * 7 | * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: Arial, sans-serif; 18 | font-size: 100%; 19 | background-color: #111; 20 | color: #555; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.documentwrapper { 26 | float: left; 27 | width: 100%; 28 | } 29 | 30 | div.bodywrapper { 31 | margin: 0 0 0 230px; 32 | } 33 | 34 | hr { 35 | border: 1px solid #B1B4B6; 36 | } 37 | 38 | div.document { 39 | background-color: #eee; 40 | } 41 | 42 | div.body { 43 | background-color: #ffffff; 44 | color: #3E4349; 45 | padding: 0 30px 30px 30px; 46 | font-size: 0.9em; 47 | } 48 | 49 | div.footer { 50 | color: #555; 51 | width: 100%; 52 | padding: 13px 0; 53 | text-align: center; 54 | font-size: 75%; 55 | } 56 | 57 | div.footer a { 58 | color: #444; 59 | text-decoration: underline; 60 | } 61 | 62 | div.related { 63 | background-color: #6BA81E; 64 | line-height: 32px; 65 | color: #fff; 66 | text-shadow: 0px 1px 0 #444; 67 | font-size: 0.9em; 68 | } 69 | 70 | div.related a { 71 | color: #E2F3CC; 72 | } 73 | 74 | div.sphinxsidebar { 75 | font-size: 0.75em; 76 | line-height: 1.5em; 77 | } 78 | 79 | div.sphinxsidebarwrapper{ 80 | padding: 20px 0; 81 | } 82 | 83 | div.sphinxsidebar h3, 84 | div.sphinxsidebar h4 { 85 | font-family: Arial, sans-serif; 86 | color: #222; 87 | font-size: 1.2em; 88 | font-weight: normal; 89 | margin: 0; 90 | padding: 5px 10px; 91 | background-color: #ddd; 92 | text-shadow: 1px 1px 0 white 93 | } 94 | 95 | div.sphinxsidebar h4{ 96 | font-size: 1.1em; 97 | } 98 | 99 | div.sphinxsidebar h3 a { 100 | color: #444; 101 | } 102 | 103 | 104 | div.sphinxsidebar p { 105 | color: #888; 106 | padding: 5px 20px; 107 | } 108 | 109 | div.sphinxsidebar p.topless { 110 | } 111 | 112 | div.sphinxsidebar ul { 113 | margin: 10px 20px; 114 | padding: 0; 115 | color: #000; 116 | } 117 | 118 | div.sphinxsidebar a { 119 | color: #444; 120 | } 121 | 122 | div.sphinxsidebar input { 123 | border: 1px solid #ccc; 124 | font-family: sans-serif; 125 | font-size: 1em; 126 | } 127 | 128 | div.sphinxsidebar input[type=text]{ 129 | margin-left: 20px; 130 | } 131 | 132 | /* -- body styles ----------------------------------------------------------- */ 133 | 134 | a { 135 | color: #005B81; 136 | text-decoration: none; 137 | } 138 | 139 | a:hover { 140 | color: #E32E00; 141 | text-decoration: underline; 142 | } 143 | 144 | div.body h1, 145 | div.body h2, 146 | div.body h3, 147 | div.body h4, 148 | div.body h5, 149 | div.body h6 { 150 | font-family: Arial, sans-serif; 151 | background-color: #BED4EB; 152 | font-weight: normal; 153 | color: #212224; 154 | margin: 30px 0px 10px 0px; 155 | padding: 5px 0 5px 10px; 156 | text-shadow: 0px 1px 0 white 157 | } 158 | 159 | div.body h1 { border-top: 20px solid white; margin-top: 0; font-size: 200%; } 160 | div.body h2 { font-size: 150%; background-color: #C8D5E3; } 161 | div.body h3 { font-size: 120%; background-color: #D8DEE3; } 162 | div.body h4 { font-size: 110%; background-color: #D8DEE3; } 163 | div.body h5 { font-size: 100%; background-color: #D8DEE3; } 164 | div.body h6 { font-size: 100%; background-color: #D8DEE3; } 165 | 166 | a.headerlink { 167 | color: #c60f0f; 168 | font-size: 0.8em; 169 | padding: 0 4px 0 4px; 170 | text-decoration: none; 171 | } 172 | 173 | a.headerlink:hover { 174 | background-color: #c60f0f; 175 | color: white; 176 | } 177 | 178 | div.body p, div.body dd, div.body li { 179 | line-height: 1.5em; 180 | } 181 | 182 | div.admonition p.admonition-title + p { 183 | display: inline; 184 | } 185 | 186 | div.highlight{ 187 | background-color: white; 188 | } 189 | 190 | div.note { 191 | background-color: #eee; 192 | border: 1px solid #ccc; 193 | } 194 | 195 | div.seealso { 196 | background-color: #ffc; 197 | border: 1px solid #ff6; 198 | } 199 | 200 | div.topic { 201 | background-color: #eee; 202 | } 203 | 204 | div.warning { 205 | background-color: #ffe4e4; 206 | border: 1px solid #f66; 207 | } 208 | 209 | p.admonition-title { 210 | display: inline; 211 | } 212 | 213 | p.admonition-title:after { 214 | content: ":"; 215 | } 216 | 217 | pre { 218 | padding: 10px; 219 | background-color: White; 220 | color: #222; 221 | line-height: 1.2em; 222 | border: 1px solid #C6C9CB; 223 | font-size: 1.1em; 224 | margin: 1.5em 0 1.5em 0; 225 | -webkit-box-shadow: 1px 1px 1px #d8d8d8; 226 | -moz-box-shadow: 1px 1px 1px #d8d8d8; 227 | } 228 | 229 | code { 230 | background-color: #ecf0f3; 231 | color: #222; 232 | /* padding: 1px 2px; */ 233 | font-size: 1.1em; 234 | font-family: monospace; 235 | } 236 | 237 | .viewcode-back { 238 | font-family: Arial, sans-serif; 239 | } 240 | 241 | div.viewcode-block:target { 242 | background-color: #f4debf; 243 | border-top: 1px solid #ac9; 244 | border-bottom: 1px solid #ac9; 245 | } 246 | 247 | div.code-block-caption { 248 | background-color: #ddd; 249 | color: #222; 250 | border: 1px solid #C6C9CB; 251 | } -------------------------------------------------------------------------------- /doc/build/html/_static/navigation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/navigation.png -------------------------------------------------------------------------------- /doc/build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/_static/plus.png -------------------------------------------------------------------------------- /doc/build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #eeffcc; } 3 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */ 8 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 9 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 10 | .highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */ 11 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 12 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 13 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 14 | .highlight .ge { font-style: italic } /* Generic.Emph */ 15 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 16 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 17 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 18 | .highlight .go { color: #333333 } /* Generic.Output */ 19 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 20 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 21 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 22 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 23 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 24 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 25 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 26 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 27 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 28 | .highlight .kt { color: #902000 } /* Keyword.Type */ 29 | .highlight .m { color: #208050 } /* Literal.Number */ 30 | .highlight .s { color: #4070a0 } /* Literal.String */ 31 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 32 | .highlight .nb { color: #007020 } /* Name.Builtin */ 33 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 34 | .highlight .no { color: #60add5 } /* Name.Constant */ 35 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 36 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 37 | .highlight .ne { color: #007020 } /* Name.Exception */ 38 | .highlight .nf { color: #06287e } /* Name.Function */ 39 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 40 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 41 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 42 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 43 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 44 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 45 | .highlight .mb { color: #208050 } /* Literal.Number.Bin */ 46 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 47 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 48 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 49 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 50 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 51 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 52 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 53 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 54 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 55 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 56 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 57 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 58 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 59 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 60 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 61 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 62 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 63 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 64 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 65 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /doc/build/html/_static/sidebar.js: -------------------------------------------------------------------------------- 1 | /* 2 | * sidebar.js 3 | * ~~~~~~~~~~ 4 | * 5 | * This script makes the Sphinx sidebar collapsible. 6 | * 7 | * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds 8 | * in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton 9 | * used to collapse and expand the sidebar. 10 | * 11 | * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden 12 | * and the width of the sidebar and the margin-left of the document 13 | * are decreased. When the sidebar is expanded the opposite happens. 14 | * This script saves a per-browser/per-session cookie used to 15 | * remember the position of the sidebar among the pages. 16 | * Once the browser is closed the cookie is deleted and the position 17 | * reset to the default (expanded). 18 | * 19 | * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. 20 | * :license: BSD, see LICENSE for details. 21 | * 22 | */ 23 | 24 | $(function() { 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | // global elements used by the functions. 34 | // the 'sidebarbutton' element is defined as global after its 35 | // creation, in the add_sidebar_button function 36 | var bodywrapper = $('.bodywrapper'); 37 | var sidebar = $('.sphinxsidebar'); 38 | var sidebarwrapper = $('.sphinxsidebarwrapper'); 39 | 40 | // for some reason, the document has no sidebar; do not run into errors 41 | if (!sidebar.length) return; 42 | 43 | // original margin-left of the bodywrapper and width of the sidebar 44 | // with the sidebar expanded 45 | var bw_margin_expanded = bodywrapper.css('margin-left'); 46 | var ssb_width_expanded = sidebar.width(); 47 | 48 | // margin-left of the bodywrapper and width of the sidebar 49 | // with the sidebar collapsed 50 | var bw_margin_collapsed = '.8em'; 51 | var ssb_width_collapsed = '.8em'; 52 | 53 | // colors used by the current theme 54 | var dark_color = $('.related').css('background-color'); 55 | var light_color = $('.document').css('background-color'); 56 | 57 | function sidebar_is_collapsed() { 58 | return sidebarwrapper.is(':not(:visible)'); 59 | } 60 | 61 | function toggle_sidebar() { 62 | if (sidebar_is_collapsed()) 63 | expand_sidebar(); 64 | else 65 | collapse_sidebar(); 66 | } 67 | 68 | function collapse_sidebar() { 69 | sidebarwrapper.hide(); 70 | sidebar.css('width', ssb_width_collapsed); 71 | bodywrapper.css('margin-left', bw_margin_collapsed); 72 | sidebarbutton.css({ 73 | 'margin-left': '0', 74 | 'height': bodywrapper.height() 75 | }); 76 | sidebarbutton.find('span').text('»'); 77 | sidebarbutton.attr('title', _('Expand sidebar')); 78 | document.cookie = 'sidebar=collapsed'; 79 | } 80 | 81 | function expand_sidebar() { 82 | bodywrapper.css('margin-left', bw_margin_expanded); 83 | sidebar.css('width', ssb_width_expanded); 84 | sidebarwrapper.show(); 85 | sidebarbutton.css({ 86 | 'margin-left': ssb_width_expanded-12, 87 | 'height': bodywrapper.height() 88 | }); 89 | sidebarbutton.find('span').text('«'); 90 | sidebarbutton.attr('title', _('Collapse sidebar')); 91 | document.cookie = 'sidebar=expanded'; 92 | } 93 | 94 | function add_sidebar_button() { 95 | sidebarwrapper.css({ 96 | 'float': 'left', 97 | 'margin-right': '0', 98 | 'width': ssb_width_expanded - 28 99 | }); 100 | // create the button 101 | sidebar.append( 102 | '
«
' 103 | ); 104 | var sidebarbutton = $('#sidebarbutton'); 105 | light_color = sidebarbutton.css('background-color'); 106 | // find the height of the viewport to center the '<<' in the page 107 | var viewport_height; 108 | if (window.innerHeight) 109 | viewport_height = window.innerHeight; 110 | else 111 | viewport_height = $(window).height(); 112 | sidebarbutton.find('span').css({ 113 | 'display': 'block', 114 | 'margin-top': (viewport_height - sidebar.position().top - 20) / 2 115 | }); 116 | 117 | sidebarbutton.click(toggle_sidebar); 118 | sidebarbutton.attr('title', _('Collapse sidebar')); 119 | sidebarbutton.css({ 120 | 'color': '#FFFFFF', 121 | 'border-left': '1px solid ' + dark_color, 122 | 'font-size': '1.2em', 123 | 'cursor': 'pointer', 124 | 'height': bodywrapper.height(), 125 | 'padding-top': '1px', 126 | 'margin-left': ssb_width_expanded - 12 127 | }); 128 | 129 | sidebarbutton.hover( 130 | function () { 131 | $(this).css('background-color', dark_color); 132 | }, 133 | function () { 134 | $(this).css('background-color', light_color); 135 | } 136 | ); 137 | } 138 | 139 | function set_position_from_cookie() { 140 | if (!document.cookie) 141 | return; 142 | var items = document.cookie.split(';'); 143 | for(var k=0; k 4 | 5 | 6 | 7 | 8 | 9 | 10 | Index — multiview 1.0 documentation 11 | 12 | 13 | 14 | 15 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 44 | 45 |
46 |
47 |
48 |
49 | 50 | 51 |

Index

52 | 53 |
54 | C 55 | | E 56 | | F 57 | | M 58 | | S 59 | | W 60 | 61 |
62 |

C

63 | 64 | 68 |
69 | 70 |

E

71 | 72 | 84 | 90 |
91 | 92 |

F

93 | 94 | 106 | 118 |
119 | 120 |

M

121 | 122 | 132 | 142 |
143 | 144 |

S

145 | 146 | 150 |
151 | 152 |

W

153 | 154 | 158 |
159 | 160 | 161 | 162 |
163 |
164 |
165 | 182 |
183 |
184 | 196 | 200 | 201 | -------------------------------------------------------------------------------- /doc/build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/build/html/objects.inv -------------------------------------------------------------------------------- /doc/build/html/py-modindex.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Python Module Index — multiview 1.0 documentation 10 | 11 | 12 | 13 | 14 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 46 | 47 |
48 |
49 |
50 |
51 | 52 | 53 |

Python Module Index

54 | 55 |
56 | m 57 |
58 | 59 | 60 | 61 | 63 | 64 | 66 | 69 | 70 | 71 | 74 | 75 | 76 | 79 | 80 | 81 | 84 | 85 | 86 | 89 |
 
62 | m
67 | multiview 68 |
    72 | multiview.cpcmv 73 |
    77 | multiview.mvmds 78 |
    82 | multiview.mvsc 83 |
    87 | multiview.mvtsne 88 |
90 | 91 | 92 |
93 |
94 |
95 | 109 |
110 |
111 | 123 | 127 | 128 | -------------------------------------------------------------------------------- /doc/build/html/search.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Search — multiview 1.0 documentation 10 | 11 | 12 | 13 | 14 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 51 | 52 |
53 |
54 |
55 |
56 | 57 |

Search

58 |
59 | 60 |

61 | Please activate JavaScript to enable the search 62 | functionality. 63 |

64 |
65 |

66 | From here you can search these documents. Enter your search 67 | words into the box below and click "search". Note that the search 68 | function will automatically search for all of the words. Pages 69 | containing fewer words won't appear in the result list. 70 |

71 |
72 | 73 | 74 | 75 |
76 | 77 |
78 | 79 |
80 | 81 |
82 |
83 |
84 | 88 |
89 |
90 | 102 | 106 | 107 | -------------------------------------------------------------------------------- /doc/build/html/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({docnames:["index","plot_mvsc"],envversion:51,filenames:["index.rst","plot_mvsc.rst"],objects:{},objnames:{},objtypes:{},terms:{"boolean":[],"case":[],"class":[0,1],"default":[],"djf\u00f1j":[],"float":1,"function":0,"import":1,"int":1,"null":[],"return":[0,1],"true":1,"try":0,AND:1,GAs:[],Its:0,MDS:0,MDs:[],The:0,Then:0,These:0,__init__:[],abba:0,about:0,abs:0,accord:[],adapt:0,adjust:[],affin:0,after:0,algorithm:0,ali:0,all:0,also:0,although:0,among:[],analysi:0,analyz:0,andrew:0,anoth:0,append:1,appli:0,applic:0,approach:0,arac:1,arang:1,archiv:0,arrai:1,array_lik:[],arthur:0,arxiv:0,assig:[],assign:0,associ:[],attempt:0,attribut:[],author:1,avail:[0,1],averag:[],axi:[],base:0,basi:[],been:0,best:0,between:0,bf02289565:0,black:1,blue:1,both:0,bound:0,brown:1,burgu:[],burgueno:1,caballero:1,calcul:0,call:[],callabl:[],callback:[],can:0,carvalho:0,center:0,close:0,clust:1,cluster:0,cmdscale:0,code:[],combin:[],commom:0,common:0,compon:0,components_:[],compos:[],compris:0,comput:0,consensu:0,consid:0,consist:1,contain:[],control:[],convers:0,correspond:[],cost:[],cpc:[],cpc_mv:[],cpcmv:[],csda:0,cut:0,cvpr:0,data:[0,1],data_typ:1,datafram:1,dataset:[0,1],datatyp:[],deca:0,decis:0,def:1,defuult:[],depend:[],der:0,desir:[],develop:0,diagon:0,differ:[0,1],dimens:0,dimension:0,dissimilar:0,distanc:[0,1],distancematric:[],distribut:0,diverg:[],divid:0,doe:0,doi:0,doubl:0,dtype:1,dure:[],each:[0,1],edu:[0,1],effect:[],effici:[],effort:0,eienvector:[],eigenvalu:[],eigenvalues_:[],eigenvector:0,eigenvectors_:[],either:1,element:[],elif:1,els:1,embed:0,embedding_:[],enumer:1,epoch:[],epoch_callback:[],equival:[],error:[],estim:0,euclidean:[],evalu:[],evalues_:[],evector:0,evectors_:[],everyth:[],exact:[],exampl:1,expect:[],expert:[],extend:0,extens:0,extract:0,fac:1,fact:0,fals:1,featur:0,fed:0,file:[],filenam:1,fin:[],find:0,find_pool:[],finish:[],first:0,firstli:0,fit:0,fit_transform:1,fou:1,found:1,four:1,fourier:1,from:[0,1],gaussian:0,gener:0,geoffrei:0,given:0,good:0,grai:1,green:1,has:[],have:0,here:[0,1],hinton:0,http:0,hypothesi:0,ics:0,ideal:[],ieee:0,ilenam:[],illustr:1,imag:0,implement:1,includ:[],index:1,indic:[],inform:0,initial_dim:[],input:0,instead:1,integ:[],intellig:0,interfac:[],is_dist:[],iter:0,itself:[],jianbo:0,jitendra:0,joint:0,jordan:0,kate:0,kernlab:0,kmean:0,kruskal:0,kullback:0,labels_count:1,languag:0,laplacian:0,larson:0,lastli:0,lauren:0,leibler:0,length:[],liebler:[],like:[],likewis:[],limit:0,linear:0,list:[],load:[],log:0,low:0,luxburg:0,maaten:0,machin:0,main:0,maintain:0,malik:0,manifold:0,mantain:[],mar:[],maraa:[],march:0,maria:1,marker:1,matplotlib:[],matric:0,matrix:0,max:0,max_it:[],maximum:0,mburgueno:1,md_md:[],mean:[],messag:[],method:0,mfeat:1,michael:0,might:[],min_cost:[],minimum:[],minut:1,mit:0,mix:[],modul:0,mor:1,more:[],morpho:1,much:0,multidimension:0,multipl:0,must:1,mv_cpc:[],mv_md:[],mvcpc:[],mvmd:[],mvsc:1,mvtsne:[],mypalett:1,myread:1,name:[],ndarrai:[],necessari:0,neg:[],neighbor:0,neighbour:1,next:[],nickolai:0,nip:0,none:[],nonmetr:0,normal:0,note:[],number:0,numer:[],numpi:1,nview:[],obtain:0,off:[],offer:0,one:0,open:1,opinion:0,optim:0,orang:1,order:0,org:0,origin:0,other:0,output:1,overal:0,packag:0,panda:1,paramet:[],part:[],path:[],pattern:0,per:[],perform:0,perplex:[],pink:1,pix:1,pixel:1,plain:0,planck:0,plot_mvmd:[],plt:[],plu:[],point:[0,1],pool:0,possibl:0,preprocess:0,press:0,princip:0,principl:0,print:1,probabilitmatrix:[],probabl:0,procedur:[],process:0,produc:0,profcorr:1,project:0,provid:[],proxim:[],psychometrika:0,purpl:1,purpos:0,pxp:[],pyplot:[],radial:[],rais:1,random:[],random_st:[],randomst:[],rang:1,ravel:1,raw:[],readdata:1,readlin:1,receiv:[],red:1,reduct:0,refer:[],relationship:0,repres:0,represent:[],result:[0,1],return_count:1,roughli:0,row:1,rst:[],run:[0,1],s10479:0,s11222:0,same:0,sampl:0,scalar:[],scale:0,scatter:[],script:1,second:[0,1],see:[],segment:0,set:[0,1],sever:[],shi:0,should:[],show:[],shown:1,sigma:[],sigmas_:[],similar:0,singl:0,skip:[],slightli:[],sne:0,solut:[],some:0,space:[0,1],specc:0,specifi:[],spectral:0,split:1,springer:0,squar:0,stage:0,standard:0,start:0,statist:0,step:0,stepwis:0,stochast:0,stop:[],store:[],string:[],student:0,suppos:[],symmetr:[],task:0,techniqu:0,tell:[],ten:1,than:0,thei:[],them:[],thi:[0,1],thiiiiiiiiiiiiiiiiiiiiiii:[],those:[],thought:0,three:0,time:1,total:1,transact:0,translat:0,trendafilov:0,tsne:0,tupl:[],tutori:0,two:0,txt:1,txtfile:1,type:[],uci:0,ulrik:0,understood:0,uniqu:1,unless:[],uoc:1,updat:[],use:[],used:[0,1],uses:[],using:0,valu:1,valueerror:1,van:0,variat:[],vector:[],view:[0,1],visual:0,von:0,wai:0,weight:0,weights_:[],weiss:0,well:[],where:[],wheter:[],whether:[],which:[],whiten:[],whose:0,wih:[],work:0,written:0,yair:0,yellow:1,zero:1},titles:["Multiview learning","Multiview Spectral Clustering with multiple features"],titleterms:{"function":[],MDS:[],altern:0,cluster:1,common:[],complex:0,compon:[],cpc:[],dimension:[],distribut:[],document:[],embed:[],exampl:[],featur:1,introduct:0,learn:0,method:[],multidimension:[],multipl:1,multiview:[0,1],mvmd:0,mvsc:0,mvtsne:0,neighbour:[],packag:[],princip:[],reduct:[],refer:0,scale:[],spectral:1,stochast:[],tsne:[],use:0,using:[],welcom:[]}}) -------------------------------------------------------------------------------- /doc/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | set SPHINXPROJ=multiview 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 20 | echo.installed, then set the SPHINXBUILD environment variable to point 21 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 22 | echo.may add the Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /doc/source/README.txt: -------------------------------------------------------------------------------- 1 | 2 | General examples 3 | ---------------- 4 | 5 | General-purpose and introductory examples for the multiview. -------------------------------------------------------------------------------- /doc/source/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # multiview documentation build configuration file, created by 5 | # sphinx-quickstart on Fri Oct 20 18:41:26 2017. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | import os 21 | import sys 22 | # sys.path.insert(0, os.path.abspath('.')) 23 | sys.path.insert(0, os.path.abspath('..')) 24 | # print(sys.path) 25 | 26 | # -- General configuration ------------------------------------------------ 27 | 28 | # If your documentation needs a minimal Sphinx version, state it here. 29 | # 30 | # needs_sphinx = '1.0' 31 | 32 | # Add any Sphinx extension module names here, as strings. They can be 33 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 34 | # ones. 35 | extensions = ['sphinx.ext.autodoc', 36 | 'sphinx.ext.doctest', 37 | 'sphinx.ext.imgmath', 38 | 'sphinx.ext.ifconfig', 39 | 'sphinxcontrib.napoleon'] # , 40 | # 'sphinx_gallery.gen_gallery'] 41 | 42 | # Napoleon setting 43 | napoleon_google_docstring = True 44 | napoleon_numpy_docstring = True 45 | 46 | # Sphinx_gallery settings 47 | # sphinx_gallery_conf = { 48 | # # path to your examples scripts 49 | # 'examples_dirs' : os.path.join(os.path.abspath('..'), 'examples'), 50 | # # path where to save gallery generated examples 51 | # 'gallery_dirs': 'auto_examples', 52 | # 'backreferences_dir': False 53 | # } 54 | 55 | # Add any paths that contain templates here, relative to this directory. 56 | templates_path = ['ytemplates'] 57 | 58 | # The suffix(es) of source filenames. 59 | # You can specify multiple suffix as a list of string: 60 | # 61 | # source_suffix = ['.rst', '.md'] 62 | source_suffix = '.rst' 63 | 64 | # The master toctree document. 65 | master_doc = 'index' 66 | 67 | # General information about the project. 68 | project = 'multiview' 69 | copyright = '2017, Maria Araceli Burgueño Caballero' 70 | author = 'Maria Araceli Burgueño Caballero' 71 | 72 | # The version info for the project you're documenting, acts as replacement for 73 | # |version| and |release|, also used in various other places throughout the 74 | # built documents. 75 | # 76 | # The short X.Y version. 77 | version = '1.0' 78 | # The full version, including alpha/beta/rc tags. 79 | release = '1.0' 80 | 81 | # The language for content autogenerated by Sphinx. Refer to documentation 82 | # for a list of supported languages. 83 | # 84 | # This is also used if you do content translation via gettext catalogs. 85 | # Usually you set "language" from the command line for these cases. 86 | language = None 87 | 88 | # List of patterns, relative to source directory, that match files and 89 | # directories to ignore when looking for source files. 90 | # This patterns also effect to html_static_path and html_extra_path 91 | exclude_patterns = [] 92 | 93 | # The name of the Pygments (syntax highlighting) style to use. 94 | pygments_style = 'sphinx' 95 | 96 | # If true, `todo` and `todoList` produce output, else they produce nothing. 97 | todo_include_todos = False 98 | 99 | 100 | # -- Options for HTML output ---------------------------------------------- 101 | 102 | # The theme to use for HTML and HTML Help pages. See the documentation for 103 | # a list of builtin themes. 104 | # 105 | html_theme = 'classic' # 'alabaster' 106 | 107 | # Theme options are theme-specific and customize the look and feel of a theme 108 | # further. For a list of options available for each theme, see the 109 | # documentation. 110 | # 111 | # html_theme_options = {} 112 | 113 | # Add any paths that contain custom static files (such as style sheets) here, 114 | # relative to this directory. They are copied after the builtin static files, 115 | # so a file named "default.css" will overwrite the builtin "default.css". 116 | html_static_path = ['ystatic'] 117 | 118 | 119 | # -- Options for HTMLHelp output ------------------------------------------ 120 | 121 | # Output file base name for HTML help builder. 122 | htmlhelp_basename = 'multiviewdoc' 123 | 124 | 125 | # -- Options for LaTeX output --------------------------------------------- 126 | 127 | latex_elements = { 128 | # The paper size ('letterpaper' or 'a4paper'). 129 | # 130 | # 'papersize': 'letterpaper', 131 | 132 | # The font size ('10pt', '11pt' or '12pt'). 133 | # 134 | # 'pointsize': '10pt', 135 | 136 | # Additional stuff for the LaTeX preamble. 137 | # 138 | # 'preamble': '', 139 | 140 | # Latex figure (float) alignment 141 | # 142 | # 'figure_align': 'htbp', 143 | 'preamble': r""" 144 | \usepackage{amsmath}\usepackage{amsfonts}\usepackage{bm} 145 | \usepackage{morefloats}\usepackage{enumitem} \setlistdepth{10} 146 | """ 147 | } 148 | 149 | # Grouping the document tree into LaTeX files. List of tuples 150 | # (source start file, target name, title, 151 | # author, documentclass [howto, manual, or own class]). 152 | latex_documents = [ 153 | (master_doc, 'multiview.tex', 'multiview Documentation', 154 | 'Maria Araceli Burgueño Caballero', 'manual'), 155 | ] 156 | 157 | 158 | # -- Options for manual page output --------------------------------------- 159 | 160 | # One entry per manual page. List of tuples 161 | # (source start file, name, description, authors, manual section). 162 | man_pages = [ 163 | (master_doc, 'multiview', 'multiview Documentation', 164 | [author], 1) 165 | ] 166 | 167 | 168 | # -- Options for Texinfo output ------------------------------------------- 169 | 170 | # Grouping the document tree into Texinfo files. List of tuples 171 | # (source start file, target name, title, author, 172 | # dir menu entry, description, category) 173 | texinfo_documents = [ 174 | (master_doc, 'multiview', 'multiview Documentation', 175 | author, 'multiview', 'One line description of project.', 176 | 'Miscellaneous'), 177 | ] 178 | -------------------------------------------------------------------------------- /doc/source/cpc.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | CPC 7 | === 8 | Multiview Common Principal Components 9 | ------------------------------------- 10 | 11 | 12 | .. automodule:: multiview.cpcmv 13 | 14 | .. autoclass:: MVCPC 15 | 16 | .. automethod:: fit 17 | .. automethod:: fit_transform 18 | -------------------------------------------------------------------------------- /doc/source/cpc.rst~: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | CPC 7 | === 8 | Multiview Common Principal Components 9 | ------------------------------------- 10 | 11 | 12 | .. automodule:: cpcmv 13 | 14 | .. autoclass:: MVCPC 15 | 16 | .. automethod:: fit 17 | .. automethod:: fit_transform 18 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. multiview documentation master file, created by 2 | sphinx-quickstart on Fri Oct 20 18:41:26 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | ================== 7 | Multiview learning 8 | ================== 9 | 10 | .. toctree:: 11 | :hidden: 12 | 13 | cpc 14 | mvmds 15 | mvsc 16 | mvtsne 17 | plot_mvmds 18 | plot_mvsc 19 | plot_mvtsne 20 | 21 | 22 | 23 | Introduction 24 | ============ 25 | 26 | Given a multiview dataset with ``v`` input data matrices, multiview dimensionality 27 | reduction methods produce a single, low-dimensional projection of the input data 28 | samples, trying to maintain as much of the original information as possible. 29 | 30 | Multiview learning can be thought of as an effort to adapt some of the manifold algorithms 31 | principles to algorithms whose main inputs are multiview data. These data can be understood 32 | as different views of the same data, so it is attempted to use these views to and all their 33 | information for dimensionality reduction and spectral clustering. 34 | 35 | Methods developed here are adaptions of single view algorithms to multiview data. 36 | Also, these modules are translation from the multiview package, firstly written in 37 | R. 38 | 39 | .. _mvmds: 40 | 41 | MVMDS 42 | ===== 43 | 44 | MVMDS (Multiview Multidimensional Scaling) ia one of the approaches to dimensionality reduction that offers the class 45 | :doc:`mvmds` to perform multiview dimensionality reduction in a similar way than 46 | the multidimensional scaling method does (similar to ``cmdscale`` in R language). 47 | In general, it is a technique used for analyzing similarity or dissimilarity data. 48 | 49 | .. image:: ystatic/mvmds.png 50 | :align: center 51 | :scale: 60 52 | 53 | Complexity 54 | ---------- 55 | MVMDS computes distance matrices from plain data matrices is so and preprocesses these distance 56 | matrices (centering and double square). Lastly, it extracts commom principal components 57 | of the processed data. The overall complexity is about 58 | :math:`O[k n^2 v]`. 59 | 60 | * :math:`n`: number of samples of each view 61 | * :math:`k`: components to extract 62 | * :math:`v`: number of different views 63 | 64 | .. _mvtsne: 65 | 66 | MvtSNE 67 | ====== 68 | 69 | Another dimensionality reduction function in this package is the class :doc:`mvtsne`, that 70 | extends the ``tsne`` algorithm (available in ``manifold`` module) to work with multiview data. 71 | It based on the conversion of affinities of data to probabilities. The affinities 72 | in the original space are represented by Gaussian joint probabilities and the affinities 73 | in the embedded space are represented by Student's t-distributions. 74 | 75 | .. image:: ystatic/mvtsne-6.png 76 | :align: center 77 | :scale: 60 78 | 79 | Complexity 80 | ---------- 81 | The MvtSNE algorithm comprises two steps: 82 | 83 | 1. **Opinion pooling finding**: MvtSNE computes optimal pooling of probabilities for 84 | each view from affinities of data points. It runs an optimizer to find the best set 85 | of weights. Start point at (1/v,..) using bounds to limit the weights to 0..1. Then, 86 | it computes KL between the different probabilities. The overall complexity of opinion 87 | pooling finding is 88 | :math:`O[n^2 v^2]` + :math:`O[w n^2]`. 89 | 90 | 91 | 2. **tSNE application**: this stage applies tSNE (t-distributed Stochastic Neighbor Embedding) 92 | to the multiple views of the same data. Its complexity is about :math:`O[n^2 v m]`. 93 | 94 | The overall complexity of MvtSNE is 95 | :math:`O[n^2 v^2] + O[w n^2] + O[n^2 v m]`. 96 | 97 | * :math:`n`: number of samples of each view 98 | * :math:`v`: number of different views 99 | * :math:`w`: weights dimension 100 | * :math:`m`: input maximum iteration 101 | 102 | .. _mvsc: 103 | 104 | MVSC 105 | ==== 106 | 107 | Given a multiview dataset with ``v`` input data matrices, multiview spectral clustering (MVSC) methods 108 | produce a single clustering assignment, considering the information from all the 109 | input views. 110 | Package ``multiview`` offers the class :doc:`mvsc` to perform multiview spectral 111 | clustering. It is an extension to spectral clustering (``kernlab::specc`` in R language) 112 | to multiview datasets. 113 | 114 | Complexity 115 | ---------- 116 | Multiview spectral clustering computes the diagonal matrix of the similarity matrices. 117 | Firstly, computes distance matrices if necessary. After that, calculates laplacian matrices, 118 | extracts commom principal components and apply KMeans algorithm to obtained data. 119 | Roughly, the complexity of MVSC is 120 | :math:`O[k n^2 v] + O[n \log(n)]`. 121 | 122 | * :math:`n`: number of samples of each view 123 | * :math:`v`: number of different views 124 | * :math:`k`: components to extract 125 | 126 | 127 | Alternative use 128 | =============== 129 | 130 | Although the methods in this package have been divided in dimensionality reduction 131 | and clustering, there is a close relationship between both tasks. In fact, all three 132 | methods can be used for both tasks. 133 | 134 | First, the data projection produced by dimensionality reduction methods can be 135 | fed to a standard clustering algorithm in order to obtain a multiview clustering. 136 | Second, as mvsc also returns the projection resulting from the k first common 137 | eigenvectors in matrix $evectors, this space can also be used as a low-dimensional 138 | embedding of the original multiview data, for visualization or other purposes. 139 | 140 | .. topic:: References: 141 | 142 | * Abbas, Ali E. 2009. "A Kullback-Leibler View of Linear and Log-Linear Pools." *Decision Analysis* 143 | 6 (1): 25-37. doi:`10.1287/deca.1080.0133 `_. 144 | 145 | * Carvalho, Arthur, and Kate Larson. 2012. "A Consensual Linear Opinion Pool." 146 | http://arxiv.org/abs/1204.5399. 147 | 148 | * Kruskal, J B. 1964. "Multidimensional scaling by optimizing goodness of fit to 149 | a nonmetric hypothesis." *Psychometrika* 29 (1): 1\-27. doi:`10.1007/BF02289565 `_. 150 | 151 | * Ng, Andrew Y, Michael I Jordan, and Yair Weiss. 2001. "On spectral clustering: 152 | Analysis and an algorithm." *Nips* 14 (14). MIT Press: 849-56. 153 | 154 | * Planck, Max, and Ulrike Von Luxburg. 2006. "A Tutorial on Spectral Clustering." 155 | *Statistics and Computing* 17 (March). Springer US: 395-416. doi 156 | `10.1007/s11222-007-9033-z `_. 157 | 158 | * Shi, Jianbo, and Jitendra Malik. 2005. "Normalized Cuts and Image Segmentation 159 | Normalized Cuts and Image Segmentation." *Pattern Analysis and Machine Intelligence, IEEE Transactions* 160 | on 22 (March): 888-905. doi:`10.1109/CVPR.1997.609407 `_. 161 | 162 | * Trendafilov, Nickolay T. 2010. "Stepwise estimation of common principal 163 | components." *Computational Statistics and Data Analysis* 54 (12): 3446-57. 164 | doi:`10.1016/j.csda.2010.03.010 `_. 165 | 166 | * Van Der Maaten, Laurens, Geoffrey Hinton, and Geoffrey Hinton van der Maaten. 167 | 2008. "Visualizing Data using t-SNE." doi:`10.1007/s10479-011-0841-3 `_. 168 | 169 | * Multiview features dataset. https://archive.ics.uci.edu/ml/datasets/Multiple+Features -------------------------------------------------------------------------------- /doc/source/index.rst~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/source/index.rst~ -------------------------------------------------------------------------------- /doc/source/mvmds.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | MV-MDS 7 | ====== 8 | Multiview Multidimensional Scaling 9 | ---------------------------------- 10 | 11 | .. automodule:: multiview.mvmds 12 | 13 | .. autoclass:: MVMDS 14 | 15 | .. automethod:: fit 16 | .. automethod:: fit_transform 17 | 18 | Examples using ``MVMDS`` 19 | ------------------------ 20 | 21 | .. raw:: html 22 | 23 |
24 | 25 | .. only:: html 26 | 27 | .. figure:: ystatic/mvmds.png 28 | :width: 25% 29 | 30 | :doc:`plot_mvmds` 31 | 32 | .. raw:: html 33 | 34 |
35 | 36 | .. only:: not html 37 | 38 | * :doc:`plot_mvmds` 39 | 40 | -------------------------------------------------------------------------------- /doc/source/mvmds.rst~: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | MV-MDS 7 | ====== 8 | Multiview Multidimensional Scaling 9 | ---------------------------------- 10 | 11 | .. automodule:: multiview.mvmds 12 | 13 | .. autoclass:: MVMDS 14 | 15 | .. automethod:: fit 16 | .. automethod:: fit_transform 17 | -------------------------------------------------------------------------------- /doc/source/mvsc.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | MV-SC 7 | ====== 8 | Multiview Spectral Clustering 9 | ----------------------------- 10 | 11 | 12 | .. automodule:: multiview.mvsc 13 | 14 | .. autoclass:: MVSC 15 | 16 | .. automethod:: fit 17 | .. automethod:: fit_transform 18 | -------------------------------------------------------------------------------- /doc/source/mvsc.rst~: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | MV-SC 7 | ====== 8 | Multiview Spectral Clustering 9 | ----------------------------- 10 | 11 | 12 | .. automodule:: mvsc 13 | 14 | .. autoclass:: MVSC 15 | 16 | .. automethod:: fit 17 | .. automethod:: fit_transform 18 | -------------------------------------------------------------------------------- /doc/source/mvtsne.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | MVtSNE 7 | ====== 8 | Multiview t-distributed Stochastic Neighbour Embedding 9 | ------------------------------------------------------ 10 | 11 | 12 | .. automodule:: multiview.mvtsne 13 | 14 | .. autoclass:: MvtSNE 15 | 16 | .. automethod:: fit 17 | .. automethod:: fit_transform 18 | 19 | Examples using ``MvtSNE`` 20 | ------------------------- 21 | 22 | .. raw:: html 23 | 24 |
25 | 26 | .. only:: html 27 | 28 | .. figure:: ystatic/mvtsne-6.png 29 | :width: 25% 30 | 31 | :doc:`plot_mvtsne` 32 | 33 | .. raw:: html 34 | 35 |
36 | 37 | .. only:: not html 38 | 39 | * :doc:`plot_mvtsne` 40 | -------------------------------------------------------------------------------- /doc/source/mvtsne.rst~: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | MVtSNE 7 | ====== 8 | Multiview t-distributed Stochastic Neighbour Embedding 9 | ------------------------------------------------------ 10 | 11 | 12 | .. automodule:: multiview.mvtsne 13 | 14 | .. autoclass:: MvtSNE 15 | 16 | .. automethod:: fit 17 | .. automethod:: fit_transform 18 | -------------------------------------------------------------------------------- /doc/source/plot_mvmds.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | ==================================== 7 | Multiview MDS with multiple features 8 | ==================================== 9 | 10 | An illustration of the multiview multidimensional scaling with the multiple features 11 | data set. It consists on the scaling of four different views. 12 | 13 | Depending on the exact implementation, the result might be slightly different, 14 | the solution might be symmetric to the one shown here. 15 | 16 | .. image:: ystatic/mvmds.png 17 | :align: center 18 | 19 | .. code-block:: python 20 | 21 | # Author: Maria Araceli Burgueno Caballero 22 | 23 | import numpy as np 24 | from mvmds import MVMDS 25 | from matplotlib import pyplot as plt 26 | 27 | def readData(filename, data_type=0): 28 | """Given a txt file, returns a numpy matrix with the values, according 29 | to datatype specified in data_type parameters.""" 30 | if data_type != 0 and data_type != 1: 31 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 32 | 'instead.' % data_type) 33 | with open(filename) as txtfile: 34 | 35 | result = [] 36 | myreader = txtfile.readlines() 37 | 38 | for row in myreader: 39 | if data_type == 0: 40 | result.append([float(x) for x in row.split()]) 41 | elif data_type == 1: 42 | result.append([int(x) for x in row.split()]) 43 | if data_type == 0: 44 | return np.array(result, dtype='float') 45 | else: 46 | return np.array(result, dtype='int') 47 | 48 | 49 | fourier = readData("mfeat-fou.txt", 0) 50 | profcorr = readData("mfeat-fac.txt", 1) 51 | pixels = readData("mfeat-pix.txt", 1) 52 | morpho = readData("mfeat-mor.txt", 0) 53 | 54 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 55 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 56 | 'brown', 'yellow', 'orange', 'gray', 'red'] 57 | 58 | is_distance = [False] * 4 59 | 60 | mvmds = MVMDS() 61 | projection = mvmds.fit_transform([fourier, profcorr, pixels, morpho], 62 | is_distance, k=2) 63 | for i in range(10): 64 | plt.scatter(projection[i * 200:200 * (i + 1), 0], 65 | projection[i * 200:200 * (1 + i), 1], 66 | c=mypalette[i], marker=markers[i]) 67 | plt.axis('off') 68 | plt.show() 69 | 70 | **Total running time of the script:** ( 0 minutes 11.5 seconds) -------------------------------------------------------------------------------- /doc/source/plot_mvmds.rst~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/source/plot_mvmds.rst~ -------------------------------------------------------------------------------- /doc/source/plot_mvsc.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | ==================================================== 7 | Multiview Spectral Clustering with multiple features 8 | ==================================================== 9 | 10 | An illustration of the multiview spectral clustering with the multiple features 11 | data set. It consists on the clustering of four different views. 12 | 13 | Here it is shown the output result of an implementation of MV SC with 10 clusters. 14 | Dataset used in this examples is available 15 | `here `_. 16 | 17 | === === === === === === === === === === === 18 | I 1 2 3 4 5 6 7 8 9 10 19 | === === === === === === === === === === === 20 | 0 181 18 0 0 0 1 0 0 0 0 21 | 1 0 1 3 1 0 0 4 189 2 0 22 | 2 0 0 0 0 1 1 3 0 0 195 23 | 3 0 0 5 10 178 0 0 3 0 4 24 | 4 0 0 0 195 0 2 0 2 1 0 25 | 5 0 0 0 5 8 186 0 0 0 1 26 | 6 0 7 1 0 0 2 0 2 188 0 27 | 7 0 0 154 1 0 0 38 2 0 5 28 | 8 4 190 0 0 0 0 0 6 0 0 29 | 9 0 6 3 1 1 3 182 4 0 0 30 | === === === === === === === === === === === 31 | 32 | .. code-block:: python 33 | 34 | # Author: Maria Araceli Burgueno Caballero 35 | import numpy as np 36 | import pandas 37 | from multiview.mvsc import MVSC 38 | 39 | 40 | def readData(filename, data_type=0): 41 | if data_type != 0 and data_type != 1: 42 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 43 | 'instead.' % data_type) 44 | with open(filename) as txtfile: 45 | 46 | result = [] 47 | myreader = txtfile.readlines() 48 | 49 | for row in myreader: 50 | if data_type == 0: 51 | result.append([float(x) for x in row.split()]) 52 | elif data_type == 1: 53 | result.append([int(x) for x in row.split()]) 54 | if data_type == 0: 55 | return np.array(result, dtype='float') 56 | else: 57 | return np.array(result, dtype='int') 58 | 59 | fourier = readData("mfeat-fou.txt", 0) 60 | profcorr = readData("mfeat-fac.txt", 1) 61 | pixels = readData("mfeat-pix.txt", 1) 62 | morpho = readData("mfeat-mor.txt", 0) 63 | 64 | classes = np.array([[x] * 200 for x in range(10)]).ravel() 65 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 66 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 67 | 'brown', 'yellow', 'orange', 'gray', 'red'] 68 | 69 | distance = [False] * 4 70 | 71 | mvsc = MVSC(k=10) 72 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 73 | clustering = clust[0] 74 | labels_count = [np.unique( 75 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 76 | for i in range(10)] 77 | clustered = np.zeros((10, 10), dtype=int) 78 | for i in range(10): 79 | for index, j in enumerate(labels_count[i][0]): 80 | clustered[i, j] = labels_count[i][1][index] 81 | classes = np.arange(10) 82 | print("############################################") 83 | print("# TEN CLUSTERS #") 84 | print("############################################") 85 | print(pandas.DataFrame(clustered, classes, classes)) 86 | 87 | 88 | Here it is shown the output result of an implementation of MV SC with 10 clusters 89 | and 2 neighbours for each point in the clustering space. 90 | 91 | === === === === === === === === === === === 92 | I 1 2 3 4 5 6 7 8 9 10 93 | === === === === === === === === === === === 94 | 0 0 0 190 0 10 0 0 0 0 0 95 | 1 192 0 0 0 0 1 6 1 0 0 96 | 2 0 0 0 197 0 0 1 2 0 0 97 | 3 8 181 0 3 0 2 3 1 2 0 98 | 4 2 0 0 0 0 193 0 0 5 0 99 | 5 0 5 0 1 0 3 0 0 191 0 100 | 6 2 0 0 0 14 1 0 0 0 183 101 | 7 1 0 0 4 0 0 170 25 0 0 102 | 8 7 0 2 0 191 0 0 0 0 0 103 | 9 5 0 0 0 4 1 0 183 7 0 104 | === === === === === === === === === === === 105 | 106 | .. code-block:: python 107 | 108 | mvsc = MVSC(k=10, neighbours=2) 109 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 110 | clustering = clust[0] 111 | labels_count = [np.unique( 112 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 113 | for i in range(10)] 114 | clustered = np.zeros((10, 10), dtype=int) 115 | for i in range(10): 116 | for index, j in enumerate(labels_count[i][0]): 117 | clustered[i, j] = labels_count[i][1][index] 118 | classes = np.arange(10) 119 | print("############################################") 120 | print("# TEN CLUSTERS AND NEIGHBOURS 2 #") 121 | print("############################################") 122 | print(pandas.DataFrame(clustered, classes, classes)) 123 | 124 | **Total running time of the script:** ( 1 minutes 10.6 seconds) -------------------------------------------------------------------------------- /doc/source/plot_mvsc.rst~: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | ==================================================== 7 | Multiview Spectral Clustering with multiple features 8 | ==================================================== 9 | 10 | An illustration of the multiview spectral clustering with the multiple features 11 | data set. It consists on the clustering of four different views. 12 | 13 | Here it is shown the output result of an implementation of MV SC with 10 clusters. 14 | Dataset used in this examples is available 15 | `here `_ 16 | 17 | === === === === === === === === === === === 18 | I 1 2 3 4 5 6 7 8 9 10 19 | === === === === === === === === === === === 20 | 0 181 18 0 0 0 1 0 0 0 0 21 | 1 0 1 3 1 0 0 4 189 2 0 22 | 2 0 0 0 0 1 1 3 0 0 195 23 | 3 0 0 5 10 178 0 0 3 0 4 24 | 4 0 0 0 195 0 2 0 2 1 0 25 | 5 0 0 0 5 8 186 0 0 0 1 26 | 6 0 7 1 0 0 2 0 2 188 0 27 | 7 0 0 154 1 0 0 38 2 0 5 28 | 8 4 190 0 0 0 0 0 6 0 0 29 | 9 0 6 3 1 1 3 182 4 0 0 30 | === === === === === === === === === === === 31 | 32 | .. code-block:: python 33 | 34 | # Author: Maria Araceli Burgueno Caballero 35 | import numpy as np 36 | import pandas 37 | from multiview.mvsc import MVSC 38 | 39 | 40 | def readData(filename, data_type=0): 41 | if data_type != 0 and data_type != 1: 42 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 43 | 'instead.' % data_type) 44 | with open(filename) as txtfile: 45 | 46 | result = [] 47 | myreader = txtfile.readlines() 48 | 49 | for row in myreader: 50 | if data_type == 0: 51 | result.append([float(x) for x in row.split()]) 52 | elif data_type == 1: 53 | result.append([int(x) for x in row.split()]) 54 | if data_type == 0: 55 | return np.array(result, dtype='float') 56 | else: 57 | return np.array(result, dtype='int') 58 | 59 | fourier = readData("mfeat-fou.txt", 0) 60 | profcorr = readData("mfeat-fac.txt", 1) 61 | pixels = readData("mfeat-pix.txt", 1) 62 | morpho = readData("mfeat-mor.txt", 0) 63 | 64 | classes = np.array([[x] * 200 for x in range(10)]).ravel() 65 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 66 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 67 | 'brown', 'yellow', 'orange', 'gray', 'red'] 68 | 69 | distance = [False] * 4 70 | 71 | mvsc = MVSC(k=10) 72 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 73 | clustering = clust[0] 74 | labels_count = [np.unique( 75 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 76 | for i in range(10)] 77 | clustered = np.zeros((10, 10), dtype=int) 78 | for i in range(10): 79 | for index, j in enumerate(labels_count[i][0]): 80 | clustered[i, j] = labels_count[i][1][index] 81 | classes = np.arange(10) 82 | print("############################################") 83 | print("# TEN CLUSTERS #") 84 | print("############################################") 85 | print(pandas.DataFrame(clustered, classes, classes)) 86 | 87 | 88 | Here it is shown the output result of an implementation of MV SC with 10 clusters 89 | and 2 neighbours for each point in the clustering space. 90 | 91 | === === === === === === === === === === === 92 | I 1 2 3 4 5 6 7 8 9 10 93 | === === === === === === === === === === === 94 | 0 0 0 190 0 10 0 0 0 0 0 95 | 1 192 0 0 0 0 1 6 1 0 0 96 | 2 0 0 0 197 0 0 1 2 0 0 97 | 3 8 181 0 3 0 2 3 1 2 0 98 | 4 2 0 0 0 0 193 0 0 5 0 99 | 5 0 5 0 1 0 3 0 0 191 0 100 | 6 2 0 0 0 14 1 0 0 0 183 101 | 7 1 0 0 4 0 0 170 25 0 0 102 | 8 7 0 2 0 191 0 0 0 0 0 103 | 9 5 0 0 0 4 1 0 183 7 0 104 | === === === === === === === === === === === 105 | 106 | .. code-block:: python 107 | 108 | mvsc = MVSC(k=10, neighbours=2) 109 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 110 | clustering = clust[0] 111 | labels_count = [np.unique( 112 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 113 | for i in range(10)] 114 | clustered = np.zeros((10, 10), dtype=int) 115 | for i in range(10): 116 | for index, j in enumerate(labels_count[i][0]): 117 | clustered[i, j] = labels_count[i][1][index] 118 | classes = np.arange(10) 119 | print("############################################") 120 | print("# TEN CLUSTERS AND NEIGHBOURS 2 #") 121 | print("############################################") 122 | print(pandas.DataFrame(clustered, classes, classes)) 123 | 124 | **Total running time of the script:** ( 1 minutes 10.6 seconds) -------------------------------------------------------------------------------- /doc/source/plot_mvtsne.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :maxdepth: 2 4 | :caption: Contents: 5 | 6 | ===================================== 7 | Multiview tSNE with multiple features 8 | ===================================== 9 | 10 | An illustration of the multiview tSNE with the multiple features 11 | data set. Dataset is split into four different views. 12 | 13 | Depending on the random values or the RandomState given as a parameter, the implementation 14 | will be different each different running. 15 | 16 | 17 | .. image:: ystatic/mvtsne-6.png 18 | :align: center 19 | 20 | .. code-block:: python 21 | 22 | # Author: Maraa Araceli Burgueno Caballero 23 | 24 | import numpy as np 25 | from matplotlib import pyplot as plt 26 | from multiview.mvtsne import MvtSNE 27 | 28 | def readData(filename, data_type=0): 29 | """Given a txt file, returns a numpy matrix with the values, according 30 | to datatype specified in data_type parameters.""" 31 | if data_type != 0 and data_type != 1: 32 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 33 | 'instead.' % data_type) 34 | with open(filename) as txtfile: 35 | 36 | result = [] 37 | myreader = txtfile.readlines() 38 | 39 | for row in myreader: 40 | if data_type == 0: 41 | result.append([float(x) for x in row.split()]) 42 | elif data_type == 1: 43 | result.append([int(x) for x in row.split()]) 44 | if data_type == 0: 45 | return np.array(result, dtype='float') 46 | else: 47 | return np.array(result, dtype='int') 48 | 49 | 50 | fourier = readData("mfeat-fou.txt", 0) 51 | profcorr = readData("mfeat-fac.txt", 1) 52 | pixels = readData("mfeat-pix.txt", 1) 53 | morpho = readData("mfeat-mor.txt", 0) 54 | 55 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 56 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 57 | 'brown', 'yellow', 'orange', 'gray', 'red'] 58 | 59 | is_distance = [False] * 4 60 | 61 | mvtsne = MvtSNE() 62 | projection = mvtsne.fit_transform([fourier, profcorr, pixels, morpho], 63 | is_distance, k=2) 64 | for i in range(10): 65 | plt.scatter(projection[i * 200:200 * (i + 1), 0], 66 | projection[i * 200:200 * (1 + i), 1], 67 | c=mypalette[i], marker=markers[i]) 68 | plt.axis('off') 69 | plt.show() 70 | 71 | **Total running time of the script:** ( 3 minutes 46.4 seconds) -------------------------------------------------------------------------------- /doc/source/plot_mvtsne.rst~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/source/plot_mvtsne.rst~ -------------------------------------------------------------------------------- /doc/source/ystatic/mvmds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/source/ystatic/mvmds.png -------------------------------------------------------------------------------- /doc/source/ystatic/mvtsne-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/doc/source/ystatic/mvtsne-6.png -------------------------------------------------------------------------------- /examples/README.txt: -------------------------------------------------------------------------------- 1 | 2 | General examples 3 | ---------------- 4 | 5 | General-purpose and introductory examples for the multiview. -------------------------------------------------------------------------------- /examples/__pycache__/cpcmv.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/examples/__pycache__/cpcmv.cpython-36.pyc -------------------------------------------------------------------------------- /examples/__pycache__/mvmds.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/examples/__pycache__/mvmds.cpython-36.pyc -------------------------------------------------------------------------------- /examples/__pycache__/mvsc.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/examples/__pycache__/mvsc.cpython-36.pyc -------------------------------------------------------------------------------- /examples/__pycache__/mvtsne.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/examples/__pycache__/mvtsne.cpython-36.pyc -------------------------------------------------------------------------------- /examples/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/examples/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /examples/plot_mvmds.py: -------------------------------------------------------------------------------- 1 | """ 2 | ============= 3 | Multiview MDS 4 | ============= 5 | 6 | An example plot of multiview MDS, using multiples views from same data thanks 7 | to data given in `UCI Machine Learning Repository 8 | `_. 9 | """ 10 | import numpy as np 11 | from matplotlib import pyplot as plt 12 | from multiview.mvmds import MVMDS 13 | 14 | 15 | def readData(filename, data_type=0): 16 | """ 17 | Given a txt file, returns a numpy matrix with the values, according 18 | to datatype specified in data_type parameters. 19 | 20 | Parameters 21 | ---------- 22 | filename: string 23 | Path or name of the txt file. 24 | data_type: integer, default 0 25 | Specifies the matrix datatype. If data_type is 0, data loaded will be 26 | float type. If data_type is 1, matrix datatype will be float. 27 | 28 | Returns 29 | ------- 30 | output: ndarray 31 | Matrix with data loaded. 32 | """ 33 | if data_type != 0 and data_type != 1: 34 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 35 | 'instead.' % data_type) 36 | with open(filename) as txtfile: 37 | 38 | result = [] 39 | myreader = txtfile.readlines() 40 | 41 | for row in myreader: 42 | if data_type == 0: 43 | result.append([float(x) for x in row.split()]) 44 | elif data_type == 1: 45 | result.append([int(x) for x in row.split()]) 46 | if data_type == 0: 47 | return np.array(result, dtype='float') 48 | else: 49 | return np.array(result, dtype='int') 50 | 51 | 52 | ##################################################### 53 | 54 | fourier = readData("mfeat-fou.txt", 0) 55 | profcorr = readData("mfeat-fac.txt", 1) 56 | pixels = readData("mfeat-pix.txt", 1) 57 | morpho = readData("mfeat-mor.txt", 0) 58 | 59 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 60 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 61 | 'brown', 'yellow', 'orange', 'gray', 'red'] 62 | 63 | is_distance = [False] * 4 64 | 65 | mvmds = MVMDS(k=2) 66 | projection = mvmds.fit_transform([fourier, profcorr, pixels, morpho], 67 | is_distance) 68 | # print(projection) 69 | for i in range(10): 70 | plt.scatter(projection[i * 200:200 * (i + 1), 0], 71 | projection[i * 200:200 * (1 + i), 1], 72 | c=mypalette[i], marker=markers[i]) 73 | plt.axis('off') 74 | plt.show() 75 | -------------------------------------------------------------------------------- /examples/plot_mvsc.py: -------------------------------------------------------------------------------- 1 | """ 2 | ============================= 3 | Multiview Spectral Clustering 4 | ============================= 5 | 6 | An example plot of multiview Spectral Clustering, using multiples views from 7 | same data thanks data given in `UCI Machine Learning Repository 8 | `_. 9 | """ 10 | import numpy as np 11 | import pandas 12 | from multiview.mvsc import MVSC 13 | 14 | 15 | def readData(filename, data_type=0): 16 | """ 17 | Given a txt file, returns a numpy matrix with the values, according 18 | to datatype specified in data_type parameters. 19 | 20 | Parameters 21 | ---------- 22 | filename: string 23 | Path or name of the txt file. 24 | data_type: integer, default 0 25 | Specifies the matrix datatype. If data_type is 0, data loaded will be 26 | float type. If data_type is 1, matrix datatype will be float. 27 | 28 | Returns 29 | ------- 30 | output: ndarray 31 | Matrix with data loaded. 32 | """ 33 | if data_type != 0 and data_type != 1: 34 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 35 | 'instead.' % data_type) 36 | with open(filename) as txtfile: 37 | 38 | result = [] 39 | myreader = txtfile.readlines() 40 | 41 | for row in myreader: 42 | if data_type == 0: 43 | result.append([float(x) for x in row.split()]) 44 | elif data_type == 1: 45 | result.append([int(x) for x in row.split()]) 46 | if data_type == 0: 47 | return np.array(result, dtype='float') 48 | else: 49 | return np.array(result, dtype='int') 50 | 51 | 52 | ##################################################### 53 | 54 | fourier = readData("mfeat-fou.txt", 0) 55 | profcorr = readData("mfeat-fac.txt", 1) 56 | pixels = readData("mfeat-pix.txt", 1) 57 | morpho = readData("mfeat-mor.txt", 0) 58 | 59 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 60 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 61 | 'brown', 'yellow', 'orange', 'gray', 'red'] 62 | 63 | distance = [False] * 4 64 | 65 | # Ten clusters 66 | mvsc = MVSC(k=10) 67 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 68 | clustering = clust[0] 69 | labels_count = [np.unique( 70 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 71 | for i in range(10)] 72 | clustered = np.zeros((10, 10), dtype=int) 73 | for i in range(10): 74 | for index, j in enumerate(labels_count[i][0]): 75 | clustered[i, j] = labels_count[i][1][index] 76 | classes = np.arange(10) 77 | print("############################################") 78 | print("# TEN CLUSTERS #") 79 | print("############################################") 80 | print(pandas.DataFrame(clustered, classes, classes)) 81 | 82 | # Ten clusters and neighbours 2 83 | mvsc = MVSC(k=10, neighbours=2) 84 | clust = mvsc.fit_transform([fourier, profcorr, pixels, morpho], distance) 85 | clustering = clust[0] 86 | labels_count = [np.unique( 87 | clustering[200 * i: 200 * (i + 1)], return_counts=True) 88 | for i in range(10)] 89 | clustered = np.zeros((10, 10), dtype=int) 90 | for i in range(10): 91 | for index, j in enumerate(labels_count[i][0]): 92 | clustered[i, j] = labels_count[i][1][index] 93 | classes = np.arange(10) 94 | print("############################################") 95 | print("# TEN CLUSTERS AND NEIGHBOURS 2 #") 96 | print("############################################") 97 | print(pandas.DataFrame(clustered, classes, classes)) 98 | -------------------------------------------------------------------------------- /examples/plot_mvtsne.py: -------------------------------------------------------------------------------- 1 | """ 2 | ============== 3 | Multiview tSNE 4 | ============== 5 | 6 | An example plot of multiview tSNE, using multiples views from same data thanks 7 | to data given in `UCI Machine Learning Repository 8 | `_. 9 | """ 10 | 11 | import numpy as np 12 | from matplotlib import pyplot as plt 13 | from multiview.mvtsne import MvtSNE 14 | 15 | 16 | def readData(filename, data_type=0): 17 | """ 18 | Given a txt file, returns a numpy matrix with the values, according 19 | to datatype specified in data_type parameters. 20 | 21 | Parameters 22 | ---------- 23 | filename: string 24 | Path or name of the txt file. 25 | data_type: integer, default 0 26 | Specifies the matrix datatype. If data_type is 0, data loaded will be 27 | float type. If data_type is 1, matrix datatype will be float. 28 | 29 | Returns 30 | ------- 31 | output: ndarray 32 | Matrix with data loaded. 33 | """ 34 | if data_type != 0 and data_type != 1: 35 | raise ValueError('data_type must be either 0 or 1. Found value %d ' 36 | 'instead.' % data_type) 37 | with open(filename) as txtfile: 38 | 39 | result = [] 40 | myreader = txtfile.readlines() 41 | 42 | for row in myreader: 43 | if data_type == 0: 44 | result.append([float(x) for x in row.split()]) 45 | elif data_type == 1: 46 | result.append([int(x) for x in row.split()]) 47 | if data_type == 0: 48 | return np.array(result, dtype='float') 49 | else: 50 | return np.array(result, dtype='int') 51 | 52 | 53 | ##################################################### 54 | 55 | fourier = readData("mfeat-fou.txt", 0) 56 | profcorr = readData("mfeat-fac.txt", 1) 57 | pixels = readData("mfeat-pix.txt", 1) 58 | morpho = readData("mfeat-mor.txt", 0) 59 | 60 | markers = ['o', '2', '<', '*', 'h', 'x', 'D', '|', '_', 'v'] 61 | mypalette = ['green', 'purple', 'pink', 'blue', 'black', 62 | 'brown', 'yellow', 'orange', 'gray', 'red'] 63 | 64 | distance = [False] * 4 65 | 66 | mvtsne = MvtSNE(k=2) 67 | projection = mvtsne.fit_transform( 68 | [fourier, profcorr, pixels, morpho], distance) 69 | 70 | projection = projection[0] 71 | for i in range(10): 72 | plt.scatter(projection[i * 200:200 * (i + 1), 0], 73 | projection[i * 200:200 * (1 + i), 1], 74 | c=mypalette[i], marker=markers[i]) 75 | plt.axis('off') 76 | plt.show() 77 | -------------------------------------------------------------------------------- /multiview.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.1 2 | Name: multiview 3 | Version: 1.0 4 | Summary: Multiview clustering and dimensionality reduction 5 | Home-page: http:// 6 | Author: María Araceli Burgueño Caballero 7 | Author-email: mburgueno@uoc.edu 8 | License: UNKNOWN 9 | Download-URL: http:// 10 | Description-Content-Type: UNKNOWN 11 | Description: 12 | Multiview clustering and dimensionality reduction 13 | ------------------------------------------------- 14 | The ``multiview`` package provides multiview methods to work with 15 | multiview data (datasets with several data matrices from the same 16 | samples). It contains methods for multiview dimensionality reduction 17 | and methods for multiview clustering. 18 | 19 | Multiview dimensionality reduction 20 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 | Given a multiview dataset with ``v`` input data matrices,multiview 22 | dimensionality reduction methods produce a single, low-dimensional 23 | projection of the input data samples, trying to mantain as much of the 24 | original information as possible. 25 | 26 | Package ``multiview`` offers the function :doc:`mvmds` to perform multiview 27 | dimensionality reduction in a similar way than the multidimensional scaling 28 | method (cmdscale in R). 29 | 30 | Another dimensionality reduction function in this package is :doc:`mvtsne`, 31 | that extends ``tsne`` in R to multiview data. 32 | 33 | Multiview clustering 34 | ~~~~~~~~~~~~~~~~~~~~ 35 | Given a multiview dataset with ``v`` input data matrices, multiview 36 | clustering methods produce a single clustering assignment, considering 37 | the information from all the input views. 38 | Package ``multiview`` offers the function :doc:`mvsc` to perform multiview 39 | spectral clustering. It is an extension to spectral clustering 40 | (``kernlab::specc`` in R) to multiview datasets. 41 | 42 | Keywords: multiview,clustering,dimensionality reduction 43 | Platform: UNKNOWN 44 | Classifier: Programming Language :: Python 45 | Classifier: Programming Language :: Python :: 2 46 | Classifier: Programming Language :: Python :: 2.7 47 | Classifier: Programming Language :: Python :: 3 48 | Classifier: Programming Language :: Python :: 3.4 49 | Classifier: Programming Language :: Python :: 3.5 50 | Classifier: Programming Language :: Python :: 3.6 51 | Classifier: Development Status :: 3 - Alpha 52 | Classifier: Environment :: Other Environment 53 | Classifier: Intended Audience :: Developers 54 | Classifier: Intended Audience :: Science/Research 55 | Classifier: License :: OSI Approved :: Python Software Foundation License 56 | Classifier: Operating System :: OS Independent 57 | Classifier: Topic :: Software Development :: Libraries :: Python Modules 58 | Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence 59 | -------------------------------------------------------------------------------- /multiview.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | MANIFEST.in 2 | setup.py 3 | doc/Makefile 4 | doc/make.bat 5 | doc/build/doctrees/cpc.doctree 6 | doc/build/doctrees/environment.pickle 7 | doc/build/doctrees/index.doctree 8 | doc/build/doctrees/mvmds.doctree 9 | doc/build/doctrees/mvsc.doctree 10 | doc/build/doctrees/mvtsne.doctree 11 | doc/build/doctrees/plot_mvmds.doctree 12 | doc/build/doctrees/plot_mvsc.doctree 13 | doc/build/doctrees/plot_mvtsne.doctree 14 | doc/build/html/.buildinfo 15 | doc/build/html/cpc.html 16 | doc/build/html/genindex.html 17 | doc/build/html/index.html 18 | doc/build/html/mvmds.html 19 | doc/build/html/mvsc.html 20 | doc/build/html/mvtsne.html 21 | doc/build/html/objects.inv 22 | doc/build/html/plot_mvmds.html 23 | doc/build/html/plot_mvsc.html 24 | doc/build/html/plot_mvtsne.html 25 | doc/build/html/py-modindex.html 26 | doc/build/html/search.html 27 | doc/build/html/searchindex.js 28 | doc/build/html/_images/mvmds.png 29 | doc/build/html/_images/mvtsne-6.png 30 | doc/build/html/_sources/cpc.rst.txt 31 | doc/build/html/_sources/index.rst.txt 32 | doc/build/html/_sources/mvmds.rst.txt 33 | doc/build/html/_sources/mvsc.rst.txt 34 | doc/build/html/_sources/mvtsne.rst.txt 35 | doc/build/html/_sources/plot_mvmds.rst.txt 36 | doc/build/html/_sources/plot_mvsc.rst.txt 37 | doc/build/html/_sources/plot_mvtsne.rst.txt 38 | doc/build/html/_static/ajax-loader.gif 39 | doc/build/html/_static/alabaster.css 40 | doc/build/html/_static/basic.css 41 | doc/build/html/_static/classic.css 42 | doc/build/html/_static/comment-bright.png 43 | doc/build/html/_static/comment-close.png 44 | doc/build/html/_static/comment.png 45 | doc/build/html/_static/contents.png 46 | doc/build/html/_static/custom.css 47 | doc/build/html/_static/doctools.js 48 | doc/build/html/_static/down-pressed.png 49 | doc/build/html/_static/down.png 50 | doc/build/html/_static/file.png 51 | doc/build/html/_static/jquery-3.1.0.js 52 | doc/build/html/_static/jquery.js 53 | doc/build/html/_static/minus.png 54 | doc/build/html/_static/mvmds.png 55 | doc/build/html/_static/mvtsne-6.png 56 | doc/build/html/_static/nature.css 57 | doc/build/html/_static/navigation.png 58 | doc/build/html/_static/plus.png 59 | doc/build/html/_static/pygments.css 60 | doc/build/html/_static/searchtools.js 61 | doc/build/html/_static/sidebar.js 62 | doc/build/html/_static/sphinxdoc.css 63 | doc/build/html/_static/underscore-1.3.1.js 64 | doc/build/html/_static/underscore.js 65 | doc/build/html/_static/up-pressed.png 66 | doc/build/html/_static/up.png 67 | doc/build/html/_static/websupport.js 68 | doc/source/README.txt 69 | doc/source/conf.py 70 | doc/source/cpc.rst 71 | doc/source/cpc.rst~ 72 | doc/source/index.rst 73 | doc/source/index.rst~ 74 | doc/source/mvmds.rst 75 | doc/source/mvmds.rst~ 76 | doc/source/mvsc.rst 77 | doc/source/mvsc.rst~ 78 | doc/source/mvtsne.rst 79 | doc/source/mvtsne.rst~ 80 | doc/source/plot_mvmds.rst 81 | doc/source/plot_mvsc.rst 82 | doc/source/plot_mvtsne.rst 83 | doc/source/ystatic/mvmds.png 84 | doc/source/ystatic/mvtsne-6.png 85 | examples/README.txt 86 | examples/mfeat-fac.txt 87 | examples/mfeat-fou.txt 88 | examples/mfeat-mor.txt 89 | examples/mfeat-pix.txt 90 | examples/plot_mvmds.py 91 | examples/plot_mvsc.py 92 | examples/plot_mvtsne.py 93 | examples/__pycache__/cpcmv.cpython-36.pyc 94 | examples/__pycache__/mvmds.cpython-36.pyc 95 | examples/__pycache__/mvsc.cpython-36.pyc 96 | examples/__pycache__/mvtsne.cpython-36.pyc 97 | examples/__pycache__/utils.cpython-36.pyc 98 | multiview/__init__.py 99 | multiview/cpcmv.py 100 | multiview/mvmds.py 101 | multiview/mvsc.py 102 | multiview/mvtsne.py 103 | multiview/utils.py 104 | multiview.egg-info/PKG-INFO 105 | multiview.egg-info/SOURCES.txt 106 | multiview.egg-info/dependency_links.txt 107 | multiview.egg-info/not-zip-safe 108 | multiview.egg-info/top_level.txt 109 | multiview/tests/__init__.py 110 | multiview/tests/test_cpcmv.py 111 | multiview/tests/test_mvmds.py 112 | multiview/tests/test_mvsc.py 113 | multiview/tests/test_mvtsne.py 114 | multiview/tests/test_utils.py -------------------------------------------------------------------------------- /multiview.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /multiview.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /multiview.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | examples 2 | multiview 3 | -------------------------------------------------------------------------------- /multiview/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | The package implements multiview data techniques. 3 | """ 4 | 5 | from .cpcmv import MVCPC 6 | from .mvmds import MVMDS 7 | from .mvsc import MVSC 8 | from .mvtsne import MvtSNE 9 | 10 | __all__ = ['MVCPC', 'MVMDS', 'MVSC', 'MvtSNE'] 11 | -------------------------------------------------------------------------------- /multiview/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/__pycache__/cpc_mv.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/__pycache__/cpc_mv.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/__pycache__/cpcmv.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/__pycache__/cpcmv.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/__pycache__/mvmds.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/__pycache__/mvmds.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/__pycache__/mvsc.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/__pycache__/mvsc.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/__pycache__/mvtsne.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/__pycache__/mvtsne.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/cpcmv.py: -------------------------------------------------------------------------------- 1 | """ 2 | CPC computes Common principal components of a set of matrices. 3 | 4 | This file uses a variation of Trendafilov (2010) method to compute 5 | the k first common principal components of a set of matrices in an 6 | efficient way 7 | """ 8 | 9 | import numpy as np 10 | import warnings 11 | from sklearn.base import BaseEstimator 12 | import scipy.sparse.linalg as sparse 13 | 14 | 15 | def cpc(x, k=0): 16 | # Adapt parameter names to those used by Trendafilov on his code 17 | n_g = np.array([x.shape[1]] * x.shape[0]) 18 | p = x.shape[1] 19 | # Shape of matrix is consider as number of matrices, number of rows and 20 | # number of colums. 21 | mcas = x.shape[0] 22 | iterator = 15 23 | n = n_g / np.sum(n_g) 24 | D = np.zeros((k, mcas)) 25 | CPC = np.zeros((p, k)) 26 | Qw = np.eye(p) 27 | 28 | s = np.zeros((p, p)) 29 | for m in np.arange(mcas): 30 | s += (n[m] * x[m]) 31 | # end of mcas for 32 | 33 | if k == p: 34 | res_vals, res_vectors = np.linalg.eigh(s) 35 | else: 36 | res_vals, res_vectors = sparse.eigsh(s, k=k) 37 | q0 = res_vectors[:, ::-1] 38 | 39 | for ncomp in np.arange(k): 40 | q = q0[:, ncomp] 41 | q = np.array(q0[:, ncomp]).reshape(len(q), 1) 42 | d = np.zeros((1, mcas)) 43 | for m in np.arange(mcas): 44 | d[:, m] = np.dot(np.dot(q.T, x[m]), q) 45 | 46 | # Second for-loop 47 | for _ in np.arange(iterator): 48 | s = np.zeros((p, p)) 49 | for m in np.arange(mcas): 50 | s += (n_g[m] * x[m] / d[:, m]) 51 | 52 | w = np.dot(s, q) 53 | if ncomp != 0: 54 | w = np.dot(Qw, w) 55 | 56 | # Presumably, the dot function return only one value 57 | q = w / np.sqrt(np.dot(w.T, w)) 58 | for m in np.arange(mcas): 59 | d[:, m] = np.dot(np.dot(q.T, x[m]), q) 60 | # end of loop for iter 61 | 62 | D[ncomp, :] = d 63 | CPC[:, ncomp] = q[:, 0] 64 | Qw -= np.dot(q, q.T) 65 | # end of loop ncomp 66 | return (D, CPC) 67 | 68 | 69 | class MVCPC(BaseEstimator): 70 | """Compute common principal components of x. 71 | 72 | Parameters 73 | ---------- 74 | 75 | k : int, default 0 76 | Number of components to extract (0 means all p components). 77 | 78 | Attributes 79 | ---------- 80 | eigenvalues_ : ndarray 81 | Stores the eigenvalues computed in the algorithm. 82 | eigenvectors_ : ndarray 83 | Stores the eigenvectors computed in the algorithm. 84 | 85 | References 86 | ---------- 87 | 88 | Trendafilov, N. (2010). Stepwise estimation of common principal 89 | components. *Computational Statistics and Data Analysis*, 54, 90 | 3446–3457. 91 | """ 92 | 93 | def __init__(self, k=0): 94 | self.k = k 95 | 96 | def fit(self, x): 97 | """Compute k common principal components of x. 98 | 99 | Parameters 100 | ---------- 101 | 102 | x : array_like or ndarray 103 | A set of n matrices of dimension pxp given as a n x p x p matrix. 104 | 105 | """ 106 | self.fit_transform(x) 107 | return self 108 | 109 | def fit_transform(self, x): 110 | """Compute k common principal components of x, and return those 111 | components. 112 | 113 | Parameters 114 | ---------- 115 | 116 | x : array_like or ndarray 117 | A set of n matrices of dimension pxp given as a n x p x p matrix. 118 | 119 | Returns 120 | ------- 121 | values : tuple 122 | Tuple with two elements: 123 | 124 | the eigenvalues 125 | 126 | the common eigenvectors 127 | 128 | Raises 129 | ------ 130 | 131 | ValueError: Matrices are not square matrices or k value is 132 | negative. 133 | 134 | Examples 135 | -------- 136 | 137 | >>> import numpy as np 138 | >>> x = np.array([[[2, 1, 8], [4, 5, 6], [3, 7, 9]], 139 | [[1, 4, 7], [2, 5, 8], [3, 6, 9]]]) 140 | >>> mv_cpc = MVCPC(k=3) 141 | >>> mv_cpc.fit_transform(x) 142 | (array([[ 16.09601677, 16.21849616], 143 | [ -0.11903382, -0.85516505], 144 | [ 0.02301705, -0.3633311 ]]), 145 | array([[ 0.45139369, -0.88875921, 0.07969196], 146 | [ 0.55811719, 0.35088538, 0.75192065], 147 | [ 0.69623914, 0.29493478, -0.65441923]])) 148 | >>> 149 | """ 150 | 151 | if x.shape[1] != x.shape[2]: 152 | raise ValueError("matrices have different size from mx n x n. " 153 | "Size found instead is %d x %d x %d" % x.shape) 154 | if self.k == 0: 155 | # If k is 0 then retrieve all the components 156 | self.k = x.shape[1] 157 | elif self.k > x.shape[1]: 158 | self.k = x.shape[1] 159 | warnings.warn("k is greater than matrix dimension. Maximum " 160 | "possible number of components is computed instead.") 161 | elif self.k < 0: 162 | raise ValueError("k value must be between 0 and number of samples" 163 | " of data matrix.") 164 | D, CPC = cpc(x, self.k) 165 | self.eigenvalues_ = D 166 | self.eigenvectors_ = CPC 167 | return (self.eigenvalues_, self.eigenvectors_) 168 | -------------------------------------------------------------------------------- /multiview/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/tests/__init__.py -------------------------------------------------------------------------------- /multiview/tests/__pycache__/cpcmv.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/tests/__pycache__/cpcmv.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/tests/__pycache__/mvmds.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/tests/__pycache__/mvmds.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/tests/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariceli3/multiview/d2eb795ccd0e9a251b1c3e07538494b7946f9c7d/multiview/tests/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /multiview/tests/test_cpcmv.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy.testing import assert_array_almost_equal 3 | from sklearn.utils.testing import assert_raises 4 | import multiview.cpcmv as cpcmv 5 | 6 | 7 | def test_cpc(): 8 | data = np.arange(50, dtype=float).reshape((2, 5, 5)) 9 | eigenvalues, eigenvectors = cpcmv.cpc(data, k=2) 10 | 11 | real_eigenvalues = np.array([[66.60954262, 176.89090037], 12 | [-6.60954262, 8.10909963]]) 13 | real_eigenvectors = np.array([[0.20303518, 0.74751369], 14 | [0.31154745, 0.45048661], 15 | [0.42005972, 0.15345953], 16 | [0.528572, -0.14356755], 17 | [0.63708427, -0.44059463]]) 18 | 19 | assert_array_almost_equal(eigenvalues, real_eigenvalues, decimal=4) 20 | assert_array_almost_equal(eigenvectors, real_eigenvectors, decimal=4) 21 | 22 | 23 | def test_cpc_error(): 24 | # k value cannot be negative 25 | data = np.arange(40, dtype=float).reshape((2, 5, 4)) 26 | cpc_est = cpcmv.MVCPC(k=-2) 27 | assert_raises(ValueError, cpc_est.fit, data) 28 | # Second and third dimensions must be equal 29 | cpc_est = cpcmv.MVCPC(k=2) 30 | assert_raises(ValueError, cpc_est.fit, data) 31 | 32 | 33 | def test_cpcmv(): 34 | data = np.arange(50, dtype=float).reshape((2, 5, 5)) 35 | 36 | cpc_est = cpcmv.MVCPC(k=2) 37 | cpc_est.fit(data) 38 | -------------------------------------------------------------------------------- /multiview/tests/test_mvmds.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy.testing import assert_array_almost_equal 3 | from sklearn.utils.testing import assert_raises 4 | import multiview.mvmds as mvmds 5 | 6 | 7 | def test_preprocess_mds(): 8 | data = np.arange(25, dtype=float).reshape((5, 5)) 9 | preprocessed_data = mvmds.preprocess_mvmds(data) 10 | 11 | sim = np.array([[40., 20., 0., -20., -40.], 12 | [20., 10., 0., -10., -20.], 13 | [0., 0., 0., 0., 0.], 14 | [-20., -10., 0., 10., 20.], 15 | [-40., -20., 0., 20., 40.]]) 16 | 17 | assert_array_almost_equal(preprocessed_data, sim, decimal=3) 18 | 19 | 20 | def test_mvmds_error(): 21 | # Data and is_distane do not have the same length. 22 | one = np.arange(25, dtype=float).reshape((5, 5)) 23 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 24 | data = [one, two] 25 | is_distance = [False, False, False] 26 | 27 | mvmds_est = mvmds.MVMDS(k=2) 28 | assert_raises(ValueError, mvmds_est.fit, data, is_distance) 29 | 30 | # Sample data matrices do not have the same number of rows 31 | one = np.arange(25, dtype=float).reshape((5, 5)) 32 | two = np.arange(25, 49, dtype=float).reshape((4, 6)) 33 | data = [one, two] 34 | is_distance = [False, False] 35 | 36 | mvmds_est = mvmds.MVMDS(k=2) 37 | assert_raises(ValueError, mvmds_est.fit, data, is_distance) 38 | 39 | # k value cannot be negative 40 | one = np.arange(25, dtype=float).reshape((5, 5)) 41 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 42 | data = [one, two] 43 | is_distance = [False, False] 44 | 45 | mvmds_est = mvmds.MVMDS(k=-2) 46 | assert_raises(ValueError, mvmds_est.fit, data, is_distance) 47 | 48 | 49 | def test_mvmds(): 50 | one = np.arange(25, dtype=float).reshape((5, 5)) 51 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 52 | data = [one, two] 53 | is_distance = [False, False] 54 | 55 | mvmds_est = mvmds.MVMDS(k=2) 56 | mvmds_est.fit(data, is_distance) 57 | -------------------------------------------------------------------------------- /multiview/tests/test_mvsc.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy.testing import assert_array_almost_equal 3 | from sklearn.utils.testing import assert_raises 4 | import multiview.mvsc as mvsc 5 | 6 | 7 | def test_laplacian_ng(): 8 | data = np.arange(25, dtype=float).reshape((5, 5)) 9 | laplacian = mvsc.laplacian_ng(data) 10 | 11 | real_laplacian = np.array([[0., 0.0534, 0.0816, 0.1028, 0.1206], 12 | [0.2672, 0.1714, 0.1527, 0.1466, 0.1450], 13 | [0.4082, 0.2400, 0.2, 0.1820, 0.1723], 14 | [0.5144, 0.2933, 0.2380, 0.2117, 0.1964], 15 | [0.6030, 0.3384, 0.2708, 0.2378, 0.2181]]) 16 | 17 | assert_array_almost_equal(laplacian, real_laplacian, decimal=4) 18 | 19 | 20 | def test_suggested_sigma(): 21 | data = np.arange(25, dtype=float).reshape((5, 5)) 22 | s_sigma = mvsc.suggested_sigma(data) 23 | 24 | real_s_sigma = 7.0 25 | 26 | assert_array_almost_equal(s_sigma, real_s_sigma, decimal=4) 27 | 28 | 29 | def test_gaussian_similarity(): 30 | data = np.arange(25, dtype=float).reshape((5, 5)) 31 | similarity = mvsc.distance_gaussian_similarity(data, 2) 32 | print(similarity) 33 | 34 | real_similarity = np.array([[1., 0.8824, 0.6065, 0.3246, 0.1353], 35 | [0.0439, 0.0110, 0.0021, 0.0003, 0.], 36 | [0., 0., 0., 0., 0.], 37 | [0., 0., 0., 0., 0.], 38 | [0., 0., 0., 0., 0.]]) 39 | 40 | assert_array_almost_equal(similarity, real_similarity, decimal=4) 41 | 42 | 43 | def test_mvsc_error(): 44 | # Data and is_distane do not have the same length. 45 | one = np.arange(25, dtype=float).reshape((5, 5)) 46 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 47 | data = [one, two] 48 | is_distance = [False, False, False] 49 | 50 | mvsc_est = mvsc.MVSC(k=2) 51 | assert_raises(ValueError, mvsc_est.fit, data, is_distance) 52 | 53 | # Sample data matrices do not have the same number of rows 54 | one = np.arange(25, dtype=float).reshape((5, 5)) 55 | two = np.arange(25, 49, dtype=float).reshape((4, 6)) 56 | data = [one, two] 57 | is_distance = [False, False] 58 | 59 | mvsc_est = mvsc.MVSC(k=2) 60 | assert_raises(ValueError, mvsc_est.fit, data, is_distance) 61 | 62 | # k value cannot be negative 63 | one = np.arange(25, dtype=float).reshape((5, 5)) 64 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 65 | data = [one, two] 66 | is_distance = [False, False] 67 | 68 | mvsc_est = mvsc.MVSC(k=-2) 69 | assert_raises(ValueError, mvsc_est.fit, data, is_distance) 70 | 71 | 72 | def test_mvsc(): 73 | one = np.arange(25, dtype=float).reshape((5, 5)) 74 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 75 | data = [one, two] 76 | is_distance = [False, False] 77 | 78 | mvsc_est = mvsc.MVSC(k=2) 79 | mvsc_est.fit(data, is_distance) 80 | -------------------------------------------------------------------------------- /multiview/tests/test_mvtsne.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from sklearn.utils.testing import assert_raises 3 | import multiview.mvtsne as mvtsne 4 | 5 | 6 | def test_mvtsne_error(): 7 | # Data and is_distane do not have the same length. 8 | one = np.arange(25, dtype=float).reshape((5, 5)) 9 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 10 | data = [one, two] 11 | is_distance = [False, False, False] 12 | 13 | mvtsne_est = mvtsne.MvtSNE(k=2) 14 | assert_raises(ValueError, mvtsne_est.fit, data, is_distance) 15 | 16 | # Sample data matrices do not have the same number of rows 17 | one = np.arange(25, dtype=float).reshape((5, 5)) 18 | two = np.arange(25, 49, dtype=float).reshape((4, 6)) 19 | data = [one, two] 20 | is_distance = [False, False] 21 | 22 | mvtsne_est = mvtsne.MvtSNE(k=2) 23 | assert_raises(ValueError, mvtsne_est.fit, data, is_distance) 24 | 25 | # k value cannot be negative 26 | one = np.arange(25, dtype=float).reshape((5, 5)) 27 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 28 | data = [one, two] 29 | is_distance = [False, False] 30 | 31 | mvtsne_est = mvtsne.MvtSNE(k=-2) 32 | assert_raises(ValueError, mvtsne_est.fit, data, is_distance) 33 | 34 | 35 | def test_mvtsne(): 36 | one = np.arange(25, dtype=float).reshape((5, 5)) 37 | two = np.arange(25, 50, dtype=float).reshape((5, 5)) 38 | data = [one, two] 39 | is_distance = [False, False] 40 | 41 | mvtsne_est = mvtsne.MvtSNE(k=2) 42 | mvtsne_est.fit(data, is_distance) 43 | -------------------------------------------------------------------------------- /multiview/tests/test_utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy.testing import assert_array_almost_equal 3 | import multiview.utils as utils 4 | 5 | 6 | def test_hbeta(): 7 | data = np.arange(25, dtype=float).reshape((5, 5)) 8 | H, P = utils.Hbeta(data, 2) 9 | 10 | real_H = 100.145867 11 | real_P = np.array([[8.64664717e-01, 1.17019644e-01, 1.58368867e-02, 12 | 2.14328955e-03, 2.90062698e-04], 13 | [3.92557174e-05, 5.31268363e-06, 7.18993544e-07, 14 | 9.73051950e-08, 1.31688261e-08], 15 | [1.78220681e-09, 2.41195464e-10, 3.26422564e-11, 16 | 4.41764902e-12, 5.97863781e-13], 17 | [8.09120641e-14, 1.09502571e-14, 1.48195615e-15, 18 | 2.00560955e-16, 2.71429737e-17], 19 | [3.67340203e-18, 4.97140904e-19, 6.72807051e-20, 20 | 9.10545327e-21, 1.23228910e-21]]) 21 | 22 | assert_array_almost_equal(H, real_H, decimal=4) 23 | assert_array_almost_equal(P, real_P, decimal=4) 24 | 25 | 26 | def test_x2p(): 27 | data = np.arange(25, dtype=float).reshape((5, 5)) 28 | P, beta = utils.x2p(data) 29 | 30 | real_P = np.array([[0., 0.25, 0.25, 0.25, 0.25], 31 | [0.25, 0., 0.25, 0.25, 0.25], 32 | [0.25, 0.25, 0., 0.25, 0.25], 33 | [0.25, 0.25, 0.25, 0., 0.25], 34 | [0.25, 0.25, 0.25, 0.25, 0.]]) 35 | real_beta = np.array([8.88178420e-16, 8.88178420e-16, 8.88178420e-16, 36 | 8.88178420e-16, 8.88178420e-16]) 37 | 38 | assert_array_almost_equal(P, real_P, decimal=4) 39 | assert_array_almost_equal(beta, real_beta, decimal=10) 40 | 41 | 42 | def test_whiten(): 43 | data = np.array([[1, 2, 3, 4], [4, 3, 2, 1], [2, 4, 1, 3], [1, 3, 2, 4]]) 44 | whitened = utils.whiten(data) 45 | 46 | real_whitened = np.array([[9.63475981e-01, 1.11961253e+00, 1.49011612e-08, 47 | 0.00000000e+00], 48 | [-1.55893688e+00, 6.91958598e-01, 0.00000000e+00, 49 | 0.00000000e+00], 50 | [-1.84007539e-01, -1.46559183e+00, 51 | -1.49011612e-08, 0.00000000e+00], 52 | [7.79468442e-01, -3.45979299e-01, 0.00000000e+00, 53 | 0.00000000e+00]]) 54 | 55 | assert_array_almost_equal(whitened, real_whitened, decimal=0) 56 | -------------------------------------------------------------------------------- /multiview/utils.py: -------------------------------------------------------------------------------- 1 | """ Utilities to be used in this package. 2 | 3 | There are mainly three functions to help other classes: 4 | Hbeta, x2p and whiten for the tsne algorithm .""" 5 | 6 | ___version___ = '1.0' 7 | ___author___ = 'Maria Araceli Burgueño Caballero' 8 | ___email___ = "mburgueno@uoc.edu" 9 | ___status___ = "Pre-Production" 10 | 11 | 12 | import numpy as np 13 | from sklearn.metrics.pairwise import euclidean_distances 14 | from sklearn.utils import check_array 15 | 16 | 17 | def Hbeta(D, beta): 18 | """Compute H beta for matrix D, given beta. 19 | 20 | Parameters 21 | ---------- 22 | 23 | D : ndarray or nscalar. 24 | Input value. 25 | beta : numeric. 26 | Number to operate with in the exponential distribution. 27 | 28 | Returns 29 | ------- 30 | 31 | (H, P) : tuple 32 | Return a tuple with H and P values. H is a float value and P 33 | can be either an scalar or a ndarray. 34 | 35 | Examples 36 | -------- 37 | 38 | >>> import numpy as np 39 | >>> matrix = np.array([[1, 2, 3], [2, 3, 4], [5, 6, 2]]) 40 | >>> hbeta = Hbeta(matrix, 3) 41 | >>> print("H -> %g\nP-> %a" % hbeta) 42 | H -> 21.6814 43 | P-> array([[ 8.66214422e-01, 4.31262766e-02, 2.14713088e-03], 44 | [ 4.31262766e-02, 2.14713088e-03, 1.06899352e-04], 45 | [ 5.32220535e-06, 2.64977002e-07, 4.31262766e-02]]) 46 | """ 47 | P = np.exp(-D * beta) 48 | sumP = np.sum(P) 49 | if sumP == 0: 50 | H = 0 51 | P = D * 0 52 | else: 53 | H = np.log(sumP) + beta * np.sum(np.dot(D, P)) / sumP 54 | P -= sumP 55 | return (H, P) 56 | 57 | 58 | def x2p(X, perplexity=15, tol=1e-5): 59 | """ Compute a pair-wise conditional matrix given input matrix. 60 | 61 | Parameters 62 | ---------- 63 | X : ndarray. 64 | Input data. Matrix with n rows. 65 | perplexity : numeric. 66 | Target perplexity. Loosely translates into the expected number of 67 | behibours per point. 68 | tol : float 69 | Tolerance to be used in the computation. It must be a small value. 70 | 71 | Returns 72 | ------- 73 | (P, beta) : tuple 74 | P: Pair-wise conditional probability matrix. 75 | beta: array used during computation. 76 | 77 | Examples 78 | -------- 79 | 80 | >>> x = np.array(([2, 4, 3], [1, 5, 7], [8, 6, 9])).T 81 | >>> x2p(x) 82 | (array([[ 0. , 0.5, 0.5], 83 | [ 0.5, 0. , 0.5], 84 | [ 0.5, 0.5, 0. ]]), array([ 8.88178420e-16, 85 | 8.88178420e-16, 8.88178420e-16])) 86 | """ 87 | X = check_array(X) 88 | n = X.shape[0] 89 | D = euclidean_distances(X) 90 | # print(D) 91 | P = np.zeros((n, n)) 92 | beta = np.array([1] * n, dtype="float64") 93 | logU = np.log(perplexity) 94 | for i in np.arange(n): 95 | betamin = -float("inf") 96 | betamax = float("inf") 97 | Di = np.delete(D[i], i) 98 | H, this_P = Hbeta(Di, beta[i]) 99 | H_diff = H - logU 100 | tries = 0 101 | while abs(H_diff) > tol and tries < 50: 102 | if H_diff > 0: 103 | betamin = beta[i] 104 | if betamax == float("inf"): 105 | beta[i] = beta[i] * 2 106 | else: 107 | beta[i] = (beta[i] + betamax) / 2 108 | else: 109 | betamax = beta[i] 110 | if betamin == -float("inf"): 111 | beta[i] = beta[i] / 2 112 | else: 113 | beta[i] = (beta[i] + betamin) / 2 114 | H, this_P = Hbeta(Di, beta[i]) 115 | H_diff = H - logU 116 | tries += 1 117 | P[i, np.arange(n) != i] = this_P 118 | return (P, beta) 119 | 120 | 121 | def whiten(X, row_norm=False, verbose=0, n_comp=-1): 122 | """Whitening of matrix X, and return that new matrix whitened. 123 | 124 | Parameters 125 | ---------- 126 | 127 | X : ndarray 128 | Input data (2D). 129 | row_norm : int, default 0 130 | If row_norm is True, then input data is scaled as well as centered. 131 | If it is False, then no center or scale is computed. 132 | verbose : int, default 0 133 | Verbosity mode. 134 | n_comp : int, default -1 135 | Number of rows of output matrix. If n_comp is -1, the number 136 | of columns of input data is set. 137 | 138 | Returns 139 | ------- 140 | 141 | X : ndarray 142 | Whitened matrix. 143 | 144 | Examples 145 | -------- 146 | 147 | >>> x = np.array(([2, 4, 3], [1, 5, 7], [8, 6, 9])).T 148 | >>> whiten(x, row_norm=True) 149 | [[ 1.22474487e+00 7.07106781e-01 -7.26265414e-08] 150 | [ -1.22474487e+00 7.07106781e-01 -3.69804654e-08] 151 | [ 2.10705234e-16 -1.41421356e+00 -5.30203132e-09]] 152 | >>> y = np.array(([1, 2, 3], [4, 5, 6], [7, 8, 9])).T 153 | >>> whiten(y) 154 | [[ 1.22474487e+00 -2.98023224e-08 0.00000000e+00] 155 | [ 0.00000000e+00 0.00000000e+00 0.00000000e+00] 156 | [ -1.22474487e+00 2.98023224e-08 0.00000000e+00]] 157 | """ 158 | if n_comp == -1: 159 | n_comp = X.shape[1] 160 | if verbose: 161 | print("Centering") 162 | n = X.shape[0] 163 | p = X.shape[1] 164 | # Centering matrix columns 165 | mean = X.mean(axis=0) 166 | sd = np.std(X, axis=0, ddof=1) 167 | X -= mean 168 | if row_norm: 169 | X = (X / sd).T 170 | else: 171 | X = X.T 172 | if verbose: 173 | print("Whitening") 174 | V = np.dot(X, X.T) / n 175 | u, s, v = np.linalg.svd(V) 176 | D = (np.diag(1 / s**(1 / 2))) 177 | K = np.dot(D, u.T) 178 | K = np.matrix(K[:n_comp, :].reshape((n_comp, p))) 179 | X = np.dot(K, X).T 180 | return X 181 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from distutils.core import setup 3 | 4 | 5 | def configuration(parent_package='', top_path=None): 6 | if os.path.exists('MANIFEST'): 7 | os.remove('MANIFEST') 8 | 9 | from numpy.distutils.misc_util import Configuration 10 | config = Configuration(None, parent_package, top_path) 11 | 12 | config.set_options(ignore_setup_xxx_py=True, 13 | assume_default_configuration=True, 14 | delegate_options_to_subpackages=True, 15 | quiet=True) 16 | 17 | config.add_subpackage('multiview') 18 | config.add_subpackage('doc') 19 | 20 | return config 21 | 22 | 23 | SCIPY_MIN_VERSION = '0.13.3' 24 | NUMPY_MIN_VERSION = '1.8.2' 25 | extra_setuptools_args = dict( 26 | zip_safe=False, # the package can run out of an .egg file 27 | include_package_data=True, 28 | extras_require={ 29 | 'alldeps': ( 30 | 'numpy >= {0}'.format(NUMPY_MIN_VERSION), 31 | 'scipy >= {0}'.format(SCIPY_MIN_VERSION), 32 | ), 33 | }, 34 | ) 35 | 36 | 37 | setup( 38 | name="multiview", 39 | packages=["multiview", "examples", "multiview.tests"], 40 | version="1.0", 41 | description="Multiview clustering and dimensionality reduction", 42 | author="María Araceli Burgueño Caballero", 43 | author_email="mburgueno@uoc.edu", 44 | url="https://github.com/mariceli3/multiview", 45 | download_url="https://github.com/mariceli3/multiview/dist/multiview-1.0.tar.gz", 46 | keywords=["multiview", "clustering", "dimensionality reduction"], 47 | zip_safe=False, 48 | include_package_data=True, 49 | classifiers=[ 50 | "Programming Language :: Python", 51 | 'Programming Language :: Python :: 2', 52 | 'Programming Language :: Python :: 2.7', 53 | 'Programming Language :: Python :: 3', 54 | 'Programming Language :: Python :: 3.4', 55 | 'Programming Language :: Python :: 3.5', 56 | 'Programming Language :: Python :: 3.6', 57 | "Development Status :: 3 - Alpha", 58 | "Environment :: Other Environment", 59 | "Intended Audience :: Developers", 60 | "Intended Audience :: Science/Research", 61 | "License :: OSI Approved :: BSD License", 62 | "Operating System :: OS Independent", 63 | "Topic :: Software Development :: Libraries :: Python Modules", 64 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 65 | ], 66 | long_description=""" 67 | Multiview clustering and dimensionality reduction 68 | ------------------------------------------------- 69 | The ``multiview`` package provides multiview methods to work with 70 | multiview data (datasets with several data matrices from the same 71 | samples). It contains methods for multiview dimensionality reduction 72 | and methods for multiview clustering. 73 | 74 | Multiview dimensionality reduction 75 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 76 | Given a multiview dataset with ``v`` input data matrices,multiview 77 | dimensionality reduction methods produce a single, low-dimensional 78 | projection of the input data samples, trying to mantain as much of the 79 | original information as possible. 80 | 81 | Package ``multiview`` offers the function :doc:`mvmds` to perform multiview 82 | dimensionality reduction in a similar way than the multidimensional scaling 83 | method (cmdscale in R). 84 | 85 | Another dimensionality reduction function in this package is :doc:`mvtsne`, 86 | that extends ``tsne`` in R to multiview data. 87 | 88 | Multiview clustering 89 | ~~~~~~~~~~~~~~~~~~~~ 90 | Given a multiview dataset with ``v`` input data matrices, multiview 91 | clustering methods produce a single clustering assignment, considering 92 | the information from all the input views. 93 | Package ``multiview`` offers the function :doc:`mvsc` to perform multiview 94 | spectral clustering. It is an extension to spectral clustering 95 | (``kernlab::specc`` in R) to multiview datasets. 96 | """ 97 | ) 98 | --------------------------------------------------------------------------------