27#include <ql/shared_ptr.hpp>
36 const std::vector<std::function<std::vector<T>(
const std::vector<const T*>&,
const T*)>>& grad,
37 std::function<
void(T&)> deleter = {},
const std::vector<bool>& keepNodes = {},
38 const std::size_t conditionalExpectationOpId = 0,
46 for (std::size_t node = 0; node < g.
size(); ++node) {
52 for (std::size_t arg = 0; arg < g.
predecessors(node).size(); ++arg) {
63 auto gr = grad[g.
opId(node)](args, &values[node]);
65 for (std::size_t p = 0; p < g.
predecessors(node).size(); ++p) {
66 derivatives[node] += derivatives[g.
predecessors(node)[p]] * gr[p];
73 for (std::size_t arg = 0; arg < g.
predecessors(node).size(); ++arg) {
83 if (!keepNodes.empty() && keepNodes[p])
88 deleter(derivatives[p]);
const std::vector< std::size_t > & predecessors(const std::size_t node) const
std::size_t maxNodeRequiringArg(const std::size_t node) const
std::size_t opId(const std::size_t node) const
void forwardDerivatives(const ComputationGraph &g, const std::vector< T > &values, std::vector< T > &derivatives, const std::vector< std::function< std::vector< T >(const std::vector< const T * > &, const T *)> > &grad, std::function< void(T &)> deleter={}, const std::vector< bool > &keepNodes={}, const std::size_t conditionalExpectationOpId=0, const std::function< T(const std::vector< const T * > &)> &conditionalExpectation={})
RandomVariable conditionalExpectation(const std::vector< const RandomVariable * > ®ressor, const std::vector< std::function< RandomVariable(const std::vector< const RandomVariable * > &)> > &basisFn, const Array &coefficients)