![]() |
LINE Solver (C++)
Templated C++ port of the LINE queueing solver
|
Gradient of a noisy function by central differences with a tuned step. More...
#include <algorithm>#include <cmath>#include <cstddef>#include <functional>#include <limits>#include <string>#include <vector>#include "line/api/sim/sim_dist.h"#include "line/util/error.h"Go to the source code of this file.
Classes | |
| struct | line::sim::SimFdEmcfdOptions |
| Options of sim_fd_emcfd, with the reference defaults. More... | |
| struct | line::sim::SimFdEmcfdResult |
| Result of sim_fd_emcfd. More... | |
Namespaces | |
| namespace | line |
| Conservation laws of a layered queueing network, enumerated from its structure. | |
| namespace | line::sim |
Functions | |
| std::vector< double > | line::sim::sim_fd_emcfd_pilot_deltas (std::size_t n1, double pilot_scale, double max_step=std::numeric_limits< double >::infinity()) |
| The E-stage perturbation sizes, clipped to max_step. | |
| SimFdEmcfdResult | line::sim::sim_fd_emcfd (const std::function< std::vector< double >(double, std::size_t)> &fhat, double x0, std::size_t n, const SimFdEmcfdOptions &o=SimFdEmcfdOptions()) |
| EM-CFD gradient estimate. | |
Gradient of a noisy function by central differences with a tuned step.
Port of matlab/src/api/sim/sim_fd_emcfd.m and sim_fd_emcfd_pilot_deltas.m (JAR jline.api.sim.SimFdEmcfd, Python line_solver.api.sim.fdtune): the Estimation-Minimization Central Finite-Difference (EM-CFD) scheme of Li and Lam (2020).
THE STEP IS NOT GUESSED, IT IS ESTIMATED. The MSE of the central difference averaged over n2 pairs at step d is B^2 d^4 + sigma^2/(2 n2 d^2), with B = f'''(x0)/6 and sigma^2 = Var fhat(x0), minimized at d* = (sigma^2/(4 n2 B^2))^(1/6). The E-stage spends n1 = max(3, floor(lambda n)) pairs at varied pilot steps and regresses the differences on 2d and 2d^3 (Li and Lam, eq. (2)) to estimate B; sigma^2 comes from the regression residuals. The M-stage runs the remaining n2 = n - n1 pairs at d* and returns their average quotient. A vector output shares one step, d*^6 = sum_j w_j sigma_j^2 / (4 n2 sum_j w_j B_j^2), with default weights 1/fbar_j^2 (zero where the pilot mean fbar_j vanishes).
The pilot steps are the stratified half-normal quantiles s n1^(-1/10) Phi^{-1}(1/2 + (i - 1/2)/(2 n1)) rather than the paper's i.i.d. normal draw: the same moments, and the same steps in all four codebases.
Reference: H. Li, H. Lam (2020). Optimally tuning finite-difference estimators. Proceedings of the 2020 Winter Simulation Conference, 457-468.
Definition in file sim_fd_emcfd.h.