html for all graphs
							parent
							
								
									918b037dde
								
							
						
					
					
						commit
						3ea5aed26e
					
				|  | @ -61,16 +61,29 @@ namespace gtsam { | |||
|     return result; | ||||
|   } | ||||
| 
 | ||||
|   /* ************************************************************************* */ | ||||
|   /* *********************************************************************** */ | ||||
|   std::string DiscreteBayesNet::markdown( | ||||
|       const KeyFormatter& keyFormatter, | ||||
|       const DiscreteFactor::Names& names) const { | ||||
|     using std::endl; | ||||
|     std::stringstream ss; | ||||
|     ss << "`DiscreteBayesNet` of size " << size() << endl << endl; | ||||
|     for(const DiscreteConditional::shared_ptr& conditional: *this) | ||||
|     for (const DiscreteConditional::shared_ptr& conditional : *this) | ||||
|       ss << conditional->markdown(keyFormatter, names) << endl; | ||||
|     return ss.str(); | ||||
|   } | ||||
| 
 | ||||
|   /* *********************************************************************** */ | ||||
|   std::string DiscreteBayesNet::html( | ||||
|       const KeyFormatter& keyFormatter, | ||||
|       const DiscreteFactor::Names& names) const { | ||||
|     using std::endl; | ||||
|     std::stringstream ss; | ||||
|     ss << "<div><p><tt>DiscreteBayesNet</tt> of size " << size() << "</p>"; | ||||
|     for (const DiscreteConditional::shared_ptr& conditional : *this) | ||||
|       ss << conditional->html(keyFormatter, names) << endl; | ||||
|     return ss.str(); | ||||
|   } | ||||
| 
 | ||||
| /* ************************************************************************* */ | ||||
| } // namespace
 | ||||
|  |  | |||
|  | @ -18,13 +18,16 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <vector> | ||||
| #include <map> | ||||
| #include <boost/shared_ptr.hpp> | ||||
| #include <gtsam/discrete/DiscreteConditional.h> | ||||
| #include <gtsam/discrete/DiscretePrior.h> | ||||
| #include <gtsam/inference/BayesNet.h> | ||||
| #include <gtsam/inference/FactorGraph.h> | ||||
| #include <gtsam/discrete/DiscretePrior.h> | ||||
| #include <gtsam/discrete/DiscreteConditional.h> | ||||
| 
 | ||||
| #include <boost/shared_ptr.hpp> | ||||
| #include <map> | ||||
| #include <string> | ||||
| #include <utility> | ||||
| #include <vector> | ||||
| 
 | ||||
| namespace gtsam { | ||||
| 
 | ||||
|  | @ -107,13 +110,17 @@ namespace gtsam { | |||
|     /// @name Wrapper support
 | ||||
|     /// @{
 | ||||
| 
 | ||||
|     /// Render as markdown table.
 | ||||
|     /// Render as markdown tables.
 | ||||
|     std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter, | ||||
|                          const DiscreteFactor::Names& names = {}) const; | ||||
| 
 | ||||
|     /// Render as html tables.
 | ||||
|     std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter, | ||||
|                      const DiscreteFactor::Names& names = {}) const; | ||||
| 
 | ||||
|     /// @}
 | ||||
| 
 | ||||
|   private: | ||||
|  private: | ||||
|     /** Serialization function */ | ||||
|     friend class boost::serialization::access; | ||||
|     template<class ARCHIVE> | ||||
|  |  | |||
|  | @ -72,5 +72,23 @@ namespace gtsam { | |||
|     return ss.str(); | ||||
|   } | ||||
| 
 | ||||
|   /* **************************************************************************/ | ||||
|   std::string DiscreteBayesTree::html( | ||||
|       const KeyFormatter& keyFormatter, | ||||
|       const DiscreteFactor::Names& names) const { | ||||
|     using std::endl; | ||||
|     std::stringstream ss; | ||||
|     ss << "<div><p><tt>DiscreteBayesTree</tt> of size " << nodes_.size() | ||||
|        << "</p>"; | ||||
|     auto visitor = [&](const DiscreteBayesTreeClique::shared_ptr& clique, | ||||
|                        size_t& indent) { | ||||
|       ss << clique->conditional()->html(keyFormatter, names); | ||||
|       return indent + 1; | ||||
|     }; | ||||
|     size_t indent; | ||||
|     treeTraversal::DepthFirstForest(*this, indent, visitor); | ||||
|     return ss.str(); | ||||
|   } | ||||
| 
 | ||||
|   /* **************************************************************************/ | ||||
|   }  // namespace gtsam
 | ||||
|  |  | |||
|  | @ -92,10 +92,14 @@ class GTSAM_EXPORT DiscreteBayesTree | |||
|   /// @name Wrapper support
 | ||||
|   /// @{
 | ||||
| 
 | ||||
|   /// Render as markdown table.
 | ||||
|   /// Render as markdown tables.
 | ||||
|   std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter, | ||||
|                        const DiscreteFactor::Names& names = {}) const; | ||||
| 
 | ||||
|   /// Render as html tables.
 | ||||
|   std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter, | ||||
|                    const DiscreteFactor::Names& names = {}) const; | ||||
| 
 | ||||
|   /// @}
 | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -410,16 +410,19 @@ string DiscreteConditional::html(const KeyFormatter& keyFormatter, | |||
|   } | ||||
|   auto frontalAssignments = this->frontalAssignments(); | ||||
|   for (const auto& a : frontalAssignments) { | ||||
|     ss << "<th>"; | ||||
|     for (auto&& it = beginFrontals(); it != endFrontals(); ++it) { | ||||
|       size_t index = a.at(*it); | ||||
|       ss << "<th>" << Translate(names, *it, index) << "</th>"; | ||||
|       ss << Translate(names, *it, index); | ||||
|     } | ||||
|     ss << "</th>"; | ||||
|   } | ||||
|   ss << "</tr>\n"; | ||||
| 
 | ||||
|   // Finish header and start body.
 | ||||
|   ss << "  </thead>\n  <tbody>\n"; | ||||
| 
 | ||||
|   // Output all rows, one per assignment:
 | ||||
|   size_t count = 0, n = frontalAssignments.size(); | ||||
|   for (const auto& a : allAssignments()) { | ||||
|     if (count == 0) { | ||||
|  |  | |||
|  | @ -131,7 +131,7 @@ namespace gtsam { | |||
|     return std::make_pair(cond, sum); | ||||
|   } | ||||
| 
 | ||||
|   /* ************************************************************************* */ | ||||
|   /* ************************************************************************ */ | ||||
|   string DiscreteFactorGraph::markdown( | ||||
|       const KeyFormatter& keyFormatter, | ||||
|       const DiscreteFactor::Names& names) const { | ||||
|  | @ -145,5 +145,18 @@ namespace gtsam { | |||
|     return ss.str(); | ||||
|   } | ||||
| 
 | ||||
|   /* ************************************************************************* */ | ||||
|   /* ************************************************************************ */ | ||||
|   string DiscreteFactorGraph::html(const KeyFormatter& keyFormatter, | ||||
|                                    const DiscreteFactor::Names& names) const { | ||||
|     using std::endl; | ||||
|     std::stringstream ss; | ||||
|     ss << "<div><p><tt>DiscreteFactorGraph</tt> of size " << size() << "</p>"; | ||||
|     for (size_t i = 0; i < factors_.size(); i++) { | ||||
|       ss << "<p>factor " << i << ":</p>"; | ||||
|       ss << factors_[i]->html(keyFormatter, names) << endl; | ||||
|     } | ||||
|     return ss.str(); | ||||
|   } | ||||
| 
 | ||||
|   /* ************************************************************************ */ | ||||
|   }  // namespace gtsam
 | ||||
|  |  | |||
|  | @ -22,18 +22,17 @@ | |||
| #include <gtsam/inference/EliminateableFactorGraph.h> | ||||
| #include <gtsam/inference/Ordering.h> | ||||
| #include <gtsam/discrete/DecisionTreeFactor.h> | ||||
| #include <gtsam/discrete/DiscreteBayesNet.h> | ||||
| #include <gtsam/base/FastSet.h> | ||||
| 
 | ||||
| #include <boost/make_shared.hpp> | ||||
| #include <string> | ||||
| #include <utility> | ||||
| #include <vector> | ||||
| 
 | ||||
| namespace gtsam { | ||||
| 
 | ||||
| // Forward declarations
 | ||||
| class DiscreteFactorGraph; | ||||
| class DiscreteFactor; | ||||
| class DiscreteConditional; | ||||
| class DiscreteBayesNet; | ||||
| class DiscreteEliminationTree; | ||||
|  | @ -144,8 +143,8 @@ public: | |||
|   /// @{
 | ||||
| 
 | ||||
|   /**
 | ||||
|    * @brief Render as markdown table | ||||
|    *  | ||||
|    * @brief Render as markdown tables | ||||
|    * | ||||
|    * @param keyFormatter GTSAM-style Key formatter. | ||||
|    * @param names optional, a map from Key to category names. | ||||
|    * @return std::string a (potentially long) markdown string. | ||||
|  | @ -153,6 +152,16 @@ public: | |||
|   std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter, | ||||
|                        const DiscreteFactor::Names& names = {}) const; | ||||
| 
 | ||||
|   /**
 | ||||
|    * @brief Render as html tables | ||||
|    * | ||||
|    * @param keyFormatter GTSAM-style Key formatter. | ||||
|    * @param names optional, a map from Key to category names. | ||||
|    * @return std::string a (potentially long) html string. | ||||
|    */ | ||||
|   std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter, | ||||
|                    const DiscreteFactor::Names& names = {}) const; | ||||
| 
 | ||||
|   /// @}
 | ||||
| }; // \ DiscreteFactorGraph
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -144,6 +144,10 @@ class DiscreteBayesNet { | |||
|                       gtsam::DefaultKeyFormatter) const; | ||||
|   string markdown(const gtsam::KeyFormatter& keyFormatter, | ||||
|                   std::map<gtsam::Key, std::vector<std::string>> names) const; | ||||
|   string html(const gtsam::KeyFormatter& keyFormatter = | ||||
|                   gtsam::DefaultKeyFormatter) const; | ||||
|   string html(const gtsam::KeyFormatter& keyFormatter, | ||||
|               std::map<gtsam::Key, std::vector<std::string>> names) const; | ||||
| }; | ||||
| 
 | ||||
| #include <gtsam/discrete/DiscreteBayesTree.h> | ||||
|  | @ -180,6 +184,10 @@ class DiscreteBayesTree { | |||
|                  gtsam::DefaultKeyFormatter) const; | ||||
|   string markdown(const gtsam::KeyFormatter& keyFormatter, | ||||
|                   std::map<gtsam::Key, std::vector<std::string>> names) const; | ||||
|   string html(const gtsam::KeyFormatter& keyFormatter = | ||||
|                   gtsam::DefaultKeyFormatter) const; | ||||
|   string html(const gtsam::KeyFormatter& keyFormatter, | ||||
|               std::map<gtsam::Key, std::vector<std::string>> names) const; | ||||
| }; | ||||
| 
 | ||||
| #include <gtsam/inference/DotWriter.h> | ||||
|  | @ -229,6 +237,10 @@ class DiscreteFactorGraph { | |||
|                  gtsam::DefaultKeyFormatter) const; | ||||
|   string markdown(const gtsam::KeyFormatter& keyFormatter, | ||||
|                   std::map<gtsam::Key, std::vector<std::string>> names) const; | ||||
|   string html(const gtsam::KeyFormatter& keyFormatter = | ||||
|                   gtsam::DefaultKeyFormatter) const; | ||||
|   string html(const gtsam::KeyFormatter& keyFormatter, | ||||
|               std::map<gtsam::Key, std::vector<std::string>> names) const; | ||||
| }; | ||||
| 
 | ||||
| }  // namespace gtsam | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue