Changeset 1292 for framspy


Ignore:
Timestamp:
02/21/24 16:50:31 (10 months ago)
Author:
Maciej Komosinski
Message:
  • in numerical experiments, genotypes which are vectors of values now use numpy arrays (instead of python lists)
  • make exceptions fatal in tests
File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/evolalg/tests/test_diferent_settings.py

    r1291 r1292  
    2222    'pxov': [0.2],
    2323    'tournament': [5],
    24     'initialgenotype':[np.array([100, 100, 100, 100]), [-100,-100]]
     24    'initialgenotype':[np.array([100, 100, 100, 100]), np.array([-100,-100])]
    2525}
    2626
     
    3434    'migration_interval': [1,5],
    3535    'number_of_populations':[1,5],
    36     'initialgenotype':[np.array([100, 100, 100, 100]), [-100,-100]]
     36    'initialgenotype':[np.array([100, 100, 100, 100]), np.array([-100,-100])]
    3737}
    3838
     
    201201
    202202def cover_to_test(params, run_exp):
    203     try:
    204         run_exp(params)
    205         return [1, None]
    206     except Exception as ex:
    207         return [0, f"Experiment {run_exp.__name__} with params: {params} failed with the stack: {ex}"]
     203    run_exp(params)
     204    return 1
    208205
    209206
    210207def run_tests():
    211     result = []
     208    results = []
     209
    212210    print("TESTING NUMERICAL")
    213211    params_sets = get_params_sets(SETTINGS_TO_TEST_NUMERIC)
    214212    print(f"Starting executing {len(params_sets)} experiments")
    215     result.extend([cover_to_test(params,test_run_experiment_numerical) for params in params_sets])
     213    results.extend([cover_to_test(params, test_run_experiment_numerical) for params in params_sets])
    216214
    217215    print("TESTING NUMERICAL ISLANDS")
    218216    params_sets = get_params_sets(SETTINGS_TO_TEST_NUMERIC_ISLAND)
    219217    print(f"Starting executing {len(params_sets)} experiments")
    220     result.extend([cover_to_test(params,test_run_experiment_numerical_islands) for params in params_sets])
     218    results.extend([cover_to_test(params,test_run_experiment_numerical_islands) for params in params_sets])
    221219
    222220    print("TESTING FRAMS NICHING")
    223221    params_sets = get_params_sets(SETTINGS_TO_TEST_FRAMS_NICHING)
    224222    print(f"Starting executing {len(params_sets)} experiments")
    225     result.extend([cover_to_test(params, test_run_experiment_frams_niching) for params in params_sets])
     223    results.extend([cover_to_test(params, test_run_experiment_frams_niching) for params in params_sets])
    226224
    227225    print("TESTING FRAMS ISLANDS")
    228226    params_sets = get_params_sets(SETTINGS_TO_TEST_FRAMS_ISLANDS)
    229227    print(f"Starting executing {len(params_sets)} experiments")
    230     result.extend([cover_to_test(params,test_run_experiment_frams_island) for params in params_sets])
    231 
    232     Successful = sum([1 for r in result  if r[0] == 1])
    233     Failed = sum([1 for r in result if r[0] == 0])
    234     print(f"{Successful} out of {len(result)} passed")
    235     if Successful < Failed:
    236         print("Experiments that failed :{Failed}")
    237         [print(r[1]) for r in result if r[1]]
     228    results.extend([cover_to_test(params,test_run_experiment_frams_island) for params in params_sets])
     229
     230    print(f"Passed tests: {sum(results)} / {len(results)}")
    238231
    239232
Note: See TracChangeset for help on using the changeset viewer.