9 #ifndef __stir_numerics_max_eigenvector_H__ 10 #define __stir_numerics_max_eigenvector_H__ 69 template <
class elemT>
75 const double tolerance = .01,
76 const unsigned long max_num_iterations = 10000UL)
82 max_eigenvector = start;
83 return Succeeded::yes;
86 const double tolerance_squared =
square(tolerance);
89 unsigned long remaining_num_iterations = max_num_iterations;
96 max_eigenvector /= norm_factor;
98 current = max_eigenvector;
99 --remaining_num_iterations;
100 }
while (change > tolerance_squared && remaining_num_iterations != 0);
102 current /=
static_cast<elemT
>(
norm(current));
106 max_eigenvector /=
static_cast<elemT
>(
norm(max_eigenvector));
108 return remaining_num_iterations == 0 ? Succeeded::no : Succeeded::yes;
128 template <
class elemT>
135 const double tolerance = .03,
136 const unsigned long max_num_iterations = 10000UL)
139 error(
"absolute_max_eigenvector_using_shifted_power_method:\n" 140 " implementation needs work for indices that don't start from 0. sorry");
150 max_eigenvalue += shift;
173 template <
class elemT>
179 const double tolerance = .03,
180 const unsigned long max_num_iterations = 10000UL)
185 if (success == Succeeded::no)
186 return Succeeded::no;
188 if (max_eigenvalue >= 0)
189 return Succeeded::yes;
198 max_eigenvalue, max_eigenvector, m, start, max_eigenvalue, tolerance, max_num_iterations);
199 if (success == Succeeded::no)
200 return Succeeded::no;
202 assert(max_eigenvalue >= 0);
203 return Succeeded::yes;
Declaration of some functions missing from std::algorithm.
Declaration of class stir::Succeeded.
Array< 1, elemT > matrix_multiply(const Array< 2, elemT > &m, const Array< 1, elemT > &vec)
matrix with vector multiplication
Definition: MatrixFunction.inl:106
int get_min_index() const
get value of first valid index
Definition: VectorWithOffset.inl:116
iterator end()
iterator 'past' the last element of the vector
Definition: VectorWithOffset.inl:198
iterT abs_max_element(iterT start, iterT end)
Like std::max_element, but comparing after taking absolute value.
Definition: more_algorithms.inl:28
Declaration of the stir::norm(), stir::norm_squared() functions and stir::NormSquared unary function...
Array< 2, elemT > diagonal_matrix(const unsigned dimension, const elemT value)
construct a diagonal matrix with all elements on the diagonal equal
Definition: MatrixFunction.inl:182
Declaration of stir::error()
iterator begin()
use to initialise an iterator to the first element of the vector
Definition: VectorWithOffset.inl:182
Succeeded absolute_max_eigenvector_using_power_method(elemT &max_eigenvalue, Array< 1, elemT > &max_eigenvector, const Array< 2, elemT > &m, const Array< 1, elemT > &start, const double tolerance=.01, const unsigned long max_num_iterations=10000UL)
Compute the eigenvalue with the largest absolute value and corresponding eigenvector of a matrix by u...
Definition: max_eigenvector.h:71
double norm_squared(const BasicCoordinate< num_dimensions, coordT > &p1)
compute (inner_product(p1,p1))
Definition: BasicCoordinate.inl:415
coordT inner_product(const BasicCoordinate< num_dimensions, coordT > &p1, const BasicCoordinate< num_dimensions, coordT > &p2)
compute sum_i p1[i] * p2[i]
Definition: BasicCoordinate.inl:408
NUMBER square(const NUMBER &x)
returns the square of a number, templated.
Definition: common.h:146
The 1-dimensional (partial) specialisation of Array.
Definition: Array.h:339
double norm(const BasicCoordinate< num_dimensions, coordT > &p1)
compute sqrt(inner_product(p1,p1))
Definition: BasicCoordinate.inl:426
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
Succeeded absolute_max_eigenvector_using_shifted_power_method(elemT &max_eigenvalue, Array< 1, elemT > &max_eigenvector, const Array< 2, elemT > &m, const Array< 1, elemT > &start, const elemT shift, const double tolerance=.03, const unsigned long max_num_iterations=10000UL)
Compute the eigenvalue with the largest absolute value and corresponding eigenvector of a matrix by u...
Definition: max_eigenvector.h:130
size_t size() const
return number of elements in this vector
Definition: VectorWithOffset.inl:542
Declaration of functions for matrices.
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
bool is_regular() const
checks if the index range is 'regular'
Definition: Array.inl:446
Succeeded max_eigenvector_using_power_method(elemT &max_eigenvalue, Array< 1, elemT > &max_eigenvector, const Array< 2, elemT > &m, const Array< 1, elemT > &start, const double tolerance=.03, const unsigned long max_num_iterations=10000UL)
Compute the eigenvalue with the largest value and corresponding eigenvector of a matrix by using the ...
Definition: max_eigenvector.h:175