The first case was fine, rejection sampling works and you don't lose too many draws.
Start by clarifying the parameters of the normal distribution (mean and standard deviation) and the truncation bounds. Then, for each constraint, choose an appropriate sampling method: inverse transform sampling for one-sided truncation, and rejection sampling or inverse transform for narrow intervals. Discuss the trade-offs between accuracy and efficiency, especially for the narrow interval [4, 4.05].
Pro tip: For the narrow interval, inverse transform sampling is more efficient than rejection sampling because the acceptance rate is extremely low. Also, mention that you can precompute the CDF values for the truncated bounds to speed up sampling.
Ask for the mean and standard deviation of the normal distribution. Confirm the truncation bounds: x > 1, 4 < x < 4.05, and x > 4.
For one-sided truncation (x > a), use inverse transform sampling: sample u ~ Uniform(Φ((a-μ)/σ), 1), then x = μ + σ Φ^{-1}(u). For two-sided truncation (a < x < b), sample u ~ Uniform(Φ((a-μ)/σ), Φ((b-μ)/σ)), then transform.
Write a function for each case. Use scipy.stats.norm for CDF and inverse CDF (ppf). For the narrow interval, ensure numerical stability by computing Φ((b-μ)/σ) - Φ((a-μ)/σ) accurately.
Test the functions by generating samples and checking they fall within bounds. Compare inverse transform vs. rejection sampling: rejection is simple but inefficient for narrow intervals; inverse transform is efficient but requires CDF inversion.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Mean and median parts were straightforward once I remembered to just take derivatives.
Start by recognizing that minimizing squared error yields the mean, absolute error yields the median, and the 90th percentile arises from minimizing an asymmetric absolute loss (quantile loss). Explain each case with mathematical reasoning, then generalize to quantile regression. Connect these to practical applications like robust regression and quantile forecasting.
Pro tip: Mention that the quantile loss is also known as the pinball loss, and that it is used in quantile regression and gradient boosting (e.g., LightGBM's objective='quantile'). This shows depth and practical awareness.
Show that the sum of squared errors is minimized by the mean. Derive by setting the derivative to zero: d/dθ Σ(x_i - θ)^2 = -2 Σ(x_i - θ) = 0 => θ = mean.
Show that the sum of absolute errors is minimized by the median. Explain that the derivative is the sign of (θ - x_i), and the subgradient condition leads to θ being any median.
Introduce the asymmetric absolute loss: L_τ(θ) = Σ [τ * max(x_i - θ, 0) + (1-τ) * max(θ - x_i, 0)]. Explain that minimizing this yields the τ-th quantile.
Set τ = 0.9. Show that the minimizer is the 90th percentile by considering the subgradient: the proportion of points below θ should be 0.9.
Mention that this loss is used in quantile regression, and that it provides a way to estimate conditional quantiles. Highlight its robustness compared to squared error.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.