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
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 polynomial p6(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
, compute y
i = fθ(x
4. Compute the testing error: Compute and report the the absolute
error = errorθ=1,n=7 = maximum
i − p6(x
If you’re wondering how to compute p6(x
), look up (np.polyval and
use the coefficients you computed in Step 2. You’re evaluating the
polynomial model’s prediction of fθ(x
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