Skip to content

Commit

Permalink
Added a parameter to fit whether to calculate confidence limits at al…
Browse files Browse the repository at this point in the history
…l (fit->cl, default: false, "set cl true" can be used to change). Changed plotting and saving defaults of confidence limits to true, so if they are calculated then by default they are also shown and saved.
  • Loading branch information
jaakkojulin committed Nov 11, 2024
1 parent 61ffab2 commit a9669fb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion qjabs/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void MainWindow::readPlotSettings()
ui->widget->setLegendVisible(settings.value("showLegend", QVariant(true)).toBool());
ui->widget->setLegendOutside(settings.value("legendOutside", QVariant(false)).toBool());
ui->widget->setEnergyAxis(settings.value("energyAxis", QVariant(false)).toBool());
confidenceLimits = settings.value("confidenceLimits", QVariant(false)).toBool();
confidenceLimits = settings.value("confidenceLimits", QVariant(true)).toBool();
plotSession();
}

Expand Down
2 changes: 1 addition & 1 deletion qjabs/plotdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void PlotDialog::readSettings()
}
ui->showlegendCheckBox->setChecked(settings.value("showLegend", QVariant(true)).toBool());
ui->legendOutsideCheckBox->setChecked(settings.value("legendOutside", QVariant(false)).toBool());
ui->confidencelimitsCheckBox->setChecked(settings.value("confidenceLimits", QVariant(false)).toBool());
ui->confidencelimitsCheckBox->setChecked(settings.value("confidenceLimits", QVariant(true)).toBool());
}

void PlotDialog::saveSettings()
Expand Down
7 changes: 5 additions & 2 deletions qjabs/plotdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>270</width>
<width>316</width>
<height>196</height>
</rect>
</property>
Expand Down Expand Up @@ -61,7 +61,10 @@
<item>
<widget class="QCheckBox" name="confidencelimitsCheckBox">
<property name="text">
<string>Show confidence limits (BETA)</string>
<string>Show confidence limits if calculated (BETA)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
Expand Down
9 changes: 6 additions & 3 deletions src/fit.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ void fit_data_defaults(fit_data *f) {
f->chisq_fast_tol = FIT_FAST_CHISQ_TOL;
f->phase_start = FIT_PHASE_FAST;
f->phase_stop = FIT_PHASE_SLOW;
f->cl = FALSE;
}

int fit_data_jspace_init(fit_data *fit, size_t n_channels_in_fit) {
Expand Down Expand Up @@ -1221,12 +1222,14 @@ int fit(fit_data *fit) {
fit_params_print_final(fit_params);
fit_correlation_print(fit->covar, MSG_VERBOSE);
fit_data_print(fit, MSG_VERBOSE);
if(fit->cl) { /* Calculate confidence limits */
#ifdef DEBUG
const char *f_uncertainty = "errors.dat";
const char *f_uncertainty = "errors.dat";
#else
const char *f_uncertainty = NULL;
const char *f_uncertainty = NULL;
#endif
fit_uncertainty_spectra(fit, J, fit->covar, f, &wts.vector, f_uncertainty);
fit_uncertainty_spectra(fit, J, fit->covar, f, &wts.vector, f_uncertainty);
}
}
gsl_multifit_nlinear_free(w);
gsl_vector_free(fit->f_iter);
Expand Down
1 change: 1 addition & 0 deletions src/fit.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ typedef struct fit_data {
double xtol; /* Tolerance of step size */
double chisq_tol; /* Chi squared relative change tolerance */
double chisq_fast_tol; /* Chi squared relative change tolerance (fast phase) */
int cl; /* Calculate confidence limits */
gsl_multifit_nlinear_fdf *fdf;
size_t dof; /* Degrees of freedom (calculated) */
struct fit_stats stats; /* Fit statistics, updated as we iterate */
Expand Down
11 changes: 3 additions & 8 deletions src/script_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,21 +286,15 @@ script_command_status script_save_spectra(script_session *s, int argc, char *con
size_t i_det = 0;
struct fit_data *fit = s->fit;
const int argc_orig = argc;
int cl = FALSE;
if(argc && strcmp(argv[0], "cl") == 0) {
cl = TRUE;
argc--;
argv++;
}
if(script_get_detector_number(fit->sim, TRUE, &argc, &argv, &i_det) || argc < 1) {
jabs_message(MSG_ERROR, "Usage: save spectra {cl} {<detector>} <file>\n");
jabs_message(MSG_ERROR, "Usage: save spectra {<detector>} <file>\n");
return SCRIPT_COMMAND_FAILURE;
}
if(argc < 1) {
jabs_message(MSG_ERROR, "Not enough arguments for save spectra.\n");
return SCRIPT_COMMAND_FAILURE;
}
if(sim_workspace_print_spectra(fit->spectra, argv[0], cl)) {
if(sim_workspace_print_spectra(fit->spectra, argv[0], fit->cl)) {
jabs_message(MSG_ERROR,
"Could not save spectra of detector %zu to file \"%s\"! There should be %zu detector(s).\n",
i_det + 1, argv[0], fit->sim->n_det);
Expand Down Expand Up @@ -1313,6 +1307,7 @@ script_command *script_commands_create(struct script_session *s) {
{JIBAL_CONFIG_VAR_DOUBLE, "xtolerance", 0, 0, &fit->xtol, NULL},
{JIBAL_CONFIG_VAR_DOUBLE, "chisq_tolerance", 0, 0, &fit->chisq_tol, NULL},
{JIBAL_CONFIG_VAR_DOUBLE, "chisq_fast_tolerance", 0, 0, &fit->chisq_fast_tol, NULL},
{JIBAL_CONFIG_VAR_BOOL, "cl", 0, 0, &fit->cl, NULL},
{JIBAL_CONFIG_VAR_SIZE, "n_bricks_max", 0, 0, &sim->params->n_bricks_max, NULL},
{JIBAL_CONFIG_VAR_BOOL, "ds", 0, 0, &sim->params->ds, NULL},
{JIBAL_CONFIG_VAR_BOOL, "rk4", 0, 0, &sim->params->rk4, NULL},
Expand Down

0 comments on commit a9669fb

Please sign in to comment.