Download code
From LiteratePrograms
Back to OCAMAWEB
Download for Windows: zip
Download for UNIX: zip, tar.gz, tar.bz2
a_lot_of_PCAs.m
1 % Copyright (c) 2010 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/OCAMAWEB?action=history&offset=20060904073442 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/OCAMAWEB?oldid=7570 25 26 function [M, v, l] = a_lot_of_PCAs(n, p, nb) 27 %< checking the argument number 28 % there can be 2 or 3 arguments 29 if nargin < 3 30 nb = 1 31 end; 32 %> 33 34 figure; hold on; 35 %< performing ACPs 36 % the number of PCAs to be preformed is nb 37 for i=1:nb 38 %< randomized input 39 % I will perform a PCA on a gaussian n X p matrix 40 M = randn(n,p); 41 %> 42 %< PCA 43 % I use eig but I could used SVD too 44 [v,l] = eig(M' * M); 45 l = diag(l); 46 csl = cumsum(l); 47 %> 48 plot(csl/csl(end)); 49 end; 50 %> 51
a_lot_of_PCAs_.m
1 % Copyright (c) 2010 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/OCAMAWEB?action=history&offset=20060904073442 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/OCAMAWEB?oldid=7570 25 26 function [M, v, l] = a_lot_of_PCAs(n, p, nb) 27 %< checking the argument number 28 % there can be 2 or 3 arguments 29 if nargin < 3 30 nb = 1 31 end; 32 %> 33 34 figure; hold on; 35 %< performing ACPs 36 % the number of PCAs to be preformed is nb 37 for i=1:nb 38 %< randomized input 39 % I will perform a PCA on a gaussian n X p matrix 40 M = randn(n,p); 41 %> 42 43 %< PCA 44 % I use eig but I could used SVD too 45 [v,l] = eig(M' * M); 46 l = diag(l); 47 csl = cumsum(l); 48 %> 49 50 plot(csl/csl(end)); 51 end; 52 %> 53 54
ocamaweb.xml
1 <ocamaweb> 2 <pdfgenerator file="dvipdfm" ext=".dvi"/> 3 <keypatterns> 4 <keypattern name="author" key="node.author" before="'" after="'"/> 5 <keypattern name="author" key="% author" before="'" after="'"/> 6 <keypattern name="author" key="% auteur" before="'" after="'"/> 7 <keypattern name="title" key="% title" before="'" after="'"/> 8 <keypattern name="title" key="% titre" before="'" after="'"/> 9 <keypattern name="project" key="% project" before="'" after="'"/> 10 <keypattern name="project" key="% projet" before="'" after="'"/> 11 <keypattern name="mailto" key="node.mailto" before="'" after="'"/> 12 <keypattern name="mailto" key="% mailto" before="'" after="'"/> 13 <keypattern name="date" key="node.date" before="'" after="'"/> 14 <keypattern name="date" key="% date" before="'" after="'"/> 15 <keypattern name="version" key="% version" before="'" after="'"/> 16 <keypattern name="version" key="VERSION" before="=" after=";"/> 17 </keypatterns> 18 <matlabwords> 19 <keyword name="function"/> 20 <keyword name="while"/> 21 <keyword name="continue"/> 22 <keyword name="try"/> 23 <keyword name="catch"/> 24 <keyword name="for"/> 25 <keyword name="end"/> 26 <keyword name="persistent"/> 27 <keyword name="switch"/> 28 <keyword name="case"/> 29 <keyword name="if"/> 30 <keyword name="else"/> 31 <keyword name="elseif"/> 32 <keyword name="return"/> 33 <keyword name="break"/> 34 <keyword name="otherwise"/> 35 </matlabwords> 36 <info/> 37 </ocamaweb> 38
