Skip to content

Conversation

@Kurtaga
Copy link
Owner

@Kurtaga Kurtaga commented Aug 26, 2025

Second assignment complete

@Kurtaga
Copy link
Owner Author

Kurtaga commented Aug 27, 2025

@mrcinv prosim za pregled

Copy link
Collaborator

@mrcinv mrcinv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For values smaller than $-5$ this formula would result in large relative error(due to catastrophic subtraction).

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).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formula will lead to large relative error for $x&lt;-5$. You can use asymptotic expansion for those values.

nodes, weights = GL_rules[n]

# symmetry: reduce to positive x
if x < 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the properties of the function ($\lim_{x \to -\infty} = 0$) it is better to do it the other way around: use symmetry to calculate positive values. This way you avoid catastrophic subtraction $1-F(-x)$ where $F(-x) \approx 1$.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants