Commit fecee9e9 authored by Sebastian Wolf's avatar Sebastian Wolf

Reworked rank adaptive (non UQ) ASD

parent e50fce5f
Pipeline #892 passed with stages
in 9 minutes
......@@ -58,6 +58,7 @@
#include "xerus/algorithms/cg.h"
#include "xerus/algorithms/decompositionAls.h"
#include "xerus/algorithms/adf.h"
#include "xerus/algorithms/asd.h"
#include "xerus/algorithms/iht.h"
#include "xerus/algorithms/largestEntry.h"
#include "xerus/algorithms/randomSVD.h"
......
// Xerus - A General Purpose Tensor Library
// Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
//
// Xerus is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// Xerus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Xerus. If not, see <http://www.gnu.org/licenses/>.
//
// For further information on Xerus visit https://libXerus.org
// or contact us at contact@libXerus.org.
/**
* @file
* @brief Header file for the ADF algorithm and its variants.
*/
#pragma once
#include "optimizationAlgorithm.h"
#include "../ttNetwork.h"
#include "../performanceData.h"
#include "../measurments.h"
namespace xerus {
class ASDVariant : public OptimizationAlgorithm {
public:
/// fully defining constructor. alternatively ALSVariants can be created by copying a predefined variant and modifying it
ASDVariant(const size_t _maxIteration, const double _targetResidual, const double _minimalResidualDecrease)
: OptimizationAlgorithm(_maxIteration, _targetResidual, _minimalResidualDecrease) { }
/**
* @brief Tries to reconstruct the (low rank) tensor _x from the given measurments.
* @param[in,out] _x On input: an initial guess of the solution, also defining the ranks. On output: The reconstruction found by the algorithm.
* @param _measurments the available measurments, can be either a SinglePointMeasurementSet or RankOneMeasurementSet.
* @param _perfData optinal performanceData object to be used.
* @returns nothing
*/
void operator()(TTTensor& _x, const RankOneMeasurementSet& _measurments, PerformanceData& _perfData) const;
/**
* @brief Tries to reconstruct the (low rank) tensor _x from the given measurments.
* @param[in,out] _x On input: an initial guess of the solution, may be of smaller rank. On output: The reconstruction found by the algorithm.
* @param _measurments the available measurments, can be either a SinglePointMeasurementSet or RankOneMeasurementSet.
* @param _maxRanks the maximal ranks the algorithm may use to decrease the resdiual.
* @param _perfData optinal performanceData object to be used.
* @returns nothing
*/
void operator()(TTTensor& _x, const RankOneMeasurementSet& _measurments, const std::vector<size_t>& _maxRanks, PerformanceData& _perfData) const;
};
/// @brief Default variant of the ASD algorithm
extern const ASDVariant TRASD;
}
// Xerus - A General Purpose Tensor Library
// Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
//
// Xerus is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// Xerus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Xerus. If not, see <http://www.gnu.org/licenses/>.
//
// For further information on Xerus visit https://libXerus.org
// or contact us at contact@libXerus.org.
/**
* @file
* @brief Header file for the OptimizationAlgorithm class.
*/
#pragma once
#include "../performanceData.h"
namespace xerus {
/**
* @brief Base class for all xerus optimization algorithms, allowing a uniform set of settings
*/
class OptimizationAlgorithm {
public:
///@brief Maximal allowed number of iterations
const size_t maxIterations;
///@brief The target relative residual at which the algorithm shall stop.
const double targetRelativeResidual;
///@brief Minimal relative decrease of the residual norm ( newRes/oldRes ) until either the ranks are increased (if allowed) or the algorithm stops.
const double minimalResidualNormDecrease;
protected:
OptimizationAlgorithm(const size_t _maxIterations, const double _targetRelativeResidual, const double _minimalResidualNormDecrease);
};
} // namespace xerus
This diff is collapsed.
// Xerus - A General Purpose Tensor Library
// Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
//
// Xerus is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// Xerus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Xerus. If not, see <http://www.gnu.org/licenses/>.
//
// For further information on Xerus visit https://libXerus.org
// or contact us at contact@libXerus.org.
/**
* @file
* @brief Implementation of the OptimizationAlgorithm class.
*/
#include <xerus/algorithms/optimizationAlgorithm.h>
namespace xerus {
OptimizationAlgorithm::OptimizationAlgorithm(const size_t _maxIterations, const double _targetRelativeResidual, const double _minimalResidualNormDecrease) : maxIterations(_maxIterations), targetRelativeResidual(_targetRelativeResidual), minimalResidualNormDecrease(_minimalResidualNormDecrease) {}
} // namespace xerus
......@@ -146,7 +146,7 @@ namespace xerus { namespace uq { namespace impl_uqRaAdf {
outX(_x),
x(_x, 0, P),
rightStack(d, std::vector<Tensor>(N)),
leftIsStack(d, std::vector<Tensor>(N)),
leftIsStack(d, std::vector<Tensor>(N)),
leftOughtStack(d, std::vector<Tensor>(N)),
rankEps(_initalRankEps),
prevRanks(tracking+1, _x.ranks())
......@@ -172,20 +172,6 @@ namespace xerus { namespace uq { namespace impl_uqRaAdf {
} else { // _corePosition > 0
const Tensor shuffledX = reshuffle(x.get_component(_position), {1, 0, 2});
Tensor measCmp, tmp;
#pragma omp parallel for firstprivate(measCmp, tmp)
for(size_t j = 0; j < N; ++j) {
contract(measCmp, positions[_position][j], shuffledX, 1);
if(_position > 1) {
contract(tmp, measCmp, true, leftIsStack[_position-1][j], false, 1);
contract(leftIsStack[_position][j], tmp, measCmp, 1);
} else { // _corePosition == 1
contract(leftIsStack[_position][j], measCmp, true, measCmp, false, 1);
}
contract(leftOughtStack[_position][j], leftOughtStack[_position-1][j], measCmp, 1);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment