xerus
a general purpose tensor library
randomSVD.h
Go to the documentation of this file.
1
// Xerus - A General Purpose Tensor Library
2
// Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
3
//
4
// Xerus is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU Affero General Public License as published
6
// by the Free Software Foundation, either version 3 of the License,
7
// or (at your option) any later version.
8
//
9
// Xerus is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU Affero General Public License for more details.
13
//
14
// You should have received a copy of the GNU Affero General Public License
15
// along with Xerus. If not, see <http://www.gnu.org/licenses/>.
16
//
17
// For further information on Xerus visit https://libXerus.org
18
// or contact us at contact@libXerus.org.
19
25
#pragma once
26
27
#include "../ttNetwork.h"
28
29
namespace
xerus
{
30
31
// TTTensor randomTTSVD(const Tensor& _x, const std::vector<size_t>& _ranks, const std::vector<size_t>& _oversampling) {
32
// std::normal_distribution<double> dist(0, 1);
33
//
34
// const size_t d = _x.degree();
35
// TTTensor u(d);
36
// Tensor b = _x;
37
//
38
// for(size_t j = d; j >= 2; --j) {
39
// const size_t s = _ranks[j-2] + _oversampling[j-2];
40
//
41
// const std::vector<size_t> mixDims(b.dimensions.cbegin(), b.dimensions.cbegin()+(j-1));
42
//
43
// std::vector<size_t> outDims({s});
44
// outDims.insert(outDims.end(), b.dimensions.cbegin()+(j-1), b.dimensions.cend());
45
//
46
// Tensor a(outDims, Tensor::Representation::Sparse, Tensor::Initialisation::Zero);
47
//
48
// if(b.is_sparse()) {
49
// const size_t staySize = misc::product(b.dimensions, j-1, b.dimensions.size());
50
//
51
// std::map<size_t, std::vector<value_t>> usedG;
52
//
53
// const auto& data = b.get_sparse_data();
54
// for(const auto& entry : data) {
55
// const size_t pos = entry.first/staySize;
56
// const size_t outPos = entry.first%staySize;
57
//
58
// auto& gEntry = usedG[pos];
59
// if(gEntry.empty()) {
60
// gEntry.reserve(s);
61
// for(size_t k = 0; k < s; ++k) {
62
// gEntry.push_back(dist(xerus::misc::randomEngine));
63
// }
64
// }
65
//
66
// for(size_t k = 0; k < s; ++k) {
67
// a[outPos+k*staySize] += gEntry[k]*entry.second;
68
// }
69
// }
70
//
71
// } else {
72
// std::vector<size_t> gDims({s});
73
// gDims.insert(gDims.end(), mixDims.cbegin(), mixDims.cend());
74
// const Tensor g = Tensor::random(gDims, dist, xerus::misc::randomEngine);
75
// contract(a, g, false, b, false, j-1);
76
// }
77
//
78
//
79
// Tensor R, Q;
80
// calculate_rq(R, Q, a, 1);
81
//
82
//
83
// if(j == d) {
84
// contract(b, b, false, Q, true, 1);
85
// Q.reinterpret_dimensions(Q.dimensions | std::vector<size_t>({1}));
86
// u.set_component(j-1, Q);
87
// } else {
88
// contract(b, b, false, Q, true, 2);
89
// u.set_component(j-1, Q);
90
// }
91
// }
92
//
93
// b.reinterpret_dimensions(std::vector<size_t>({1}) | b.dimensions);
94
// u.set_component(0, b);
95
//
96
// u.round(_ranks);
97
//
98
// return u;
99
}
100
101
xerus
The main namespace of xerus.
Definition:
basic.h:37
include
xerus
algorithms
randomSVD.h
Generated on Wed Jul 19 2017 16:25:11 for xerus by Doxygen 1.8.13