Description
Consider the parameterized family of functions,
fθ(x) = 1
1 + exp(−θx)
, x ∈ [−5, 5].
The parameter θ controls how smooth fθ is near x = 0, as shown:
-5 0 5
x
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
fθ(x)
θ=1
θ=2
θ=10
To start this homework, let θ = 1.
1. Generate training data: Create a vector with n = 7 evenly spaced points in the interval
[−5, 5]. (In Matlab, you can do this with linspace.) For each point xi
in this vector, compute
yi = fθ(xi). You should now have 7 pairs (xi
, yi). Provide a printout of the 7 pairs (e.g., in a
table).
2. Train the model: Construct the Vandermonde system and solve for the coefficients of the
unique degree 6 interpolating polynomial p6(x). Provide a printout of the 6 coefficients.
3. Generate testing data: Create a new vector with 101 evenly spaced points in [−5, 5]. For each
point x
0
i
, compute y
0
i = fθ(x
0
i
). Report the mean (mean in Matlab) and standard deviation (std
in Matlab) from the set of points y
0
1
, . . . , y0
101.
4. Compute the testing error: Compute and report the the absolute testing error:
error = errorθ=1,n=7 = maximum
1≤i≤101
| y
0
i − p6(x
0
i
)|
1
Note that the error depends on the value of θ and the number of training points / the degree of
the polynomial.
5. Repeat steps 1-4 with θ = 10. How does the error change? What does that tell you about the
quality of the polynomial approximation for the two functions?
6. EXTRA CREDIT (15pts): Repeat steps 1-4 with θ = 10 and n = 8, 9, . . . , 15. Plot errorθ=10,n
versus n on a semilog scale. How does the polynomial approximation converge as n increases?
2