Commit 3a4b9469 authored by Sebastian Wolf's avatar Sebastian Wolf

Add noise option to measurments

parent dbd34299
Pipeline #899 passed with stages
in 8 minutes and 46 seconds
......@@ -76,6 +76,8 @@ namespace xerus {
void sort(const bool _positionsOnly = false);
void add_noise(const double _epsilon);
void measure(std::vector<value_t>& _values, const Tensor& _solution) const;
// void measure(std::vector<value_t>& _values, const TTTensor& _solution) const; NICE: Minor speedup
......@@ -143,6 +145,8 @@ namespace xerus {
void normalize();
void add_noise(const double _epsilon);
void measure(std::vector<value_t>& _values, const Tensor& _solution) const;
......
......@@ -510,7 +510,7 @@ namespace xerus { namespace impl_TrASD {
void ASDVariant::operator()(TTTensor& _x, const RankOneMeasurementSet& _measurments, PerformanceData& _perfData) const {
impl_TrASD::InternalSolver<3> solver(_x, _measurments, *this, initialRankEps, _x.ranks(), _perfData);
impl_TrASD::InternalSolver<1> solver(_x, _measurments, *this, initialRankEps, _x.ranks(), _perfData);
solver.solve();
}
......
......@@ -113,6 +113,17 @@ namespace xerus {
return std::sqrt(norm);
}
void SinglePointMeasurementSet::add_noise(const double _epsilon) {
const auto cSize = size();
const auto noiseTensor = Tensor::random({size()});
const double norm = xerus::frob_norm(noiseTensor);
for(size_t i = 0; i < cSize; ++i) {
measuredValues[i] += (_epsilon/norm)*noiseTensor[i];
}
}
void SinglePointMeasurementSet::measure(std::vector<value_t>& _values, const Tensor& _solution) const {
const auto cSize = size();
......@@ -259,9 +270,6 @@ namespace xerus {
// --------------------- RankOneMeasurementSet -----------------
......@@ -383,6 +391,17 @@ namespace xerus {
}
void RankOneMeasurementSet::add_noise(const double _epsilon) {
const auto cSize = size();
const auto noiseTensor = Tensor::random({size()});
const double norm = xerus::frob_norm(noiseTensor);
for(size_t i = 0; i < cSize; ++i) {
measuredValues[i] += (_epsilon/norm)*noiseTensor[i];
}
}
void RankOneMeasurementSet::measure(std::vector<value_t>& _values, const Tensor& _solution) const {
REQUIRE(_solution.degree() == degree(), "Degrees of solution and measurements must match!");
......@@ -516,7 +535,7 @@ namespace xerus {
positions.push_back(randOnePosition);
}
measuredValues.resize(_numMeasurements, 0);
measuredValues.resize(_numMeasurements, 0.0);
}
......
......@@ -55,7 +55,7 @@ void expose_leastSquaresAlgorithms() {
.def("get_runtime", &PerformanceData::get_runtime)
.def("add", +[](PerformanceData &_this, size_t _itr, const double _res, const TTTensor &_x, const size_t _flags) {
_this.add(_itr, _res, _x, _flags);
}, (arg("iterationCount"), arg("residual"), arg("x"), arg("flags")=0) )
}, (arg("iteration"), arg("residual"), arg("x"), arg("flags")=0) )
.def("add", +[](PerformanceData &_this, const double _res, const TTTensor &_x, size_t _flags) {
_this.add(_res, _x, _flags);
}, (arg("residual"), arg("x"), arg("flags")=0) )
......@@ -68,7 +68,7 @@ void expose_leastSquaresAlgorithms() {
;
class_<PerformanceData::DataPoint>("DataPoint", no_init)
.def_readonly("iterationCount", &PerformanceData::DataPoint::iterationCount)
.def_readonly("iteration", &PerformanceData::DataPoint::iteration)
.def_readonly("elapsedTime", &PerformanceData::DataPoint::elapsedTime)
.def_readonly("residuals", &PerformanceData::DataPoint::residuals)
.def_readonly("error", &PerformanceData::DataPoint::error)
......
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