xerus
a general purpose tensor library
measurments.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 <set>
28 #include <random>
29 #include <functional>
30 
31 #include "basic.h"
32 
33 #include "misc/math.h"
34 #include "misc/containerSupport.h"
35 
36 namespace xerus {
37  class Tensor;
38  class TensorNetwork;
39 
44  public:
45  std::vector<std::vector<size_t>> positions;
46  std::vector<value_t> measuredValues;
47 
48  SinglePointMeasurementSet() = default;
51 
54 
55  static SinglePointMeasurementSet random(const size_t _numMeasurements, const std::vector<size_t>& _dimensions);
56 
57  static SinglePointMeasurementSet random(const size_t _numMeasurements, const Tensor& _solution);
58 
59  static SinglePointMeasurementSet random(const size_t _numMeasurements, const TensorNetwork& _solution);
60 
61  static SinglePointMeasurementSet random(const size_t _numMeasurements, const std::vector<size_t>& _dimensions, std::function<value_t(const std::vector<size_t>&)> _callback);
62 
63 
64  size_t size() const;
65 
66  size_t degree() const;
67 
68  value_t frob_norm() const;
69 
70  void add(std::vector<size_t> _position, const value_t _measuredValue);
71 
72  void sort(const bool _positionsOnly = false);
73 
74 
75  void measure(const Tensor& _solution);
76 
77  void measure(const TensorNetwork& _solution);
78 
79  void measure(std::function<value_t(const std::vector<size_t>&)> _callback);
80 
81 
82  double test(const Tensor& _solution) const;
83 
84  double test(const TensorNetwork& _solution) const;
85 
86  double test(std::function<value_t(const std::vector<size_t>&)> _callback) const;
87 
88 
89  private:
90  void create_random_positions(const size_t _numMeasurements, const std::vector<size_t>& _dimensions);
91  };
92 
93 
95  public:
96  std::vector<std::vector<Tensor>> positions;
97  std::vector<value_t> measuredValues;
98 
99  RankOneMeasurementSet() = default;
100  RankOneMeasurementSet(const RankOneMeasurementSet& _other) = default;
101  RankOneMeasurementSet( RankOneMeasurementSet&& _other) = default;
102 
103  RankOneMeasurementSet(const SinglePointMeasurementSet& _other, const std::vector<size_t> &_dimensions);
104 
105  RankOneMeasurementSet& operator=(const RankOneMeasurementSet& _other) = default;
107 
108  static RankOneMeasurementSet random(const size_t _numMeasurements, const std::vector<size_t>& _dimensions);
109 
110  static RankOneMeasurementSet random(const size_t _numMeasurements, const Tensor& _solution);
111 
112  static RankOneMeasurementSet random(const size_t _numMeasurements, const TensorNetwork& _solution);
113 
114  static RankOneMeasurementSet random(const size_t _numMeasurements, const std::vector<size_t>& _dimensions, std::function<value_t(const std::vector<Tensor>&)> _callback);
115 
116 
117  size_t size() const;
118 
119  size_t degree() const;
120 
121  value_t frob_norm() const;
122 
123  void add(const std::vector<Tensor>& _position, const value_t _measuredValue);
124 
125  void sort(const bool _positionsOnly);
126 
127  void normalize();
128 
129 
130  void measure(const Tensor& _solution);
131 
132  void measure(const TensorNetwork& _solution);
133 
134  void measure(std::function<value_t(const std::vector<Tensor>&)> _callback);
135 
136 
137  double test(const Tensor& _solution) const;
138 
139  double test(const TensorNetwork& _solution) const;
140 
141  double test(std::function<value_t(const std::vector<Tensor>&)> _callback) const;
142 
143 
144  private:
145  void create_random_positions(const size_t _numMeasurements, const std::vector<size_t>& _dimensions);
146  };
147 
148  namespace internal {
149  int comp(const Tensor& _a, const Tensor& _b);
150  }
151 }
Header file for some additional math functions.
void sort(const bool _positionsOnly=false)
Definition: measurments.cpp:89
double test(const Tensor &_solution) const
Header file for the standard contaienr support functions.
Very general class used to represent arbitary tensor networks.
Definition: tensorNetwork.h:42
Class used to represent a single point measurments.
Definition: measurments.h:43
The main namespace of xerus.
Definition: basic.h:37
Class that handles simple (non-decomposed) tensors in a dense or sparse representation.
Definition: tensor.h:70
std::vector< value_t > measuredValues
Definition: measurments.h:97
SinglePointMeasurementSet & operator=(const SinglePointMeasurementSet &_other)=default
std::vector< std::vector< Tensor > > positions
Definition: measurments.h:96
int comp(const Tensor &_a, const Tensor &_b)
Header file for shorthand notations that are xerus specific but used throughout the library...
double value_t
The type of values to be used by xerus.
Definition: basic.h:43
std::vector< std::vector< size_t > > positions
Definition: measurments.h:45
static SinglePointMeasurementSet random(const size_t _numMeasurements, const std::vector< size_t > &_dimensions)
Definition: measurments.cpp:42
void measure(const Tensor &_solution)
void add(std::vector< size_t > _position, const value_t _measuredValue)
Definition: measurments.cpp:83
std::vector< value_t > measuredValues
Definition: measurments.h:46