class QPanda::Variational::expression¶
Overview¶
A proxy class for the Variational::var. More…
#include <expression.h> class expression { public: // construction expression(var root); // methods var getRoot() const; std::vector<var> findLeaves(); MatrixXd propagate(); MatrixXd propagate(const std::vector<var>& leaves); std::unordered_set<var> findNonConsts(const std::vector<var>&); std::unordered_set<var> findNonConsts(const std::unordered_set<var>&); void backpropagate(std::unordered_map<var, MatrixXd>& leaves); void backpropagate( std::unordered_map<var, MatrixXd>& leaves, const std::unordered_set<var>& nonconsts ); std::unordered_set<var> findVariables(); };
Detailed Documentation¶
A proxy class for the Variational::var.
Construction¶
expression(var root)
Construct a new expression object.
Parameters:
root |
the root variable, denoting the y in dy/dx. |
Methods¶
var getRoot() const
Get the root.
Returns:
var the root, denoting the y in dy/dx.
std::vector<var> findLeaves()
recursively finding the leaves for the root
Returns:
std::vector<var> the vector of the leaves
MatrixXd propagate()
feed forward the expression, return the value
Returns:
MatrixXd The result
MatrixXd propagate(const std::vector<var>& leaves)
feed forward the expression with given leaves
Parameters:
leaves |
leaves either generated by expression::findLeaves or assigned by user (usually not including the training data placeholders). |
Returns:
MatrixXd The reuslts.
std::unordered_set<var> findNonConsts(const std::vector<var>&)
find all non-constants variable for the given leaves. if there is some variable not related in the path from the root to the leaves, it will not be added into the set
Returns:
std::unordered_set<var> All non-constants variables.
void backpropagate(std::unordered_map<var, MatrixXd>& leaves)
backpropagation and evalute all gradients.
Parameters:
leaves |
The var-grad map. This function will update the gradients. |
void backpropagate( std::unordered_map<var, MatrixXd>& leaves, const std::unordered_set<var>& nonconsts )
backpropagation and evalute all gradients.
Parameters:
leaves |
The var-grad map. This function will update the gradients. |
nonconsts |
all non-constants. using this to remove unnecessary nodes from the gradient-evaluation. |