26 #include "../../../include/xerus/misc/internal.h" 30 const size_t numMeasurments = _measurments.
size();
31 const size_t degree = _x.
degree();
32 const size_t USER_MEASUREMENTS_PER_ITR = numMeasurments;
38 std::vector<value_t> currentValues(numMeasurments);
39 std::vector<size_t> measurementOrder(numMeasurments);
40 std::iota(measurementOrder.begin(), measurementOrder.end(), 0);
44 Index i1, i2, i3, i4, i5;
49 std::vector<size_t> twoR(_x.
ranks());
50 for (
auto &r : twoR) {
58 for(
size_t iteration = 0; iteration < 1000000; ++iteration) {
61 for(
size_t i = 0; i < numMeasurments; ++i) {
62 currentValues[i] = _x[_measurments.
positions[i]];
70 value_t bestResidual = residual*2;
73 for (
value_t beta = 1/ALPHA_CHG; beta < ALPHA_CHG*1.5; beta *= ALPHA_CHG) {
75 for(
size_t d = 0; d < degree; ++d) {
77 Tensor newComp({d == 0 ? 1 : (currComp.
dimensions[0]+USER_MEASUREMENTS_PER_ITR), currComp.
dimensions[1], d == degree-1 ? 1 : (currComp.
dimensions[2]+USER_MEASUREMENTS_PER_ITR)});
80 for(
size_t r1 = 0; r1 < currComp.
dimensions[0]; ++r1) {
81 for(
size_t n = 0; n < currComp.
dimensions[1]; ++n) {
82 for(
size_t r2 = 0; r2 < currComp.
dimensions[2]; ++r2) {
83 newComp[{r1, n, r2}] = currComp[{r1, n, r2}];
90 for(
size_t i = 0; i < USER_MEASUREMENTS_PER_ITR; ++i) {
91 newComp[{0, _measurments.
positions[measurementOrder[i]][d], i+currComp.
dimensions[2]}] = beta*alpha*(_measurments.
measuredValues[measurementOrder[i]] - currentValues[measurementOrder[i]]);
93 }
else if (d!=degree-1) {
94 for(
size_t i = 0; i < USER_MEASUREMENTS_PER_ITR; ++i) {
99 for(
size_t i = 0; i < USER_MEASUREMENTS_PER_ITR; ++i) {
100 newComp[{i + currComp.
dimensions[0], _measurments.
positions[measurementOrder[i]][d], 0}] = 1.0;
109 for (
size_t o=0; o<1; ++o) {
112 std::vector<Tensor> stack;
114 for (
size_t i=degree-1; i>0; --i) {
117 stack.emplace_back(next);
121 for (
size_t i=0; i<degree; ++i) {
132 for(
size_t i = 0; i < numMeasurments; ++i) {
135 residual = std::sqrt(residual);
140 if (residual <= bestResidual) {
142 bestResidual = residual;
143 newAlpha = alpha * beta;
146 residual = bestResidual;
148 LOG(newAlpha, alpha);
150 _perfData.
add(iteration, bestResidual, _x, 0);
Tensor & component(const size_t _idx)
Complete access to a specific component of the TT decomposition.
Class used to represent a single point measurments.
DimensionTuple dimensions
Vector containing the individual dimensions of the tensor.
The main namespace of xerus.
Class that handles simple (non-decomposed) tensors in a dense or sparse representation.
static Tensor XERUS_warn_unused ones(DimensionTuple _dimensions)
: Returns a Tensor with all entries equal to one.
size_t degree() const
Gets the degree of the TensorNetwork.
void move_core(const size_t _position, const bool _keepRank=false)
Move the core to a new position.
std::vector< size_t > ranks() const
Gets the ranks of the TTNetwork.
void set_component(const size_t _idx, Tensor _T)
Sets a specific component of the TT decomposition.
Default include file for the xerus library.
double IHT(TTTensor &_x, const SinglePointMeasurementSet &_measurments, PerformanceData &_perfData=NoPerfData)
constexpr T sqr(const T &_a) noexcept
: Calculates _a*_a.
double value_t
The type of values to be used by xerus.
Class used to represent indices that can be used to write tensor calculations in index notation...
std::vector< std::vector< size_t > > positions
std::vector< value_t > measuredValues
const Tensor & get_component(const size_t _idx) const
Read access to a specific component of the TT decomposition.