Skip to main content

Generic Models

PhyTorch provides a comprehensive library of generic curve-fitting models that can be applied across various scientific domains. These models use the same unified API as all PhyTorch models.

Linear Model

Simple linear regression:

y=ax+by = a \cdot x + b

Usage

from phytorch import fit
from phytorch.models.generic import Linear
import numpy as np

data = {
'x': np.array([1, 2, 3, 4, 5]),
'y': np.array([2.1, 3.9, 6.2, 7.8, 10.1])
}

result = fit(Linear(), data)
print(f"Slope: {result.parameters['a']:.2f}")
print(f"Intercept: {result.parameters['b']:.2f}")

result.plot()

Parameters

ParameterDescriptionUnits
aSlope-
bIntercept-

Sigmoidal Model

Rational sigmoid curve for S-shaped responses:

y=ymax1+xx50sy = \frac{y_{max}}{1 + \left|\frac{x}{x_{50}}\right|^s}

Usage

from phytorch import fit
from phytorch.models.generic import Sigmoidal

data = {
'x': np.array([-3, -2, -1, 0, 1, 2, 3]),
'y': np.array([0.5, 1.2, 2.5, 5.0, 7.5, 9.0, 9.8])
}

result = fit(Sigmoidal(), data)
result.plot()

Parameters

ParameterDescriptionUnits
ymaxMaximum response-
x50Half-saturation point-
sSteepness parameter-

Rectangular Hyperbola

Saturating hyperbola commonly found in resource-limited and biological processes:

y=ymaxxx50+xy = \frac{y_{max} \cdot x}{x_{50} + x}

This model describes processes such as enzyme kinetics (Michaelis-Menten), light response curves, and nutrient uptake.

Usage

from phytorch import fit
from phytorch.models.generic import RectangularHyperbola

# Saturating response data
data = {
'x': np.array([0.5, 1, 2, 5, 10, 20, 50]),
'y': np.array([2.5, 4.5, 7.5, 12, 15, 17, 19])
}

result = fit(RectangularHyperbola(), data)
print(f"ymax: {result.parameters['ymax']:.2f}")
print(f"x50: {result.parameters['x50']:.2f}")

Parameters

ParameterDescriptionUnits
ymaxMaximum asymptotic value-
x50Half-saturation constant-

Non-rectangular Hyperbola

More flexible saturation curve:

y=αx+ymax(αx+ymax)24θαxymax2θy = \frac{\alpha x + y_{max} - \sqrt{(\alpha x + y_{max})^2 - 4\theta\alpha x y_{max}}}{2\theta}

Usage

from phytorch import fit
from phytorch.models.generic import NonrectangularHyperbola

result = fit(NonrectangularHyperbola(), data)

Parameters

ParameterDescriptionUnits
ymaxMaximum response-
alphaInitial slope-
thetaCurvature (0-1)-

Arrhenius Model

Temperature response following Arrhenius kinetics:

y=yrefexp[HaR(1Tref1x)]y = y_{ref} \cdot \exp\left[\frac{H_a}{R} \left(\frac{1}{T_{ref}} - \frac{1}{x}\right)\right]

where R=0.008314R = 0.008314 kJ/(mol·K) and Tref=298.15T_{ref} = 298.15 K.

Usage

from phytorch import fit
from phytorch.models.generic import Arrhenius

# Temperature in Kelvin
data = {
'x': np.array([283, 288, 293, 298, 303, 308]),
'y': np.array([50, 70, 95, 125, 160, 200])
}

result = fit(Arrhenius(), data)
print(f"Activation energy: {result.parameters['Ha']:.1f} kJ/mol")

Parameters

ParameterDescriptionTypical RangeUnits
yrefValue at reference T--
HaActivation energy30-100kJ/mol

Peaked Arrhenius Model

Temperature response with high-temperature deactivation:

y=ymaxfarr(x)fpeak(x)y = y_{max} \cdot f_{arr}(x) \cdot f_{peak}(x)

where:

farr(x)=exp[HaR(1Tref1x)]f_{arr}(x) = \exp\left[\frac{H_a}{R}\left(\frac{1}{T_{ref}} - \frac{1}{x}\right)\right] fpeak(x)=1+exp[HdR(1Topt1Tref)ln(HdHa1)]1+exp[HdR(1Topt1x)ln(HdHa1)]f_{peak}(x) = \frac{1 + \exp\left[\frac{H_d}{R}\left(\frac{1}{T_{opt}} - \frac{1}{T_{ref}}\right) - \ln\left(\frac{H_d}{H_a} - 1\right)\right]}{1 + \exp\left[\frac{H_d}{R}\left(\frac{1}{T_{opt}} - \frac{1}{x}\right) - \ln\left(\frac{H_d}{H_a} - 1\right)\right]}

with R=0.008314R = 0.008314 kJ/(mol·K) and Tref=298.15T_{ref} = 298.15 K.

Usage

from phytorch import fit
from phytorch.models.generic import PeakedArrhenius

# Temperature response with optimum
data = {
'x': np.linspace(280, 320, 20),
'y': measured_response
}

result = fit(PeakedArrhenius(), data)
print(f"Optimal temperature: {result.parameters['Topt']:.1f} K")

Parameters

ParameterDescriptionUnits
ymaxMaximum at Topt-
HaActivation energykJ/mol
HdDeactivation energykJ/mol
ToptOptimal temperatureK

Gaussian Model

Bell-shaped curve:

y=aexp[(xμ)22σ2]y = a \cdot \exp\left[-\frac{(x - \mu)^2}{2\sigma^2}\right]

Usage

from phytorch import fit
from phytorch.models.generic import Gaussian

result = fit(Gaussian(), data)
print(f"Peak location: {result.parameters['mu']:.2f}")
print(f"Width: {result.parameters['sigma']:.2f}")

Parameters

ParameterDescriptionUnits
aPeak height-
muPeak location-
sigmaWidth-

Weibull Distribution

Weibull probability density function:

y=kλ(xx0λ)k1exp[(xx0λ)k]y = \frac{k}{\lambda}\left(\frac{x - x_0}{\lambda}\right)^{k-1}\exp\left[-\left(\frac{x - x_0}{\lambda}\right)^k\right]

Usage

from phytorch import fit
from phytorch.models.generic import Weibull

result = fit(Weibull(), data)

Parameters

ParameterDescriptionUnits
x0Location parameter-
lambdaScale parameter-
kShape parameter-

Beta Distribution

Flexible distribution on bounded interval:

y=a(xxmin)α1(xmaxx)β1B(α,β)(xmaxxmin)α+β1y = a \cdot \frac{(x - x_{min})^{\alpha-1}(x_{max} - x)^{\beta-1}}{B(\alpha, \beta)(x_{max} - x_{min})^{\alpha+\beta-1}}

Usage

from phytorch import fit
from phytorch.models.generic import Beta

result = fit(Beta(), data)

Parameters

ParameterDescriptionUnits
aAmplitude-
alphaShape parameter 1-
betaShape parameter 2-
xminLower bound-
xmaxUpper bound-

Custom Parameter Bounds

All models support custom parameter constraints:

from phytorch import fit, FitOptions

options = FitOptions(
bounds={
'ymax': (0, 100),
'x50': (-10, 10)
}
)

result = fit(Sigmoidal(), data, options)

Model Selection

Use information criteria for model comparison:

# Fit multiple models
models = [Linear(), Sigmoidal(), RectangularHyperbola()]
results = [fit(model, data) for model in models]

# Compare R²
for i, result in enumerate(results):
print(f"Model {i+1}: R² = {result.r_squared:.4f}")

References

  • Michaelis, L., & Menten, M. L. (1913). The kinetics of invertase action. Biochem. z, 49, 333-369.
  • Arrhenius, S. (1889). On the reaction velocity of the inversion of cane sugar by acids. Z. Phys. Chem, 4, 226-248.
  • Thornley, J. H. M., & Johnson, I. R. (1990). Plant and Crop Modelling: A Mathematical Approach to Plant and Crop Physiology. Oxford University Press.