Evaluation API Reference
Functions for evaluating trained retinal models, including correlation metrics, oracle computations, and variance analysis.
Metrics
metrics
correlation_numpy
correlation_numpy(
y1: ndarray,
y2: ndarray,
axis: None | int | tuple[int, ...] = -1,
eps: float = 1e-08,
**kwargs,
) -> ndarray
Compute the correlation between two NumPy arrays along the specified dimension(s).
Source code in openretina/eval/metrics.py
12 13 14 15 16 17 18 19 | |
MSE_numpy
MSE_numpy(
y1: ndarray,
y2: ndarray,
axis: None | int | tuple[int, ...] = -1,
**kwargs,
) -> ndarray
Compute the mean squared error between two NumPy arrays along the specified dimension(s).
Source code in openretina/eval/metrics.py
22 23 24 | |
poisson_loss_numpy
poisson_loss_numpy(
y_true: ndarray,
y_pred: ndarray,
eps: float = 1e-08,
mean_axis: None | int | tuple[int, ...] = -1,
) -> ndarray
Compute the Poisson loss between two NumPy arrays.
Source code in openretina/eval/metrics.py
27 28 29 30 31 | |
model_predictions
model_predictions(
loader, model: Module, data_key, device
) -> tuple[ndarray, ndarray]
computes model predictions for a given dataloader and a model Returns: target: ground truth, i.e. neuronal firing rates of the neurons output: responses as predicted by the network
Source code in openretina/eval/metrics.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
corr_stop
corr_stop(
model: Module,
loader,
avg: bool = True,
device: str = "cpu",
)
Returns either the average correlation of all neurons or the correlations per neuron. Gets called by early stopping and the model performance evaluation
Source code in openretina/eval/metrics.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
corr_stop3d
corr_stop3d(
model: Module,
loader,
avg: bool = True,
device: str = "cpu",
)
Returns either the average correlation of all neurons or the correlations per neuron. Gets called by early stopping and the model performance evaluation
Source code in openretina/eval/metrics.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
explainable_vs_total_var
explainable_vs_total_var(
repeated_outputs: Float[
ndarray, "frames repeats neurons"
],
eps: float = 1e-09,
) -> tuple[
Float[ndarray, " neurons"], Float[ndarray, " neurons"]
]
Adapted from neuralpredictors. Compute the ratio of explainable to total variance per neuron. See Cadena et al., 2019: https://doi.org/10.1371/journal.pcbi.1006897
| PARAMETER | DESCRIPTION |
|---|---|
repeated_outputs
|
numpy array with shape (images/time, repeats, neurons) containing the responses.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
A tuple containing: - var_ratio (array): Ratio of explainable to total variance per neuron - explainable_var (array): Explainable variance for each neuron
TYPE:
|
Source code in openretina/eval/metrics.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
feve
feve(
targets: Float[ndarray, "frames repeats neurons"],
predictions: Float[ndarray, "frames repeats neurons"]
| Float[ndarray, "frames neurons"],
) -> Float[ndarray, " neurons"]
Adapted from neuralpredictors. Compute the fraction of explainable variance explained per neuron
| PARAMETER | DESCRIPTION |
|---|---|
targets
|
Neuron responses (ground truth) over time / different images across repetitions.
TYPE:
|
predictions
|
Model predictions to the repeated images, either including or excluding
TYPE:
|
repetitions. Dimensions
|
np.array(images/time, num_repeats, num_neurons) or np.array(images/time, num_neurons)
|
Returns: FEVe (np.array): the fraction of explainable variance explained per neuron
Source code in openretina/eval/metrics.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
crop_responses
crop_responses(
responses: ndarray, predictions: ndarray
) -> tuple[ndarray, int]
Crop responses to match prediction length, accounting for temporal lag.
| PARAMETER | DESCRIPTION |
|---|---|
responses
|
Array of responses, last axis is time.
TYPE:
|
predictions
|
Array of predictions, first axis is time.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ndarray, int]
|
Tuple of (cropped responses, lag). |
Source code in openretina/eval/metrics.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
Oracles
oracles
oracle_corr_jackknife
oracle_corr_jackknife(
repeated_responses: Float[
ndarray, "frames repeats neurons"
],
cut_first_n_frames: int | None = None,
) -> tuple[
Float[ndarray, " neurons"],
Float[ndarray, " frames repeats neurons"],
]
Adapted from neuralpredictors. Compute the oracle correlations per neuron by averaging over repeated responses in a leave one out fashion. Note that oracle_corr_jackknife underestimates the true oracle correlation.
| PARAMETER | DESCRIPTION |
|---|---|
repeated_responses
|
numpy array with shape (images/time, repeats, neuron responses).
TYPE:
|
cut_first_n_frames
|
if provided, indicated how many frames to cut from the repeated responses.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
A tuple containing: - oracle_score (array): Oracle correlation for each neuron - oracle (array): Oracle responses for each neuron
TYPE:
|
Source code in openretina/eval/oracles.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
global_mean_oracle
global_mean_oracle(
responses: Float[ndarray, "frames repeats neurons"]
| Float[ndarray, "frames neurons"],
cut_first_n_frames: int | None = None,
) -> Float[ndarray, " neurons"]
Compute the oracle correlation between each neuron's response and the global mean response.
The global mean oracle correlation represents how well each neuron's activity can be predicted by the average response across all neurons at each time point.
| PARAMETER | DESCRIPTION |
|---|---|
responses
|
Neural responses array. Can be either: - 3D array of shape (frames, repeats, neurons) - 2D array of shape (frames, neurons) which will be treated as single repeat
TYPE:
|
return_oracle
|
If True, returns both correlation values and oracle responses. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[ndarray, ' neurons']
|
|
Note
The function automatically handles single-repeat data by adding a singleton dimension.
Source code in openretina/eval/oracles.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |