From c21e35c4c00b40c900ea127c9dd62cf964df2548 Mon Sep 17 00:00:00 2001 From: Maruf Rahman Date: Tue, 3 Dec 2024 00:44:27 +1100 Subject: [PATCH] Updated tests for checking quality of model fitting --- sira/fit_model.py | 6 +++--- tests/test_response_algorithms.py | 26 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/sira/fit_model.py b/sira/fit_model.py index 9d9915f..fee6624 100644 --- a/sira/fit_model.py +++ b/sira/fit_model.py @@ -290,9 +290,9 @@ def fit_prob_exceed_model( y_sample = ydata_2d[dx] ds_level = system_limit_states[dx] - print(f"\nDebug - Processing DS{dx}: {ds_level}") - print(f"Debug - y_sample mean: {np.mean(y_sample)}") - print(f"Debug - y_sample min/max: {np.min(y_sample)}/{np.max(y_sample)}") + print(f"\nDebug info - Processing DS{dx}: {ds_level}") + print(f"Debug info - y_sample mean: {np.mean(y_sample)}") + print(f"Debug info - y_sample min/max: {np.min(y_sample)}/{np.max(y_sample)}") params_odict = fit_cdf_model( x_sample, y_sample, dist=distribution, tag=f"Limit State: {ds_level}") diff --git a/tests/test_response_algorithms.py b/tests/test_response_algorithms.py index a8c8e1c..a903a2e 100644 --- a/tests/test_response_algorithms.py +++ b/tests/test_response_algorithms.py @@ -176,11 +176,15 @@ def test_model_fitting_no_crossover(distribution): for damage_state in [1, 2]: fit_stats = fitted_params_dict[damage_state]['fit_statistics'] - assert fit_stats['chisqr'] < 0.1, \ - f"Poor fit quality for {distribution}, DS{damage_state}: chi-square = {fit_stats['chisqr']}" + assert fit_stats['chisqr'] < 0.5, \ + f"Very poor quality fit quality for\n "\ + f"{distribution}, DS{damage_state}: chi-square = {fit_stats['chisqr']}" - # assert fitted_params_dict[1]['fit_statistics']['chisqr'] <= 0.1 - # assert fitted_params_dict[2]['fit_statistics']['chisqr'] <= 0.1 + # params = fitted_params_dict[damage_state]['parameters'] + # for param_name, param_data in params.items(): + # assert param_data > 0, \ + # f"Invalid parameter value for {param_name} "\ + # f"in {distribution}, DS{damage_state}" shutil.rmtree(TEMP_OUTPUT) @@ -217,11 +221,15 @@ def test_model_fitting_with_crossover(distribution): for damage_state in [1, 2]: fit_stats = fitted_params_dict[damage_state]['fit_statistics'] - assert fit_stats['chisqr'] < 0.1, \ - f"Poor fit quality for {distribution}, DS{damage_state}: chi-square = {fit_stats['chisqr']}" - - # assert fitted_params_dict[1]['fit_statistics']['chisqr'] <= 0.1 - # assert fitted_params_dict[2]['fit_statistics']['chisqr'] <= 0.1 + assert fit_stats['chisqr'] < 0.5, \ + f"Very poor quality fit quality for\n "\ + f"{distribution}, DS{damage_state}: chi-square = {fit_stats['chisqr']}" + + # params = fitted_params_dict[damage_state]['parameters'] + # for param_name, param_data in params.items(): + # assert param_data > 0, \ + # f"Invalid parameter value for {param_name} "\ + # f"in {distribution}, DS{damage_state}" shutil.rmtree(TEMP_OUTPUT)