skneuromsi.bayesian._kording2007 module

Implementation of multisensory integration models in Python.

class skneuromsi.bayesian._kording2007.Kording2007(*, n=1, mode0='auditory', mode1='visual', position_range=(-42, 42), position_res=1.7142857142857142, time_range=(0, 1), time_res=1, seed=None)[source]

Bases: SKNMSIMethodABC

Bayesian Causal Inference model for multisensory integration.

This model based on Kording et al. (2007) uses Bayesian principles to infer whether two unimodal signals come from a common cause or different causes. It combines auditory and visual signals and evaluates the probability of a common cause based on the observed signals.

This implementation is inspired on the Matlab version of the BCI Toolbox (Zhu, Beierholm & Shams, 2024).

References

[Kording et al., 2007] [Zhu et al., 2024a]

Notes

The Bayesian Causal Inference model uses the following formulation:

\[p(C \mid x_{1}, x_{2}) = \frac{p(x_{1}, x_{2} \mid C), p(C)}{p(x_{1}, x_{2})}\]

where \(x_{1}\) and \(x_{2}\) are two unimodal signals, and \(C\) is a binary variable representing the number of causes in the environment.

The posterior probability of the signals having a single cause in the environment is defined as follows:

\[p(C = 1 \mid x_{1}, x_{2}) = \frac{p(x_{1}, x_{2} \mid C=1), p(C=1)}{p(x_{1}, x_{2} \mid C=1) \, p(C=1) + p(x_{1}, x_{2} \mid C=2), (1 - p(C=1))}\]

The likelihood is computed as:

\[p(x_{1}, x_{2} \mid C = 1) = \int\int p(x_{1}, x_{2} \mid X) p(X) dX\]

Here, \(p(C = 1)\) is the prior probability of a common cause (default is 0.5). \(X\) denotes the attributes of the stimuli (e.g., distance), which are then represented in the nervous system as \(x_{1}\) and \(x_{2}\).

These equations show that the inference of a common cause of two unisensory signals is computed by combining the likelihood and prior of signals having a common cause. A higher likelihood occurs if the two unisensory signals are similar, which in turn increases the probability of inferring that the signals have a common cause.

property mode0

Returns the name of the first sensory modality.

Returns:

The name of the first sensory modality.

Return type:

str

property mode1

Returns the name of the second sensory modality.

Returns:

The name of the second sensory modality.

Return type:

str

property n

Returns the number of simulations.

Returns:

The number of simulations to run.

Return type:

int

property time_range

Returns the range of time steps considered.

Returns:

The range of time steps.

Return type:

tuple of int

property time_res

Returns the resolution of time steps considered.

Returns:

The resolution of time steps.

Return type:

int

property position_range

Returns the range of positions considered for estimation.

Returns:

The range of positions. E.g., (-42, 43).

Return type:

tuple of float

property position_res

Returns the resolution of positions considered for estimation.

Returns:

The resolution of positions. E.g., 1.7142857142857142.

Return type:

float

property random

Returns the random number generator.

Returns:

The random number generator.

Return type:

numpy.random.Generator

input_computation(unisensory_position, unisensory_var, noise)[source]

Computes the unisensory input.

Unisensory input considers the position estimate and variance. In this implementation noise is optional.

Parameters:
  • unisensory_position (float) – The position estimate for the sensory modality.

  • unisensory_var (float) – The variance of the sensory modality.

  • noise (bool) – Whether to include noise in the computation.

Returns:

The computed input for the sensory modality.

Return type:

float

unisensory_estimator(unisensory_var, unisensory_var_hat, prior_var, prior_mu, unisensory_input)[source]

Estimates the unisensory posterior given the input and prior.

Parameters:
  • unisensory_var (float) – The variance of the sensory modality.

  • unisensory_var_hat (float) – The estimated variance of the sensory modality.

  • prior_var (float) – The prior variance of the cause.

  • prior_mu (float) – The prior mean of the cause.

  • unisensory_input (float) – The input value for the sensory modality.

Returns:

The posterior estimate of the sensory modality.

Return type:

float

multisensory_estimator(auditory_estimate, visual_estimate, auditory_var, visual_var, prior_var, prior_mu, multisensory_var, multisensory_var_hat, n, auditory_ind_var, visual_ind_var, p_common, strategy, possible_locations, auditory_input, visual_input)[source]

Estimates the multisensory posterior using Bayesian inference.

Parameters:
  • auditory_estimate (float) – The auditory estimate of the sensory modality.

  • visual_estimate (float) – The visual estimate of the sensory modality.

  • auditory_var (float) – The variance of the auditory modality.

  • visual_var (float) – The variance of the visual modality.

  • prior_var (float) – The prior variance of the cause.

  • prior_mu (float) – The prior mean of the cause.

  • multisensory_var (float) – The variance of the multisensory estimate.

  • multisensory_var_hat (float) – The estimated variance of the multisensory estimate.

  • n (int) – Number of simulations.

  • auditory_ind_var (float) – The variance of the independent auditory estimate.

  • visual_ind_var (float) – The variance of the independent visual estimate.

  • p_common (float) – The prior probability of a common cause.

  • strategy (str) – The strategy for model selection (“selection”, “averaging”, “matching”).

  • possible_locations (np.ndarray) – The possible positions to consider for estimation.

  • auditory_input (float) – The input value for the auditory modality.

  • visual_input (float) – The input value for the visual modality.

Returns:

A dictionary with keys: - “auditory”: The auditory posterior estimate. - “visual”: The visual posterior estimate. - “multi”: The multisensory posterior estimate. - “pc”: The posterior probability of a common cause.

Return type:

dict

set_random(rng)[source]

Sets the random number generator.

Parameters:

rng (numpy.random.Generator) – The random number generator to set.

run(*, auditory_position=-15, visual_position=15, auditory_sigma=2.0, visual_sigma=10.0, p_common=0.5, prior_sigma=20.0, prior_mu=0, strategy='averaging', noise=True, causes_kind='count', dimension='space')[source]

Runs the Bayesian causal inference model.

Parameters:
  • auditory_position (float) – The position of the auditory stimulus.

  • visual_position (float) – The position of the visual stimulus.

  • auditory_sigma (float) – The standard deviation of the auditory stimulus.

  • visual_sigma (float) – The standard deviation of the visual stimulus.

  • p_common (float) – The prior probability of a common cause.

  • prior_sigma (float) – The standard deviation of the prior cause.

  • prior_mu (float) – The mean of the prior cause.

  • strategy (str) – The strategy for model selection (“selection”, “averaging”, “matching”).

  • noise (bool) – Whether to include noise in the computation.

  • causes_kind (str) – The type of cause to calculate (“count” or “prob”).

  • dimension (str) – The dimension to run the model (“space” or “time”).

Returns:

A tuple containing: - dict: Response dictionary with “auditory”, “visual”, and “multi” keys. - dict: Extra information with “mean_p_common_cause”, “p_common_cause”, and “causes_kind”.

Return type:

tuple

calculate_causes(mean_p_common_cause, causes_kind, **kwargs)[source]

Calculates the causes of the stimuli.

Parameters:
  • mean_p_common_cause (float or np.ndarray) – The average probability of a common cause across simulations.

  • causes_kind (str) – The type of cause to calculate (“count” or “prob”).

Returns:

The number of causes if causes_kind is “count”, the probability of a unique cause if causes_kind is “prob”, or None if no valid cause type is specified.

Return type:

int or float or None