MUQ  0.4.3
muq::Modeling::ModGraphPiece Class Reference

A muq::Modeling::ModPiece created from a muq::Modeling::WorkGraph. More...

#include <ModGraphPiece.h>

Inheritance diagram for muq::Modeling::ModGraphPiece:

Detailed Description

A muq::Modeling::ModPiece created from a muq::Modeling::WorkGraph.

Definition at line 23 of file ModGraphPiece.h.

Public Member Functions

 ModGraphPiece (std::shared_ptr< WorkGraph > graph, std::vector< std::shared_ptr< ConstantVector > > const &constantPieces, std::vector< std::string > const &inputNames, std::shared_ptr< ModPiece > outputNode)
 Construct a muq::Modeling::ModGraphPiece. More...
 
virtual ~ModGraphPiece ()=default
 Default destructor. More...
 
std::shared_ptr< WorkGraphGetGraph ()
 
std::vector< std::shared_ptr< ConstantVector > > GetConstantPieces ()
 
std::shared_ptr< ModGraphPieceGetSubModel (std::string const &nodeName) const
 Returns another ModGraphPiece containing only part of the graph making up this model. More...
 
std::vector< int > MatchInputs (std::shared_ptr< ModGraphPiece > otherPiece) const
 Matches inputs with another ModGraphPiece by looking at node names and edges. More...
 
std::shared_ptr< ModGraphPieceGradientGraph (unsigned int const outputDimWrt, unsigned int const inputDimWrt)
 
std::shared_ptr< ModGraphPieceJacobianGraph (unsigned int const outputDimWrt, unsigned int const inputDimWrt)
 
std::string GetOutputName () const
 
std::shared_ptr< ModPieceGetOutputPiece () const
 
- Public Member Functions inherited from muq::Modeling::ModPiece
 ModPiece (std::vector< int > const &inputSizes, std::vector< int > const &outputSizes)
 
 ModPiece (Eigen::VectorXi const &inputSizes, Eigen::VectorXi const &outputSizes)
 
virtual ~ModPiece ()=default
 
virtual double GetRunTime (const std::string &method="Evaluate") const override
 Get the average run time for one of the implemented methods. More...
 
virtual void ResetCallTime () override
 Resets the number of call and times. More...
 
virtual unsigned long int GetNumCalls (const std::string &method="Evaluate") const override
 get the number of times one of the implemented methods has been called. More...
 
virtual std::vector< Eigen::VectorXd > const & Evaluate (std::vector< Eigen::VectorXd > const &input)
 Evaluate the ModPiece. More...
 
virtual std::vector< Eigen::VectorXd > const & Evaluate (ref_vector< Eigen::VectorXd > const &input)
 
 VARIADIC_TO_REFVECTOR (Evaluate, Eigen::VectorXd, std::vector< Eigen::VectorXd > const &)
 
virtual Eigen::VectorXd const & Gradient (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity)
 Compute the Gradient \(J^Tv\). More...
 
virtual Eigen::VectorXd const & Gradient (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity)
 
Eigen::VectorXd const & Gradient (unsigned int outWrt, unsigned int inWrt, Eigen::VectorXd const &last, Eigen::VectorXd const &sens)
 
template<typename... Args>
Eigen::VectorXd const & Gradient (unsigned int wrtOut, unsigned int wrtIn, Args const &... args)
 
Eigen::VectorXd const & ApplyHessian (unsigned int outWrt, unsigned int inWrt1, unsigned int inWrt2, Eigen::VectorXd const &last, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
template<typename... Args>
Eigen::VectorXd const & ApplyHessian (unsigned int wrtOut, unsigned int wrtIn1, unsigned int wrtIn2, Args const &... args)
 
virtual Eigen::MatrixXd const & Jacobian (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input)
 Compute the Jacobian of this ModPiece. More...
 
virtual Eigen::MatrixXd const & Jacobian (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input)
 
template<typename... Args>
Eigen::MatrixXd const & Jacobian (unsigned int outWrt, unsigned int inWrt, Args const &... args)
 
template<typename... Args>
Eigen::MatrixXd JacobianByFD (unsigned int outWrt, unsigned int inWrt, Args const &... args)
 
template<typename... Args>
Eigen::MatrixXd ApplyJacobianByFD (unsigned int outWrt, unsigned int inWrt, Args const &... args)
 
virtual Eigen::VectorXd const & ApplyJacobian (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 Apply the Jacobian of this ModPiece to a vector. More...
 
virtual Eigen::VectorXd const & ApplyJacobian (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 
Eigen::VectorXd const & ApplyJacobian (unsigned int outWrt, unsigned int inWrt, Eigen::VectorXd const &last, Eigen::VectorXd const &sens)
 
template<typename... Args>
Eigen::VectorXd const & ApplyJacobian (unsigned int wrtOut, unsigned int wrtIn, Args const &... args)
 
virtual Eigen::VectorXd GradientByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity)
 
virtual Eigen::VectorXd GradientByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity)
 
virtual Eigen::MatrixXd JacobianByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input)
 
virtual Eigen::MatrixXd JacobianByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input)
 
virtual Eigen::VectorXd ApplyJacobianByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd ApplyJacobianByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd const & ApplyHessian (unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd const & ApplyHessian (unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd ApplyHessianByFD (unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd ApplyHessianByFD (unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
void EnableCache ()
 
void DisableCache ()
 
bool CacheStatus () const
 
virtual void SetWarnLevel (unsigned int newLevel)
 
- Public Member Functions inherited from muq::Modeling::WorkPiece
 WorkPiece ()
 Create a muq::Modeling::WorkPiece with no fixed number of inputs and outputs and variable input/output types. More...
 
 WorkPiece (int const num, WorkPiece::Fix const fix=WorkPiece::Fix::Inputs)
 Create a muq::Modeling::WorkPiece with either a fixed number of inputs or outputs and variable input/output types. More...
 
 WorkPiece (int const numIns, int const numOuts)
 Create a muq::Modeling::WorkPiece with a fixed number of inputs and outputs but variable input/output types. More...
 
 WorkPiece (std::vector< std::string > const &types, WorkPiece::Fix const fix=WorkPiece::Fix::Inputs)
 Create a muq::Modeling::WorkPiece with either a fixed number of inputs with specified types or a fixed number of outputs with specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &types, WorkPiece::Fix const fix=WorkPiece::Fix::Inputs)
 Create a muq::Modeling::WorkPiece where either some of the inputs have specified types or some of the outputs have specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &types, int const num, WorkPiece::Fix const fixTypes=WorkPiece::Fix::Inputs, WorkPiece::Fix const fixNum=WorkPiece::Fix::Inputs)
 Create a muq::Modeling::WorkPiece where either some of the inputs have specified types or some of the outputs have specified types and either the number of inputs or the number of outputs is fixed. More...
 
 WorkPiece (std::vector< std::string > const &types, int const num)
 Create a muq::Modeling::WorkPiece with a fixed number of inputs with specified types and a fixed number of outputs (of uknown type) More...
 
 WorkPiece (int const num, std::vector< std::string > const &types)
 Create a muq::Modeling::WorkPiece with a fixed number of outputs with specified types and a fixed number of inputs (of uknown type) More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, int const numIns, int const numOuts)
 Create a muq::Modeling::WorkPiece where some of the inputs are known and we know the input and output numbers. More...
 
 WorkPiece (int const numIns, std::map< unsigned int, std::string > const &outTypes, int const numOuts)
 Create a muq::Modeling::WorkPiece where some of the outputs are known and we know the input and output numbers. More...
 
 WorkPiece (std::vector< std::string > const &inTypes, std::vector< std::string > const &outTypes)
 Create a muq::Modeling::WorkPiece with a fixed number of inputs and outputs with specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, std::vector< std::string > const &outTypes)
 Create a muq::Modeling::WorkPiece where some of the inputs are known and all of the outputs have specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, int const num, std::vector< std::string > const &outTypes)
 Create a muq::Modeling::WorkPiece where some of the inputs are known with a known number of inputs and all of the outputs have specified types. More...
 
 WorkPiece (std::vector< std::string > const &inTypes, std::map< unsigned int, std::string > const &outTypes)
 Create a muq::Modeling::WorkPiece where some of the outputs and all of the inputs have specified types. More...
 
 WorkPiece (std::vector< std::string > const &inTypes, std::map< unsigned int, std::string > const &outTypes, int const num)
 Create a muq::Modeling::WorkPiece where some of the outputs with a known number of outputs and all of the inputs have specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, std::map< unsigned int, std::string > const &outTypes)
 Create a muq::Mdoeling::WorkPiece where some of the inputs and some of the outputs have specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, int const numIn, std::map< unsigned int, std::string > const &outTypes)
 Create a muq::Mdoeling::WorkPiece where some of the inputs and some of the outputs have specified types with a fixed number of inputs. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, std::map< unsigned int, std::string > const &outTypes, int const numOut)
 Create a muq::Mdoeling::WorkPiece where some of the inputs and some of the outputs have specified types with a fixed number of outputs. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, int const numIn, std::map< unsigned int, std::string > const &outTypes, int const numOut)
 Create a muq::Mdoeling::WorkPiece where some of the inputs and some of the outputs have specified types with a fixed number of inputs and outputs. More...
 
virtual ~WorkPiece ()
 Default destructor. More...
 
std::vector< boost::any > const & Evaluate (std::vector< boost::any > const &ins)
 Evaluate this muq::Modeling::WorkPiece. More...
 
std::vector< boost::any > const & Evaluate (ref_vector< boost::any > const &ins)
 Evaluate this muq::Modeling::WorkPiece using references to the inputs. More...
 
std::vector< boost::any > const & Evaluate ()
 Evaluate this muq::Modeling::WorkPiece in the case that there are no inputs. More...
 
template<typename... Args>
std::vector< boost::any > const & Evaluate (Args... args)
 Evalaute this muq::Modeling::WorkPiece using multiple arguments. More...
 
std::string const & Name ()
 Get the (unique) name of this work piece. More...
 
void SetName (std::string const &newName)
 Set the name of this work piece. More...
 
std::string InputType (unsigned int inputNum, bool const demangle=true) const
 Get the input type (if we know it) for a specific input. More...
 
int InputSize (unsigned int inputNum) const
 Get the length of a vector valued input with fixed size. More...
 
void SetInputSize (unsigned int inputNum, int newSize)
 
std::string OutputType (unsigned int outputNum, bool const demangle=true) const
 Get the output type (if we know it) for a specific output. More...
 
std::map< unsigned int, std::string > OutputTypes () const
 Get the output types. More...
 
std::map< unsigned int, std::string > InputTypes () const
 Get the input types. More...
 
unsigned int ID () const
 Get the unique ID number. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from muq::Modeling::WorkPiece
static ref_vector< const boost::any > ToRefVector (std::vector< boost::any > const &anyVec)
 Create vector of references from a vector of boost::any's. More...
 
static ref_vector< const Eigen::VectorXd > ToRefVector (std::vector< Eigen::VectorXd > const &anyVec)
 
- Public Attributes inherited from muq::Modeling::ModPiece
const Eigen::VectorXi inputSizes
 
const Eigen::VectorXi outputSizes
 
- Public Attributes inherited from muq::Modeling::WorkPiece
int numInputs
 The number of inputs. More...
 
int numOutputs
 The number of outputs. More...
 

Constructor & Destructor Documentation

◆ ModGraphPiece()

ModGraphPiece::ModGraphPiece ( std::shared_ptr< WorkGraph graph,
std::vector< std::shared_ptr< ConstantVector > > const &  constantPieces,
std::vector< std::string > const &  inputNames,
std::shared_ptr< ModPiece outputNode 
)

Construct a muq::Modeling::ModGraphPiece.

Typically muq::Modeling::ModGraphPiece's are constructed by calling muq::Modeling::WorkGraph::CreateModPiece

Parameters
[in]graphFrom inputs to the output-of-interest
[in]constantPiecesPointers to the muq::Modeling::ConstantVector's that hold the graph's inputs
[in]inputNamesThe names of each node in the graph corresponding to the constantPieces
[in]outputNodeThe muq::Modeling::ModPiece that we ultimately want to evaluate

Definition at line 20 of file ModGraphPiece.cpp.

References adjointRunOrders, filtered_graphs, muq::Modeling::ModPiece::inputSizes, muq::Modeling::WorkPiece::numInputs, runOrder, nlohmann::detail::dtoa_impl::v, and wgraph.

◆ ~ModGraphPiece()

virtual muq::Modeling::ModGraphPiece::~ModGraphPiece ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ ApplyHessianImpl()

void ModGraphPiece::ApplyHessianImpl ( unsigned int const  outWrt,
unsigned int const  inWrt1,
unsigned int const  inWrt2,
ref_vector< Eigen::VectorXd > const &  input,
Eigen::VectorXd const &  sens,
Eigen::VectorXd const &  vec 
)
overrideprivatevirtual

Reimplemented from muq::Modeling::ModPiece.

Definition at line 477 of file ModGraphPiece.cpp.

References GradientGraph(), muq::Modeling::ModPiece::hessAction, and hessianPieces.

◆ ApplyJacobianImpl()

void ModGraphPiece::ApplyJacobianImpl ( unsigned int const  outputDimWrt,
unsigned int const  inputDimWrt,
ref_vector< Eigen::VectorXd > const &  input,
Eigen::VectorXd const &  vec 
)
overrideprivatevirtual

Compute the action of the Jacobian for this muq::Modeling::WorkGraphPiece using the chain rule.

Parameters
[in]wrtInWe are taking the Jacobian with respect to this input
[in]wrtOutWe are taking the Jacobian of this output
[in]vecWe are applying the Jacobian to this object
[in]inputsInputs to the muq::Modeling::WorkGraphPiece

Reimplemented from muq::Modeling::ModPiece.

Definition at line 498 of file ModGraphPiece.cpp.

References muq::Modeling::ModPiece::jacobianAction, JacobianGraph(), and jacobianPieces.

◆ ConstructInputSizes()

Eigen::VectorXi ModGraphPiece::ConstructInputSizes ( std::vector< std::shared_ptr< ConstantVector > > const &  constantPiecesIn)
staticprivate

Definition at line 467 of file ModGraphPiece.cpp.

◆ EvaluateImpl()

void ModGraphPiece::EvaluateImpl ( ref_vector< Eigen::VectorXd > const &  inputs)
overrideprivatevirtual

Evaluate each muq::Modeling::WorkPiece in the graph.

Parameters
[in]inputsInputs to the muq::Modeling::WorkGraphPiece

Implements muq::Modeling::ModPiece.

Definition at line 516 of file ModGraphPiece.cpp.

References FillOutputMap(), outputID, muq::Modeling::ModPiece::outputs, SetInputs(), and valMap.

◆ FillOutputMap()

void ModGraphPiece::FillOutputMap ( )
private

Fill the map from each node's muq::Modeling::WorkPiece::ID to its outputs.

Definition at line 772 of file ModGraphPiece.cpp.

References GetNodeInputs(), runOrder, muq::Modeling::WorkPiece::ToRefVector(), valMap, and wgraph.

Referenced by EvaluateImpl(), and JacobianImpl().

◆ GetConstantPieces()

std::vector<std::shared_ptr<ConstantVector> > muq::Modeling::ModGraphPiece::GetConstantPieces ( )
inline

Definition at line 44 of file ModGraphPiece.h.

References constantPieces.

◆ GetGraph()

std::shared_ptr<WorkGraph> muq::Modeling::ModGraphPiece::GetGraph ( )
inline

Definition at line 42 of file ModGraphPiece.h.

References wgraph.

◆ GetInputIndex()

int ModGraphPiece::GetInputIndex ( std::shared_ptr< WorkPiece > const &  piece) const
private

Returns the input index of this ModGraphPiece that corresponds to the the specified placeholder ModPiece. If the ModPiece is not an input, than -1 is returned.

Definition at line 59 of file ModGraphPiece.cpp.

References constantPieces.

Referenced by GradientGraph(), and JacobianGraph().

◆ GetNodeInputs()

ref_vector< Eigen::VectorXd > ModGraphPiece::GetNodeInputs ( boost::graph_traits< Graph >::vertex_descriptor  node) const
private

Get the inputs from muq::Modeling::WorkGraphPiece::valMap to a specified node in the graph.

Parameters
[in]idThe ID of the node of interest
Returns
A reference vector of inputs to that node

Definition at line 809 of file ModGraphPiece.cpp.

References InputNodes(), valMap, and wgraph.

Referenced by FillOutputMap(), and JacobianImpl().

◆ GetOutputName()

std::string muq::Modeling::ModGraphPiece::GetOutputName ( ) const
inline

Returns the name of the output node in the graph.

Definition at line 94 of file ModGraphPiece.h.

References outputPiece, and wgraph.

◆ GetOutputPiece()

std::shared_ptr<ModPiece> muq::Modeling::ModGraphPiece::GetOutputPiece ( ) const
inline

Returns the output ModPiece.

Definition at line 97 of file ModGraphPiece.h.

References outputPiece.

◆ GetSubModel()

std::shared_ptr< ModGraphPiece > ModGraphPiece::GetSubModel ( std::string const &  nodeName) const

Returns another ModGraphPiece containing only part of the graph making up this model.

Consider the graph for a posterior density. You might have 5 nodes in the graph: "Parameters", "Prior", "Likelihood", "Forward Model", and "Posterior". This function returns a model using only a subset of these nodes. For example, calling GetSubModel with the node name "Likelihood" will return a new ModGraphPiece containing three nodes: "Parameters", "Forward Model", and "Likelihood". The resulting model will only evaluate the likelihood.

Parameters
[in]nodeNameThe name of a node in the graph that will serve as the new "output" node.
Returns
A ModGraphPiece with the "nodeName" node as output.

Definition at line 885 of file ModGraphPiece.cpp.

References constantPieces, and wgraph.

◆ GradientGraph()

std::shared_ptr< ModGraphPiece > ModGraphPiece::GradientGraph ( unsigned int const  outputDimWrt,
unsigned int const  inputDimWrt 
)

Returns a ModGraphPiece that, when evaluated, returns the gradient of this ModPiece. Note that the returned ModPiece will have an additional input for the sensitivity vector used in the Gradient call.

Definition at line 69 of file ModGraphPiece.cpp.

References muq::Modeling::WorkGraph::AddEdge(), muq::Modeling::WorkGraph::AddNode(), adjointRunOrders, constantPieces, muq::Modeling::WorkGraph::CreateModPiece(), nlohmann::detail::dtoa_impl::e, filtered_graphs, GetInputIndex(), muq::Modeling::WorkGraph::graph, muq::Modeling::ModPiece::inputSizes, muq::Modeling::ModPiece::outputSizes, runOrder, and wgraph.

Referenced by ApplyHessianImpl(), and GradientImpl().

◆ GradientImpl()

void ModGraphPiece::GradientImpl ( unsigned int const  outputDimWrt,
unsigned int const  inputDimWrt,
ref_vector< Eigen::VectorXd > const &  input,
Eigen::VectorXd const &  sensitivity 
)
overrideprivatevirtual

Compute the action of the Jacobian transpose for this muq::Modeling::WorkGraphPiece using the chain rule.

Parameters
[in]wrtInWe are taking the Jacobian with respect to this input
[in]wrtOutWe are taking the Jacobian of this output
[in]vecWe are applying the Jacobian transpose to this object
[in]inputsInputs to the muq::Modeling::WorkGraphPiece

Reimplemented from muq::Modeling::ModPiece.

Definition at line 531 of file ModGraphPiece.cpp.

References muq::Modeling::ModPiece::gradient, GradientGraph(), and gradientPieces.

◆ InputNodes()

std::map< unsigned int, std::vector< std::pair< unsigned int, unsigned int > > > ModGraphPiece::InputNodes ( boost::graph_traits< Graph >::vertex_descriptor const &  node) const
private

Get a the input nodes for a node.

Parameters
[in]nodeWe want the input nodes for this node
Returns
A map from the input node's ID to the input/output number

Definition at line 745 of file ModGraphPiece.cpp.

References nlohmann::detail::dtoa_impl::e, muq::Modeling::WorkPiece::id, and wgraph.

Referenced by GetNodeInputs().

◆ JacobianGraph()

std::shared_ptr< ModGraphPiece > ModGraphPiece::JacobianGraph ( unsigned int const  outputDimWrt,
unsigned int const  inputDimWrt 
)

Returns a ModGraphPiece that, when evaluated, returns the action of the Jacobian of this ModPiece on a vector. Note that the returned ModPiece will have an additional input for the vector that we want to apply the Jacobian to.

If the node has multiple inputs, than we have to sum the Jacobians for each of them. Here, we add a SumPiece if necessary, and store the name of the node returning the cumulative Jacobian action.

Definition at line 288 of file ModGraphPiece.cpp.

References muq::Modeling::WorkGraph::AddEdge(), muq::Modeling::WorkGraph::AddNode(), adjointRunOrders, constantPieces, muq::Modeling::WorkGraph::CreateModPiece(), nlohmann::detail::dtoa_impl::e, filtered_graphs, GetInputIndex(), muq::Modeling::WorkGraph::graph, muq::Modeling::WorkGraph::HasNode(), muq::Modeling::ModPiece::inputSizes, muq::Modeling::WorkPiece::name, muq::Modeling::ModPiece::outputSizes, runOrder, and wgraph.

Referenced by ApplyJacobianImpl().

◆ JacobianImpl()

void ModGraphPiece::JacobianImpl ( unsigned int const  outputDimWrt,
unsigned int const  inputDimWrt,
ref_vector< Eigen::VectorXd > const &  input 
)
overrideprivatevirtual

Compute the Jacobian for this muq::Modeling::WorkGraphPiece using the chain rule.

Parameters
[in]wrtInWe are taking the Jacobian with respect to this input
[in]wrtOutWe are taking the Jacobian of this output
[in]inputsInputs to the muq::Modeling::WorkGraphPiece

Reimplemented from muq::Modeling::ModPiece.

Definition at line 550 of file ModGraphPiece.cpp.

References adjointRunOrders, FillOutputMap(), filtered_graphs, GetNodeInputs(), muq::Modeling::ModPiece::inputSizes, muq::Modeling::ModPiece::jacobian, outputID, RequiredInputs(), RequiredOutputs(), and SetInputs().

◆ MatchInputs()

std::vector< int > ModGraphPiece::MatchInputs ( std::shared_ptr< ModGraphPiece otherPiece) const

Matches inputs with another ModGraphPiece by looking at node names and edges.

Assume this ModGraphPiece has three inputs call \(x_1\), \(x_2\), and \(y\), where \(x_i\) denotes the \(i^{th}\) input of a node \(x\). Let there be another ModGraphPiece with inputs \(x_2\), \(y\), and \(z\). This function tries to match the inputs between the two ModGraphPieces by looking at the node names and input indices. It returns the input indices of *this that correspond to the inputs of the other piece, with the value "-1" reserved for nonoverlapping inputs. For the example above, the result would be \([1,2,-1]\).

@params[in] otherPiece The other ModGraphPiece that we want to match with the inputs to this piece.

Returns
A std::vector containing indices into the inputs of this ModGraphPiece that correspond with the inputs of the otherPiece. The length of this vector is equal to the number of inputs of otherPiece.

Definition at line 896 of file ModGraphPiece.cpp.

References constantPieces, muq::Modeling::ModPiece::outputs, and wgraph.

◆ RequiredInputs()

std::vector< std::tuple< unsigned int, unsigned int, unsigned int > > ModGraphPiece::RequiredInputs ( boost::graph_traits< FilteredGraph >::vertex_descriptor const &  node,
unsigned int const  wrtIn 
) const
private

Get the required inputs for a node in one of the filtered graphs.

Parameters
[in]nodeWe want the inputs of this node
[in]wrtInThe input whose downstream nodes we care about
Returns
The input nodes — tuple: the input WorkPiece ID, the output number, and the input number

Definition at line 863 of file ModGraphPiece.cpp.

References filtered_graphs, muq::Modeling::WorkPiece::ID(), and wgraph.

Referenced by JacobianImpl().

◆ RequiredOutputs()

std::vector< std::tuple< unsigned int, unsigned int, unsigned int > > ModGraphPiece::RequiredOutputs ( boost::graph_traits< FilteredGraph >::vertex_descriptor const &  node,
unsigned int const  wrtIn,
unsigned int  wrtOut 
) const
private

Get the required outputs for a node in one of the filtered graphs.

Parameters
[in]nodeWe want the outputs of this node
[in]wrtInThe input whose downstream nodes we care about
[in]wrtOutThe output we are ultimately trying to differentiate wrt
Returns
The output nodes — tuple: the output WorkPiece ID, the output number, and the input number

Definition at line 831 of file ModGraphPiece.cpp.

References filtered_graphs, muq::Modeling::WorkPiece::ID(), outputID, and wgraph.

Referenced by JacobianImpl().

◆ SetInputs()

void ModGraphPiece::SetInputs ( ref_vector< Eigen::VectorXd > const &  inputs)
private

Set the inputs.

Set the inputs in each the muq::Modeling::ConstantPiece.

Definition at line 737 of file ModGraphPiece.cpp.

References constantPieces.

Referenced by EvaluateImpl(), and JacobianImpl().

Member Data Documentation

◆ adjointRunOrders

std::vector<std::deque<boost::graph_traits<Graph>::vertex_descriptor> > muq::Modeling::ModGraphPiece::adjointRunOrders
private

Like muq::Modeling::WorkGraphPiece::runOrder, but specific to which input node is used (also in output->input order)

Definition at line 212 of file ModGraphPiece.h.

Referenced by GradientGraph(), JacobianGraph(), JacobianImpl(), and ModGraphPiece().

◆ constantPieces

std::vector<std::shared_ptr<ConstantVector> > muq::Modeling::ModGraphPiece::constantPieces
private

◆ filtered_graphs

std::vector<std::shared_ptr<FilteredGraph> > muq::Modeling::ModGraphPiece::filtered_graphs
private

◆ gradientPieces

std::map<std::pair<unsigned int, unsigned int>, std::shared_ptr<ModGraphPiece> > muq::Modeling::ModGraphPiece::gradientPieces
private

Definition at line 104 of file ModGraphPiece.h.

Referenced by GradientImpl().

◆ hessianPieces

std::map<std::tuple<unsigned int, unsigned int, unsigned int>, std::shared_ptr<ModGraphPiece> > muq::Modeling::ModGraphPiece::hessianPieces
private

Definition at line 106 of file ModGraphPiece.h.

Referenced by ApplyHessianImpl().

◆ jacobianPieces

std::map<std::pair<unsigned int, unsigned int>, std::shared_ptr<ModGraphPiece> > muq::Modeling::ModGraphPiece::jacobianPieces
private

Definition at line 105 of file ModGraphPiece.h.

Referenced by ApplyJacobianImpl().

◆ outputID

unsigned int muq::Modeling::ModGraphPiece::outputID
private

The ID of the WorkPiece corresponding to the output node.

Definition at line 223 of file ModGraphPiece.h.

Referenced by EvaluateImpl(), JacobianImpl(), and RequiredOutputs().

◆ outputPiece

std::shared_ptr<ModPiece> muq::Modeling::ModGraphPiece::outputPiece
private

Definition at line 225 of file ModGraphPiece.h.

Referenced by GetOutputName(), and GetOutputPiece().

◆ runOrder

std::deque<boost::graph_traits<Graph>::vertex_descriptor> muq::Modeling::ModGraphPiece::runOrder
private

Run order computed during construction (input->output order)

Definition at line 206 of file ModGraphPiece.h.

Referenced by FillOutputMap(), GradientGraph(), JacobianGraph(), and ModGraphPiece().

◆ valMap

std::unordered_map<unsigned int, ref_vector<Eigen::VectorXd> > muq::Modeling::ModGraphPiece::valMap
private

A the map from each node's muq::Modeling::WorkPiece::ID to its outputs.

Definition at line 220 of file ModGraphPiece.h.

Referenced by EvaluateImpl(), FillOutputMap(), and GetNodeInputs().

◆ wgraph

std::shared_ptr<WorkGraph> muq::Modeling::ModGraphPiece::wgraph
private

The documentation for this class was generated from the following files: