Histogram method for a vector

NMODL and the Channel Builder.
Post Reply
ylzang
Posts: 27
Joined: Sun Mar 08, 2015 3:38 am

Histogram method for a vector

Post by ylzang »

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.
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Histogram method for a vector

Post by ted »

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.
ylzang
Posts: 27
Joined: Sun Mar 08, 2015 3:38 am

Re: Histogram method for a vector

Post by ylzang »

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.
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
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Histogram method for a vector

Post by ted »

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")
}
ylzang
Posts: 27
Joined: Sun Mar 08, 2015 3:38 am

Re: Histogram method for a vector

Post by ylzang »

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")
}
Thanks, this is really great.
Post Reply