This example uses to toy Markov chain model to introduce some operations on the main linear algebra backend that bitrl is using namely Eigen.
The driver code for this tutorial is shown below.
#include <algorithm>
#include <cmath>
#include <iostream>
#include <random>
#include <tuple>
#include <utility>
{
{
auto result = mat;
for (uint i = 0; i < power - 1; ++i)
{
result *= mat;
}
return result;
}
{
std::cout << "[" << mat(0, 0) << " , " << mat(0, 1) << "]" << std::endl;
std::cout << "[" << mat(1, 0) << " , " << mat(1, 1) << "]" << std::endl;
}
}
{
std::cout << "After 3 steps..." << std::endl;
std::cout << "After 50 steps..." << std::endl;
std::cout << "After 100 steps..." << std::endl;
v1[0] = 1.0;
v1[1] = 0.0;
std::cout << "v_3=" << v1.transpose() * t_3 << std::endl;
std::cout << "v_50=" << v1.transpose() * t_50 << std::endl;
std::cout << "v_100=" << v1.transpose() * t_100 << std::endl;
v1[0] = 0.5;
v1[1] = 0.5;
std::cout << "v_3=" << v1.transpose() * t_3 << std::endl;
std::cout << "v_50=" << v1.transpose() * t_50 << std::endl;
std::cout << "v_100=" << v1.transpose() * t_100 << std::endl;
return 0;
}
int main()
Definition discounted_returns.cpp:19
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
Eigen::MatrixX< T > DynMat
Dynamically sized matrix to use around the library.
Definition bitsim_types.h:51
double real_t
real_t
Definition bitsim_types.h:20
Eigen::RowVectorX< T > DynVec
Dynamically sized row vector.
Definition bitsim_types.h:101
Definition markov_chain.cpp:11
DynMat< real_t > compute_matrix_power(const DynMat< real_t > &mat, uint_t power)
Definition markov_chain.cpp:22
void print_matrix(const DynMat< real_t > &mat)
Definition markov_chain.cpp:35
DynMat< real_t > create_transition_matrix()
Definition markov_chain.cpp:19