$24
Consider the parameterized family of functions,
fθ(x) =
1
, x ∈ [−5, 5].
1 + exp( θx)
−
The parameter θ controls how smooth fθ is near x = 0, as shown:
1
0.9
0.8
0.7
0.6
( )X
0.5
θ
F
0.4
0.3
0.2
θ=1
0.1
θ=2
θ=10
0
-5
0
5
X
To start this homework, let θ = 1.
1. Generate training data: Create a vector with n = 7 evenly spaced points in the interval [−5, 5]. For each point xi in this vector, compute yi = fθ(xi). You should now have 7 pairs (xi, yi). Make a nice table with the seven input/output pairs.
2. Train the model: Construct the Vandermonde system and solve for the coefficients of the unique degree-6 interpolating polynomialp6(x). Make a nice table of the 7 coefficients. And make a plot showing both fθ(x) and p6(x) over the domain [−5, 5]. Does this look like a good approximation? Explain your assessment.
3. Generate testing data: Create a new vector with 101 evenly spaced points in [−5, 5]. For each point x′i, compute yi′ = fθ(x′i).
1
4. Compute the testing error: Compute and report the the absolute testing error:
error = errorθ=1,n=7
= maximum
| yi′ − p6(xi′ ) |
|yi′ |
i
If you’re wondering how to compute p6(x′i), look up (np.polyval and use the coefficients you computed in Step 2. You’re evaluating the polynomial model’s prediction of fθ(x′i).
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?
2