Skip to content

Commit

Permalink
Improve roadmap (#2)
Browse files Browse the repository at this point in the history
* Clarify comments

* Added a new roadmap goal

* Fixes installation from Pip procedure
  • Loading branch information
mbaudin47 authored Nov 29, 2024
1 parent 6680e46 commit b51acc0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ To install from Pip:

```bash
pip install numericalderivative
python setup.py install
```

## References
Expand All @@ -70,4 +69,12 @@ python setup.py install
benchmark problems
- Use a relative precision in SteplemanWinarsky and GillMurraySaundersWright.
- Remove NumericalDerivative: move it to FiniteDifferenceFormula.
- Add finite_differences from menum and cite (Baudin, 2023).
Reference : https://github.com/mbaudin47/menum_code
https://github.com/mbaudin47/menum_code/blob/cec64dea8d205da796d1f578b42948115257b3bb/Scripts-Eleves/Py3/numdiff.py#L801

- Implement the method of:

Shi, H. J. M., Xie, Y., Xuan, M. Q., & Nocedal, J. (2022). Adaptive finite-difference interval estimation for noisy derivative-free optimization. _SIAM Journal on Scientific Computing_, _44_(4), A2302-A2321.


6 changes: 3 additions & 3 deletions numericalderivative/DerivativeBenchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ def __init__(self, alpha=1.0e6):
References
----------
Gill, P. E., Murray, W., Saunders, M. A., & Wright, M. H. (1983).
Computing forward-difference intervals for numerical optimization.
SIAM Journal on Scientific and Statistical Computing, 4(2), 310-321.
- Gill, P. E., Murray, W., Saunders, M. A., & Wright, M. H. (1983).
Computing forward-difference intervals for numerical optimization.
SIAM Journal on Scientific and Statistical Computing, 4(2), 310-321.
"""
if alpha <= 0.0:
raise ValueError(f"alpha = {alpha} should be > 0")
Expand Down
6 changes: 3 additions & 3 deletions numericalderivative/DumontetVignes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""
References
----------
Dumontet, J., & Vignes, J. (1977).
Détermination du pas optimal dans le calcul des dérivées sur ordinateur.
RAIRO. Analyse numérique, 11 (1), 13-25.
- Dumontet, J., & Vignes, J. (1977).
Détermination du pas optimal dans le calcul des dérivées sur ordinateur.
RAIRO. Analyse numérique, 11 (1), 13-25.
"""

import numpy as np
Expand Down
22 changes: 19 additions & 3 deletions numericalderivative/FiniteDifferenceFormula.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,18 @@ def compute_third_derivative(self, step):
third_derivative : float
The approximate f'''(x).
References
----------
- Dumontet, J., & Vignes, J. (1977).
Détermination du pas optimal dans le calcul des dérivées sur ordinateur.
RAIRO. Analyse numérique, 11 (1), 13-25.
"""
t = np.zeros(4)
t[0] = self.function_eval(self.x + 2 * step)
t[1] = -self.function_eval(self.x - 2 * step) # Fixed wrt paper
t[2] = -2.0 * self.function_eval(self.x + step)
t[3] = 2.0 * self.function_eval(self.x - step) # Fixed wrt paper
third_derivative = np.sum(t) / (2 * step**3) # Eq. 27 et 35
third_derivative = np.sum(t) / (2 * step**3) # Eq. 27 and 35 in (D&V, 1977)
return third_derivative

def compute_first_derivative_central(self, step):
Expand Down Expand Up @@ -134,11 +139,17 @@ def compute_first_derivative_forward(self, step):
-------
second_derivative : float
An estimate of f''(x).
References
----------
- Gill, P. E., Murray, W., Saunders, M. A., & Wright, M. H. (1983).
Computing forward-difference intervals for numerical optimization.
SIAM Journal on Scientific and Statistical Computing, 4(2), 310-321.
"""
step = (self.x + step) - self.x # Magic trick
if step <= 0.0:
raise ValueError("Zero computed step. Cannot perform finite difference.")
# Eq. 1, page 311 in (GMS, 1983)
# Eq. 1, page 311 in (GMS&W, 1983)
x1 = self.x + step
first_derivative = (self.function(x1) - self.function(self.x)) / step
return first_derivative
Expand Down Expand Up @@ -166,11 +177,16 @@ def compute_second_derivative_central(self, step):
second_derivative : float
An estimate of f''(x).
References
----------
- Gill, P. E., Murray, W., Saunders, M. A., & Wright, M. H. (1983).
Computing forward-difference intervals for numerical optimization.
SIAM Journal on Scientific and Statistical Computing, 4(2), 310-321.
"""
step = (self.x + step) - self.x # Magic trick
if step <= 0.0:
raise ValueError("Zero computed step. Cannot perform finite difference.")
# Eq. 8 page 314
# Eq. 8 page 314 in (GMS&W, 1983)
second_derivative = (
self.function_eval(self.x + step)
- 2 * self.function_eval(self.x)
Expand Down
6 changes: 3 additions & 3 deletions numericalderivative/GillMurraySaundersWright.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""
References
----------
Gill, P. E., Murray, W., Saunders, M. A., & Wright, M. H. (1983).
Computing forward-difference intervals for numerical optimization.
SIAM Journal on Scientific and Statistical Computing, 4(2), 310-321.
- Gill, P. E., Murray, W., Saunders, M. A., & Wright, M. H. (1983).
Computing forward-difference intervals for numerical optimization.
SIAM Journal on Scientific and Statistical Computing, 4(2), 310-321.
"""

import numpy as np
Expand Down

0 comments on commit b51acc0

Please sign in to comment.