I am wondering whether Vector.histogram can return the bin number of each data in the edge? Just like the function in Matlab, [bincounts,ind] = histc(data,bin ranges)
I know it is easy to get this value by iterations, but it will cause a terrible time consumption in my simulation. It will be used in parameter searching and will be implemented a lot of times. Also the number of data points may be several thousands. Any suggestions? Thanks.
Histogram method for a vector

 Site Admin
 Posts: 5545
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: Histogram method for a vector
Suggest reading the Programmers' Reference documentation of the Vector class's hist and histogram methods
https://www.neuron.yale.edu/neuron/stat ... ector.html
and then trying them on a toy problem to determine whether one of them produces suitable results in a short enough time. Please let me know whether one of them does what you want.
https://www.neuron.yale.edu/neuron/stat ... ector.html
and then trying them on a toy problem to determine whether one of them produces suitable results in a short enough time. Please let me know whether one of them does what you want.
Re: Histogram method for a vector
Thanks for the reply. No, the histogram provided by Neuron can not solve my problem.histogram can give me the information about the number of data points in each bin. However, I want to know the index of each data point to the bin. For example, it can generate a vector which has the same size as the data. The value in the vector correspond to its index to the bin. like a vector (1 5 3 7) means the first data point will be located in the first bin, the second data point will be in the fifth bin. I can realise it by comparing the data and the bin through a lot of iterations. But I want to use it to compute the error function in the parameter search. Then it will take terrible time during the iteration of searching for parameters.ted wrote:Suggest reading the Programmers' Reference documentation of the Vector class's hist and histogram methods
https://www.neuron.yale.edu/neuron/stat ... ector.html
and then trying them on a toy problem to determine whether one of them produces suitable results in a short enough time. Please let me know whether one of them does what you want.

 Site Admin
 Posts: 5545
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: Histogram method for a vector
Make your own replacement. Test this to make sure it works properly.
Code: Select all
// $o1 vector whose elements are to be binned
// $2 binwidth
// $3 left edge of first bin
obfunc binvec() { localobj tobj
tobj = $o1.c
tobj.sub($3)
tobj.div($2)
return tobj.apply("int")
}
Re: Histogram method for a vector
Thanks, this is really great.ted wrote:Make your own replacement. Test this to make sure it works properly.Code: Select all
// $o1 vector whose elements are to be binned // $2 binwidth // $3 left edge of first bin obfunc binvec() { localobj tobj tobj = $o1.c tobj.sub($3) tobj.div($2) return tobj.apply("int") }