Tutorial 1 — Getting Started¶
This notebook verifies your metasignal installation and walks through the three input arrays every function expects.
1. Verify the install¶
In [1]:
Copied!
import numpy as np
import metasignal
from metasignal import stdpy
print(f"metasignal loaded from: {metasignal.__file__}")
rng = np.random.default_rng(0)
stim = rng.choice([0, 1], 200)
resp = np.where(rng.random(200) < 0.75, stim, 1 - stim)
conf = rng.integers(1, 5, 200)
meas = stdpy.compute_all_measures(stim, resp, conf, n_ratings=4)
print("Output shape:", meas.shape) # (26,)
import numpy as np
import metasignal
from metasignal import stdpy
print(f"metasignal loaded from: {metasignal.__file__}")
rng = np.random.default_rng(0)
stim = rng.choice([0, 1], 200)
resp = np.where(rng.random(200) < 0.75, stim, 1 - stim)
conf = rng.integers(1, 5, 200)
meas = stdpy.compute_all_measures(stim, resp, conf, n_ratings=4)
print("Output shape:", meas.shape) # (26,)
metasignal loaded from: /Users/saurabhext/Documents/metasignal/src/metasignal/__init__.py
Output shape: (26,)
2. Input format¶
| Argument | Values | Meaning |
|---|---|---|
stim |
0 / 1 | Stimulus category (0 = S1/noise, 1 = S2/signal) |
resp |
0 / 1 | Participant response |
conf |
1 … n_ratings | Confidence rating (1 = lowest) |
n_ratings |
int | Total number of confidence categories |
3. Build a minimal dataset¶
In [2]:
Copied!
rng = np.random.default_rng(42)
n_trials, n_ratings = 300, 4
stim = rng.choice([0, 1], n_trials)
resp = np.where(rng.random(n_trials) < 0.80, stim, 1 - stim)
correct = (stim == resp)
conf = np.where(
correct,
rng.integers(3, n_ratings + 1, n_trials),
rng.integers(1, 3, n_trials),
)
print(f"Trials : {n_trials}")
print(f"Accuracy : {correct.mean():.1%}")
print(f"Mean conf: {conf.mean():.2f}")
rng = np.random.default_rng(42)
n_trials, n_ratings = 300, 4
stim = rng.choice([0, 1], n_trials)
resp = np.where(rng.random(n_trials) < 0.80, stim, 1 - stim)
correct = (stim == resp)
conf = np.where(
correct,
rng.integers(3, n_ratings + 1, n_trials),
rng.integers(1, 3, n_trials),
)
print(f"Trials : {n_trials}")
print(f"Accuracy : {correct.mean():.1%}")
print(f"Mean conf: {conf.mean():.2f}")
Trials : 300 Accuracy : 77.3% Mean conf: 3.05
4. Type-1 SDT parameters¶
In [3]:
Copied!
dprime, c, ln_beta = stdpy.compute_sdt_resp(stim, resp)
print(f"d' = {dprime:.3f}")
print(f"criterion = {c:.3f}")
dprime, c, ln_beta = stdpy.compute_sdt_resp(stim, resp)
print(f"d' = {dprime:.3f}")
print(f"criterion = {c:.3f}")
d' = 1.499 criterion = 0.069
5. Convert trials to response counts¶
In [4]:
Copied!
nr_s1, nr_s2 = stdpy.trials_to_counts(stim, resp, conf, n_ratings=n_ratings)
print("nr_s1 shape:", nr_s1.shape)
print("nr_s1:", nr_s1)
print("nr_s2:", nr_s2)
nr_s1, nr_s2 = stdpy.trials_to_counts(stim, resp, conf, n_ratings=n_ratings)
print("nr_s1 shape:", nr_s1.shape)
print("nr_s1:", nr_s1)
print("nr_s2:", nr_s2)
nr_s1 shape: (8,) nr_s1: [60. 63. 0. 0. 16. 16. 0. 0.] nr_s2: [ 0. 0. 20. 16. 0. 0. 53. 56.]
6. Inspect the full 26-element output¶
In [5]:
Copied!
MEASURE_NAMES = [
"meta-d'", "AUC2", "Gamma", "Phi", "DeltaConf",
"M-Ratio", "AUC2-Ratio", "Gamma-Ratio", "Phi-Ratio", "DeltaConf-Ratio",
"M-Diff", "AUC2-Diff", "Gamma-Diff", "Phi-Diff", "DeltaConf-Diff",
"metaNoise", "metaUncertainty", "d'", "c", "mean_conf",
"logL", "AIC", "BIC", "AICc", "k", "n",
]
meas = stdpy.compute_all_measures(stim, resp, conf, n_ratings=n_ratings)
for i, (name, val) in enumerate(zip(MEASURE_NAMES, meas)):
flag = "NaN" if np.isnan(val) else f"{val:.4f}"
print(f" [{i:2d}] {name:<20s} = {flag}")
MEASURE_NAMES = [
"meta-d'", "AUC2", "Gamma", "Phi", "DeltaConf",
"M-Ratio", "AUC2-Ratio", "Gamma-Ratio", "Phi-Ratio", "DeltaConf-Ratio",
"M-Diff", "AUC2-Diff", "Gamma-Diff", "Phi-Diff", "DeltaConf-Diff",
"metaNoise", "metaUncertainty", "d'", "c", "mean_conf",
"logL", "AIC", "BIC", "AICc", "k", "n",
]
meas = stdpy.compute_all_measures(stim, resp, conf, n_ratings=n_ratings)
for i, (name, val) in enumerate(zip(MEASURE_NAMES, meas)):
flag = "NaN" if np.isnan(val) else f"{val:.4f}"
print(f" [{i:2d}] {name:<20s} = {flag}")
[ 0] meta-d' = 7.6642 [ 1] AUC2 = 1.0000 [ 2] Gamma = 1.0000 [ 3] Phi = 0.8553 [ 4] DeltaConf = 1.9706 [ 5] M-Ratio = 5.1551 [ 6] AUC2-Ratio = 1.4269 [ 7] Gamma-Ratio = 1.6859 [ 8] Phi-Ratio = 2.7669 [ 9] DeltaConf-Ratio = 2.9124 [10] M-Diff = 6.1775 [11] AUC2-Diff = 0.2992 [12] Gamma-Diff = 0.4068 [13] Phi-Diff = 0.5462 [14] DeltaConf-Diff = 1.2940 [15] metaNoise = 0.1008 [16] metaUncertainty = 0.0100 [17] d' = 1.4987 [18] c = 0.0694 [19] mean_conf = 3.0533 [20] logL = -220.3121 [21] AIC = 454.6242 [22] BIC = 480.5972 [23] AICc = 455.0051 [24] k = 7.0000 [25] n = 302.0000