Conversation
|
@mrcinv prosim za pregled |
mrcinv
left a comment
There was a problem hiding this comment.
@kurtaga Nice solution. The code is well structured. There are no doc strings for functions. To find the error you've compared the results to existing implementation.
Existing implementation might not be available in other similar cases, so it would be better to calculate the error estimate with your code only.
The report is well written and explains nicely the design.
| - Moderate values (2 ≤ x ≤ 5): Gauss–Legendre quadrature (fixed steps). | ||
| - Large $x > 5$: Asymptotic expansion. | ||
|
|
||
| We can also take advantage of the symmetry of the normal distribution: |
There was a problem hiding this comment.
For values smaller than
| In our case, the weight function is simply $w(t) = 1$, which makes Gauss–Legendre the appropriate choice (other Gaussian quadratures such as Gauss–Hermite or Gauss–Laguerre are used when exponential weight functions appear). | ||
|
|
||
| To ensure constant-time evaluation, we use a fixed rule (10-point Gauss–Legendre), with nodes and weights obtained from published tables and hardcoded into the implementation. Reliable tables can be found online, e.g.: | ||
| [https://pomax.github.io/bezierinfo/legendre-gauss.html](Gaussian Quadrature Weights and Abscissae). |
There was a problem hiding this comment.
There is also a package FastGaussQuadrature for that.
|
|
||
| # Asymptotic Expansion | ||
|
|
||
| For large arguments ($x > 5$), we can use an asymptotic expansion to approximate the standard normal CDF. The idea is to express the CDF in terms of the complementary error function: |
There was a problem hiding this comment.
The asymptotic expansion is not derived. Where did you find it? Please add the derivation of the expansion or a reference to the source where you found it.
| asymptotic_terms::Int=10) | ||
|
|
||
| if x < 0 | ||
| return 1.0 - my_cdf(-x; |
There was a problem hiding this comment.
This formula will lead to large relative error for
| nodes, weights = GL_rules[n] | ||
|
|
||
| # symmetry: reduce to positive x | ||
| if x < 0 |
There was a problem hiding this comment.
Due to the properties of the function (
Second assignment complete