Skip to content

Commit

Permalink
Updated tests for checking quality of model fitting
Browse files Browse the repository at this point in the history
  • Loading branch information
marufr committed Dec 2, 2024
1 parent ddbaa68 commit c21e35c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions sira/fit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
26 changes: 17 additions & 9 deletions tests/test_response_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c21e35c

Please sign in to comment.