Rank: 256 based on 399 downloads (last 30 days) and 19 files submitted
photo

Francesco Pozzi

E-mail

Personal Profile:
Professional Interests:
Evolution on Networks

 

Watch this Author's files

 

Files Posted by Francesco View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
17 Dec 2013 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi average mean statisti... 14 7
18 Sep 2012 Screenshot Inequality Package Inequality Metrics: Gini Coefficient associated to the Lorenz Curve, Theil and Atkinson indexes Author: Francesco Pozzi statistics, probability, gini, lorenz curve, theil, atkinson 38 4
  • 5.0
5.0 | 1 rating
25 Jun 2012 Weighted Covariance Matrix Calculates a Weighted Covariance Matrix Author: Francesco Pozzi statistics, correlation, covariance, weighted covariance, weighted correlation 40 0
07 Jun 2012 Weighted Correlation Matrix Compute coefficients of the Weighted Correlation Matrix, as an alternative to CORRCOEFF Author: Francesco Pozzi statistics, probability, correlation, weighted correlation 61 9
  • 4.66667
4.7 | 3 ratings
07 Jun 2012 Weighted Kendall Rank Correlation Matrix Fast Weighted Kendall Rank Correlation Matrix (much much faster than Matlab CORR) Author: Francesco Pozzi corrcoef, corr, weighted kendall rank... 27 2
  • 5.0
5.0 | 1 rating
Comments and Ratings by Francesco View all
Updated File Comments Rating
26 Jan 2014 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi

@Oleg Komarov In the example I am comparing the accuracy of Y2 and Y3 and I show that 'accuratemovav' is as accurate as can possibly be. Using 'filter' will be faster than looping but obviously **less accurate**:

tic, Y4 = filter(ones(1,w)/w,1,X); toc, Y4(1:2499, :) = [];
all(abs(Y4(:) - Y3(:)) < 1e-12)
all(abs(Y4(:) - Y3(:)) < 1e-15)

For this reason you should compare its speed with 'fastmovav', not with 'accuratemovav'. In fact you are supposed to use the latter only if you believe that accuracy is going to be an issue.

26 Jan 2014 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi

@Oleg Komarov In the example I am comparing the accuracy of Y1 and Y3 and I show that 'accuratemovav' is as accurate as can possibly be. Using 'filter' will be faster than the loop but obviously **less accurate**:

tic, Y4 = filter(ones(1,w)/w,1,X); toc, Y4(1:2499, :) = [];
all(abs(Y4(:) - Y3(:)) < 1e-12)
all(abs(Y4(:) - Y3(:)) < 1e-15)

15 Dec 2013 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi

@Jan Simon, thank you for your very useful comment.

I have just submitted the new functions with some of the improvements you suggested.

"size(size(X), 2)" is now replaced by "ndims(X)". The inplace operation "a = a + b" is now replaced by "a += b" and "a = a / b" is avoided in favour of "a /= b".

My understanding is that, in the mex functions, counters "hh", "ii" and "jj" should be of type "mwSignedIndex"; "w", "m", "n" and "m2" should be of type "mwSize". This is what I have done, please let me know if you think that different types should be applied.

Checks are still in the .m file as 1) I am not confident enough to implement them in the mex file yet (perhaps I will do this in the next weeks) and 2) I reckon checks are a reasonable price to pay (and if some user thinks otherwise they can still call the mex functions directly).

12 Dec 2013 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi

@Jos, thank you for your comment. Your function is fast but has some limitations: 1. apparently accepts only odd numbers for the sliding window; 2. it's certainly slower than my function (please test this with large matrices, for example 10000-by-3000 with a window equal to 5001); 3. it doesn't seem to provide more accurate results than mine.

Earlier today I have submitted a new version where two functions are proposed, one is very fast and a bit inaccurate and the other is very accurate and a bit slower. In few hours it should be visible. Please let me know your opinion - I think that the moving average is so important that it should have a built-in function, a mex function is probably the closest option.

Possible drawbacks of my functions: they don't accept NaN values; only accept double precision values; only work for column vectors or 2D matrices; etc.

07 Nov 2013 Plot Circle in 3D Plots a Circle with arbitrary direction in 3D Author: Christian Reinbacher

But the author should consider adding some comments on how to use the function. For example, given two points on a sphere, how do you define the input "normal"?

Comments and Ratings on Francesco's Files View all
Updated File Comment by Comments Rating
26 Jan 2014 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi Pozzi, Francesco

@Oleg Komarov In the example I am comparing the accuracy of Y2 and Y3 and I show that 'accuratemovav' is as accurate as can possibly be. Using 'filter' will be faster than looping but obviously **less accurate**:

tic, Y4 = filter(ones(1,w)/w,1,X); toc, Y4(1:2499, :) = [];
all(abs(Y4(:) - Y3(:)) < 1e-12)
all(abs(Y4(:) - Y3(:)) < 1e-15)

For this reason you should compare its speed with 'fastmovav', not with 'accuratemovav'. In fact you are supposed to use the latter only if you believe that accuracy is going to be an issue.

26 Jan 2014 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi Pozzi, Francesco

@Oleg Komarov In the example I am comparing the accuracy of Y1 and Y3 and I show that 'accuratemovav' is as accurate as can possibly be. Using 'filter' will be faster than the loop but obviously **less accurate**:

tic, Y4 = filter(ones(1,w)/w,1,X); toc, Y4(1:2499, :) = [];
all(abs(Y4(:) - Y3(:)) < 1e-12)
all(abs(Y4(:) - Y3(:)) < 1e-15)

26 Jan 2014 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi Komarov, Oleg

A loop is definitely a slow solution, but you can also use filter(), which is still significantly slower than fastmovav() but also significantly faster than the accurate version:

Y2 = filter(ones(1,w)/w,1,X);

15 Dec 2013 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi Pozzi, Francesco

@Jan Simon, thank you for your very useful comment.

I have just submitted the new functions with some of the improvements you suggested.

"size(size(X), 2)" is now replaced by "ndims(X)". The inplace operation "a = a + b" is now replaced by "a += b" and "a = a / b" is avoided in favour of "a /= b".

My understanding is that, in the mex functions, counters "hh", "ii" and "jj" should be of type "mwSignedIndex"; "w", "m", "n" and "m2" should be of type "mwSize". This is what I have done, please let me know if you think that different types should be applied.

Checks are still in the .m file as 1) I am not confident enough to implement them in the mex file yet (perhaps I will do this in the next weeks) and 2) I reckon checks are a reasonable price to pay (and if some user thinks otherwise they can still call the mex functions directly).

14 Dec 2013 Fast or Accurate Moving Average (mex functions) Return the moving average of 2D matrix X, given a running window w Author: Francesco Pozzi Simon, Jan

Calculating the sum at first an dividing by the window length afterwards is not efficient, because this doubles the memory requirements. It would be faster to perform the division directly in the C-code.

The inplace operations in C are nicer and faster:
y[ii * m2] = y[ii * m2] + x[ii * m + hh];
Better:
y[ii * m2] += x[ii * m + hh]

Using INT as type for indexing operations is a bad idea in times of 32 and 64 bit machines. Better rely on the well defined types mwIndex, mwSignedIndex and mwSize.

Usind NDIMS() is slightly nicer than "size(size(X), 2) == 2". The overhead of checking the size and type of the input is much smaller, when you implement it inside the MEX function. For small arrays almost all of the time is spent with the checks in the M-file now, while such checks have almost no measurable dely inside a MEX function.

Contact us