Skip to content

Commit

Permalink
Swap out optimizer for CmaEsSampler in stab flex test
Browse files Browse the repository at this point in the history
It runs faster, max_iterations controls the number
of evaluations. It also seems to get rid of the
issue of differences between fp32 and fp64 results. Will need to look into what is going on
with differential evolution.
  • Loading branch information
davidt0x committed Oct 16, 2024
1 parent 2ef2b25 commit bf95aff
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions tests/composition/pec/test_stab_flex_pec_fit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import psyneulink as pnl

import optuna
import pytest

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'pytest' is not used.

from psyneulink.core.components.functions.nonstateful.fitfunctions import (
Expand Down Expand Up @@ -470,7 +472,7 @@ def test_stab_flex_cond_fit():
],
data=data_to_fit,
optimization_function=PECOptimizationFunction(
method="differential_evolution", max_iterations=1
method=optuna.samplers.CmaEsSampler(seed=0), max_iterations=10
),
num_estimates=num_estimates,
initial_seed=42,
Expand All @@ -485,24 +487,14 @@ def test_stab_flex_cond_fit():
optimal_parameters = pec.optimized_parameter_values

# These aren't the recovered parameters, we are doing too few trials and too few estimates to get the correct
# results. FP32 results are very different from FP64 results, this seems strange, we will need to investigate
# what is going on here. Maybe it effects the randomization somehow?
if pytest.helpers.llvm_current_fp_precision() == 'fp32':
expected_results = {
'Task Activations [Act1, Act2]-1.gain': 2.316350155331747,
'Automaticity-weighted Stimulus Input [w*S1, w*S2]-1.slope': 0.04222951406320785,
'DDM-1.threshold[threshold=0.7]': 0.49284829086077964,
'DDM-1.threshold[threshold=0.3]': 0.3469243996445839,
'DDM-1.non_decision_time': 0.38630189671150356
}
else:
expected_results = {
'Task Activations [Act1, Act2]-1.gain': 1.3820085411824117,
'Automaticity-weighted Stimulus Input [w*S1, w*S2]-1.slope': 0.014784656669402561,
'DDM-1.threshold[threshold=0.7]': 0.48339391888454464,
'DDM-1.threshold[threshold=0.3]': 0.3098280374938238,
'DDM-1.non_decision_time': 0.1278625281322982
}
# results.
expected_results = {
'Task Activations [Act1, Act2]-1.gain': 3.87419,
'Automaticity-weighted Stimulus Input [w*S1, w*S2]-1.slope': 0.0125,
'DDM-1.threshold[threshold=0.7]': 0.30939,
'DDM-1.threshold[threshold=0.3]': 0.22168,
'DDM-1.non_decision_time': 0.28659999999999997
}

for key, value in expected_results.items():
np.testing.assert_allclose(optimal_parameters[key], value, rtol=1e-6)

0 comments on commit bf95aff

Please sign in to comment.