Data¶
Package¶
data
¶
psyphy.data¶
submodule for handling psychophysical experiment data.
Includes: - dataset: ResponseData, TrialBatch, loaders - transforms: color/model space conversions - io: save/load datasets
Classes:
| Name | Description |
|---|---|
ResponseData |
Container for psychophysical trial data. |
TrialBatch |
Container for a proposed batch of trials |
ResponseData
¶
Container for psychophysical trial data.
Attributes:
| Name | Type | Description |
|---|---|---|
refs |
List[Any]
|
List of reference stimuli. |
comparisons |
List[Any]
|
List of comparison stimuli. |
responses |
List[int]
|
List of subject responses (e.g., 0/1 or categorical). |
Methods:
| Name | Description |
|---|---|
add_batch |
Append responses for a batch of trials. |
add_trial |
append a single trial. |
copy |
Create a deep copy of this dataset. |
from_arrays |
Construct ResponseData from arrays. |
merge |
Merge another dataset into this one (in-place). |
tail |
Return last n trials as a new ResponseData. |
to_numpy |
Return refs, comparisons, responses as numpy arrays. |
Source code in src/psyphy/data/dataset.py
trials
¶
add_batch
¶
add_batch(
responses: list[int], trial_batch: TrialBatch
) -> None
Append responses for a batch of trials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
responses
|
List[int]
|
Responses corresponding to each (ref, comparison) in the trial batch. |
required |
trial_batch
|
TrialBatch
|
The batch of proposed trials. |
required |
Source code in src/psyphy/data/dataset.py
add_trial
¶
append a single trial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
Any
|
Reference stimulus (numpy array, list, etc.) |
required |
comparison
|
Any
|
Probe stimulus |
required |
resp
|
int
|
Subject response (binary or categorical) |
required |
Source code in src/psyphy/data/dataset.py
copy
¶
copy() -> ResponseData
Create a deep copy of this dataset.
Returns:
| Type | Description |
|---|---|
ResponseData
|
New dataset with copied data |
Source code in src/psyphy/data/dataset.py
from_arrays
¶
from_arrays(
X: ndarray | ndarray,
y: ndarray | ndarray,
*,
comparisons: ndarray | ndarray | None = None,
) -> ResponseData
Construct ResponseData from arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
(array, shape(n_trials, 2, input_dim) or (n_trials, input_dim))
|
Stimuli. If 3D, second axis is [reference, comparison]. If 2D, comparisons must be provided separately. |
required |
y
|
(array, shape(n_trials))
|
Responses |
required |
comparisons
|
(array, shape(n_trials, input_dim))
|
Probe stimuli. Only needed if X is 2D. |
None
|
Returns:
| Type | Description |
|---|---|
ResponseData
|
Data container |
Examples:
Source code in src/psyphy/data/dataset.py
merge
¶
merge(other: ResponseData) -> None
Merge another dataset into this one (in-place).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
ResponseData
|
Dataset to merge |
required |
Source code in src/psyphy/data/dataset.py
tail
¶
tail(n: int) -> ResponseData
Return last n trials as a new ResponseData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of trials to keep |
required |
Returns:
| Type | Description |
|---|---|
ResponseData
|
New dataset with last n trials |
Source code in src/psyphy/data/dataset.py
TrialBatch
¶
Container for a proposed batch of trials
Attributes:
| Name | Type | Description |
|---|---|---|
stimuli |
List[Tuple[Any, Any]]
|
Each trial is a (reference, comparison) tuple. |
Methods:
| Name | Description |
|---|---|
from_stimuli |
Construct a TrialBatch from a list of stimuli (ref, comparison) pairs. |
Source code in src/psyphy/data/dataset.py
Data Containers for Response Data and Proposed Next Trials¶
dataset
¶
dataset.py
Core data containers for psyphy.
defines: - ResponseData: container for psychophysical trial data - TrialBatch: container for a proposed batch of trials
Notes
- Data is stored in standard NumPy (mutable!) arrays or Python lists.
- Use numpy for I/O and analysis.
- Convert to jax.numpy (jnp) (immutable!) arrays only when passing into WPPM or inference engines that require JAX/Optax.
Classes:
| Name | Description |
|---|---|
ResponseData |
Container for psychophysical trial data. |
TrialBatch |
Container for a proposed batch of trials |
ResponseData
¶
Container for psychophysical trial data.
Attributes:
| Name | Type | Description |
|---|---|---|
refs |
List[Any]
|
List of reference stimuli. |
comparisons |
List[Any]
|
List of comparison stimuli. |
responses |
List[int]
|
List of subject responses (e.g., 0/1 or categorical). |
Methods:
| Name | Description |
|---|---|
add_batch |
Append responses for a batch of trials. |
add_trial |
append a single trial. |
copy |
Create a deep copy of this dataset. |
from_arrays |
Construct ResponseData from arrays. |
merge |
Merge another dataset into this one (in-place). |
tail |
Return last n trials as a new ResponseData. |
to_numpy |
Return refs, comparisons, responses as numpy arrays. |
Source code in src/psyphy/data/dataset.py
trials
¶
add_batch
¶
add_batch(
responses: list[int], trial_batch: TrialBatch
) -> None
Append responses for a batch of trials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
responses
|
List[int]
|
Responses corresponding to each (ref, comparison) in the trial batch. |
required |
trial_batch
|
TrialBatch
|
The batch of proposed trials. |
required |
Source code in src/psyphy/data/dataset.py
add_trial
¶
append a single trial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
Any
|
Reference stimulus (numpy array, list, etc.) |
required |
comparison
|
Any
|
Probe stimulus |
required |
resp
|
int
|
Subject response (binary or categorical) |
required |
Source code in src/psyphy/data/dataset.py
copy
¶
copy() -> ResponseData
Create a deep copy of this dataset.
Returns:
| Type | Description |
|---|---|
ResponseData
|
New dataset with copied data |
Source code in src/psyphy/data/dataset.py
from_arrays
¶
from_arrays(
X: ndarray | ndarray,
y: ndarray | ndarray,
*,
comparisons: ndarray | ndarray | None = None,
) -> ResponseData
Construct ResponseData from arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
(array, shape(n_trials, 2, input_dim) or (n_trials, input_dim))
|
Stimuli. If 3D, second axis is [reference, comparison]. If 2D, comparisons must be provided separately. |
required |
y
|
(array, shape(n_trials))
|
Responses |
required |
comparisons
|
(array, shape(n_trials, input_dim))
|
Probe stimuli. Only needed if X is 2D. |
None
|
Returns:
| Type | Description |
|---|---|
ResponseData
|
Data container |
Examples:
Source code in src/psyphy/data/dataset.py
merge
¶
merge(other: ResponseData) -> None
Merge another dataset into this one (in-place).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
ResponseData
|
Dataset to merge |
required |
Source code in src/psyphy/data/dataset.py
tail
¶
tail(n: int) -> ResponseData
Return last n trials as a new ResponseData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of trials to keep |
required |
Returns:
| Type | Description |
|---|---|
ResponseData
|
New dataset with last n trials |
Source code in src/psyphy/data/dataset.py
TrialBatch
¶
Container for a proposed batch of trials
Attributes:
| Name | Type | Description |
|---|---|---|
stimuli |
List[Tuple[Any, Any]]
|
Each trial is a (reference, comparison) tuple. |
Methods:
| Name | Description |
|---|---|
from_stimuli |
Construct a TrialBatch from a list of stimuli (ref, comparison) pairs. |
Source code in src/psyphy/data/dataset.py
Transforms (e.g., from RGB to model space)¶
transforms
¶
transforms.py
color space transformations.
functions (MVP stubs): - to_model_space(rgb): map RGB stimulus values into model space - to_rgb(model_coords): map from model space back to RGB
Future extensions: - other color spaces
Functions:
| Name | Description |
|---|---|
model_to_stimuli |
Map from model space coordinates to RGB values. |
stimuli_to_model_space |
Map RGB stimulus values to model space coordinates. |
Attributes:
| Name | Type | Description |
|---|---|---|
ArrayLike |
|
model_to_stimuli
¶
model_to_stimuli(model_coords: ArrayLike) -> ndarray
Map from model space coordinates to RGB values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_coords
|
array - like
|
Model space coordinates. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
RGB values (MVP: identical to input). |
Source code in src/psyphy/data/transforms.py
stimuli_to_model_space
¶
stimuli_to_model_space(rgb: ArrayLike) -> ndarray
Map RGB stimulus values to model space coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb
|
array - like
|
RGB values, shape (3,) or similar. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Model-space coordinates (MVP: identical to input). |
Source code in src/psyphy/data/transforms.py
I/O¶
io
¶
io.py
I/O utilities for saving and loading psyphy data.
Supports: - CSV for human-readable trial logs - Pickle (.pkl) for Posterior and ResponseData checkpoints?
Notes
- Data is stored in NumPy arrays (via ResponseData.to_numpy()).
- Convert to jax.numpy when passing into models.
Functions:
| Name | Description |
|---|---|
load_posterior |
Load a Posterior object from pickle. |
load_responses_csv |
Load ResponseData from a CSV file. |
save_posterior |
Save a Posterior object to disk using pickle. |
save_responses_csv |
Save ResponseData to a CSV file. |
Attributes:
| Name | Type | Description |
|---|---|---|
PathLike |
|
load_posterior
¶
load_responses_csv
¶
load_responses_csv(path: PathLike) -> ResponseData
Load ResponseData from a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
|
required |
Returns:
| Type | Description |
|---|---|
ResponseData
|
|
Source code in src/psyphy/data/io.py
save_posterior
¶
save_responses_csv
¶
save_responses_csv(
data: ResponseData, path: PathLike
) -> None
Save ResponseData to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ResponseData
|
|
required |
path
|
str or Path
|
|
required |