Commit e50fce5f authored by Wolf's avatar Wolf

Minor adjustments

parent fa1beb95
Pipeline #891 passed with stages
in 8 minutes and 39 seconds
......@@ -33,32 +33,30 @@
namespace xerus {
void decomposition_als(TTTensor& _x, const Tensor& _b, const double _eps, const size_t _maxIterations) {
void decomposition_als(TTTensor& _x, const Tensor& _b, const double _eps, const size_t _numHalfSweeps) {
Index k, iU, iX, iL, rU, rL;
Tensor newXi;
double lastResidual = frob_norm(Tensor(_x) - _b);
// LOG(bla, "Initial residual " << lastResidual);
for(size_t iteration = 0; iteration < _maxIterations; ++iteration) {
for(size_t iteration = 0; iteration < _numHalfSweeps; iteration += 2) {
// Move right
for(size_t pos = 0; pos < _x.degree(); ++pos) { XERUS_REQUIRE_TEST;
// LOG(bla, "Optimizing position " << pos);
_x.move_core(pos);
std::pair<TensorNetwork, TensorNetwork> split = _x.chop(pos);
_x.component(pos)(rU, iX, rL) = split.first(iU&1, rU)*split.second(rL, iL&1)*_b(iU^pos, iX, iL&(pos+1));
}
// Move left
for(size_t pos = _x.degree()-2; pos > 0; --pos) { XERUS_REQUIRE_TEST;
// LOG(bla, "Optimizing position " << pos);
_x.move_core(pos);
std::pair<TensorNetwork, TensorNetwork> split = _x.chop(pos);
_x.component(pos)(rU, iX, rL) = split.first(iU&1, rU)*split.second(rL, iL&1)*_b(iU^pos, iX, iL&(pos+1));
if(iteration+1 < _numHalfSweeps) {
for(size_t pos = _x.degree()-2; pos > 0; --pos) { XERUS_REQUIRE_TEST;
_x.move_core(pos);
std::pair<TensorNetwork, TensorNetwork> split = _x.chop(pos);
_x.component(pos)(rU, iX, rL) = split.first(iU&1, rU)*split.second(rL, iL&1)*_b(iU^pos, iX, iL&(pos+1));
}
}
double residual = frob_norm(Tensor(_x) - _b);
// LOG(bla, "New residual " << residual << ", residual change " << (lastResidual-residual)/residual);
if(residual < EPSILON || (lastResidual-residual)/residual < _eps) { return; }
lastResidual = residual;
}
......
......@@ -112,5 +112,7 @@ TTTensor randomTTSVD(const Tensor& _x, const std::vector<size_t>& _ranks, const
return ttX;
}
} // namespace xerus
......@@ -45,7 +45,7 @@ namespace xerus { namespace uq { namespace impl_uqRaAdf {
const size_t d;
const double targetResidual;
const size_t maxRank = 40;
const size_t maxRank = 50;
const double minRankEps = 1e-8;
const double epsDecay = 0.8;
......
......@@ -1300,9 +1300,10 @@ namespace xerus {
const Tensor& componentA = _A.get_component(i);
const Tensor& componentB = _B.get_component(i);
const Tensor::Representation newRep = componentA.is_sparse() && componentB.is_sparse() ? Tensor::Representation::Sparse : Tensor::Representation::Dense;
Tensor newComponent(isOperator ?
Tensor::DimensionTuple({componentA.dimensions.front()*componentB.dimensions.front(), componentA.dimensions[1], componentA.dimensions[2], componentA.dimensions.back()*componentB.dimensions.back()}) :
Tensor::DimensionTuple({componentA.dimensions.front()*componentB.dimensions.front(), componentA.dimensions[1], componentA.dimensions.back()*componentB.dimensions.back()}), newRep);
Tensor newComponent(isOperator ?
Tensor::DimensionTuple({componentA.dimensions.front()*componentB.dimensions.front(), componentA.dimensions[1], componentA.dimensions[2], componentA.dimensions.back()*componentB.dimensions.back()}) :
Tensor::DimensionTuple({componentA.dimensions.front()*componentB.dimensions.front(), componentA.dimensions[1], componentA.dimensions.back()*componentB.dimensions.back()}),
newRep);
perform_component_product<isOperator>(newComponent, componentA, componentB);
......
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