shimazaki / adaptivekde Goto Github PK
View Code? Open in Web Editor NEWPython module for adaptive kernel density estimation
License: Apache License 2.0
Python module for adaptive kernel density estimation
License: Apache License 2.0
using your function : sskernel :
while anlyzing multiple data sessions I encountered the following problem :
Traceback (most recent call last):
File "/home/azare/groups/PrimNeu/Aryo/analysis/fit/automate_mix_psth_fit_nmz_10_re_sig_8_unit_14_opt.py", line 458, in <module>
kv , t , okbw = KDE(l_f_8_soi_ms[i])
File "/home/azare/groups/PrimNeu/Aryo/analysis/opt/KDE.py", line 133, in KDE
y = y * len(spike_times)
UnboundLocalError: local variable 'y' referenced before assignment
The problematic input array :
np.array([425.36666667, 230.6 , 35.86666667])
While an array of only 3 elemtns is not realistic to be considered as data, this was running through a loop of hundreds of sessions, hence such input data is also imaginable.
The program stuck in the middle of a loop with the above error.
It seems to me that in this case, your while statement was never satisfied (not 'True') :
AdaptiveKDE/adaptivekde/sskernel.py
Line 109 in 64a0696
The code needs to cast from a float to an int when making the call to np.ceil(). Right now it wont run unless the code is normalized to integer values.
I would like to mention about adding an option to the current sskernel or ssvkernel functions :
It seems to me that your functions normalize the plot so that the area under the curve would be 1.
The similar function in your colleague's (Shinomoto) website returns similar plots but the y axis has a different scale (possibly not normalized).
https://s-shinomoto.com/histograms/python/KDE_rate_v4.py
While normalization has particular advantages, I would also like to get an estimated real (absolute) firing rate.
The reason is that I would like to compare the firing rate of different sessions.
How can this be achieved ?
First, many thanks for providing this package.
I would like to mention a small bug in this program :
The following line outputs a float :
AdaptiveKDE/adaptivekde/sshist.py
Line 63 in 64a0696
The line thereafter ('range' function) accepts an integer :
AdaptiveKDE/adaptivekde/sshist.py
Line 64 in 64a0696
This can simply be fixed by type-casting when defining 'N_MAX' :
N_MAX = int ( min(np.floor((x_max - x_min) / (2*dx)), max(N)) )
I would like to mention a small but important improvement to the program.
np.int & np.float are aliases of the python operator 'int' , 'float' respectively. They are deprecated in newer versions of numpy.
Usage of them does not make any error but since they are extensively used in your program, there are over 10 warnings per analysis session, which if used in a loop of many sessions, may cause crashing of the IDE and may decrease the speed of the program.
Just using 'int' or 'float' instead is safe & is preferred.
Below I put the program warnings :
N = sum(y_hist).astype(np.float)
/home/azare/anaconda3/envs/env_2/lib/python3.10/site-packages/adaptivekde/ssvkernel.py:99: DeprecationWarning: np.float
is a deprecated alias for the builtin float
. To silence this warning, use float
by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64
here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
f = np.linspace(0, n-1, n.astype(np.int)) / n
/home/azare/anaconda3/envs/env_2/lib/python3.10/site-packages/adaptivekde/ssvkernel.py:268: DeprecationWarning: np.int
is a deprecated alias for the builtin int
. To silence this warning, use int
by itself. Doing this will not modify any behavior and is safe. When replacing np.int
, you may wish to use e.g. np.int64
or np.int32
to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
hi i cannot find any documentation on how to use this?
Dear developers of AdaptiveKDE method,
I am trying to use this package for estimating the temporal firing rate profile from spike trains of several trials. I had a look a the function "ssvkernel" and I am having trouble understanding the input parameters of this function. The argument "x" says it requires "The one-dimensional samples drawn from the underlying density". I am not able to figure out how to transform information in the trial spike trains of my data before supplying it to "x". Could you provide an example use case, preferably, the code used to generate Fig. 4(b) or (c) of the reference?
Thank you.
Sincerely
Ajay
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.