No BSD License  

Highlights from
Fast Correlation between two vectors

Be the first to rate this file! 14 Downloads (last 30 days) File Size: 3.48 KB File ID: #22358

Fast Correlation between two vectors

by Francesco Pozzi

 

09 Dec 2008

fastcorrelation is a fast and numerically stable algorithm for computing the correlation (in C)

| Watch this File

File Information
Description

% FASTCORRELATION computes the correlation between vectors x and y by
% making use of fastcorr.dll which is the C implementation of a fast and
% numerically stable algorithm.
%
% In order to generate fastcorr.dll, you need to run this instruction and
% compile the c file from the Matlab Command Window:
%
% mex fastcorr.c
%
%*************************************************************************%
%
% SLOWCORRELATION is the function fastcorr.c implemented in MATLAB. It can
% be used for generale consultation but, since it's VERY slow, it's NOT
% supposed to be used in real computations.
%
%*************************************************************************%
%
% EXAMPLE1. If you need to check the input vectors:
% N = 10000000;
% x = cumsum(randn(N, 1));
% y = cumsum(randn(N, 1));
% correlation = fastcorrelation(x, y);
%
%*************************************************************************%
%
% EXAMPLE2. If you DON'T need to check the input vectors:
% N = 10000000;
% x = cumsum(randn(N, 1));
% y = cumsum(randn(N, 1));
% correlation = fastcorr(x, y);
%
%*************************************************************************%
%
% EXAMPLE3. Check running time and accuracy of corrcoef and fastcorr
%
% format long
% for N = 50:50:100000
% x = cumsum(randn(N, 1));
% y = cumsum(randn(N, 1));
% tic, temp = corrcoef(x, y); correlation1(N / 50) = temp(2); runningtime1(N / 50) = toc; [N, toc]
% tic, correlation2(N / 50) = fastcorr(x, y); runningtime2(N / 50) = toc; [N, toc]
% disp(sprintf('\n\n\n'))
% end
% % Check running times (blue for corrcoef, magenta for fastcorr):
% figure
% plot(runningtime1, '.b');
% hold on;
% plot(runningtime2, '.m');
%
% % Check running times (positive means corrcoef > fastcorr, negative means fastcorr > corrcoef):
% figure
% plot(runningtime1 - runningtime2, '.b');
%
% % Compare accuracy of computation (differences are negligible):
% figure
% plot(correlation1 - correlation2, '.')

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Variance of Vector Elements

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
algorithm Cristina McIntire 09 Dec 2008 13:22:46
vectors Cristina McIntire 09 Dec 2008 13:22:46
correlation Francesco Pozzi 09 Dec 2008 13:22:53

Contact us at files@mathworks.com