Add Print Coefficients Option to Fit Operation

Codex·GPT-6-astra·Maxwell-Rosen·2d ago·9min·4 Checkpoints·5 file changes·+192/-28·174.3K tokens

Add an option to '/home/maxwell-rosen/postgkyl/src/postgkyl/operations/fit.py' which prints the coefficients of the fitted curve

2d ago·2.5s

I’ll check the fit API and CLI conventions, then add an option to print the fitted coefficients.

I’ll add print_coeffs=False, exposed as --print_coeffs in the CLI. It will print one coefficient list per component, labeled with the model and component index.

Added print_coeffs=False to fit.py. Enable it to print coefficients for each component:

Verified: 113 tests passed, plus API and CLI output checks.

So I get the output like this pgkyl zzim-ion_source_integrated_moms.gkyl zzim-ion_bflux_xupper_integrated_HamiltonianMoments.gkyl sel -c 0 ev "f1 f0 / 2 *" sel --z0 100: fit -f 'exp_plateau' -p fit 'exp_plateau', component 0: coefficients = [0.1884599782521278, -8959.07543390874, 1.2269165753085576]

Which is not the most readable. It's difficult to know what the coefficients represent. Please increase the detail in the descriptions of what the fitted coefficients are, perhaps adding the equation it is fitted to with the relevant variables

2d ago·2.1s

I’ll add the fitted equation and label each coefficient with its parameter name, using the existing model definitions as the source.

For exp_plateau, the report will show f(x) = A * exp(b * x) + C and explain A as the initial offset, b as the exponential rate, and C as the plateau. I’ll add descriptions for the other built-in models too, and print named values to 12 significant digits.

Updated -p to show the equation, parameter meanings, and named values. Your example now prints:

All built-in models have descriptions. Full precision remains in the returned dataset. Verified: 113 tests passed.

I'd also like to see R^2 and other fit characteristics

2d ago·2.6s

I’ll add R², coefficient uncertainties, and residual error statistics to the printed report, along with the fitted interval when window=True.

The fitter already computes R² and coefficient uncertainties. I’ll add RMSE, residual standard error, sample count, and degrees of freedom, all calculated over the points actually fitted.

I also found a copy of the previous report pasted into numerics/fit.py, which prevents Python from importing it. I’ll remove that stray text so the checks can run.

The report now includes the fit statistics and coefficient uncertainties. Checks confirm that windowed fits report errors only for the selected window; constant-data R² and estimates with no residual degrees of freedom are labeled undefined. All 116 targeted tests passed.

Your existing fit ... -p command now also prints:

  • Coefficient uncertainties (±1σ)
  • RMSE, residual sum of squares, and residual standard error
  • Sample count, parameter count, and degrees of freedom
  • Fitted coordinate ranges

For windowed fits, statistics cover only the selected window.

Verified: 116 tests passed.