libeblearn
|
#include <ebl_tester.h>
Public Member Functions | |
module_tester (double thres=1e-6, T rrange_min=-1.0, T rrange_max=1.0, FILE *out=stdout) | |
idx< double > | test_jacobian (module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out) |
idx< double > | test_jacobian_param (parameter< bbstate_idx< T > > &p, module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out) |
idx< double > | test_hessian (module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out) |
idx< double > | test_hessian_param (parameter< bbstate_idx< T > > &p, module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out) |
double | get_acc_thres () const |
get accuracy threshold | |
void | set_acc_thres (double acc_thres) |
set accuracy threshold | |
T | get_rrange () const |
get random range | |
void | set_rrange (T rrange) |
set random range | |
FILE * | get_out () const |
get ostream used | |
void | set_out (FILE *out) |
set ostream | |
Protected Member Functions | |
void | get_jacobian_fprop (module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out, idx< T > &jac) |
void | get_jacobian_fprop_param (parameter< bbstate_idx< T > > &p, module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out, idx< T > &jac) |
void | get_jacobian_bprop (module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out, idx< T > &jac) |
Get jacobian using bprop for derivative of 'out' w.r.t. 'in'. | |
void | get_jacobian_bprop_param (parameter< bbstate_idx< T > > &p, module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out, idx< T > &jac) |
void | get_hessian_fprop (module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out, idx< T > &jac) |
void | get_hessian_fprop_param (parameter< bbstate_idx< T > > &p, module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out, idx< T > &jac) |
void | get_hessian_bprop (module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out, idx< T > &jac) |
Get hessian using bprop for derivative of 'out' w.r.t. 'in'. | |
void | get_hessian_bprop_param (parameter< bbstate_idx< T > > &p, module_1_1< T > &m, bbstate_idx< T > &in, bbstate_idx< T > &out, idx< T > &jac) |
void | report_err (idx< T > &a, idx< T > &b, const char *msg) |
Print error between 'a' and 'b' with message 'msg'. | |
idx< double > | get_errs (idx< T > &a, idx< T > &b) |
Returns a 2-elements idx with 0: max error 1: total error. | |
Protected Attributes | |
double | acc_thres |
accuracy threshold | |
T | rrange_min |
T | rrange_max |
random initialization range | |
FILE * | out |
output stream | |
idx< T > | jac_fprop |
idx< T > | jac_bprop |
idx< T > | jac_bbprop |
Jacobians from *prop. | |
idx< T > | jac_pfprop |
idx< T > | jac_pbprop |
idx< T > | jac_pbbprop |
Jacobians wrt params. | |
idx< T > | hes_fprop |
idx< T > | hes_bprop |
idx< T > | hes_bbprop |
Hessians from *prop. | |
idx< T > | hes_pfprop |
idx< T > | hes_pbprop |
idx< T > | hes_pbbprop |
Hessians wrt params. |
Tests any module that is descendant of module_1_1. (includes layers) bprop to input and to parameters are validated with finite difference approximations.
This class is not meant to replace the testing framework for eblearn developers but it should be useful for eblearn users that create new modules using this library as a binary reference
ebl::module_tester< T >::module_tester | ( | double | thres = 1e-6 , |
T | rrange_min = -1.0 , |
||
T | rrange_max = 1.0 , |
||
FILE * | out = stdout |
||
) |
out : reference to ostream to push results thres : threshold to decide bprop and finite diff jacobian are same or different this might be tricky because if the modules accumulates derivatives, then the difference will inevitably grow, so user has to have a sense of what is valid default : 1e-8 rrange : range that is used to randomize the input state and parameter objects. if this value is very small, then the jacobians will always be very similar
void ebl::module_tester< T >::get_hessian_bprop_param | ( | parameter< bbstate_idx< T > > & | p, |
module_1_1< T > & | m, | ||
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out, | ||
idx< T > & | jac | ||
) | [protected] |
Get hessian using bprop for derivative of 'out' w.r.t. 'p'.
p | The parameter object that was used to allocate the parameters of module. This should contain the parameter of this module only. |
void ebl::module_tester< T >::get_hessian_fprop | ( | module_1_1< T > & | m, |
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out, | ||
idx< T > & | jac | ||
) | [protected] |
Get hessian using 1st order central finite differnce approximation for derivative of 'out' w.r.t. 'in' using module 'm'.
void ebl::module_tester< T >::get_hessian_fprop_param | ( | parameter< bbstate_idx< T > > & | p, |
module_1_1< T > & | m, | ||
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out, | ||
idx< T > & | jac | ||
) | [protected] |
Get hessian using 1st order central finite differnce approximation for derivative of 'out' w.r.t. 'p' using module 'm'.
p | The parameter object that was used to allocate the parameters of module. This should contain the parameter of this module only. |
void ebl::module_tester< T >::get_jacobian_bprop_param | ( | parameter< bbstate_idx< T > > & | p, |
module_1_1< T > & | m, | ||
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out, | ||
idx< T > & | jac | ||
) | [protected] |
Get jacobian using bprop for derivative of 'out' w.r.t. 'p'.
p | The parameter object that was used to allocate the parameters of module. This should contain the parameter of this module only. |
void ebl::module_tester< T >::get_jacobian_fprop | ( | module_1_1< T > & | m, |
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out, | ||
idx< T > & | jac | ||
) | [protected] |
Get jacobian using 1st order central finite differnce approximation for derivative of 'out' w.r.t. 'in' using module 'm'.
void ebl::module_tester< T >::get_jacobian_fprop_param | ( | parameter< bbstate_idx< T > > & | p, |
module_1_1< T > & | m, | ||
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out, | ||
idx< T > & | jac | ||
) | [protected] |
Get jacobian using 1st order central finite differnce approximation for derivative of 'out' w.r.t. 'p' using module 'm'.
p | The parameter object that was used to allocate the parameters of module. This should contain the parameter of this module only. |
idx< double > ebl::module_tester< T >::test_hessian | ( | module_1_1< T > & | m, |
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out | ||
) |
Test the 2nd derivatives of 'in' w.r.t. 'out' with module 'm'. This returns an idx with 2 elements, 0: maximum error 1: total error.
idx< double > ebl::module_tester< T >::test_hessian_param | ( | parameter< bbstate_idx< T > > & | p, |
module_1_1< T > & | m, | ||
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out | ||
) |
Test the 2nd derivatives of 'out' w.r.t. parameters 'p' of module 'm'.
p | The parameter object that was used to allocate the parameters of module. this parameter object should contain the parameter of only this module. This returns an idx with 2 elements, 0: maximum error 1: total error. |
idx< double > ebl::module_tester< T >::test_jacobian | ( | module_1_1< T > & | m, |
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out | ||
) |
Test the 1st derivatives of 'in' w.r.t. 'out' with module 'm'. This returns an idx with 2 elements, 0: maximum error 1: total error.
idx< double > ebl::module_tester< T >::test_jacobian_param | ( | parameter< bbstate_idx< T > > & | p, |
module_1_1< T > & | m, | ||
bbstate_idx< T > & | in, | ||
bbstate_idx< T > & | out | ||
) |
Test the 1st derivatives of 'out' w.r.t. parameters 'p' of module 'm'.
p | The parameter object that was used to allocate the parameters of module. this parameter object should contain the parameter of only this module. This returns an idx with 2 elements, 0: maximum error 1: total error. |