Page 1 of 1

Histogram method for a vector

Posted: Thu Oct 01, 2015 1:51 am
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.

Re: Histogram method for a vector

Posted: Thu Oct 01, 2015 12:59 pm
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.

Re: Histogram method for a vector

Posted: Fri Oct 16, 2015 3:48 am
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.

Re: Histogram method for a vector

Posted: Fri Oct 16, 2015 3:50 pm
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")
}

Re: Histogram method for a vector

Posted: Sat Oct 17, 2015 9:54 pm
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.