Covariance Field: Visualizing Spatially-Varying Thresholds¶
This example demonstrates how to work with the WPPMCovarianceField abstraction for visualizing spatially-varying perceptual thresholds in the Wishart Process Psychophysical Model (WPPM).
The covariance field provides a clean, functional interface for: - Evaluating covariance matrices at different stimulus locations
-
Visualizing threshold countours (as ellipses)
-
Understanding how perceptual noise varies across stimulus space
You can run this complete example yourself with:
Mathematical Background¶
A covariance field \(\Sigma(x)\) maps stimulus locations to covariance matrices, representing how perceptual thresholds vary across space.
Wishart Process Covariance¶
The full WPPM uses a Wishart Process to model spatially-varying, full covariance:
where:
- \(\phi_{ij}(x)\): Chebyshev basis functions
- \(W_{ij}\): Learned coefficients
- \(\lambda\): Numerical stabilizer (
diag_term)
Imports¶
| Required Imports | |
|---|---|
Example 1: Single Point Threshold Ellipse¶
Creating a Wishart Covariance Field¶
First, we create a WPPM model in Wishart mode with 5×5 basis functions (basis_degree=4) and sample a covariance field from the prior:
Key parameters:
- basis_degree=4: Activates Wishart mode with 5×5 Chebyshev basis functions (degrees 0-4)
- extra_dims=1: Adds embedding dimensions for richer covariance structure
- variance_scale=0.03, decay_rate=0.3: Control spatial smoothness
- field(x): Callable interface makes the field feel like a mathematical function
Visualizing a Single Threshold Ellipse¶
We can visualize the threshold at a single point as an ellipse:
Threshold ellipse at point (0.5, 0.5). The ellipse shape encodes the covariance structure: elongation shows correlation direction, size shows threshold magnitude.
Example 2: Covariance Field Grid¶
Batch Evaluation Across Stimulus Space¶
To see how thresholds vary across space, we evaluate the covariance field at multiple points:
Batch evaluation methods:
1. field.cov_batch(X) - Explicit batch method
2. jax.vmap(field)(X) - JAX vmap on callable interface
3. both are equivalent and efficient
Visualizing the Ellipse Field¶
5×5 grid of uncertainty ellipses showing spatial variation. note how ellipse size, shape, and orientation vary smoothly across the stimulus space.
Example 3: Custom Covariance Fields¶
Sampling Different Fields¶
You can sample multiple fields from the prior or create fields from custom parameters:
| Custom Field from Different Prior Sample | |
|---|---|
Visualizing Custom Fields¶
Different prior sample produces different spatial pattern.
API Reference¶
Construction Methods¶
| Method | Description | Use Case |
|---|---|---|
from_prior(model, key) |
Sample from prior | Initialization, visualization |
from_posterior(posterior) |
Extract fitted field | Analysis after fitting |
from_params(model, params) |
Custom parameters | testing / load fitted params from e.g. different subject |
Evaluation Methods¶
| Method | Input Shape | Output Shape | Description |
|---|---|---|---|
field(x) |
(d,) |
(d, d) |
Callable interface |
field.cov(x) |
(d,) |
(d, d) |
Explicit covariance |
field.cov_batch(X) |
(n, d) |
(n, d, d) |
Batch evaluation |
jax.vmap(field)(X) |
(n, d) |
(n, d, d) |
JAX vmap |
where:
- d = embedding_dim (Wishart mode)
- n = number of evaluation points
Properties¶
| Property | Returns | Description |
|---|---|---|
field.is_wishart_mode |
bool |
True if spatially-varying |
field.model |
WPPM |
Associated model |
field.params |
dict |
Parameter dictionary |
Integration with WPPM Workflow¶
Here's how the covariance field would integrate into the full WPPM workflow: