Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nstat/matlab_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def run_point_process_reference(*, matlab_repo: str | Path | None = None, seed:
for i=1:sC.numSpikeTrains
ppSpikeCounts(i) = length(sC.getNST(i).spikeTimes);
end
ppLambdaHead = lambda.data(1:5,1)';
ppLambdaHead = lambda.data(1:10,1)';
""",
nargout=0,
)
Expand Down Expand Up @@ -106,13 +106,15 @@ def run_simulated_network_reference(*, matlab_repo: str | Path | None = None, se
[tout,~,yout] = sim('SimulatedNetwork2',[stim.minTime stim.maxTime],options,stim.dataToStructure);
netSpikeCounts = [sum(yout(:,1)>.5), sum(yout(:,2)>.5)];
netProbHead = yout(1:5,3:4);
netStateHead = yout(1:5,1:2);
netActual = [0 1; -4 0];
""",
nargout=0,
)
return {
"spike_counts": _to_numpy(engine.workspace["netSpikeCounts"]).reshape(-1),
"prob_head": _to_numpy(engine.workspace["netProbHead"]),
"state_head": _to_numpy(engine.workspace["netStateHead"]),
"actual_network": _to_numpy(engine.workspace["netActual"]),
}

Expand Down
7 changes: 5 additions & 2 deletions tests/test_matlab_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def test_matlab_reference_executes_only_when_engine_is_available() -> None:
network = run_simulated_network_reference(matlab_repo=MATLAB_REPO_ROOT)

assert point_process["spike_counts"].shape == (5,)
assert point_process["lambda_head"].shape == (10,)
assert network["spike_counts"].shape == (2,)
assert network["prob_head"].shape == (5, 2)
assert network["state_head"].shape == (5, 2)
np.testing.assert_allclose(network["actual_network"], np.array([[0.0, 1.0], [-4.0, 0.0]], dtype=float))


Expand All @@ -57,7 +59,7 @@ def test_native_point_process_simulation_matches_matlab_lambda_head_when_engine_
)
matlab_ref = run_point_process_reference(matlab_repo=MATLAB_REPO_ROOT, seed=5)

np.testing.assert_allclose(lambda_cov.data[:5, 0], matlab_ref["lambda_head"], rtol=1e-6, atol=1e-8)
np.testing.assert_allclose(lambda_cov.data[:10, 0], matlab_ref["lambda_head"], rtol=1e-6, atol=1e-8)


@pytest.mark.skipif(not MATLAB_REPO_ROOT.exists(), reason="MATLAB reference repo not available")
Expand All @@ -69,4 +71,5 @@ def test_native_network_simulation_preserves_matlab_connectivity_layout_when_eng
matlab_ref = run_simulated_network_reference(matlab_repo=MATLAB_REPO_ROOT, seed=4)

np.testing.assert_allclose(native.actual_network, matlab_ref["actual_network"])
assert matlab_ref["prob_head"].shape == (5, 2)
np.testing.assert_allclose(native.lambda_delta[:5], matlab_ref["prob_head"], rtol=1e-6, atol=1e-8)
assert np.all((matlab_ref["state_head"] == 0.0) | (matlab_ref["state_head"] == 1.0))