From e033c323222d5dc6f4b8d9abd98ba8d439488440 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Wed, 24 Jun 2026 08:41:04 -0400 Subject: [PATCH] Fix Exp/Power fit docs to match returned log-space intercept MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ExpCurveFitAlgorithm` and `PowerCurveFitAlgorithm` linearize in log space, so the returned `sol.u = (a, b)` has `b` equal to the intercept in log space, not the multiplicative scale factor. The docstrings and README claimed the model was `y = b*exp(a*x)` / `y = b*x^a` with `b` returned directly, which is inconsistent with the actual `(a, log(b))` output (as already demonstrated by the tutorial's `exp(sol.u[2])` recovery and the `sol.u[2] ≈ log(2.0)` assertions in test/linfit_exp.jl and test/linfit_power.jl). Restate the models as `y = exp(a*x + b)` and `y = exp(a*log(x) + b)`, matching the linear fit `log(y) = a*f(x) + b`, and document that the multiplicative scale factor is recovered as `exp(b)`. Closes #110 Co-Authored-By: Chris Rackauckas Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01C5bhhA1XYyVaBq2YQfKiRz --- README.md | 4 ++-- docs/src/tutorials/getting_started.md | 10 ++++++++-- src/common_interface.jl | 20 ++++++++++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 283a2837..d45e2c2c 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ CurveFit.jl provides the following fitting algorithms: - **Linear fitting**: `LinearCurveFitAlgorithm` - General linear fits with customizable transformations - **Log fitting**: `LogCurveFitAlgorithm` - Fits `y = a*log(x) + b` -- **Power fitting**: `PowerCurveFitAlgorithm` - Fits `y = b*x^a` -- **Exponential fitting**: `ExpCurveFitAlgorithm` - Fits `y = b*exp(a*x)` +- **Power fitting**: `PowerCurveFitAlgorithm` - Fits `y = exp(a*log(x) + b)` (returns `(a, b)`; scale factor is `exp(b)`) +- **Exponential fitting**: `ExpCurveFitAlgorithm` - Fits `y = exp(a*x + b)` (returns `(a, b)`; scale factor is `exp(b)`) - **Polynomial fitting**: `PolynomialFitAlgorithm` - Fits polynomials of arbitrary degree - **Rational polynomial fitting**: `RationalPolynomialFitAlgorithm` - Fits rational functions p(x)/q(x) - **Sum of exponentials**: `ExpSumFitAlgorithm` - Fits `y = k + p1*exp(λ1*t) + p2*exp(λ2*t) + ...` diff --git a/docs/src/tutorials/getting_started.md b/docs/src/tutorials/getting_started.md index 2c850d27..f9c37f98 100644 --- a/docs/src/tutorials/getting_started.md +++ b/docs/src/tutorials/getting_started.md @@ -112,7 +112,10 @@ println("Prediction at x=5: ", sol(5.0)) ## Exponential Fitting -Fit an exponential function `y = b * exp(a * x)`: +Fit an exponential function `y = exp(a * x + b)`. The fit is performed in +log-linear space, so `sol.u = (a, b)` returns the log-space intercept `b`; the +multiplicative scale factor of the equivalent form `y = B * exp(a * x)` is +`B = exp(b)`: ```@example exponential using CurveFit @@ -132,7 +135,10 @@ println("Scale factor (b): ", exp(sol.u[2])) ## Power Law Fitting -Fit a power law `y = b * x^a`: +Fit a power law `y = exp(a * log(x) + b)`. The fit is performed in log-log +space, so `sol.u = (a, b)` returns the log-space intercept `b`; the +multiplicative scale factor of the equivalent form `y = B * x^a` is +`B = exp(b)`: ```@example power using CurveFit diff --git a/src/common_interface.jl b/src/common_interface.jl index f0d938ff..6f14adc3 100644 --- a/src/common_interface.jl +++ b/src/common_interface.jl @@ -254,14 +254,18 @@ to fit. This algorithm does not support passing weights through `sigma` in We want to solve for `a` and `b` such that: ```math -y = b x^a +y = \exp(a \log(x) + b) = \exp(b)\, x^a ``` -This is equivalent to a linear fit in log-log space, i.e., +This is a linear fit in log-log space, i.e., ```math -\log(y) = a \log(x) + \log(b) +\log(y) = a \log(x) + b ``` + +The returned parameters are `(a, b)`, where `b` is the intercept in log space. +The multiplicative scale factor `B` of the equivalent form ``y = B x^a`` is +recovered as ``B = \exp(b)``. """ PowerCurveFitAlgorithm() = LinearCurveFitAlgorithm(; xfun = log, yfun = log) @@ -274,14 +278,18 @@ fit. This algorithm does not support passing weights through `sigma` in We want to solve for `a` and `b` such that: ```math -y = b \exp(a x) +y = \exp(a x + b) ``` -This is equivalent to a linear fit in log-linear space, i.e., +This is a linear fit in log-linear space, i.e., ```math -\log(y) = a x + \log(b) +\log(y) = a x + b ``` + +The returned parameters are `(a, b)`, where `b` is the intercept in log space. +The multiplicative scale factor `B` of the equivalent form ``y = B \exp(a x)`` +is recovered as ``B = \exp(b)``. """ ExpCurveFitAlgorithm() = LinearCurveFitAlgorithm(; xfun = identity, yfun = log)