kopia lustrzana https://github.com/vsamy/DiFipp
Updates...
rodzic
544bead65c
commit
934a0ed17f
|
@ -134,9 +134,9 @@ vectN_t<T, N> operator()() const
|
||||||
|
|
||||||
// Centered Noise-Robust differentiators (tangency at 4th order): http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
|
// Centered Noise-Robust differentiators (tangency at 4th order): http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
|
||||||
template <typename T, size_t N> struct GetCNR4Coeffs { vectN_t<T, N> operator()() const; };
|
template <typename T, size_t N> struct GetCNR4Coeffs { vectN_t<T, N> operator()() const; };
|
||||||
template <typename T> struct GetCNR4Coeffs<T, 3> { vectN_t<T, 3> operator()() const { return vectN_t<T, 3>{ T(-5), T(12), T(39), T(0), T(-39), T(-12), T(5) } / T(96); } };
|
template <typename T> struct GetCNR4Coeffs<T, 7> { vectN_t<T, 7> operator()() const { return vectN_t<T, 7>{ T(-5), T(12), T(39), T(0), T(-39), T(-12), T(5) } / T(96); } };
|
||||||
template <typename T> struct GetCNR4Coeffs<T, 4> { vectN_t<T, 4> operator()() const { return vectN_t<T, 4>{ T(-2), T(-1), T(16), T(27) } / T(96); } };
|
template <typename T> struct GetCNR4Coeffs<T, 9> { vectN_t<T, 9> operator()() const { return vectN_t<T, 9>{ T(-2), T(-1), T(16), T(27), T(0), T(-27), T(-16), T(1), T(2) } / T(96); } };
|
||||||
template <typename T> struct GetCNR4Coeffs<T, 5> { vectN_t<T, 5> operator()() const { return vectN_t<T, 5>{ T(-11), T(-32), T(39), T(256), T(322) } / T(1536); } };
|
template <typename T> struct GetCNR4Coeffs<T, 11> { vectN_t<T, 11> operator()() const { return vectN_t<T, 11>{ T(-11), T(-32), T(39), T(256), T(322), T(0), T(-322), T(-256), T(-39), T(32), T(11) } / T(1536); } };
|
||||||
|
|
||||||
// Centered Noise-Robust differentiators for irregular space data: http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
|
// Centered Noise-Robust differentiators for irregular space data: http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
|
||||||
template <typename T, size_t N, typename CNRCoeffs> vectN_t<T, N> GetCNRISDCoeffs()
|
template <typename T, size_t N, typename CNRCoeffs> vectN_t<T, N> GetCNRISDCoeffs()
|
||||||
|
|
|
@ -27,9 +27,70 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "differentiators.h"
|
#include "differentiators.h"
|
||||||
|
#include "noisy_function_generator.h"
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE("Sinus central derivative", "[sin][dentral]", float, double)
|
constexpr const int STEPS = 200;
|
||||||
|
constexpr const int SIN_FREQUENCY = 60;
|
||||||
|
|
||||||
|
using namespace difi;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct TestFun {
|
||||||
|
vectX_t<T> f;
|
||||||
|
vectX_t<T> d;
|
||||||
|
int center;
|
||||||
|
double eps;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, typename Filter>
|
||||||
|
struct TestRunner {
|
||||||
|
void operator()(const TestFun<T>& tf, Filter& f)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 50; ++i)
|
||||||
|
f.step(tf.f(i)); // First initialize, some steps
|
||||||
|
|
||||||
|
for (int i = 20; i < STEPS; ++i)
|
||||||
|
REQUIRE_SMALL(std::abs(f.step(tf.f(i)) - tf.d(i - tf.center)), tf.eps);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, size_t Ind, typename... Ts>
|
||||||
|
struct Tester {
|
||||||
|
void operator()(const TestFun<T>& tf, std::tuple<Ts...> f)
|
||||||
|
{
|
||||||
|
TestRunner(tf, std::get<Ind>(f));
|
||||||
|
Tester<T, Ind - 1, Ts...>(tf, f);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, typename... Ts>
|
||||||
|
struct Tester<T, 0, Ts...> {
|
||||||
|
void operator()(const TestFun<T>& tf, std::tuple<Ts...> f)
|
||||||
|
{
|
||||||
|
TestRunner(tf, std::get<0>(f));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, size_t N>
|
||||||
|
using centralList = std::tuple<CentralDiff<T, N>, LowNoiseLanczosDiff<T, N>, SuperLowNoiseLanczosDiff<T, N>, CenteredNoiseRobust2Diff<T, N>, CenteredNoiseRobust4Diff<T, N>>;
|
||||||
|
|
||||||
|
TEMPLATE_TEST_CASE("Sinus time-fixed central derivative", "[sin][central]", float, double)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
FunctionGenerator<TestType> fg = sinGenerator<TestType>(STEPS, SIN_FREQUENCY);
|
||||||
|
|
||||||
|
auto list7 = centralList<TestType, 7>{};
|
||||||
|
TestFun<TestType> list7Param = {std::get<0>(fg), std::get<2>(fg), 3, std::numeric_limits<TestType>::epsilon() * 100};
|
||||||
|
TestFun<TestType> list7NoisyParam = {std::get<1>(fg), std::get<2>(fg), 3, std::numeric_limits<TestType>::epsilon() * 100};
|
||||||
|
auto list9 = centralList<TestType, 9>{};
|
||||||
|
TestFun<TestType> list9Param = {std::get<0>(fg), std::get<2>(fg), 4, std::numeric_limits<TestType>::epsilon() * 100};
|
||||||
|
TestFun<TestType> list9NoisyParam = {std::get<1>(fg), std::get<2>(fg), 4, std::numeric_limits<TestType>::epsilon() * 100};
|
||||||
|
|
||||||
|
// Check no noisy function
|
||||||
|
|
||||||
|
|
||||||
|
// Check for noisy function
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ template <typename T>
|
||||||
using FunctionGenerator = std::tuple<difi::vectX_t<T>, difi::vectX_t<T>, difi::vectX_t<T>>;
|
using FunctionGenerator = std::tuple<difi::vectX_t<T>, difi::vectX_t<T>, difi::vectX_t<T>>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
FunctionGenerator sinGenerator(int nrSteps, T omega, T dt = 0.001)
|
FunctionGenerator<T> sinGenerator(int nrSteps, T frequency, T dt = 0.001)
|
||||||
{
|
{
|
||||||
using namespace difi;
|
using namespace difi;
|
||||||
|
|
||||||
|
@ -49,21 +49,21 @@ FunctionGenerator sinGenerator(int nrSteps, T omega, T dt = 0.001)
|
||||||
|
|
||||||
for (int i = 0; i < nrSteps; ++i) {
|
for (int i = 0; i < nrSteps; ++i) {
|
||||||
// truth
|
// truth
|
||||||
truth(i) = std::sin(2 * pi<T> * omega * i * dt);
|
truth(i) = std::sin(2 * pi<T> * frequency * i * dt);
|
||||||
|
|
||||||
// noisy
|
// noisy
|
||||||
std::normal_distribution<T> d{truth(i), T(0.01)};
|
std::normal_distribution<T> d{truth(i), T(0.01)};
|
||||||
noisy(i) = truth(i) + d(gen);
|
noisy(i) = truth(i) + d(gen);
|
||||||
|
|
||||||
// derivative
|
// derivative
|
||||||
derivative(i) = 2 * pi<T> * omega * i * std::cos(2 * pi<T> * omega * i * dt);
|
derivative(i) = 2 * pi<T> * frequency * i * std::cos(2 * pi<T> * frequency * i * dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { truth, noisy, derivative };
|
return { truth, noisy, derivative };
|
||||||
}
|
}
|
||||||
|
|
||||||
template <Typename T>
|
template <typename T>
|
||||||
FunctionGenerator polyGenerator(int nrSteps, difi::VectX_t<T> coeffs, T dt = 0.001)
|
FunctionGenerator<T> polyGenerator(int nrSteps, difi::vectX_t<T> coeffs, T dt = 0.001)
|
||||||
{
|
{
|
||||||
using namespace difi;
|
using namespace difi;
|
||||||
Expects(coeffs.size() >=2);
|
Expects(coeffs.size() >=2);
|
||||||
|
|
Ładowanie…
Reference in New Issue