xerus
a general purpose tensor library
xerus::ADFVariant::InternalSolver< MeasurmentSet > Class Template Reference

#include <adf.h>

Collaboration diagram for xerus::ADFVariant::InternalSolver< MeasurmentSet >:

Public Member Functions

 InternalSolver (TTTensor &_x, const std::vector< size_t > &_maxRanks, const MeasurmentSet &_measurments, const size_t _maxIteration, const double _targetResidualNorm, const double _minimalResidualNormDecrease, PerformanceData &_perfData)
 
double solve ()
 Tries to solve the reconstruction problem with the current settings. More...
 

Protected Member Functions

void calculate_projected_gradient (const size_t _corePosition)
 : Calculates the component at _corePosition of the projected gradient from the residual, i.e. E(A^T(b-Ax)). More...
 
void calculate_residual (const size_t _corePosition)
 (Re-)Calculates the current residual, i.e. Ax-b. More...
 
std::vector< value_tcalculate_slicewise_norm_A_projGrad (const size_t _corePosition)
 : Calculates ||P_n (A(E(A^T(b-Ax)))))|| = ||P_n (A(E(A^T(residual)))))|| = ||P_n (A(E(gradient)))|| for each n, where P_n sets all entries equals zero except where the index at _corePosition is equals n. In case of RankOneMeasurments, the calculation is not slicewise (only n=0 is set). More...
 
void construct_stacks (std::unique_ptr< xerus::Tensor[] > &_stackSaveSlot, std::vector< std::vector< size_t > > &_updates, const std::unique_ptr< Tensor *[]> &_stackMem, const bool _forward)
 Constructes either the forward or backward stack. That is, it determines the groups of partially equale measurments. Therby stetting (forward/backward)- Updates, StackMem and SaveSlot. More...
 
std::vector< Tensorget_fixed_components (const Tensor &_component)
 Returns a vector of tensors containing the slices of _component where the second dimension is fixed. More...
 
template<class PositionType >
void perform_dyadic_product (const size_t _localLeftRank, const size_t _localRightRank, const value_t *const _leftPtr, const value_t *const _rightPtr, value_t *const _deltaPtr, const value_t _residual, const PositionType &_position, value_t *const _scratchSpace)
 Calculates one internal step of calculate_projected_gradient. In particular the dyadic product of the leftStack, the rightStack and the position vector. More...
 
template<>
void perform_dyadic_product (const size_t _localLeftRank, const size_t _localRightRank, const value_t *const _leftPtr, const value_t *const _rightPtr, value_t *const _deltaPtr, const value_t _residual, const size_t &_position, value_t *const)
 
template<>
void perform_dyadic_product (const size_t _localLeftRank, const size_t _localRightRank, const value_t *const _leftPtr, const value_t *const _rightPtr, value_t *const _deltaPtr, const value_t _residual, const Tensor &_position, value_t *const _scratchSpace)
 
void resize_stack_tensors ()
 Resizes the unqiue stack tensors to correspond to the current ranks of x. More...
 
void solve_with_current_ranks ()
 Basically the complete algorithm, trying to reconstruct x using its current ranks. More...
 
void update_backward_stack (const size_t _corePosition, const Tensor &_currentComponent)
 For each measurment sets the backwardStack at the given _corePosition to the contraction between the backwardStack at the previous corePosition (i.e. +1) and the given component contracted with the component of the measurment operator. For _corePosition == corePosition and _currentComponent == x.components(corePosition) this really updates the stack, otherwise it uses the stack as scratch space. More...
 
template<>
void update_backward_stack (const size_t _corePosition, const Tensor &_currentComponent)
 
template<>
void update_backward_stack (const size_t _corePosition, const Tensor &_currentComponent)
 
void update_forward_stack (const size_t _corePosition, const Tensor &_currentComponent)
 For each measurment sets the forwardStack at the given _corePosition to the contraction between the forwardStack at the previous corePosition (i.e. -1) and the given component contracted with the component of the measurment operator. For _corePosition == corePosition and _currentComponent == x.components(corePosition) this really updates the stack, otherwise it uses the stack as scratch space. More...
 
template<>
void update_forward_stack (const size_t _corePosition, const Tensor &_currentComponent)
 
template<>
void update_forward_stack (const size_t _corePosition, const Tensor &_currentComponent)
 
void update_x (const std::vector< value_t > &_normAProjGrad, const size_t _corePosition)
 Updates the current solution x. For SinglePointMeasurments the is done for each slice speratly, for RankOneMeasurments there is only one combined update. More...
 
template<>
void update_x (const std::vector< value_t > &_normAProjGrad, const size_t _corePosition)
 
template<>
void update_x (const std::vector< value_t > &_normAProjGrad, const size_t _corePosition)
 

Static Protected Member Functions

static double calculate_norm_of_measured_values (const MeasurmentSet &_measurments)
 calculates the two-norm of the measured values. More...
 

Protected Attributes

Tensor *const *const backwardStack
 Array [numMeasurments][degree]. For positions larger than the current corePosition and for each measurment, this array contains the pre-computed contraction of the last _ component tensors and the last _ components of the measurment operator. These tensors are deduplicated in the sense that for each unqiue part of the position only one tensor is actually stored, which is why the is an array of pointers. The Tensors at the current corePosition are used as scratch space. For convinience the underlying array (forwardStackMem) is larger, wherefore also the positions -1 and degree are allow, all poining to a {1} tensor containing 1 as only entry. Note that position zero must not be used. More...
 
std::unique_ptr< Tensor *[]> backwardStackMem
 Ownership holder for a (degree+2)*numMeasurments array of Tensor pointers. (Not used directly) More...
 
std::unique_ptr< Tensor[]> backwardStackSaveSlots
 Ownership holder for the unqiue Tensors referenced in backwardStack. More...
 
std::vector< std::vector< size_t > > backwardUpdates
 Vector containing for each corePosition a vector of the smallest ids of each group of unique backwardStack entries. More...
 
const size_t degree
 Degree of the solution. More...
 
Tensor *const *const forwardStack
 Array [numMeasurments][degree]. For positions smaller than the current corePosition and for each measurment, this array contains the pre-computed contraction of the first _ component tensors and the first _ components of the measurment operator. These tensors are deduplicated in the sense that for each unqiue part of the position only one tensor is actually stored, which is why the is an array of pointers. The Tensors at the current corePosition are used as scatch space. For convinience the underlying array (forwardStackMem) is larger, wherefore also the positions -1 and degree are allow, all poining to a {1} tensor containing 1 as only entry. Note that position degree-1 must not be used. More...
 
std::unique_ptr< Tensor *[]> forwardStackMem
 Ownership holder for a (degree+2)*numMeasurments array of Tensor pointers. (Not used directly) More...
 
std::unique_ptr< Tensor[]> forwardStackSaveSlots
 Ownership holder for the unqiue Tensors referenced in forwardStack. More...
 
std::vector< std::vector< size_t > > forwardUpdates
 Vector containing for each corePosition a vector of the smallest ids of each group of unique forwardStack entries. More...
 
const Index i1
 
size_t iteration
 The current iteration. More...
 
double lastResidualNorm
 The residual norm of the last iteration. More...
 
const size_t maxIterations
 Maximal allowed number of iterations (one iteration = one sweep) More...
 
const std::vector< size_t > maxRanks
 Maximally allowed ranks. More...
 
std::unique_ptr< double[]> measurmentNorms
 : Norm of each rank one measurment operator More...
 
const MeasurmentSet & measurments
 Reference to the measurment set (external ownership) More...
 
const double minimalResidualNormDecrease
 Minimal relative decrease of the residual norm ( (oldRes-newRes)/oldRes ) until either the ranks are increased (if allowed) or the algorithm stops. More...
 
const value_t normMeasuredValues
 The two norm of the measured values. More...
 
const size_t numMeasurments
 Number of measurments (i.e. measurments.size()) More...
 
PerformanceDataperfData
 : Reference to the performanceData object (external ownership) More...
 
Tensor projectedGradientComponent
 The current projected Gradient component. That is E(A^T(Ax-b)) More...
 
const Index r1
 Indices for all internal functions. More...
 
const Index r2
 
std::vector< value_tresidual
 The current residual, saved as vector (instead of a order one tensor). More...
 
double residualNorm
 Current residual norm. Updated at the beginning of each iteration. More...
 
const double targetResidualNorm
 The target residual norm at which the algorithm shall stop. More...
 
TTTensorx
 Reference to the current solution (external ownership) More...
 

Detailed Description

template<class MeasurmentSet>
class xerus::ADFVariant::InternalSolver< MeasurmentSet >

Definition at line 43 of file adf.h.

Constructor & Destructor Documentation

◆ InternalSolver()

template<class MeasurmentSet>
xerus::ADFVariant::InternalSolver< MeasurmentSet >::InternalSolver ( TTTensor _x,
const std::vector< size_t > &  _maxRanks,
const MeasurmentSet &  _measurments,
const size_t  _maxIteration,
const double  _targetResidualNorm,
const double  _minimalResidualNormDecrease,
PerformanceData _perfData 
)
inline

Definition at line 188 of file adf.h.

Member Function Documentation

◆ calculate_norm_of_measured_values()

template<class MeasurmentSet >
double xerus::ADFVariant::InternalSolver< MeasurmentSet >::calculate_norm_of_measured_values ( const MeasurmentSet &  _measurments)
staticprotected

calculates the two-norm of the measured values.

Definition at line 37 of file adf.cpp.

◆ calculate_projected_gradient()

template<class MeasurmentSet >
void xerus::ADFVariant::InternalSolver< MeasurmentSet >::calculate_projected_gradient ( const size_t  _corePosition)
inlineprotected

: Calculates the component at _corePosition of the projected gradient from the residual, i.e. E(A^T(b-Ax)).

Definition at line 360 of file adf.cpp.

◆ calculate_residual()

template<class MeasurmentSet >
void xerus::ADFVariant::InternalSolver< MeasurmentSet >::calculate_residual ( const size_t  _corePosition)
protected

(Re-)Calculates the current residual, i.e. Ax-b.

Definition at line 291 of file adf.cpp.

◆ calculate_slicewise_norm_A_projGrad()

template<class MeasurmentSet >
std::vector< value_t > xerus::ADFVariant::InternalSolver< MeasurmentSet >::calculate_slicewise_norm_A_projGrad ( const size_t  _corePosition)
protected

: Calculates ||P_n (A(E(A^T(b-Ax)))))|| = ||P_n (A(E(A^T(residual)))))|| = ||P_n (A(E(gradient)))|| for each n, where P_n sets all entries equals zero except where the index at _corePosition is equals n. In case of RankOneMeasurments, the calculation is not slicewise (only n=0 is set).

measurmentNorms[i]

measurmentNorms[i]

Definition at line 414 of file adf.cpp.

◆ construct_stacks()

template<class MeasurmentSet>
void xerus::ADFVariant::InternalSolver< MeasurmentSet >::construct_stacks ( std::unique_ptr< xerus::Tensor[] > &  _stackSaveSlot,
std::vector< std::vector< size_t > > &  _updates,
const std::unique_ptr< Tensor *[]> &  _stackMem,
const bool  _forward 
)
protected

Constructes either the forward or backward stack. That is, it determines the groups of partially equale measurments. Therby stetting (forward/backward)- Updates, StackMem and SaveSlot.

Definition at line 103 of file adf.cpp.

◆ get_fixed_components()

template<class MeasurmentSet >
std::vector< Tensor > xerus::ADFVariant::InternalSolver< MeasurmentSet >::get_fixed_components ( const Tensor _component)
protected

Returns a vector of tensors containing the slices of _component where the second dimension is fixed.

Definition at line 207 of file adf.cpp.

◆ perform_dyadic_product() [1/3]

template<class MeasurmentSet>
template<class PositionType >
void xerus::ADFVariant::InternalSolver< MeasurmentSet >::perform_dyadic_product ( const size_t  _localLeftRank,
const size_t  _localRightRank,
const value_t *const  _leftPtr,
const value_t *const  _rightPtr,
value_t *const  _deltaPtr,
const value_t  _residual,
const PositionType &  _position,
value_t *const  _scratchSpace 
)
protected

Calculates one internal step of calculate_projected_gradient. In particular the dyadic product of the leftStack, the rightStack and the position vector.

◆ perform_dyadic_product() [2/3]

template<>
void xerus::ADFVariant::InternalSolver< SinglePointMeasurementSet >::perform_dyadic_product ( const size_t  _localLeftRank,
const size_t  _localRightRank,
const value_t *const  _leftPtr,
const value_t *const  _rightPtr,
value_t *const  _deltaPtr,
const value_t  _residual,
const size_t &  _position,
value_t const 
)
inlineprotected

Definition at line 315 of file adf.cpp.

◆ perform_dyadic_product() [3/3]

template<>
void xerus::ADFVariant::InternalSolver< RankOneMeasurementSet >::perform_dyadic_product ( const size_t  _localLeftRank,
const size_t  _localRightRank,
const value_t *const  _leftPtr,
const value_t *const  _rightPtr,
value_t *const  _deltaPtr,
const value_t  _residual,
const Tensor _position,
value_t *const  _scratchSpace 
)
inlineprotected

Definition at line 334 of file adf.cpp.

◆ resize_stack_tensors()

template<class MeasurmentSet >
void xerus::ADFVariant::InternalSolver< MeasurmentSet >::resize_stack_tensors ( )
protected

Resizes the unqiue stack tensors to correspond to the current ranks of x.

Definition at line 194 of file adf.cpp.

◆ solve()

template<class MeasurmentSet >
double xerus::ADFVariant::InternalSolver< MeasurmentSet >::solve ( )

Tries to solve the reconstruction problem with the current settings.

Definition at line 567 of file adf.cpp.

◆ solve_with_current_ranks()

template<class MeasurmentSet >
void xerus::ADFVariant::InternalSolver< MeasurmentSet >::solve_with_current_ranks ( )
protected

Basically the complete algorithm, trying to reconstruct x using its current ranks.

Definition at line 490 of file adf.cpp.

◆ update_backward_stack() [1/3]

template<class MeasurmentSet>
void xerus::ADFVariant::InternalSolver< MeasurmentSet >::update_backward_stack ( const size_t  _corePosition,
const Tensor _currentComponent 
)
protected

For each measurment sets the backwardStack at the given _corePosition to the contraction between the backwardStack at the previous corePosition (i.e. +1) and the given component contracted with the component of the measurment operator. For _corePosition == corePosition and _currentComponent == x.components(corePosition) this really updates the stack, otherwise it uses the stack as scratch space.

◆ update_backward_stack() [2/3]

template<>
void xerus::ADFVariant::InternalSolver< SinglePointMeasurementSet >::update_backward_stack ( const size_t  _corePosition,
const Tensor _currentComponent 
)
protected

Definition at line 218 of file adf.cpp.

◆ update_backward_stack() [3/3]

template<>
void xerus::ADFVariant::InternalSolver< RankOneMeasurementSet >::update_backward_stack ( const size_t  _corePosition,
const Tensor _currentComponent 
)
protected

Definition at line 234 of file adf.cpp.

◆ update_forward_stack() [1/3]

template<class MeasurmentSet>
void xerus::ADFVariant::InternalSolver< MeasurmentSet >::update_forward_stack ( const size_t  _corePosition,
const Tensor _currentComponent 
)
protected

For each measurment sets the forwardStack at the given _corePosition to the contraction between the forwardStack at the previous corePosition (i.e. -1) and the given component contracted with the component of the measurment operator. For _corePosition == corePosition and _currentComponent == x.components(corePosition) this really updates the stack, otherwise it uses the stack as scratch space.

◆ update_forward_stack() [2/3]

template<>
void xerus::ADFVariant::InternalSolver< SinglePointMeasurementSet >::update_forward_stack ( const size_t  _corePosition,
const Tensor _currentComponent 
)
protected

Definition at line 255 of file adf.cpp.

◆ update_forward_stack() [3/3]

template<>
void xerus::ADFVariant::InternalSolver< RankOneMeasurementSet >::update_forward_stack ( const size_t  _corePosition,
const Tensor _currentComponent 
)
protected

Definition at line 271 of file adf.cpp.

◆ update_x() [1/3]

template<class MeasurmentSet>
void xerus::ADFVariant::InternalSolver< MeasurmentSet >::update_x ( const std::vector< value_t > &  _normAProjGrad,
const size_t  _corePosition 
)
protected

Updates the current solution x. For SinglePointMeasurments the is done for each slice speratly, for RankOneMeasurments there is only one combined update.

◆ update_x() [2/3]

template<>
void xerus::ADFVariant::InternalSolver< SinglePointMeasurementSet >::update_x ( const std::vector< value_t > &  _normAProjGrad,
const size_t  _corePosition 
)
protected

Definition at line 469 of file adf.cpp.

◆ update_x() [3/3]

template<>
void xerus::ADFVariant::InternalSolver< RankOneMeasurementSet >::update_x ( const std::vector< value_t > &  _normAProjGrad,
const size_t  _corePosition 
)
protected

Definition at line 482 of file adf.cpp.

Member Data Documentation

◆ backwardStack

template<class MeasurmentSet>
Tensor* const* const xerus::ADFVariant::InternalSolver< MeasurmentSet >::backwardStack
protected

Array [numMeasurments][degree]. For positions larger than the current corePosition and for each measurment, this array contains the pre-computed contraction of the last _ component tensors and the last _ components of the measurment operator. These tensors are deduplicated in the sense that for each unqiue part of the position only one tensor is actually stored, which is why the is an array of pointers. The Tensors at the current corePosition are used as scratch space. For convinience the underlying array (forwardStackMem) is larger, wherefore also the positions -1 and degree are allow, all poining to a {1} tensor containing 1 as only entry. Note that position zero must not be used.

Definition at line 124 of file adf.h.

◆ backwardStackMem

template<class MeasurmentSet>
std::unique_ptr<Tensor*[]> xerus::ADFVariant::InternalSolver< MeasurmentSet >::backwardStackMem
protected

Ownership holder for a (degree+2)*numMeasurments array of Tensor pointers. (Not used directly)

Definition at line 116 of file adf.h.

◆ backwardStackSaveSlots

template<class MeasurmentSet>
std::unique_ptr<Tensor[]> xerus::ADFVariant::InternalSolver< MeasurmentSet >::backwardStackSaveSlots
protected

Ownership holder for the unqiue Tensors referenced in backwardStack.

Definition at line 127 of file adf.h.

◆ backwardUpdates

template<class MeasurmentSet>
std::vector<std::vector<size_t> > xerus::ADFVariant::InternalSolver< MeasurmentSet >::backwardUpdates
protected

Vector containing for each corePosition a vector of the smallest ids of each group of unique backwardStack entries.

Definition at line 130 of file adf.h.

◆ degree

template<class MeasurmentSet>
const size_t xerus::ADFVariant::InternalSolver< MeasurmentSet >::degree
protected

Degree of the solution.

Definition at line 59 of file adf.h.

◆ forwardStack

template<class MeasurmentSet>
Tensor* const* const xerus::ADFVariant::InternalSolver< MeasurmentSet >::forwardStack
protected

Array [numMeasurments][degree]. For positions smaller than the current corePosition and for each measurment, this array contains the pre-computed contraction of the first _ component tensors and the first _ components of the measurment operator. These tensors are deduplicated in the sense that for each unqiue part of the position only one tensor is actually stored, which is why the is an array of pointers. The Tensors at the current corePosition are used as scatch space. For convinience the underlying array (forwardStackMem) is larger, wherefore also the positions -1 and degree are allow, all poining to a {1} tensor containing 1 as only entry. Note that position degree-1 must not be used.

Definition at line 106 of file adf.h.

◆ forwardStackMem

template<class MeasurmentSet>
std::unique_ptr<Tensor*[]> xerus::ADFVariant::InternalSolver< MeasurmentSet >::forwardStackMem
protected

Ownership holder for a (degree+2)*numMeasurments array of Tensor pointers. (Not used directly)

Definition at line 98 of file adf.h.

◆ forwardStackSaveSlots

template<class MeasurmentSet>
std::unique_ptr<Tensor[]> xerus::ADFVariant::InternalSolver< MeasurmentSet >::forwardStackSaveSlots
protected

Ownership holder for the unqiue Tensors referenced in forwardStack.

Definition at line 109 of file adf.h.

◆ forwardUpdates

template<class MeasurmentSet>
std::vector<std::vector<size_t> > xerus::ADFVariant::InternalSolver< MeasurmentSet >::forwardUpdates
protected

Vector containing for each corePosition a vector of the smallest ids of each group of unique forwardStack entries.

Definition at line 112 of file adf.h.

◆ i1

template<class MeasurmentSet>
const Index xerus::ADFVariant::InternalSolver< MeasurmentSet >::i1
protected

Definition at line 53 of file adf.h.

◆ iteration

template<class MeasurmentSet>
size_t xerus::ADFVariant::InternalSolver< MeasurmentSet >::iteration
protected

The current iteration.

Definition at line 83 of file adf.h.

◆ lastResidualNorm

template<class MeasurmentSet>
double xerus::ADFVariant::InternalSolver< MeasurmentSet >::lastResidualNorm
protected

The residual norm of the last iteration.

Definition at line 89 of file adf.h.

◆ maxIterations

template<class MeasurmentSet>
const size_t xerus::ADFVariant::InternalSolver< MeasurmentSet >::maxIterations
protected

Maximal allowed number of iterations (one iteration = one sweep)

Definition at line 74 of file adf.h.

◆ maxRanks

template<class MeasurmentSet>
const std::vector<size_t> xerus::ADFVariant::InternalSolver< MeasurmentSet >::maxRanks
protected

Maximally allowed ranks.

Definition at line 62 of file adf.h.

◆ measurmentNorms

template<class MeasurmentSet>
std::unique_ptr<double[]> xerus::ADFVariant::InternalSolver< MeasurmentSet >::measurmentNorms
protected

: Norm of each rank one measurment operator

Definition at line 133 of file adf.h.

◆ measurments

template<class MeasurmentSet>
const MeasurmentSet& xerus::ADFVariant::InternalSolver< MeasurmentSet >::measurments
protected

Reference to the measurment set (external ownership)

Definition at line 65 of file adf.h.

◆ minimalResidualNormDecrease

template<class MeasurmentSet>
const double xerus::ADFVariant::InternalSolver< MeasurmentSet >::minimalResidualNormDecrease
protected

Minimal relative decrease of the residual norm ( (oldRes-newRes)/oldRes ) until either the ranks are increased (if allowed) or the algorithm stops.

Definition at line 80 of file adf.h.

◆ normMeasuredValues

template<class MeasurmentSet>
const value_t xerus::ADFVariant::InternalSolver< MeasurmentSet >::normMeasuredValues
protected

The two norm of the measured values.

Definition at line 71 of file adf.h.

◆ numMeasurments

template<class MeasurmentSet>
const size_t xerus::ADFVariant::InternalSolver< MeasurmentSet >::numMeasurments
protected

Number of measurments (i.e. measurments.size())

Definition at line 68 of file adf.h.

◆ perfData

template<class MeasurmentSet>
PerformanceData& xerus::ADFVariant::InternalSolver< MeasurmentSet >::perfData
protected

: Reference to the performanceData object (external ownership)

Definition at line 136 of file adf.h.

◆ projectedGradientComponent

template<class MeasurmentSet>
Tensor xerus::ADFVariant::InternalSolver< MeasurmentSet >::projectedGradientComponent
protected

The current projected Gradient component. That is E(A^T(Ax-b))

Definition at line 95 of file adf.h.

◆ r1

template<class MeasurmentSet>
const Index xerus::ADFVariant::InternalSolver< MeasurmentSet >::r1
protected

Indices for all internal functions.

Definition at line 53 of file adf.h.

◆ r2

template<class MeasurmentSet>
const Index xerus::ADFVariant::InternalSolver< MeasurmentSet >::r2
protected

Definition at line 53 of file adf.h.

◆ residual

template<class MeasurmentSet>
std::vector<value_t> xerus::ADFVariant::InternalSolver< MeasurmentSet >::residual
protected

The current residual, saved as vector (instead of a order one tensor).

Definition at line 92 of file adf.h.

◆ residualNorm

template<class MeasurmentSet>
double xerus::ADFVariant::InternalSolver< MeasurmentSet >::residualNorm
protected

Current residual norm. Updated at the beginning of each iteration.

Definition at line 86 of file adf.h.

◆ targetResidualNorm

template<class MeasurmentSet>
const double xerus::ADFVariant::InternalSolver< MeasurmentSet >::targetResidualNorm
protected

The target residual norm at which the algorithm shall stop.

Definition at line 77 of file adf.h.

◆ x

template<class MeasurmentSet>
TTTensor& xerus::ADFVariant::InternalSolver< MeasurmentSet >::x
protected

Reference to the current solution (external ownership)

Definition at line 56 of file adf.h.


The documentation for this class was generated from the following files: