28 #include "../ttNetwork.h" 29 #include "../performanceData.h" 30 #include "../measurments.h" 42 template<
class MeasurmentSet>
142 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);
164 template<
class PositionType>
179 void update_x(
const std::vector<value_t>& _normAProjGrad,
const size_t _corePosition);
189 const std::vector<size_t>& _maxRanks,
190 const MeasurmentSet& _measurments,
191 const size_t _maxIteration,
192 const double _targetResidualNorm,
193 const double _minimalResidualNormDecrease,
197 maxRanks(
TTTensor::reduce_to_maximal_ranks(_maxRanks, _x.dimensions)),
199 measurments(_measurments),
200 numMeasurments(_measurments.size()),
203 maxIterations(_maxIteration),
204 targetResidualNorm(_targetResidualNorm),
205 minimalResidualNormDecrease(_minimalResidualNormDecrease),
208 residualNorm(
std::numeric_limits<double>::max()),
209 lastResidualNorm(
std::numeric_limits<double>::max()),
211 residual(numMeasurments),
213 forwardStackMem(new
Tensor*[numMeasurments*(degree+2)]),
214 forwardStack(forwardStackMem.get()+numMeasurments),
215 forwardUpdates(degree),
217 backwardStackMem(new
Tensor*[numMeasurments*(degree+2)]),
218 backwardStack(backwardStackMem.get()+numMeasurments),
219 backwardUpdates(degree),
221 measurmentNorms(new double[numMeasurments]),
226 XERUS_REQUIRE(numMeasurments > 0,
"Need at very least one measurment.");
227 XERUS_REQUIRE(measurments.degree() ==
degree,
"Measurment degree must coincide with x degree.");
238 ADFVariant(
const size_t _maxIteration,
const double _targetResidual,
const double _minimalResidualDecrease)
239 : maxIterations(_maxIteration), targetResidualNorm(_targetResidual), minimalResidualNormDecrease(_minimalResidualDecrease) { }
248 template<
class MeasurmentSet>
251 return solver.
solve();
262 template<
class MeasurmentSet>
264 InternalSolver<MeasurmentSet> solver(_x, _maxRanks, _measurments, maxIterations, targetResidualNorm, minimalResidualNormDecrease, _perfData);
265 return solver.
solve();
double residualNorm
Current residual norm. Updated at the beginning of each iteration.
std::unique_ptr< Tensor *[]> backwardStackMem
Ownership holder for a (degree+2)*numMeasurments array of Tensor pointers. (Not used directly) ...
std::vector< Tensor > get_fixed_components(const Tensor &_component)
Returns a vector of tensors containing the slices of _component where the second dimension is fixed...
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 ...
std::vector< value_t > residual
The current residual, saved as vector (instead of a order one tensor).
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 f...
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 equa...
PerformanceData & perfData
: Reference to the performanceData object (external ownership)
void solve_with_current_ranks()
Basically the complete algorithm, trying to reconstruct x using its current ranks.
std::vector< std::vector< size_t > > forwardUpdates
Vector containing for each corePosition a vector of the smallest ids of each group of unique forwardS...
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)).
double targetResidualNorm
Target residual. The algorithm will stop upon reaching a residual smaller than this value...
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...
The main namespace of xerus.
Class that handles simple (non-decomposed) tensors in a dense or sparse representation.
double solve()
Tries to solve the reconstruction problem with the current settings.
const double minimalResidualNormDecrease
Minimal relative decrease of the residual norm ( (oldRes-newRes)/oldRes ) until either the ranks are ...
Tensor *const *const backwardStack
Array [numMeasurments][degree]. For positions larger than the current corePosition and for each measu...
const size_t degree
Degree of the solution.
Wrapper class for all ADF variants.
const ADFVariant ADF
Default variant of the ADF algorithm.
size_t iteration
The current iteration.
Tensor *const *const forwardStack
Array [numMeasurments][degree]. For positions smaller than the current corePosition and for each meas...
std::unique_ptr< Tensor[]> forwardStackSaveSlots
Ownership holder for the unqiue Tensors referenced in forwardStack.
std::vector< size_t > ranks() const
Gets the ranks of the TTNetwork.
std::vector< value_t > calculate_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)))|| f...
std::unique_ptr< Tensor *[]> forwardStackMem
Ownership holder for a (degree+2)*numMeasurments array of Tensor pointers. (Not used directly) ...
void calculate_residual(const size_t _corePosition)
(Re-)Calculates the current residual, i.e. Ax-b.
std::unique_ptr< double[]> measurmentNorms
: Norm of each rank one measurment operator
const std::vector< size_t > maxRanks
Maximally allowed ranks.
double operator()(TTTensor &_x, const MeasurmentSet &_measurments, const std::vector< size_t > &_maxRanks, PerformanceData &_perfData) const
Tries to reconstruct the (low rank) tensor _x from the given measurments.
double minimalResidualNormDecrease
InternalSolver(TTTensor &_x, const std::vector< size_t > &_maxRanks, const MeasurmentSet &_measurments, const size_t _maxIteration, const double _targetResidualNorm, const double _minimalResidualNormDecrease, PerformanceData &_perfData)
#define XERUS_REQUIRE(condition, message)
Checks whether condition is true. logs an error otherwise via XERUS_LOG(error, message).
const double targetResidualNorm
The target residual norm at which the algorithm shall stop.
double operator()(TTTensor &_x, const MeasurmentSet &_measurments, PerformanceData &_perfData) const
Tries to reconstruct the (low rank) tensor _x from the given measurments.
const value_t normMeasuredValues
The two norm of the measured values.
double value_t
The type of values to be used by xerus.
std::vector< std::vector< size_t > > backwardUpdates
Vector containing for each corePosition a vector of the smallest ids of each group of unique backward...
const size_t numMeasurments
Number of measurments (i.e. measurments.size())
virtual void require_correct_format() const override
Tests whether the network resembles that of a TTTensor and checks consistency with the underlying ten...
void resize_stack_tensors()
Resizes the unqiue stack tensors to correspond to the current ranks of x.
ADFVariant(const size_t _maxIteration, const double _targetResidual, const double _minimalResidualDecrease)
fully defining constructor. alternatively ALSVariants can be created by copying a predefined variant ...
Class used to represent indices that can be used to write tensor calculations in index notation...
static double calculate_norm_of_measured_values(const MeasurmentSet &_measurments)
calculates the two-norm of the measured values.
const MeasurmentSet & measurments
Reference to the measurment set (external ownership)
size_t maxIterations
Maximum number of sweeps to perform. Set to 0 for infinite.
std::unique_ptr< Tensor[]> backwardStackSaveSlots
Ownership holder for the unqiue Tensors referenced in backwardStack.
double lastResidualNorm
The residual norm of the last iteration.
const size_t maxIterations
Maximal allowed number of iterations (one iteration = one sweep)
Tensor projectedGradientComponent
The current projected Gradient component. That is E(A^T(Ax-b))
const Index r1
Indices for all internal functions.
TTTensor & x
Reference to the current solution (external ownership)
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...