Posterior¶
Package¶
posterior
¶
posterior¶
Posterior representations and diagnostics.
This subpackage provides: - Posterior : wrapper around model parameters, samples, and prediction APIs. - diagnostics : tools for checking posterior quality (ESS, R-hat, etc.).
MVP implementation
- Posterior: stores MAP parameters and delegates predictions to WPPM.
- Diagnostics: stubs and simple summaries.
Future extensions
- Posterior: store MCMC samples, support predictive intervals.
- Diagnostics: effective sample size, R-hat, posterior predictive checks.
Classes:
Name | Description |
---|---|
Posterior |
MVP Posterior (MAP only). |
Functions:
Name | Description |
---|---|
effective_sample_size |
Estimate effective sample size (ESS) to calculate the number of independent |
rhat |
Compute R-hat convergence diagnostic. |
Posterior
¶
Bases: BasePosterior
MVP Posterior (MAP only).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
dict
|
MAP parameter dictionary. |
required |
model
|
WPPM
|
Model instance used for predictions. |
required |
Notes
- This is effectively a MAPPosterior.
- Future subclasses (LaplacePosterior, MCMCPosterior) will extend BasePosterior with real sampling logic.
Methods:
Name | Description |
---|---|
MAP_params |
Return the MAP parameters. |
predict_prob |
Predict probability of correct response for a stimulus. |
predict_thresholds |
Predict discrimination threshold contour around a reference stimulus. |
sample |
Draw parameter samples from the posterior. |
Attributes:
Name | Type | Description |
---|---|---|
model |
|
|
params |
|
Source code in src/psyphy/posterior/posterior.py
MAP_params
¶
predict_prob
¶
Predict probability of correct response for a stimulus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stimulus
|
tuple
|
(reference, probe). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Probability of correct response. |
Notes
Delegates to WPPM.predict_prob(). This is not recursion: Posterior calls WPPM’s method with stored params.
Source code in src/psyphy/posterior/posterior.py
predict_thresholds
¶
Predict discrimination threshold contour around a reference stimulus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference
|
ndarray
|
Reference point in model space. |
required |
criterion
|
float
|
Target performance (e.g., 2/3 for oddity). |
0.667
|
directions
|
int
|
Number of directions to probe. |
16
|
Returns:
Type | Description |
---|---|
ndarray
|
Contour points (MVP: unit circle). |
MVP
Returns a placeholder unit circle.
Future
- Search outward in each direction until performance crosses criterion.
- Average over posterior samples (Laplace, MCMC) to get credible intervals.
Source code in src/psyphy/posterior/posterior.py
sample
¶
sample(num_samples: int = 1)
Draw parameter samples from the posterior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_samples
|
int
|
Number of samples. |
1
|
Returns:
Type | Description |
---|---|
list of dict
|
Parameter sets. |
MVP
Returns MAP params repeated n times.
Future
- LaplacePosterior: draw from N(mean, cov).
- MCMCPosterior: return stored samples.
Source code in src/psyphy/posterior/posterior.py
effective_sample_size
¶
effective_sample_size(samples: ndarray) -> float
Estimate effective sample size (ESS) to calculate the number of independent samples that a correlated MCMC chain is equivalent to.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples
|
ndarray
|
Posterior samples, shape (n_samples, ...). |
required |
Returns:
Type | Description |
---|---|
float
|
Effective sample size (stub). |
Notes
MVP: Returns the number of samples. Full WPPM mode: Compute ESS using autocorrelation structure.
Source code in src/psyphy/posterior/diagnostics.py
rhat
¶
rhat(chains: ndarray) -> float
Compute R-hat convergence diagnostic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chains
|
ndarray
|
Posterior samples across chains, shape (n_chains, n_samples, ...). |
required |
Returns:
Type | Description |
---|---|
float
|
R-hat statistic (stub). |
Notes
MVP: Always returns 1.0. Full WPPM mode: Implement Gelman-Rubin diagnostic [1]
References:
1 |
|
Source code in src/psyphy/posterior/diagnostics.py
Posterior Representation¶
posterior
¶
posterior.py
Posterior representation for WPPM.
MVP implementation: - Posterior = MAPPosterior (point estimate only). - Stores one parameter set and delegates predictions to WPPM.
Design note
- This class inherits from BasePosterior.
- In the future, other subclasses (LaplacePosterior, MCMCPosterior) will also inherit from BasePosterior, each implementing the same interface.
Classes:
Name | Description |
---|---|
Posterior |
MVP Posterior (MAP only). |
Posterior
¶
Bases: BasePosterior
MVP Posterior (MAP only).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
dict
|
MAP parameter dictionary. |
required |
model
|
WPPM
|
Model instance used for predictions. |
required |
Notes
- This is effectively a MAPPosterior.
- Future subclasses (LaplacePosterior, MCMCPosterior) will extend BasePosterior with real sampling logic.
Methods:
Name | Description |
---|---|
MAP_params |
Return the MAP parameters. |
predict_prob |
Predict probability of correct response for a stimulus. |
predict_thresholds |
Predict discrimination threshold contour around a reference stimulus. |
sample |
Draw parameter samples from the posterior. |
Attributes:
Name | Type | Description |
---|---|---|
model |
|
|
params |
|
Source code in src/psyphy/posterior/posterior.py
MAP_params
¶
predict_prob
¶
Predict probability of correct response for a stimulus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stimulus
|
tuple
|
(reference, probe). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Probability of correct response. |
Notes
Delegates to WPPM.predict_prob(). This is not recursion: Posterior calls WPPM’s method with stored params.
Source code in src/psyphy/posterior/posterior.py
predict_thresholds
¶
Predict discrimination threshold contour around a reference stimulus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference
|
ndarray
|
Reference point in model space. |
required |
criterion
|
float
|
Target performance (e.g., 2/3 for oddity). |
0.667
|
directions
|
int
|
Number of directions to probe. |
16
|
Returns:
Type | Description |
---|---|
ndarray
|
Contour points (MVP: unit circle). |
MVP
Returns a placeholder unit circle.
Future
- Search outward in each direction until performance crosses criterion.
- Average over posterior samples (Laplace, MCMC) to get credible intervals.
Source code in src/psyphy/posterior/posterior.py
sample
¶
sample(num_samples: int = 1)
Draw parameter samples from the posterior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_samples
|
int
|
Number of samples. |
1
|
Returns:
Type | Description |
---|---|
list of dict
|
Parameter sets. |
MVP
Returns MAP params repeated n times.
Future
- LaplacePosterior: draw from N(mean, cov).
- MCMCPosterior: return stored samples.
Source code in src/psyphy/posterior/posterior.py
Diagnostics¶
diagnostics
¶
diagnostics.py
Posterior diagnostics.
Provides functions to check quality of posterior inference.
MVP implementation: - Stubs for effective sample size and R-hat.
Full WPPM mode: - Implement real diagnostics from posterior chains. - Include posterior predictive checks.
Functions:
Name | Description |
---|---|
effective_sample_size |
Estimate effective sample size (ESS) to calculate the number of independent |
rhat |
Compute R-hat convergence diagnostic. |
effective_sample_size
¶
effective_sample_size(samples: ndarray) -> float
Estimate effective sample size (ESS) to calculate the number of independent samples that a correlated MCMC chain is equivalent to.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples
|
ndarray
|
Posterior samples, shape (n_samples, ...). |
required |
Returns:
Type | Description |
---|---|
float
|
Effective sample size (stub). |
Notes
MVP: Returns the number of samples. Full WPPM mode: Compute ESS using autocorrelation structure.
Source code in src/psyphy/posterior/diagnostics.py
rhat
¶
rhat(chains: ndarray) -> float
Compute R-hat convergence diagnostic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chains
|
ndarray
|
Posterior samples across chains, shape (n_chains, n_samples, ...). |
required |
Returns:
Type | Description |
---|---|
float
|
R-hat statistic (stub). |
Notes
MVP: Always returns 1.0. Full WPPM mode: Implement Gelman-Rubin diagnostic [1]
References:
1 |
|