braintools.cogtask.von_mises#
- braintools.cogtask.von_mises(key, coherence_key=None, kappa=2.0, base_value=0.5, max_coherence=100.0, as_index=True, num_dirs=None)[source]#
Von Mises (circular-normal) directional encoder.
Output is a normalized von Mises tuning curve in
[base_value, 1].- Parameters:
key (
str) – Context key holding the direction. Whenas_index=True(default) the value is an integer index in[0, num_dirs)and is converted to2π * idx / num_dirs. Whenas_index=Falseit is an angle in radians (matchingcircular).coherence_key (
str|None) – Context key with a coherence in[0, max_coherence]. IfNonethe encoder usesmax_coherence(full strength).kappa (
float) – Concentration parameter; higher values give sharper tuning.base_value (
float) – Floor of the response after normalization.max_coherence (
float) – Coherence normalization constant.as_index (
bool) – Interpretctx[key]as an integer index rather than radians. The default matches the working-memory tasks which passsample_idx.num_dirs (
int|None) – Number of discrete directions whenas_index=True. Defaults tofeature.num.
- Returns:
Encoder function (ctx, feature) -> np.ndarray
- Return type:
Examples
>>> import jax.numpy as jnp >>> import numpy as np >>> from braintools.cogtask import Context, Feature, von_mises >>> ctx = Context() >>> ctx.update(sample_idx=2, direction=jnp.pi, coherence=25.0) >>> # Direction index 2 of 4: the third unit responds maximally >>> np.asarray(von_mises('sample_idx')(ctx, Feature(4, 'stimulus')), dtype=float).round(3) array([0.5 , 0.56, 1. , 0.56]) >>> # Angle in radians; lower coherence flattens the tuning curve >>> enc = von_mises('direction', 'coherence', as_index=False) >>> np.asarray(enc(ctx, Feature(4, 'motion')), dtype=float).round(3) array([0.5 , 0.689, 1. , 0.689])