23 #include <boost/spirit/include/qi.hpp> 24 #include <boost/spirit/include/phoenix.hpp> 30 namespace qi = boost::spirit::qi;
31 namespace ph = boost::phoenix;
35 typedef string::const_iterator
It;
36 using boost::phoenix::val;
38 using boost::phoenix::push_back;
66 qi::rule<It, qi::space_type, Signature::Table()>
table, or_, and_,
rows;
67 qi::rule<It, Signature::Row()>
true_, false_,
row;
69 table = or_ | and_ |
rows;
70 or_ = qi::lit(
"OR")[qi::_val =
logic(
false,
true,
true,
true)];
71 and_ = qi::lit(
"AND")[qi::_val =
logic(
false,
false,
false,
true)];
72 rows = +(row | true_ | false_);
73 row = qi::double_ >> +(
"/" >> qi::double_);
74 true_ = qi::lit(
"T")[qi::_val =
T];
75 false_ = qi::lit(
"F")[qi::_val =
F];
82 It
f = spec.begin(),
l = spec.end();
84 qi::lit(
"OR")[
ph::ref(table) =
logic(
false,
true,
true,
true)]) ||
86 qi::lit(
"AND")[
ph::ref(table) =
logic(
false,
false,
false,
true)]))
90 istringstream iss(spec);
92 while (iss >> token) {
94 It tf = token.
begin(), tl = token.end();
96 qi::double_[push_back(
ph::ref(values), qi::_1)] >> +(
"/" >> qi::double_[push_back(
ph::ref(values), qi::_1)]) |
97 qi::lit(
"T")[
ph::ref(values) = T] |
101 table.push_back(values);
110 for (
size_t i = 1;
i < row.size();
i++)
116 for (
size_t i = 0;
i < table.size();
i++)
117 os << table[
i] << endl;
127 keys.push_back(
key_);
134 js.push_back(
key_.first);
142 const size_t nrStates =
table_->at(0).size();
143 for (
size_t j = 0;
j < nrStates;
j++) {
145 assert(
row.size() == nrStates);
146 cpt.push_back(
row[
j]);
160 for (
size_t i = 0;
i < row.size();
i++)
162 for (
size_t i = 0;
i < row.size();
i++)
200 os << (s.
spec_ ? *s.
spec_ :
"no spec") << endl;
204 os <<
"spec could not be parsed" << endl;
const boost::optional< Table > & table() const
const MATRIX::ConstRowXpr row(const MATRIX &A, size_t j)
std::ostream & operator<<(std::ostream &os, const Dih6 &m)
qi::rule< It, qi::space_type, Signature::Table()> table
signatures for conditional densities
boost::optional< std::string > spec_
Signature & operator,(const DiscreteKey &parent)
boost::optional< Table > table_
Signature operator|(const DiscreteKey &key, const DiscreteKey &parent)
std::vector< double > cpt() const
static void normalize(Signature::Row &row)
Signature & operator=(const std::string &spec)
DiscreteKeys discreteKeys() const
static const Line3 l(Rot3(), 1, 1)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
KeyVector indices() const
std::pair< Key, size_t > DiscreteKey
Signature(const DiscreteKey &key)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Signature::Table logic(bool ff, bool ft, bool tf, bool tt)
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
Signature operator%(const DiscreteKey &key, const string &parent)
const_iterator begin() const
string::const_iterator It
std::vector< double > Row
qi::rule< It, Signature::Row()> true_
ofstream os("timeSchurFactors.csv")
GTSAM_EXPORT friend std::ostream & operator<<(std::ostream &os, const Signature &s)
struct gtsam::parser::Grammar grammar
def parse(input_path, output_path, quiet=False, generate_xml_flag=True)
bool parse_table(const string &spec, Signature::Table &table)
DiscreteKeys is a set of keys that can be assembled using the & operator.
const DiscreteKey & key() const