Skip to content

Commit de8e171

Browse files
Enhance documentation with additional API coverage and examples
- Improve EnsembleAnalysis.md with additional advanced functions - Enhance AlgorithmTraits.md with more comprehensive examples - Add SpecializedProblems.md documenting specialized problem types: * NonlinearLeastSquaresProblem, SCCNonlinearProblem * SampledIntegralProblem, IncrementingODEProblem * TwoPointBVProblem, IntervalNonlinearProblem * HomotopyNonlinearFunction and related types - Update pages.jl to include new documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 184851c commit de8e171

File tree

5 files changed

+296
-4
lines changed

5 files changed

+296
-4
lines changed

docs/pages.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pages = [
55
"Interfaces" => Any[
66
"interfaces/Array_and_Number.md",
77
"interfaces/Problems.md",
8+
"interfaces/SpecializedProblems.md",
89
"interfaces/SciMLFunctions.md",
910
"interfaces/Algorithms.md",
1011
"interfaces/AlgorithmTraits.md",

docs/src/assets/Project.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
4+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
5+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
6+
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
7+
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
8+
9+
[compat]
10+
Documenter = "1"
11+
ModelingToolkit = "10"
12+
OrdinaryDiffEq = "6"
13+
Plots = "1"
14+
SciMLBase = "1.74, 2"
15+
StochasticDiffEq = "6"

docs/src/interfaces/AlgorithmTraits.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ TimeChoiceIterator(ts)
157157
```julia
158158
using SciMLBase, OrdinaryDiffEq
159159

160-
function select_ode_algorithm(prob, needs_ad=false, needs_complex=false)
161-
candidates = [Tsit5(), Vern7(), RadauIIA5(), TRBDF2()]
160+
function select_ode_algorithm(prob, needs_ad=false, needs_complex=false,
161+
needs_high_precision=false)
162+
candidates = [Tsit5(), Vern7(), RadauIIA5(), TRBDF2(), Euler()]
162163

163164
for alg in candidates
164165
# Check AD compatibility
@@ -171,6 +172,11 @@ function select_ode_algorithm(prob, needs_ad=false, needs_complex=false)
171172
continue
172173
end
173174

175+
# Check high precision support
176+
if needs_high_precision && !allows_arbitrary_number_types(alg)
177+
continue
178+
end
179+
174180
# Prefer adaptive algorithms for general use
175181
if isadaptive(alg)
176182
return alg
@@ -180,9 +186,22 @@ function select_ode_algorithm(prob, needs_ad=false, needs_complex=false)
180186
return Tsit5() # fallback
181187
end
182188

183-
# Usage
189+
# Usage examples
184190
prob = ODEProblem(f, u0, tspan, p)
185-
alg = select_ode_algorithm(prob, needs_ad=true)
191+
192+
# Basic usage
193+
alg = select_ode_algorithm(prob)
194+
195+
# For sensitivity analysis
196+
alg_ad = select_ode_algorithm(prob, needs_ad=true)
197+
198+
# For complex-valued problems
199+
alg_complex = select_ode_algorithm(prob, needs_complex=true)
200+
201+
# For high precision computations
202+
prob_bigfloat = ODEProblem(f, BigFloat.(u0), BigFloat.(tspan), BigFloat.(p))
203+
alg_hp = select_ode_algorithm(prob_bigfloat, needs_high_precision=true)
204+
186205
sol = solve(prob, alg)
187206
```
188207

docs/src/interfaces/EnsembleAnalysis.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,30 @@ timepoint_cor(ensemble_sol, t)
150150

151151
These functions help analyze relationships between different state variables in the ensemble.
152152

153+
## Additional Analysis Functions
154+
155+
### Advanced Timestep Functions
156+
157+
```julia
158+
timestep_weighted_meancov(ensemble_sol, i, weights)
159+
timestep_meancor(ensemble_sol, i)
160+
timestep_meancov(ensemble_sol, i)
161+
```
162+
163+
- `timestep_weighted_meancov`: Computes weighted mean and covariance at timestep `i`
164+
- `timestep_meancor`: Computes mean and correlation matrix at timestep `i`
165+
- `timestep_meancov`: Computes mean and covariance matrix at timestep `i`
166+
167+
### Advanced Timepoint Functions
168+
169+
```julia
170+
timepoint_weighted_meancov(ensemble_sol, t, weights)
171+
timepoint_meancor(ensemble_sol, t)
172+
timepoint_meancov(ensemble_sol, t)
173+
```
174+
175+
Similar to timestep versions but operating at specific time points via interpolation.
176+
153177
## Usage Examples
154178

155179
### Basic Statistical Analysis
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# Specialized Problem Types
2+
3+
SciMLBase provides several specialized problem types that extend the basic problem interface for specific use cases. These problems offer enhanced functionality for particular mathematical structures or solution approaches.
4+
5+
## Overview
6+
7+
Specialized problem types in SciMLBase include:
8+
- Nonlinear least squares problems
9+
- Strongly connected component (SCC) nonlinear problems
10+
- Sampled integral problems
11+
- Incremental ODE problems
12+
- Two-point boundary value problems
13+
- Homotopy and interval nonlinear problems
14+
15+
## Nonlinear Least Squares Problems
16+
17+
### NonlinearLeastSquaresProblem
18+
19+
```julia
20+
NonlinearLeastSquaresProblem(f, u0, p=nothing)
21+
```
22+
23+
A specialized nonlinear problem type for least squares optimization where the objective is to minimize `||f(u, p)||²`.
24+
25+
**Arguments:**
26+
- `f`: A function that computes the residual vector
27+
- `u0`: Initial guess for the solution
28+
- `p`: Parameters (optional)
29+
30+
**Use Cases:**
31+
- Parameter estimation and data fitting
32+
- Inverse problems where the model-data misfit is measured in L2 norm
33+
- Problems where the Jacobian structure can be exploited for efficiency
34+
35+
**Example:**
36+
```julia
37+
using SciMLBase
38+
39+
# Define residual function for curve fitting
40+
function residual!(r, u, p)
41+
# u = [a, b] are parameters to fit
42+
# p = (x_data, y_data)
43+
x_data, y_data = p
44+
for i in eachindex(x_data)
45+
r[i] = u[1] * exp(u[2] * x_data[i]) - y_data[i]
46+
end
47+
end
48+
49+
# Create problem
50+
x_data = [0.0, 1.0, 2.0, 3.0]
51+
y_data = [1.0, 2.7, 7.4, 20.1]
52+
u0 = [1.0, 1.0] # Initial guess for [a, b]
53+
prob = NonlinearLeastSquaresProblem(residual!, u0, (x_data, y_data))
54+
```
55+
56+
## Strongly Connected Component Problems
57+
58+
### SCCNonlinearProblem
59+
60+
```julia
61+
SCCNonlinearProblem(f, u0, p=nothing)
62+
```
63+
64+
A specialized nonlinear problem for systems that can be decomposed into strongly connected components, enabling more efficient solution strategies.
65+
66+
**Use Cases:**
67+
- Large sparse nonlinear systems with block structure
68+
- Chemical reaction networks with distinct time scales
69+
- Circuit simulation with hierarchical organization
70+
- Systems where graph-based decomposition improves efficiency
71+
72+
**Benefits:**
73+
- Exploits sparsity patterns for improved performance
74+
- Enables divide-and-conquer solution strategies
75+
- Reduces memory requirements for large systems
76+
77+
## Integral Problems
78+
79+
### SampledIntegralProblem
80+
81+
```julia
82+
SampledIntegralProblem(y, x, p=nothing)
83+
```
84+
85+
A specialized integral problem for pre-sampled data where the integrand values are known at specific points.
86+
87+
**Arguments:**
88+
- `y`: Function values at sample points
89+
- `x`: Sample points (quadrature nodes)
90+
- `p`: Parameters (optional)
91+
92+
**Use Cases:**
93+
- Integration of experimental or simulation data
94+
- Monte Carlo integration with pre-computed samples
95+
- Adaptive quadrature where function evaluations are expensive
96+
97+
**Example:**
98+
```julia
99+
using SciMLBase
100+
101+
# Pre-sampled data points
102+
x = [0.0, 0.5, 1.0, 1.5, 2.0]
103+
y = sin.(x) # Function values at sample points
104+
105+
# Create sampled integral problem
106+
prob = SampledIntegralProblem(y, x)
107+
108+
# The integral can now be computed using various quadrature rules
109+
# without additional function evaluations
110+
```
111+
112+
## Incremental ODE Problems
113+
114+
### IncrementingODEProblem
115+
116+
```julia
117+
IncrementingODEProblem(f, u0, tspan, p=nothing)
118+
```
119+
120+
A specialized ODE problem type for systems where the right-hand side represents increments or rates that accumulate over time.
121+
122+
**Use Cases:**
123+
- Population models with birth/death processes
124+
- Chemical reaction systems with mass conservation
125+
- Economic models with cumulative effects
126+
- Systems where conservation laws must be maintained
127+
128+
**Features:**
129+
- Built-in conservation checking
130+
- Specialized integrators that preserve invariants
131+
- Enhanced numerical stability for accumulative processes
132+
133+
## Boundary Value Problems
134+
135+
### TwoPointBVProblem
136+
137+
```julia
138+
TwoPointBVProblem(f, bc, u0, tspan, p=nothing)
139+
```
140+
141+
A specialized boundary value problem for two-point boundary conditions.
142+
143+
**Arguments:**
144+
- `f`: The differential equation function
145+
- `bc`: Boundary condition function
146+
- `u0`: Initial guess for the solution
147+
- `tspan`: Time interval
148+
- `p`: Parameters (optional)
149+
150+
**Use Cases:**
151+
- Shooting methods for boundary value problems
152+
- Optimal control problems with fixed endpoints
153+
- Eigenvalue problems with specific boundary conditions
154+
155+
### SecondOrderBVProblem and TwoPointSecondOrderBVProblem
156+
157+
```julia
158+
SecondOrderBVProblem(f, bc, u0, du0, tspan, p=nothing)
159+
TwoPointSecondOrderBVProblem(f, bc, u0, du0, tspan, p=nothing)
160+
```
161+
162+
Specialized for second-order differential equations with boundary conditions.
163+
164+
**Use Cases:**
165+
- Mechanical systems with position and velocity constraints
166+
- Beam deflection problems
167+
- Quantum mechanics eigenvalue problems
168+
169+
## Interval and Homotopy Problems
170+
171+
### IntervalNonlinearProblem
172+
173+
```julia
174+
IntervalNonlinearProblem(f, u_interval, p=nothing)
175+
```
176+
177+
A nonlinear problem type for bracketing rootfinders where the solution is known to lie within a specific interval.
178+
179+
**Arguments:**
180+
- `f`: Function to find roots of
181+
- `u_interval`: Interval `[a, b]` containing the root
182+
- `p`: Parameters (optional)
183+
184+
**Use Cases:**
185+
- Guaranteed root finding with interval arithmetic
186+
- Robust rootfinding when derivative information is unreliable
187+
- Global optimization in one dimension
188+
189+
### HomotopyNonlinearFunction
190+
191+
A specialized function type for homotopy continuation methods where the problem is gradually deformed from a simple form to the target problem.
192+
193+
**Use Cases:**
194+
- Polynomial root finding
195+
- Global optimization via continuation
196+
- Bifurcation analysis and parameter continuation
197+
198+
## Performance Considerations
199+
200+
### Memory and Computational Efficiency
201+
202+
- **Specialized Storage**: Many specialized problems use tailored data structures that reduce memory overhead
203+
- **Exploiting Structure**: Problems like `SCCNonlinearProblem` exploit mathematical structure for faster solution
204+
- **Reduced Function Evaluations**: `SampledIntegralProblem` avoids repeated function calls
205+
206+
### Algorithm Selection
207+
208+
Different specialized problems work best with specific algorithm families:
209+
210+
```julia
211+
# Example: Choosing algorithms based on problem type
212+
function select_algorithm(prob)
213+
if prob isa NonlinearLeastSquaresProblem
214+
return LevenbergMarquardt() # Exploits least squares structure
215+
elseif prob isa SCCNonlinearProblem
216+
return NewtonRaphson() # Good for sparse structured systems
217+
elseif prob isa IntervalNonlinearProblem
218+
return Bisection() # Guaranteed convergence in intervals
219+
else
220+
return TrustRegion() # General purpose fallback
221+
end
222+
end
223+
```
224+
225+
## Integration with the SciML Ecosystem
226+
227+
Specialized problems integrate seamlessly with:
228+
- **Automatic Differentiation**: Support for forward and reverse mode AD
229+
- **Sensitivity Analysis**: Parameter sensitivity computation
230+
- **Ensemble Simulations**: Monte Carlo and parameter sweep studies
231+
- **Symbolic Computing**: Integration with ModelingToolkit.jl for symbolic problem setup
232+
233+
These specialized problem types provide targeted solutions for specific mathematical structures while maintaining compatibility with the broader SciML ecosystem's tools and workflows.

0 commit comments

Comments
 (0)