#include <VectorValues.h>
Public Types | |
typedef Values::const_iterator | const_iterator |
Const iterator over vector values. More... | |
typedef std::map< Key, size_t > | Dims |
Keyed vector dimensions. More... | |
typedef Values::iterator | iterator |
Iterator over vector values. More... | |
typedef value_type | KeyValuePair |
Typedef to pair<Key, Vector> More... | |
typedef boost::shared_ptr< This > | shared_ptr |
shared_ptr to this class More... | |
typedef Values::value_type | value_type |
Typedef to pair<Key, Vector> More... | |
Protected Types | |
typedef VectorValues | This |
typedef ConcurrentMap< Key, Vector > | Values |
Collection of Vectors making up a VectorValues. More... | |
Protected Attributes | |
Values | values_ |
Vectors making up this VectorValues. More... | |
Private Member Functions | |
template<class ARCHIVE > | |
void | serialize (ARCHIVE &ar, const unsigned int) |
Friends | |
class | boost::serialization::access |
Standard Constructors | |
VectorValues () | |
VectorValues (const VectorValues &first, const VectorValues &second) | |
template<class CONTAINER > | |
VectorValues (const CONTAINER &c) | |
VectorValues (const VectorValues &c) | |
template<typename ITERATOR > | |
VectorValues (ITERATOR first, ITERATOR last) | |
VectorValues (const Vector &c, const Dims &dims) | |
Constructor from Vector, with Dims. More... | |
VectorValues (const Vector &c, const Scatter &scatter) | |
Constructor from Vector, with Scatter. More... | |
static VectorValues | Zero (const VectorValues &other) |
Standard Interface | |
GTSAM_EXPORT friend std::ostream & | operator<< (std::ostream &, const VectorValues &) |
overload operator << to print to stringstream More... | |
size_t | size () const |
size_t | dim (Key j) const |
bool | exists (Key j) const |
Vector & | at (Key j) |
const Vector & | at (Key j) const |
Vector & | operator[] (Key j) |
const Vector & | operator[] (Key j) const |
void | update (const VectorValues &values) |
iterator | insert (const std::pair< Key, Vector > &key_value) |
template<class... Args> | |
std::pair< VectorValues::iterator, bool > | emplace (Key j, Args &&...args) |
iterator | insert (Key j, const Vector &value) |
void | insert (const VectorValues &values) |
std::pair< iterator, bool > | tryInsert (Key j, const Vector &value) |
void | erase (Key var) |
void | setZero () |
iterator | begin () |
Iterator over variables. More... | |
const_iterator | begin () const |
Iterator over variables. More... | |
iterator | end () |
Iterator over variables. More... | |
const_iterator | end () const |
Iterator over variables. More... | |
iterator | find (Key j) |
const_iterator | find (Key j) const |
void | print (const std::string &str="VectorValues", const KeyFormatter &formatter=DefaultKeyFormatter) const |
bool | equals (const VectorValues &x, double tol=1e-9) const |
Advanced Interface | |
Vector | vector () const |
template<typename CONTAINER > | |
Vector | vector (const CONTAINER &keys) const |
Vector | vector (const Dims &dims) const |
void | swap (VectorValues &other) |
bool | hasSameStructure (const VectorValues other) const |
Linear algebra operations | |
GTSAM_EXPORT VectorValues | operator* (const double a, const VectorValues &v) |
double | dot (const VectorValues &v) const |
double | norm () const |
double | squaredNorm () const |
VectorValues | operator+ (const VectorValues &c) const |
VectorValues | add (const VectorValues &c) const |
VectorValues & | operator+= (const VectorValues &c) |
VectorValues & | addInPlace (const VectorValues &c) |
VectorValues & | addInPlace_ (const VectorValues &c) |
VectorValues | operator- (const VectorValues &c) const |
VectorValues | subtract (const VectorValues &c) const |
VectorValues | scale (const double a) const |
VectorValues & | operator*= (double alpha) |
VectorValues & | scaleInPlace (double alpha) |
This class represents a collection of vector-valued variables associated each with a unique integer index. It is typically used to store the variables of a GaussianFactorGraph. Optimizing a GaussianFactorGraph or GaussianBayesNet returns this class.
For basic usage, such as receiving a linear solution from gtsam solving functions, or creating this class in unit tests and examples where speed is not important, you can use a simple interface:
Example:
Access is through the variable Key j, and returns a SubVector, which is a view on the underlying data structure.
This class is additionally used in gradient descent and dog leg to store the gradient.
Definition at line 74 of file VectorValues.h.
typedef Values::const_iterator gtsam::VectorValues::const_iterator |
Const iterator over vector values.
Definition at line 82 of file VectorValues.h.
typedef std::map<Key, size_t> gtsam::VectorValues::Dims |
Keyed vector dimensions.
Definition at line 86 of file VectorValues.h.
typedef Values::iterator gtsam::VectorValues::iterator |
Iterator over vector values.
Definition at line 81 of file VectorValues.h.
Typedef to pair<Key, Vector>
Definition at line 85 of file VectorValues.h.
typedef boost::shared_ptr<This> gtsam::VectorValues::shared_ptr |
shared_ptr to this class
Definition at line 83 of file VectorValues.h.
|
protected |
Definition at line 76 of file VectorValues.h.
typedef Values::value_type gtsam::VectorValues::value_type |
Typedef to pair<Key, Vector>
Definition at line 84 of file VectorValues.h.
|
protected |
Collection of Vectors making up a VectorValues.
Definition at line 77 of file VectorValues.h.
|
inline |
Default constructor creates an empty VectorValues.
Definition at line 94 of file VectorValues.h.
gtsam::VectorValues::VectorValues | ( | const VectorValues & | first, |
const VectorValues & | second | ||
) |
Merge two VectorValues into one, this is more efficient than inserting elements one by one.
Definition at line 37 of file VectorValues.cpp.
|
inlineexplicit |
Create from another container holding pair<Key,Vector>.
Definition at line 102 of file VectorValues.h.
|
inline |
Implicit copy constructor to specialize the explicit constructor from any container.
Definition at line 105 of file VectorValues.h.
|
inline |
Create from a pair of iterators over pair<Key,Vector>.
Definition at line 109 of file VectorValues.h.
Constructor from Vector, with Dims.
Definition at line 47 of file VectorValues.cpp.
Constructor from Vector, with Scatter.
Definition at line 64 of file VectorValues.cpp.
VectorValues gtsam::VectorValues::add | ( | const VectorValues & | c | ) | const |
Element-wise addition, synonym for operator+(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).
Definition at line 281 of file VectorValues.cpp.
VectorValues & gtsam::VectorValues::addInPlace | ( | const VectorValues & | c | ) |
Element-wise addition in-place, synonym for operator+=(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).
Definition at line 304 of file VectorValues.cpp.
VectorValues & gtsam::VectorValues::addInPlace_ | ( | const VectorValues & | c | ) |
Element-wise addition in-place, but allows for empty slots in *this. Slower
Definition at line 310 of file VectorValues.cpp.
Read/write access to the vector value with key j
, throws std::out_of_range if j
does not exist, identical to operator[](Key).
Definition at line 137 of file VectorValues.h.
Access the vector value with key j
(const version), throws std::out_of_range if j
does not exist, identical to operator[](Key).
Definition at line 150 of file VectorValues.h.
|
inline |
Iterator over variables.
Definition at line 226 of file VectorValues.h.
|
inline |
Iterator over variables.
Definition at line 227 of file VectorValues.h.
Return the dimension of variable j
.
Definition at line 128 of file VectorValues.h.
double gtsam::VectorValues::dot | ( | const VectorValues & | v | ) | const |
Dot product with another VectorValues, interpreting both as vectors of their concatenated values. Both VectorValues must have the same structure (checked when NDEBUG is not defined).
Definition at line 229 of file VectorValues.cpp.
|
inline |
Emplace a vector value
with key j
. Throws an invalid_argument exception if the key j
is already used.
value | The vector to be inserted. |
j | The index with which the value will be associated. |
Definition at line 183 of file VectorValues.h.
|
inline |
Iterator over variables.
Definition at line 228 of file VectorValues.h.
|
inline |
Iterator over variables.
Definition at line 229 of file VectorValues.h.
bool gtsam::VectorValues::equals | ( | const VectorValues & | x, |
double | tol = 1e-9 |
||
) | const |
equals required by Testable for unit testing
Definition at line 161 of file VectorValues.cpp.
|
inline |
Erase the vector with the given key, or throw std::out_of_range if it does not exist
Definition at line 216 of file VectorValues.h.
|
inline |
Check whether a variable with key j
exists.
Definition at line 131 of file VectorValues.h.
Return the iterator corresponding to the requested key, or end() if no variable is present with this key.
Definition at line 235 of file VectorValues.h.
|
inline |
Return the iterator corresponding to the requested key, or end() if no variable is present with this key.
Definition at line 241 of file VectorValues.h.
bool gtsam::VectorValues::hasSameStructure | ( | const VectorValues | other | ) | const |
Check if this VectorValues has the same structure (keys and dimensions) as another
Definition at line 222 of file VectorValues.cpp.
VectorValues::iterator gtsam::VectorValues::insert | ( | const std::pair< Key, Vector > & | key_value | ) |
Insert a vector value
with key j
. Throws an invalid_argument exception if the key j
is already used.
value | The vector to be inserted. |
j | The index with which the value will be associated. |
Definition at line 90 of file VectorValues.cpp.
Insert a vector value
with key j
. Throws an invalid_argument exception if the key j
is already used.
value | The vector to be inserted. |
j | The index with which the value will be associated. |
Definition at line 195 of file VectorValues.h.
void gtsam::VectorValues::insert | ( | const VectorValues & | values | ) |
Insert all values from values
. Throws an invalid_argument exception if any keys to be inserted are already used.
Definition at line 118 of file VectorValues.cpp.
double gtsam::VectorValues::norm | ( | ) | const |
Vector L2 norm
Definition at line 247 of file VectorValues.cpp.
VectorValues & gtsam::VectorValues::operator*= | ( | double | alpha | ) |
Element-wise scaling by a constant in-place.
Definition at line 368 of file VectorValues.cpp.
VectorValues gtsam::VectorValues::operator+ | ( | const VectorValues & | c | ) | const |
Element-wise addition, synonym for add(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).
Definition at line 261 of file VectorValues.cpp.
VectorValues & gtsam::VectorValues::operator+= | ( | const VectorValues & | c | ) |
Element-wise addition in-place, synonym for operator+=(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).
Definition at line 287 of file VectorValues.cpp.
VectorValues gtsam::VectorValues::operator- | ( | const VectorValues & | c | ) | const |
Element-wise subtraction, synonym for subtract(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).
Definition at line 323 of file VectorValues.cpp.
Read/write access to the vector value with key j
, throws std::out_of_range if j
does not exist, identical to at(Key).
Definition at line 161 of file VectorValues.h.
Access the vector value with key j
(const version), throws std::out_of_range if j
does not exist, identical to at(Key).
Definition at line 165 of file VectorValues.h.
void gtsam::VectorValues::print | ( | const std::string & | str = "VectorValues" , |
const KeyFormatter & | formatter = DefaultKeyFormatter |
||
) | const |
print required by Testable for unit testing
Definition at line 153 of file VectorValues.cpp.
VectorValues gtsam::VectorValues::scale | ( | const double | a | ) | const |
Element-wise scaling by a constant.
Definition at line 362 of file VectorValues.cpp.
VectorValues & gtsam::VectorValues::scaleInPlace | ( | double | alpha | ) |
Element-wise scaling by a constant in-place.
Definition at line 376 of file VectorValues.cpp.
|
inlineprivate |
Definition at line 359 of file VectorValues.h.
void gtsam::VectorValues::setZero | ( | ) |
Set all values to zero vectors.
Definition at line 127 of file VectorValues.cpp.
|
inline |
Number of variables stored.
Definition at line 125 of file VectorValues.h.
double gtsam::VectorValues::squaredNorm | ( | ) | const |
Squared vector L2 norm
Definition at line 252 of file VectorValues.cpp.
VectorValues gtsam::VectorValues::subtract | ( | const VectorValues & | c | ) | const |
Element-wise subtraction, synonym for operator-(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).
Definition at line 343 of file VectorValues.cpp.
void gtsam::VectorValues::swap | ( | VectorValues & | other | ) |
Swap the data in this VectorValues with another.
Definition at line 206 of file VectorValues.cpp.
insert that mimics the STL map insert - if the value already exists, the map is not modified and an iterator to the existing value is returned, along with 'false'. If the value did not exist, it is inserted and an iterator pointing to the new element, along with 'true', is returned.
Definition at line 207 of file VectorValues.h.
void gtsam::VectorValues::update | ( | const VectorValues & | values | ) |
For all key/value pairs in values
, replace values with corresponding keys in this class with those in values
. Throws std::out_of_range if any keys in values
are not present in this class.
Definition at line 100 of file VectorValues.cpp.
Vector gtsam::VectorValues::vector | ( | ) | const |
Retrieve the entire solution as a single vector
Definition at line 173 of file VectorValues.cpp.
|
inline |
Access a vector that is a subset of relevant keys.
Definition at line 262 of file VectorValues.h.
Access a vector that is a subset of relevant keys, dims version.
Definition at line 190 of file VectorValues.cpp.
|
static |
Create a VectorValues with the same structure as other
, but filled with zeros.
Definition at line 77 of file VectorValues.cpp.
|
friend |
Serialization function
Definition at line 357 of file VectorValues.h.
|
friend |
Element-wise scaling by a constant.
Definition at line 349 of file VectorValues.cpp.
|
friend |
overload operator << to print to stringstream
|
protected |
Vectors making up this VectorValues.
Definition at line 78 of file VectorValues.h.