Skip to content

Feature/fittable params#52

Open
viniviena wants to merge 8 commits intomainfrom
feature/fittable-params
Open

Feature/fittable params#52
viniviena wants to merge 8 commits intomainfrom
feature/fittable-params

Conversation

@viniviena
Copy link
Copy Markdown
Collaborator

This pull request introduces several improvements and simplifications to the adsorption isotherm fitting workflow, focusing on easier usage, new solver support, and improved flexibility for parameter fitting. The main changes include a new interface for partial parameter fitting, addition of a local deterministic optimizer, and updates to tutorials and data handling for clarity and correctness.

Key changes:

Isotherm Fitting Infrastructure

  • Added support for partial parameter fitting by introducing a fittable vector to IsothermFittingProblem, allowing users to specify which model parameters should be optimized and which should remain fixed. The simplified constructor now automatically guesses initial parameters and bounds, with validation for the fittable vector.
  • Added a new NLSolversIsothermFittingSolver struct and corresponding solve method, enabling local deterministic optimization (e.g., L-BFGS) via the NLSolvers package. This provides an alternative to the existing global stochastic Differential Evolution solver. [1] [2]
  • Updated the fit function interface to support the new fittable parameter and to allow selection between solvers. Comprehensive docstring and usage examples were added.
  • Updated internal logic to reconstruct models from only the fittable parameters, ensuring correct mapping between optimized variables and model fields. [1] [2]
  • Exported the new solver and updated symbols.

Tutorial and Documentation Updates

  • Simplified the usage of IsothermFittingProblem in the tutorials, removing the need for manual initial guesses and bounds in most cases, and reflecting the new default behavior. Updated plotting and pressure unit handling for clarity and correctness. [1] [2] [3] [4] [5] [6] [7]
  • Updated pressure units and axis labels in the tutorial to consistently use bar instead of Pa, matching the raw data and improving clarity. [1] [2]

Data Handling and Utilities

  • Added a new method for isotherm_data that accepts a scalar temperature and broadcasts it to a vector, simplifying data preparation for fixed-temperature isotherms.
  • Minor bugfixes and clarifications in function calls and pressure handling in tutorials. [1] [2] [3]

Other Fixes

  • Corrected a function call in the IAST method to use the correct step function.
  • Updated the potential theory method to use the correct phase volume search mode and fixed a broadcasting bug in loading calculations. [1] [2]

viniviena and others added 8 commits November 18, 2025 22:12
… PTA solvers

- Add solve_at_potential_fugacity_single for single-component systems using ForwardDiff
- Change volume calls from :stable to :unknown for better convergence
- Add comprehensive tests comparing ChemPotentialMethod vs FugacityCoefficientMethod
- Set default time_limit to 20.0 seconds in DEIsothermFittingSolver
- Modify fit() to accept optional fittable parameter vector
- Update IsothermFittingProblem to track fittable parameters
- Add to_vec_fittable() and from_vec_fittable() helper functions
- Simplify @with_metadata macro (remove hardcoded fittable flags)
- Update Freundlich model to estimate β from temperature dependence
- Users can now control which parameters to fit without modifying source code

Example usage:
  fit(Freundlich, data)  # fit all parameters
  fit(Freundlich, data, fittable=[true, true, false, true])  # fix β
Sips model fixes:
- Add safeguard for division by zero when f0 (defaults to f=1)
- Fix energy sign convention: use -1/(R*T) in regression for correct E sign
- Remove double negation in return statement (was causing positive E)
- Add default E value for single temperature case
- Add NaN/Inf checks for all parameters with sensible defaults

Quadratic model fixes:
- Replace complex 5-parameter regression with Langmuir-based initial guess
- Use same K and E for both Ka and Kb parameters
- Set Kb=0.1*Ka (quadratic term as small correction)
- Preserve original implementation as commented block for reference
- Provides more stable and robust initial values

Test additions:
- Add fittable parameters test using LangmuirS1 model
- Test that non-fittable parameters preserve initial guess values
- Test that fittable parameters are actually optimized
- Verify loss improvement with selective fitting

These changes improve numerical stability and provide better starting points
for the optimization algorithms, reducing NaN/Inf issues during fitting.
Documentation updates:
- Simplified tutorial examples to use new IsothermFittingProblem API
- Removed manual bounds and x0 specification from tutorials
- Fixed pressure units in documentation (bar instead of Pa)
- Updated bestisotherm tutorial with cleaner examples
- Added isotherm_data convenience method for scalar temperature

Model bounds improvements:
- Changed Toth parameter bounds from (-Inf, Inf) to finite ranges
- Changed ThermodynamicLangmuir Bᵢᵩ bounds to (-1e3, 1e3)
- Prevents logspace transformation issues with infinite bounds
- Makes optimization more stable and predictable

Minor fixes:
- Fixed whitespace in isotherm_methods.jl
- Updated x0_guess_fit for ThermodynamicLangmuir to use nextfloat
- Updated x0_guess_fit for Toth to use cleaner default values

These changes improve user experience by simplifying the API usage
in tutorials and preventing numerical issues with infinite bounds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants