Skip to content

Commit b2f0413

Browse files
committed
advice on chebregression
1 parent 885db24 commit b2f0413

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ We also have a function `chebregression(x, y, [lb, ub,], order)` that
3333
can perform multidimensional Chebyshev least-square fitting. It
3434
returns a Chebyshev polynomial of a given `order` (tuple) fit
3535
to a set of points `x[i]` and values `y[i]`, optionally in a box
36-
with bounds `lb, ub` (which default to bounding box for `x`).
36+
with bounds `lb, ub` (which default to bounding box for `x`). For fitting
37+
from arbitrary points `x` (not Chebyshev points) and/or for fitting
38+
noisy data, it is generally advisable
39+
for the number of points to be much larger than the number of polynomial
40+
terms `prod(order .+ 1)` to avoid [Runge phenomena](https://en.wikipedia.org/wiki/Runge%27s_phenomenon)
41+
and/or [overfitting](https://en.wikipedia.org/wiki/Overfitting).
3742

3843
### 1d Example
3944

@@ -64,14 +69,14 @@ julia> cos(2x + 3cos(4x)) * (2 - 12sin(4x)) # exact derivative
6469
-13.700760631142602
6570
```
6671

67-
Interpolation is most efficient and accurate if we evaluate our function at the points given by `chebpoints`. However, we can also perform least-square polynomial fitting (in the Chebyshev basis, which is well behaved even at high degree) from an *arbitrary* set of points — this is useful if the points were specified externally, or if we want to "smooth" the data by fitting to a polynomial of lower degree than for interpolation. For example, we can fit the same function above, again to a degree-200 Chebyshev polynomial, using 10000 *random* points in the domain:
72+
Interpolation is most efficient and accurate if we evaluate our function at the points given by `chebpoints`. However, we can also perform least-square polynomial fitting (in the Chebyshev basis, which is well behaved even at high degree if there are sufficiently many data points) from an *arbitrary* set of points — this is useful if the points were specified externally, or if we want to "smooth" the data by fitting to a polynomial of lower degree than for interpolation. For example, we can fit the same function above, again to a degree-200 Chebyshev polynomial, using 10000 *random* points in the domain:
6873
```jl
6974
xr = rand(10000) * 10 # 10000 uniform random points in [0, 10]
70-
c = chebregression(xr, f.(xr), 0, 10, 200) # fit to a degree-200 polynomial
75+
cr = chebregression(xr, f.(xr), 0, 10, 200) # fit to a degree-200 polynomial
7176
```
7277
which gives:
7378
```jl
74-
julia> maximum(@. abs(c(xx) - f(xx)))
79+
julia> maximum(@. abs(cr(xx) - f(xx)))
7580
1.4655330320523241e-5
7681
```
7782

0 commit comments

Comments
 (0)