A graph of connected muq::Modeling::WorkPiece's. More...
#include <WorkGraph.h>
A graph of connected muq::Modeling::WorkPiece's.
Definition at line 20 of file WorkGraph.h.
Public Member Functions | |
WorkGraph () | |
virtual | ~WorkGraph () |
virtual std::shared_ptr< WorkGraph > | Clone () const |
unsigned int | NumNodes () const |
Get the number of nodes in the graph. More... | |
unsigned int | NumEdges () const |
Get the number of edgess in the graph. More... | |
void | AddNode (std::shared_ptr< WorkPiece > input, std::string const &name) |
Add a new node to the graph. More... | |
void | RemoveNode (std::string const &name) |
void | AddEdge (std::string const &nameFrom, unsigned int const outputDim, std::string const &nameTo, unsigned int const inputDim) |
Add a new edge to the graph. More... | |
bool | HasNode (std::string const &name) const |
Is the given node in the graph? More... | |
std::vector< std::pair< int, int > > | GetEdges (std::string const &srcName, std::string const &tgtName) |
Returns all edges going from node name1 to node name2. More... | |
void | Visualize (std::string const &filename) const |
Visualize the graph. More... | |
std::vector< std::string > | GetParents (std::string const &name) const |
std::string | GetParent (std::string const &name, int inputIndex) const |
std::vector< std::string > | GetChildren (std::string const &name) const |
std::shared_ptr< WorkGraph > | DependentCut (std::string const &nameOut) const |
Create a new graph cutting any of the nodes that do not affect the output node. More... | |
std::shared_ptr< WorkGraphPiece > | CreateWorkPiece (std::string const &node) const |
Create a muq::Modeling::WorkPiece whose output matches a given node. More... | |
std::shared_ptr< ModGraphPiece > | CreateModPiece (std::string const &node, std::vector< std::string > const &inNames=std::vector< std::string >()) const |
Create a muq::Modeling::ModPiece whose output matches a given node. More... | |
bool | Constant (std::string const &node) const |
Check to see if a node is constant? More... | |
std::vector< boost::any > const & | GetConstantOutputs (std::string const &node) const |
Get the output values for a constant node. More... | |
std::shared_ptr< WorkPiece > | GetPiece (std::string const &name) |
std::string | GetName (std::shared_ptr< WorkPiece > piece) const |
void | Print (std::ostream &fout=std::cout) const |
std::vector< std::pair< std::string, int > > | GetInputNames () const |
Find the inputs to the graph. More... | |
std::vector< std::pair< std::string, int > > | GetOutputNames () const |
Find the outputs to the graph. More... | |
void | BindNode (std::string const &nodeName, std::vector< boost::any > const &x) |
void | BindEdge (std::string const &nodeName, unsigned int inputDim, boost::any const &x) |
Friends | |
class | WorkGraphPiece |
class | ModGraphPiece |
WorkGraph::WorkGraph | ( | ) |
Definition at line 50 of file WorkGraph.cpp.
|
virtual |
Definition at line 52 of file WorkGraph.cpp.
void WorkGraph::AddEdge | ( | std::string const & | nameFrom, |
unsigned int const | outputDim, | ||
std::string const & | nameTo, | ||
unsigned int const | inputDim | ||
) |
Add a new edge to the graph.
[in] | nameFrom | The name of the upstream node. |
[in] | outputDim | The output dimension of "nameFrom" that will be given to "nameTo" |
[in] | nameTo | The name of the downstream node. |
[in] | inputDim | The input dimension of "nameTo" that will be given the output of "nameFrom" |
Definition at line 206 of file WorkGraph.cpp.
References GetNodeIterator(), graph, and nlohmann::to_string().
Referenced by BindEdge(), muq::SamplingAlgorithms::DILIKernel::CreateLikelihood(), muq::Modeling::ModGraphPiece::GradientGraph(), muq::Modeling::ModGraphPiece::JacobianGraph(), and main().
void WorkGraph::AddNode | ( | std::shared_ptr< WorkPiece > | input, |
std::string const & | name | ||
) |
Add a new node to the graph.
[in] | input | A pointer to a muq::Modelling::Core::WorkPiece that will be called when this node is evaluated. |
[in] | name | A string representing a unique name for this node. |
Definition at line 195 of file WorkGraph.cpp.
References graph, and HasNode().
Referenced by BindEdge(), muq::SamplingAlgorithms::DILIKernel::CreateLikelihood(), muq::Modeling::ModGraphPiece::GradientGraph(), muq::Modeling::ModGraphPiece::JacobianGraph(), and main().
void WorkGraph::BindEdge | ( | std::string const & | nodeName, |
unsigned int | inputDim, | ||
boost::any const & | x | ||
) |
Like BindNode, but only for an edge. This function actually creates a new node in the system and fixes the value of that node. The new node name is constructed using
As a naming example, if nodeName is "x" and inputDim is 2, this function will create a new node with name "x_FixedInput2"
[in] | nodeName | The name of the existing node whose input we wish to set |
[in] | inputDim | The input of "nodeName" to fix |
[in] | x | The value the input should be set to |
Definition at line 777 of file WorkGraph.cpp.
References AddEdge(), AddNode(), nlohmann::detail::dtoa_impl::e, GetNodeIterator(), graph, and nlohmann::to_string().
void WorkGraph::BindNode | ( | std::string const & | nodeName, |
std::vector< boost::any > const & | x | ||
) |
Fix the value of a particular node to a constant value and remove any input edges from that node. After binding a node or edge, if DependentCut is called, any group of constant nodes will be grouped into a single node. This is a useful feature when offline computations are required for a model.
[in] | nodeName | The node to bind |
[in] | x | The value that "nodeName" will be fixed at. Note that x must be the same size of the existing output of "nodeName" |
Definition at line 754 of file WorkGraph.cpp.
References GetNodeIterator(), and graph.
|
virtual |
Definition at line 54 of file WorkGraph.cpp.
References graph.
|
private |
Check to see if a node is constant?
A constant node is nonrandom, has no random dependencies, and either has no inputs or all of its inputs are given by const ant upstream nodes
[in] | node | We want to know if this node is constant. |
Definition at line 1006 of file WorkGraph.cpp.
References Constant(), nlohmann::detail::dtoa_impl::e, and graph.
bool WorkGraph::Constant | ( | std::string const & | node | ) | const |
Check to see if a node is constant?
A constant node is nonrandom, has no random dependencies, and either has no inputs or all of its inputs are given by const ant upstream nodes
[in] | node | The name of the node |
Definition at line 1002 of file WorkGraph.cpp.
References GetNodeIterator().
Referenced by Constant(), DependentCut(), GetConstantOutputs(), and RecursiveCut().
std::shared_ptr< ModGraphPiece > WorkGraph::CreateModPiece | ( | std::string const & | node, |
std::vector< std::string > const & | inNames = std::vector<std::string>() |
||
) | const |
Create a muq::Modeling::ModPiece whose output matches a given node.
[in] | node | The name of the output node |
[in] | inNames | The name (and order) of the input nodes—defaults to the order of the graph |
Definition at line 591 of file WorkGraph.cpp.
References DependentCut(), nlohmann::detail::dtoa_impl::e, graph, and HasNode().
Referenced by muq::SamplingAlgorithms::DILIKernel::CreateLikelihood(), muq::Modeling::ModGraphPiece::GradientGraph(), muq::Modeling::ModGraphPiece::JacobianGraph(), and main().
std::shared_ptr< WorkGraphPiece > WorkGraph::CreateWorkPiece | ( | std::string const & | node | ) | const |
Create a muq::Modeling::WorkPiece whose output matches a given node.
[in] | node | The name of the output node |
Definition at line 523 of file WorkGraph.cpp.
References DependentCut(), and HasNode().
std::shared_ptr< WorkGraph > WorkGraph::DependentCut | ( | std::string const & | nameOut | ) | const |
Create a new graph cutting any of the nodes that do not affect the output node.
[in] | nameOut | The output node we care about |
Definition at line 477 of file WorkGraph.cpp.
References Constant(), GetConstantOutputs(), GetNodeIterator(), graph, and RecursiveCut().
Referenced by CreateModPiece(), and CreateWorkPiece().
std::vector< std::string > WorkGraph::GetChildren | ( | std::string const & | name | ) | const |
Returns a list of the downstream nodes.
Definition at line 137 of file WorkGraph.cpp.
References nlohmann::detail::dtoa_impl::e, GetNodeIterator(), graph, and nlohmann::detail::dtoa_impl::v.
|
private |
Get the output values for a constant node.
[out] | outs | The output values for the node (returned by reference) |
[in] | node | We want the output values of this node |
Definition at line 943 of file WorkGraph.cpp.
References Constant(), nlohmann::detail::dtoa_impl::e, GetConstantOutputs(), and graph.
std::vector< boost::any > const & WorkGraph::GetConstantOutputs | ( | std::string const & | node | ) | const |
Get the output values for a constant node.
[out] | outs | The output values for the node (returned by reference) |
[in] | node | The name of the node |
Definition at line 936 of file WorkGraph.cpp.
References Constant(), and GetNodeIterator().
Referenced by DependentCut(), GetConstantOutputs(), and RecursiveCut().
std::vector< std::pair< int, int > > WorkGraph::GetEdges | ( | std::string const & | srcName, |
std::string const & | tgtName | ||
) |
Returns all edges going from node name1 to node name2.
[in] | srcName | The name of the source node |
[in] | tgtName | The name of the target node |
Definition at line 69 of file WorkGraph.cpp.
References nlohmann::detail::dtoa_impl::e, GetNodeIterator(), and graph.
std::vector< std::pair< std::string, int > > WorkGraph::GetInputNames | ( | ) | const |
Find the inputs to the graph.
Definition at line 153 of file WorkGraph.cpp.
References graph, and GraphInputs().
std::string WorkGraph::GetName | ( | std::shared_ptr< WorkPiece > | piece | ) | const |
Given a WorkPiece, return the name of the node containing that piece.
Definition at line 749 of file WorkGraph.cpp.
References GetNodeIterator(), and graph.
|
private |
Definition at line 269 of file WorkGraph.cpp.
References graph, and nlohmann::detail::dtoa_impl::v.
|
private |
Get a vertex_iterator to the node with name "name".
[in] | name | The name of a node in the graph |
Definition at line 258 of file WorkGraph.cpp.
References graph, and nlohmann::detail::dtoa_impl::v.
Referenced by AddEdge(), BindEdge(), BindNode(), Constant(), DependentCut(), GetChildren(), GetConstantOutputs(), GetEdges(), GetName(), GetParent(), GetParents(), GetPiece(), HasNode(), and RemoveNode().
std::vector< std::pair< std::string, int > > WorkGraph::GetOutputNames | ( | ) | const |
Find the outputs to the graph.
Definition at line 164 of file WorkGraph.cpp.
References graph, and GraphOutputs().
std::string WorkGraph::GetParent | ( | std::string const & | name, |
int | inputIndex | ||
) | const |
Get the upstream node with an edge that comes input input inputIndex.
Definition at line 120 of file WorkGraph.cpp.
References nlohmann::detail::dtoa_impl::e, GetNodeIterator(), graph, and nlohmann::detail::dtoa_impl::v.
std::vector< std::string > WorkGraph::GetParents | ( | std::string const & | name | ) | const |
Returns a list of the upstream nodes.
Definition at line 98 of file WorkGraph.cpp.
References nlohmann::detail::dtoa_impl::e, GetNodeIterator(), graph, and nlohmann::detail::dtoa_impl::v.
|
private |
Definition at line 736 of file WorkGraph.cpp.
References graph.
std::shared_ptr< WorkPiece > WorkGraph::GetPiece | ( | std::string const & | name | ) |
Returns the work piece at a particular node in the graph.
Definition at line 720 of file WorkGraph.cpp.
References GetNodeIterator(), graph, and nlohmann::detail::dtoa_impl::v.
|
private |
Find the inputs to the graph.
Definition at line 335 of file WorkGraph.cpp.
References nlohmann::detail::dtoa_impl::e, graph, and nlohmann::detail::dtoa_impl::v.
Referenced by GetInputNames(), and Visualize().
|
private |
Find the outputs to the graph.
Definition at line 282 of file WorkGraph.cpp.
References nlohmann::detail::dtoa_impl::e, graph, and nlohmann::detail::dtoa_impl::v.
Referenced by GetOutputNames(), and Visualize().
|
private |
Is there an edge between two vertices?
[in] | vOut | The node whose output is going to vIn |
[in] | vIn | The node whose is recieving output from vOut |
[in] | inputDim | The dimension of the vIn that the output is going to |
Definition at line 388 of file WorkGraph.cpp.
References graph.
|
private |
Is the given node in the graph?
[out] | iter | If the node exists, this is an iterator to it. If the node does not exist, this is the end iterator |
[in] | name | The name of the node |
Definition at line 186 of file WorkGraph.cpp.
References GetNodeIterator(), and graph.
bool WorkGraph::HasNode | ( | std::string const & | name | ) | const |
Is the given node in the graph?
[in] | name | The name of the node |
Definition at line 177 of file WorkGraph.cpp.
Referenced by AddNode(), CreateModPiece(), CreateWorkPiece(), and muq::Modeling::ModGraphPiece::JacobianGraph().
unsigned int WorkGraph::NumEdges | ( | ) | const |
Get the number of edgess in the graph.
Definition at line 92 of file WorkGraph.cpp.
References graph.
unsigned int WorkGraph::NumNodes | ( | ) | const |
Get the number of nodes in the graph.
Definition at line 86 of file WorkGraph.cpp.
References graph.
void WorkGraph::Print | ( | std::ostream & | fout = std::cout | ) | const |
Print the nodes and edges of this graph to std::cout.
Definition at line 697 of file WorkGraph.cpp.
References nlohmann::detail::dtoa_impl::e, graph, and nlohmann::detail::dtoa_impl::v.
|
private |
Recursively go upstream from a node, copying nodes.
Copies the upstream nodes into a new graph. If a node is constant it evaluates it and lumps all of the upstream nodes from that node into a muq::Modeling::ConstantParameters
[in] | vOld | The old vertex, where we beging copying from |
[in] | vNew | The new vertex, a copy of the old one on the new graph |
[in,out] | newGraph | All of the (nonconstant) upstreams nodes from vOld will be copied are copied to this new graph |
Definition at line 402 of file WorkGraph.cpp.
References Constant(), nlohmann::detail::dtoa_impl::e, GetConstantOutputs(), graph, and nlohmann::detail::dtoa_impl::v.
Referenced by DependentCut().
void WorkGraph::RemoveNode | ( | std::string const & | name | ) |
Definition at line 61 of file WorkGraph.cpp.
References GetNodeIterator(), and graph.
void WorkGraph::Visualize | ( | std::string const & | filename | ) | const |
Visualize the graph.
[in] | filename | The name of the file where the graph visualization is to be stored |
Definition at line 857 of file WorkGraph.cpp.
References graph, GraphInputs(), GraphOutputs(), and nlohmann::detail::dtoa_impl::v.
|
friend |
Definition at line 23 of file WorkGraph.h.
|
friend |
Definition at line 22 of file WorkGraph.h.
|
private |
The directed graph that represents this muq::Modeling::Core::WorkGraph.
Definition at line 245 of file WorkGraph.h.
Referenced by AddEdge(), AddNode(), BindEdge(), BindNode(), Clone(), Constant(), CreateModPiece(), DependentCut(), GetChildren(), GetConstantOutputs(), GetEdges(), GetInputNames(), GetName(), GetNodeIterator(), GetOutputNames(), GetParent(), GetParents(), GetPiece(), muq::Modeling::ModGraphPiece::GradientGraph(), GraphInputs(), GraphOutputs(), HasEdge(), HasNode(), muq::Modeling::ModGraphPiece::JacobianGraph(), NumEdges(), NumNodes(), Print(), RecursiveCut(), RemoveNode(), and Visualize().