TriangularArray class
Triangular arrays.
A triangular array behaves like a matrix with the structure
x x x x x x x x x x x x x x x
and all other elements omitted. This structure appears naturally in the representation of a vine copula model and related algorithms. Each row corresponds to one tree in the vine, starting from the top. In each tree (=row), each column represents an edge.
For truncated vine models the last few trees are omitted. For example, a 3-truncated version of the above array contains the elements
x x x x x x x x x x x x
Only the elements indicated by xs are stored and can be accessed.
The data structure is templated and any type or class can be used to fill the entries (xs) of the triangular array.
Constructors, destructors, conversion operators
- TriangularArray() defaulted
-
TriangularArray(size_
t d) explicit - Construct a triangular array of dimension
d. -
TriangularArray(size_
t d, size_ t trunc_lvl) - Construct a truncated triangular array.
- TriangularArray(const std::vector<std::vector<T>>& rows) explicit
- Construct a truncated triangular array from nested vector.
-
template<typename Json, typename std::enable_if<std::is_same<typename std::decay<Json>::type, nlohmann::json>::value, int>::type = 0>TriangularArray(const Json& input) explicit
- Constructs a triangular array from a
nlohmann::jsonobject.
Public functions
-
auto operator()(size_
t row, size_ t column) -> T& - Access one element of the trapezoid (writable).
-
auto operator()(size_
t row, size_ t column) const -> T - Access one element of the trapezoid (non-writable).
- auto operator==(const TriangularArray<T>& rhs) const -> bool
- Equality operator to compare two TriangularArray objects.
- auto operator<(const TriangularArray<T>& rhs) const -> bool
- Lexicographic comparison operator for sorting.
-
auto truncate(size_
t trunc_lvl) -> void - Truncates the trapezoid. If the trapezoid is already truncated at a level less than
trunc_lvl, the function does nothing. -
auto get_trunc_lvl() const -> size_
t - Gets the truncation level of the underlying vine..
-
auto get_dim() const -> size_
t - Gets the dimension of the underlying vine (the matrix has
d-1columns and.min(trunv_lvl, d-1)rows). - auto to_json() const -> nlohmann::json
- Converts the triangular array to a
nlohmann::jsonobject. - auto to_list() const -> std::vector<std::vector<T>>
- Converts the triangular array to a nested vector of rows.
- auto str() const -> std::string
- represent triangular array as a string.
Function documentation
vinecopulib:: TriangularArray<_1>:: TriangularArray(size_ t d) explicit
Construct a triangular array of dimension d.
| Parameters | |
|---|---|
| d | The dimension of the underlying vine. |
The array has d-1 columns and d-1 rows.
vinecopulib:: TriangularArray<_1>:: TriangularArray(size_ t d,
size_ t trunc_lvl)
Construct a truncated triangular array.
| Parameters | |
|---|---|
| d | The dimension of the vine. |
| trunc_lvl | The truncation level. |
The array has d-1 columns and min(trunc_lvl, d-1) rows.
vinecopulib:: TriangularArray<_1>:: TriangularArray(const std::vector<std::vector<T>>& rows) explicit
Construct a truncated triangular array from nested vector.
| Parameters | |
|---|---|
| rows | A vector of rows; the length of the first row defines the dimension of the triangular array. The number of rows defines the truncation level. |
An arrax of dimension d has d-1 columns and min(trunc_lvl, d-1) rows.
template<typename T _1>
template<typename Json, typename std::enable_if<std::is_same<typename std::decay<Json>::type, nlohmann::json>::value, int>::type = 0>
vinecopulib:: TriangularArray<_1>:: TriangularArray(const Json& input) explicit
Constructs a triangular array from a nlohmann::json object.
| Parameters | |
|---|---|
| input | The nlohmann::json object to convert from. |
The "data" field must contain the rows of the array (as written by to_); the dimension and truncation level are derived from the rows. Templated so that brace-enclosed initializer lists keep selecting the nested-vector constructor.
bool vinecopulib:: TriangularArray<_1>:: operator==(const TriangularArray<T>& rhs) const
Equality operator to compare two TriangularArray objects.
| Parameters | |
|---|---|
| rhs | Right-hand-side of the equality operator. |
nlohmann::json vinecopulib:: TriangularArray<_1>:: to_json() const
Converts the triangular array to a nlohmann::json object.
| Returns | The nlohmann::json object containing the array. |
|---|
The result contains the fields "d" (dimension), "t" (truncation level), and "data" (the rows of the array); it can be converted back with the JSON constructor.