comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Automatic Binsize Calculations
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Automatic Binsize Calculations [message #76264] Sun, 29 May 2011 09:42
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Gianguido Cianci writes:

> Here's what I came up with, using sshist_2d.pro
> (http://tinyurl.com/3on7bzx) that automagically finds bin size:

I don't have a television, so while I listened to Djokovic
defeat Gasquet on the French Open Radio I was fooling
around using the 1D version of sshist to calculate
a default bin size for cgHistoplot. What I discovered
is that I get completely different results depending
on the data type of the input data!

I modified sshist a bit to get the bin size out of it
as a keyword:

; Author: Shigenobu Hirose at JAMSTEC
; based on original paper
; Shimazaki and Shinomoto, Neural Computation 19, 1503-1527, 2007
; http://toyoizumilab.brain.riken.jp/hideaki/res/histogram.htm l
;
function sshist, data, x=x, cost=cost, nbin=nbin, binsize=binsize

COMPILE_OPT idl2

nbin_min = 2
nbin_max = 200

ntrial = nbin_max - nbin_min + 1

nbin = INDGEN(ntrial) + nbin_min

delta = FLTARR(ntrial)
cost = FLTARR(ntrial)

for n = 0, ntrial-1 do begin
delta[n] = (MAX(data) - MIN(data)) / (nbin[n] - 1)

k = HISTOGRAM(data, nbins=nbin[n])

kmean = MEAN(k)
kvari = MEAN((k - kmean)^2)
cost[n] = (2. * kmean - kvari) / delta[n]^2
endfor

n = (WHERE(cost eq MIN(cost)))[0]
k = HISTOGRAM(data, nbins=nbin[n], locations=x, reverse_indices=ri)

if arg_present(binsize) then binsize = delta[n]
return, k

end

But, look at this:

IDL> void = sshist(cgdemodata(21), binsize=bs) & print, bs
9.00000
IDL> void = sshist(fix(cgdemodata(21)), binsize=bs) & print, bs
1.00000
IDL> void = sshist(long(cgdemodata(21)), binsize=bs) & print, bs
1.00000
IDL> void = sshist(float(cgdemodata(21)), binsize=bs) & print, bs
1.33684

I have NO idea why this is occurring. :-(

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Previous Topic: Re: Strange WHERE issue?
Next Topic: procedure with arbitrary parameter

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 12:37:53 PDT 2025

Total time taken to generate the page: 1.68267 seconds