Repository navigation
Generate drift - #2683
Generate drift#2683
Conversation
…ce into generate_drift
…ce into generate_drift
h-mayorquin
left a comment
There was a problem hiding this comment.
I would like to point out an issue of design.
When I came up with the idea of the NoiseGenerator what I wanted is to have an object whose memory footprint I could control finely to solve memory bugs. Then, as this object became the center of the hybrid project more and more bells and whistles were added to it. Overall I feel that's fine because the second objective seems more important than the first.
However, I don't see why we can't have both. I would propose creating a WhiteNoiseGenerator that just generates noise and has a memory profile that we can finely control.
Then we can use that WhiteNoiseGenerator and wrap it to produce the data sampled from a multivariate normal that you want here by using the spectral formulation:
Another option is just to have two generators and eat some duplication of code which is fine as well.
| if isinstance(firing_rates, tuple): | ||
| rng = np.random.default_rng(seed=seed) | ||
| lim0, lim1 = firing_rates | ||
| firing_rates = rng.random(num_units) * (lim1 - lim0) + lim0 |
There was a problem hiding this comment.
There was a problem hiding this comment.
I was thinking that random was uniform no ?
Lets use uniform it is more explicit maybe.
There was a problem hiding this comment.
Yeah, but only between 0 and 1. With uniform you don't need to do the math yourself as you can specificy high and low.
There was a problem hiding this comment.
I also vote for uniform(lim0, lim1)
| firing_rates : float or array_like, default: 3.0 | ||
| firing_rates : float or array_like or tuple, default: 3.0 | ||
| Firing rate(s) in Hz. Can be a single value for all units or an array of firing rates with | ||
| each element being the firing rate for one unit |
There was a problem hiding this comment.
Let's add documentation for the tuple.
| rng.standard_normal(size=(self.noise_block_size, self.num_channels), dtype=self.dtype) * noise_levels | ||
| ) | ||
|
|
||
| if self.cov_matrix is None: |
There was a problem hiding this comment.
Another option is that the cov is the identity by default and then you don't need this if. But I am not sure if this is less performant.
Maybe we can do that later.
There was a problem hiding this comment.
This internally make a np.dot I think so handling None is good no ?
There was a problem hiding this comment.
I meant that if cov=None then cov=np.eye(number_of_channels) and then you don't have the if.
But I think this version is more memory efficient when cov is None as it avoids the creation of a large matrix.
|
|
||
| if np.isscalar(firing_rates): | ||
| firing_rates = np.full(num_units, firing_rates, dtype="float64") | ||
| firing_rates = _ensure_firing_rates(firing_rates, num_units, seed) |
There was a problem hiding this comment.
You can pass the rng as well as mentioned above?
There was a problem hiding this comment.
The thing is that if the rng is used before or not depending other global option then we do not have the same.
With this seed given we somehow reset the generator whatever happen.
There was a problem hiding this comment.
You are correct. This is a very good point for reproducibility. Passing the rng means you are passing state which is wrong.
| return displacement_vectors, displacement_unit_factor, displacement_sampling_frequency, displacements_steps | ||
|
|
||
|
|
||
| def generate_noise( |
There was a problem hiding this comment.
Please make a noise_tools.py file
|
@h-mayorquin. If the object would become too complex, ok for several classes. But here it is really a minimal change and I think having only one class is ok no ? |
Yeah, the complexity is not there yet but it always accumulates sloly. The memory foot-print is still the same for the I was mentioning this as something to keep an eye on but this should not stop this PR from being merged. Once the two different purposes drift enough appart we should separate. |
@alejoe91 : this is a important piece that @yger will need during my vaccation.
This refactor a bit some parameters in core.generate.
But this mainly add the function
generate_drifting_recording()with a nice and simple API to generate drift recordings.Do you think we could merge this very soon ?