1 #ifndef VTESTBED_CORE_ARMA_HH     2 #define VTESTBED_CORE_ARMA_HH     7 #include <vtestbed/base/blitz.hh>     8 #include <vtestbed/core/fourier_transform.hh>     9 #include <vtestbed/core/wavy_surface_generator.hh>    10 #include <vtestbed/core/yule_walker_solver.hh>    31             _nbadroots(nbadroots) {}
    34             num_bad_roots() 
const noexcept {
    35                 return this->_nbadroots;
    39             what() 
const noexcept 
override {
    40                 return "AR/MA process is not stationary/invertible: "    41                     "some roots lie inside unit disk.";
    47         template <
class T, 
int N>
    77         template <
class T, 
int N>
    81         template <
class T, 
int N>
    84             blitz::Array<T,N> lhs,
    85             blitz::Array<T,N> rhs,
    89         template <
class T, 
int N>
    90         inline blitz::Array<T,N>
    91         covariance(blitz::Array<T,N> lhs, blitz::Array<T,N> rhs) {
    93             return covariance<T,N>(lhs, rhs, fft);
    96         template <
class T, 
int N>
    97         inline blitz::Array<T,N>
    99             blitz::Array<T,N> lhs,
   100             blitz::Array<T,N> rhs,
   103             const auto& lhs_stat = statistics(lhs);
   104             const auto& rhs_stat = statistics(rhs);
   105             blitz::Array<T,N> result(covariance<T,N>(
   106                 blitz::Array<T,N>(lhs - lhs_stat.mean()),
   107                 blitz::Array<T,N>(rhs - rhs_stat.mean()),
   110             const T denominator = lhs_stat.variance() * rhs_stat.variance();
   111             if (denominator > 0) {
   112                 result /= std::sqrt(denominator);
   117         template <
class T, 
int N>
   118         inline blitz::Array<T,N>
   119         correlation(blitz::Array<T,N> lhs, blitz::Array<T,N> rhs) {
   120             Chirp_Z_transform<std::complex<T>,N> fft(rhs.shape());
   121             return correlation<T,N>(lhs, rhs, fft);
   124         template <
class T, 
int N>
   132             using typename base_type::array_type;
   141             typedef blitz::TinyVector<T,N> vec3;
   142             typedef blitz::RectDomain<N> rect3;
   147             array_type _coefficients;
   148             T _whitenoisevariance{0};
   151             vec3 _alpha{0,0,0.01};
   166             has_coefficients()
 const {
   167                 return this->_coefficients.size() > 0;
   172                 return this->_acf.size() > 0;
   176             has_acf_generator()
 const {
   177                 return static_cast<bool>(this->_acf_generator);
   182                 this->_acf_generator = std::move(ptr);
   187             acf_generator()
 const {
   188                 return this->_acf_generator;
   192             acf(array_type acf_in) {
   193                 this->_acf.reference(acf_in);
   194                 this->_acf_generator = 
nullptr;
   197             inline const array_type&
   198             acf() 
const noexcept {
   202             inline const array_type&
   203             coefficients() 
const noexcept {
   204                 return this->_coefficients;
   208             white_noise_variance() 
const noexcept {
   209                 return this->_whitenoisevariance;
   213             variance() 
const noexcept {
   214                 return *this->_acf.data();
   220             template <
class SeedSequence>
   222             seed(SeedSequence& seq) {
   223                 this->_prng.seed(seq);
   228                 this->_solver = std::move(ptr);
   232             coefficient_solver() 
const noexcept {
   233                 return this->_solver.get();
   237             coefficient_solver() noexcept {
   238                 return this->_solver.get();
   242             decay(
const vec3& rhs) {
   247             decay() 
const noexcept {
   252             calculate_coefficients();
   257             generate_white_noise(array_type result);
   266         template <
class T, 
int N>
   274             using typename base_type::array_type;
   276             using typename base_type::solver_ptr;
   291             generate(
const grid_type& grid, array_type& result) 
override;
   300         template <
class T, 
int N>
   314             using typename base_type::array_type;
   321                 this->coefficient_solver(
   332             generate(
const grid_type& grid, array_type& result) 
override;
   340 #endif // vim:filetype=cpp 
Based on autoregerssive model.
 
void validate_process(blitz::Array< T, N > phi)
Check AR (MA) process stationarity (invertibility).
 
blitz::Array< T, N > auto_covariance(const blitz::Array< T, N > &rhs)
Computes autocovariance function of three-dimensional field.
 
A region defined by start and end index and lower and upper bound for each dimension.
 
Multi-dimensional solver that determines MA model coefficients from ACF.
 
Based on moving-average model.
 
Base class for wavy surface generators.