17 #ifndef OPENKALMAN_SCALEDSIGMAPOINTSBASE_HPP 18 #define OPENKALMAN_SCALEDSIGMAPOINTSBASE_HPP 36 template<
typename Derived>
52 template<std::
size_t dim>
53 static constexpr
auto W()
55 return Derived::template unscaled_W<dim>() / (Derived::alpha * Derived::alpha);
65 template<std::
size_t dim>
66 static constexpr
auto W_m0()
68 return (Derived::template unscaled_W0<dim>() - 1) / (Derived::alpha * Derived::alpha) + 1;
79 template<std::
size_t dim>
80 static constexpr
auto W_c0()
82 return W_m0<dim>() + 1 - Derived::alpha * Derived::alpha + Derived::beta;
86 template<std::
size_t,
typename Scalar>
87 static constexpr
auto cat_dummy_function(
const Scalar w) {
return w; };
90 template<std::size_t dim,
typename Weights,
typename Scalar, std::size_t ... ints>
91 static auto cat_weights(
const Scalar w0, std::index_sequence<ints...>)
93 return Weights {w0, cat_dummy_function<ints, Scalar>(W<dim>())...};
97 template<std::
size_t dim,
typename Weights>
98 static auto mean_weights()
101 constexpr
auto count = index_dimension_of_v<Weights, 0>;
102 return cat_weights<dim, Weights, Scalar>(W_m0<dim>(), std::make_index_sequence<count - 1> {});
106 template<std::
size_t dim,
typename Weights>
107 static auto covariance_weights()
110 constexpr
auto count = index_dimension_of_v<Weights, 0>;
111 return cat_weights<dim, Weights, Scalar>(W_c0<dim>(), std::make_index_sequence<count - 1> {});
116 #ifdef __cpp_concepts 117 template<std::
size_t dim, typed_matrix YMeans> requires has_untyped_index<YMeans, 1> and
120 template<std::
size_t dim,
typename YMeans, std::enable_if_t<typed_matrix<YMeans> and has_untyped_index<YMeans, 1> and
121 (index_dimension_of<YMeans, 0>::value == coordinates::stat_dimension_of_v<vector_space_descriptor_of_t<YMeans, 0>>),
int> = 0>
124 weighted_means(YMeans&& y_means)
126 static_assert(index_dimension_of_v<YMeans, 1> == Derived::template sigma_point_count<dim>);
128 std::tuple<index_dimension_of<YMeans, 1>, Axis>>;
129 return make_self_contained(std::forward<YMeans>(y_means) * mean_weights<dim, Weights>());
143 #ifdef __cpp_concepts 144 template<std::
size_t dim,
typename InputDist,
bool return_cross = false, typed_matrix X, typed_matrix Y> requires
145 (index_dimension_of_v<X, 1> == index_dimension_of_v<Y, 1>) and
146 compares_with<vector_space_descriptor_of_t<X, 0>,
typename DistributionTraits<InputDist>::StaticDescriptor>
148 template<std::size_t dim,
typename InputDist,
bool return_cross =
false,
typename X,
typename Y, std::enable_if_t<
150 compares_with<vector_space_descriptor_of_t<X, 0>,
typename DistributionTraits<InputDist>::StaticDescriptor>,
156 static_assert(index_dimension_of_v<X, 1> == Derived::template sigma_point_count<dim>);
157 constexpr
auto count = index_dimension_of_v<X, 1>;
159 auto weights = covariance_weights<dim, Weights>();
161 if constexpr(cholesky_form<InputDist>)
163 if constexpr (W_c0<dim>() < 0)
166 const auto [y_deviations_head, y_deviations_tail] =
split_horizontal<1, count - 1>(y_deviations);
167 const auto [weights_head, weights_tail] =
split_vertical<Axis, Dimensions<count - 1>>(weights);
168 const auto sqrt_weights_tail = apply_coefficientwise([](
const auto x){
return values::sqrt(x); }, weights_tail);
173 rank_update(out_covariance, y_deviations_head, W_c0<dim>());
175 if constexpr (return_cross)
177 auto cross_covariance = make_self_contained(x_deviations *
to_diagonal(weights) *
adjoint(y_deviations));
178 return std::tuple {std::move(out_covariance), std::move(cross_covariance)};
182 return out_covariance;
187 const auto sqrt_weights = apply_coefficientwise([](
const auto x){
return values::sqrt(x); }, weights);
191 if constexpr (return_cross)
193 auto cross_covariance = make_self_contained(x_deviations *
to_diagonal(weights) *
adjoint(y_deviations));
194 return std::tuple {std::move(out_covariance), std::move(cross_covariance)};
198 return out_covariance;
205 auto out_covariance = make_self_contained(
make_covariance(y_deviations * w_yT));
207 if constexpr (return_cross)
209 auto cross_covariance = make_self_contained(x_deviations * w_yT);
210 return std::tuple {std::move(out_covariance), std::move(cross_covariance)};
214 return out_covariance;
223 #endif //OPENKALMAN_SCALEDSIGMAPOINTSBASE_HPP auto split_horizontal(M &&m)
Split Covariance or SquareRootCovariance vertically. Result is a tuple of typed matrices.
Definition: covariance-overloads.hpp:355
Definition: ScaledSigmaPointsBase.hpp:37
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
decltype(auto) constexpr to_diagonal(Arg &&arg)
Convert an indexible object into a diagonal matrix.
Definition: to_diagonal.hpp:32
static auto covariance(const X &x_deviations, const Y &y_deviations)
Calculate the posterior covariance, given prior and posterior deviations from the sigma points...
Definition: ScaledSigmaPointsBase.hpp:154
constexpr auto sqrt(const Arg &arg)
A constexpr alternative to std::sqrt.
Definition: sqrt.hpp:46
decltype(auto) constexpr adjoint(Arg &&arg)
Take the adjoint of a matrix.
Definition: adjoint.hpp:33
typename vector_space_descriptor_of< T, N >::type vector_space_descriptor_of_t
helper template for vector_space_descriptor_of.
Definition: vector_space_descriptor_of.hpp:56
constexpr bool covariance
T is a specialization of either Covariance or SquareRootCovariance.
Definition: object-types.hpp:161
decltype(auto) constexpr LQ_decomposition(A &&a)
Perform an LQ decomposition of matrix A=[L,0]Q, L is a lower-triangular matrix, and Q is orthogonal...
Definition: LQ_decomposition.hpp:33
std::decay_t< decltype(make_dense_object< T, layout, S >(std::declval< D >()))> dense_writable_matrix_t
An alias for a dense, writable matrix, patterned on parameter T.
Definition: dense_writable_matrix_t.hpp:38
auto make_covariance(Arg &&arg)
Make a Covariance from a covariance_nestable, specifying the fixed_pattern.
Definition: Covariance.hpp:735
The dimension of an index for a matrix, expression, or array.
Definition: index_dimension_of.hpp:34
auto split_vertical(M &&m)
Split Covariance or SquareRootCovariance vertically. Result is a tuple of typed matrices.
Definition: covariance-overloads.hpp:340
Definition: basics.hpp:48