www.pudn.com > ica_v0.04.rar > example.sci


//
// example.sci
//
// Time-stamp: 
//
// Simple example using the ica program from Scilab.
//
// The ica program is called repeatedly so that the progress
// of the unmixing matrix being learnt can be monitored.
//
// Programmer: Peter Stepien
//             pstepien@sedal.usyd.edu.au
//             CEL, School of Electrical & Information Engineering
//             The University of Sydney
//             SYDNEY NSW 2006 Australia
//
//             COPYRIGHT 1997-2001

// Greeting
printf('\nICA Program Example Script (Scilab)\n');
printf('------------------------------------------------------------\n\n');

// Clear everything first
clear();

// Generate input data
s=grand(2,10000,'exp',1).*sign(rand(2,10000,'normal'));
s=s-mean(s,'c')*ones(1,10000);
A=[0.7,0.2;-0.3,0.9];
x=A*s;

// Save the input data to file
fd=mopen('ica.in','wb',0);
mput(x,'d',fd);
mclose(fd);

// Start main loop
printf('Running ica ...\n');
W_path=zeros(1,10);
old_w=eye(2,2);
for i=1:10,
  
  // Run the ica program
  if i==1 then
    unix('ica -c 2 -n 5 -l 0.0001 -nounmix -w');
  else
    unix('ica -c 2 -n 5 -l 0.0001 -nounmix -w -iw');
  end;

  // Read in the resultant unmixing matrix
  fd=mopen('ica_w.out','rb',0);
  W=mget(2*2,'d',fd);
  mclose(fd);
  W=matrix(W,2,2);
  
  // Calculate the update difference for plotting
  W_path(i)=sqrt(mean((W-old_w).^2));
  
  // Get ready for the next loop
  old_w=W;
  unix('mv ica_w.out ica_w.in');
  
end;
printf('Finished.\n');

// Plot learning path
printf('Plot learning path ...\n');
xbasc();
plot2d(W_path);
xtitle('W Learning Path');

// Print the unmixing results
printf('Print unmixing results ...\n\n');
printf('The mixing matrix:\n');
disp(A);
printf('\nThe resultant unmixing matrix:\n');
disp(W);
printf('\nThe product of the mixing and unmixing matrices (normalised):\n');
WA=W*A;
WA(1,:)=WA(1,:)/WA(1,1);
WA(2,:)=WA(2,:)/WA(2,2);
disp(WA);

// Finished
printf('\n------------------------------------------------------------\n');