Parcourir la source

Transférer les fichiers vers ''

Matthieu PUIGT il y a 5 ans
Parent
commit
0cf0905a24
5 fichiers modifiés avec 134 ajouts et 0 suppressions
  1. 50 0
      Demo.m
  2. 18 0
      README.m
  3. 13 0
      add_paths.m
  4. 44 0
      plots.m
  5. 9 0
      stop_rule.m

+ 50 - 0
Demo.m

@@ -0,0 +1,50 @@
+% Author : F. Yahaya
+% Date: 06/09/2018
+% Contact: farouk.yahaya@univ-littoral.fr
+
+% clear all variables
+% First, initialize the random number generator to make the results in each
+% test repeatable.
+% using a seed of 1 rng(1)
+
+% Goal: Execute the algorithms viz., Vanila NeNMF, Randomized Power
+% Iterations NeNMF (RPI), Randomized Subspace Iterations NeNMF (RSI) for
+% sizes: [m,n]=500, 5000,10000.
+
+% Tmax : Execution time in seconds.
+% mat_size : Give a name to your matrix size for easier identification of output
+% Total_Tests : Total number of test to perform. E.g. we made 40 tests.
+
+clear
+clc
+Tmax =15;
+Total_Tests=40;
+
+
+
+for i=1:Total_Tests
+    
+   mat_size='500x500'; % this is just for naming. To change matrix size, open the "data_simulation.m" file and change                                
+                        % your mxn matrix size as desired.
+    
+    
+%     % Randomized Subspace Iterations (NeNMF) 
+    
+    clearvars -except i Tmax mat_size Total_Tests;
+   load( ['synthetic_data/data_',mat_size,'_',int2str(i),'.mat'])
+    [ W_RSI_NeNMF , H_RSI_NeNMF,RRE_RSI_NeNMF, T_RSI_NeNMF] = RSI_NeNMF(X, Winit , Hinit ,r, Tmax);
+   save( ['output/RSI_NeNMF_',mat_size,'_',int2str(i),'.mat'], 'RRE_RSI_NeNMF', 'T_RSI_NeNMF', '-v7.3' )
+  
+    % VANILA NeNMF
+    clearvars -except i Tmax mat_size Total_Tests;
+   load( ['synthetic_data/data_',mat_size,'_',int2str(i),'.mat'])
+    [ W_VANILLA , H_VANILLA,RRE_VANILLA_NeNMF, T_VANILLA_NeNMF ] = VANILLA_NeNMF(X , Winit , Hinit,Tmax );
+   save( ['output/vanilla_NeNMF_',mat_size,'_',int2str(i),'.mat'], 'RRE_VANILLA_NeNMF', 'T_VANILLA_NeNMF', '-v7.3' )
+
+    disp( ['iter:',int2str(i), ' of ', mat_size , '   OK!'] )
+    
+end
+
+disp(['matrix size ', '( ',mat_size,' )', ' : all ',int2str(Total_Tests), ' Tests', ' completed!' ]);
+
+

+ 18 - 0
README.m

@@ -0,0 +1,18 @@
+% This is a matlab code for Non-negative Matrix Factorization via Nesterov's
+% Optimal Gradient Method.
+
+% In this project we have applied random projections to the aforementioned
+% technique via two variants of random projections,namely:
+
+% 1. Randomized Power iterations RPI NeNMF
+% 2. Randomized Subspace Iterations RSI NeNMF
+
+% HOW TO RUN THE CODE.
+%
+% Step 1: run the file "add_paths", to ensure all the folders and files are added to your matlab working path.
+% Step 2: run the file "data_simulations", to generate your synthetic data.
+% step 3: run the file "Demo" to execute the functions available in the folder "algorithms"
+
+% Results of the execution are saved in the folder "output"
+
+% To make plots, use the file "plots".

+ 13 - 0
add_paths.m

@@ -0,0 +1,13 @@
+addpath(pwd);
+
+cd output/;
+addpath(genpath(pwd));
+cd ..;
+
+cd synthetic_data/;
+addpath(genpath(pwd));
+cd ..;
+
+cd algorithms/;
+addpath(genpath(pwd));
+cd ..;

+ 44 - 0
plots.m

@@ -0,0 +1,44 @@
+% Author : F. Yahaya
+% Date: 06/09/2018
+% Contact: farouk.yahaya@univ-littoral.fr
+
+clear
+clc
+Total_Tests=40;
+mat_size='500x500'; % this is just for naming. To change matrix size, open the "data_simulation.m" file and change                                
+                        % your mxn matrix size as desired.
+
+for i=1:Total_Tests
+    
+  load(['output/RSI_NeNMF_',mat_size,'_',int2str(i),'.mat'] , 'RRE_RSI_NeNMF', 'T_RSI_NeNMF')
+%     load(['output/RPI_',mat_size,'_',int2str(i),'.mat'] , 'RRE_RPI','T_RPI' )
+    load(['output/vanilla_NeNMF_',mat_size,'_',int2str(i),'.mat'] , 'RRE_VANILLA_NeNMF', 'T_VANILLA_NeNMF' )
+    
+    
+    rRE_RSI_NeNMF(i,:)  = RRE_RSI_NeNMF;
+    t_RSI_NeNMF(i,:) = T_RSI_NeNMF;
+    
+%     rRE_RPI(i,:)  = RRE_RPI;
+%     t_RPI(i,:) = T_RPI;
+    rRE_VANILLA_NeNMF(i,:)  = RRE_VANILLA_NeNMF;
+    t_VANILLA_NeNMF(i,:) = T_VANILLA_NeNMF;
+    
+end
+
+figure,
+subplot(211)
+semilogy(t_VANILLA_NeNMF',rRE_VANILLA_NeNMF','b')
+hold on, semilogy(t_RSI_NeNMF',rRE_RSI_NeNMF','r')
+axis([0 15 1e-4 1.01]) 
+xlabel('CPU time (s)')
+ylabel('RRE')
+
+
+
+
+subplot(212), semilogy([0:length(t_VANILLA_NeNMF)-1],rRE_VANILLA_NeNMF','b')
+hold on, semilogy([0:length(t_RSI_NeNMF)-1],rRE_RSI_NeNMF','r')
+axis([0 40 1e-4 1.01]) 
+xlabel('Iterations')
+ylabel('RRE')
+

+ 9 - 0
stop_rule.m

@@ -0,0 +1,9 @@
+function retVal=stop_rule(X,gradX)
+% Stopping Criterions
+% Written by Naiyang (ny.guan@gmail.com)
+
+
+pGrad=gradX(gradX<0|X>0);
+retVal=norm(pGrad);
+
+end