octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Potential Addition: hist3


From: Daniel J Sebald
Subject: Re: Potential Addition: hist3
Date: Sun, 24 Jun 2012 03:23:48 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 06/21/2012 10:14 PM, Andrew Lampinen wrote:
Hello,

Attached is a hist3.m file for a bivariate histogram function, somewhat
similar to matlab's hist3. It's one of the main functions I've missed in
octave, so I wrote this and thought I'd submit it to you for
consideration, since it seems like it would be useful for matlab
compatibility, etc. My code is probably not the most efficient, since
I've not had extensive experience writing for octave, but at least it's
a starting point.

Hi Andrew,

Yes, there may be some ways to speed up the code.  In particular, this loop:

for i = 1:length (X) %For each data point
  x_loc = find(x_bins > X(i,1))(1) - 1;
  y_loc = find(y_bins > X(i,2))(1) - 1;
  A(x_loc, y_loc) += 1;
endfor

Could possibly be done without looping or without using find(). Here's a path to explore:

* Imagine some affine transform on X, i.e., Y = m*X + b so that if one were to toss the fractional part of Y what would be left is the bin number.
* Use sum(Y == i, 1) to figure the count.

Now, this all depends on the number of bins compared to the number of samples. If the number of bins is large compared to the number of samples then your first method is more efficient.

Another thing to consider might be the use of standard deviation rather than min and max for determining bin width. The problem with min/max is that for some distributions those outliers can vary wildly so the histogram could end up with a resolution not matching the bulk of the data so well. Try using standard deviation for determining bin size, and either toss the outliers or group the outliers with the extreme bins. (A few extra at the extrema is the way a Galton's board can look if the span of the bins isn't very wide: http://ptrow.com/articles/Galton_June_07.htm)

Dan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]