-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnumerical_diff.h
More file actions
29 lines (22 loc) · 1.07 KB
/
numerical_diff.h
File metadata and controls
29 lines (22 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef NUMERICAL_DIFF_H
#define NUMERICAL_DIFF_H
#include "expr.h"
#define NUMERICAL_DIFF_DEFAULT_H 1e-7
/* Compute dense numerical Jacobian via central differences.
* Returns malloc'd row-major array (node->size x node->n_vars).
* Caller must free(). */
double *numerical_jacobian(expr *node, const double *u, double h);
/* Evaluate analytical Jacobian, compute numerical Jacobian,
* and compare. Returns 1 on match, 0 on mismatch.
* Prints diagnostic on first failing entry. */
int check_jacobian_num(expr *node, const double *u, double h);
/* Compute dense numerical weighted-sum Hessian via central
* differences on the gradient g(u) = J(u)^T w.
* Returns malloc'd row-major array (n_vars x n_vars).
* Caller must free(). */
double *numerical_wsum_hess(expr *node, const double *u, const double *w, double h);
/* Evaluate analytical wsum_hess, compute numerical wsum_hess,
* and compare. Returns 1 on match, 0 on mismatch.
* Prints diagnostic on first failing entry. */
int check_wsum_hess(expr *node, const double *u, const double *w, double h);
#endif /* NUMERICAL_DIFF_H */