Dynamic Neural Field Composer 0.0.0
A C++20 library and interactive application for building and simulating Dynamic Neural Field (DNF) architectures.
Loading...
Searching...
No Matches
oscillatory_kernel_2d.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <sstream>
5#include <iomanip>
6#include <array>
7
8#include "tools/math.h"
9#include "kernel.h"
10
11//https://github.com/stevenlovegrove/Pangolin/issues/352
12#ifdef max
13#undef max
14#endif
15
16#ifdef min
17#undef min
18#endif
19
21{
29 {
30 double amplitude;
31 double decay;
36
37 explicit OscillatoryKernel2DParameters(double amplitude = 1.0, double decay = 0.08,
38 double zeroCrossings = 0.3,
39 double amplitudeGlobal = -0.01,
40 bool circular = true, bool normalized = true)
43 {
44 if (this->zeroCrossings < 0.0) this->zeroCrossings = 0.0;
45 else if (this->zeroCrossings > 1.0) this->zeroCrossings = 1.0;
46 if (this->decay <= 0.0) this->decay = 0.01;
47 }
48
50 {
51 constexpr double epsilon = 1e-6;
52 return std::abs(amplitude - other.amplitude) < epsilon &&
53 std::abs(decay - other.decay) < epsilon &&
54 std::abs(zeroCrossings - other.zeroCrossings) < epsilon &&
55 std::abs(amplitudeGlobal - other.amplitudeGlobal) < epsilon &&
56 circular == other.circular &&
57 normalized == other.normalized;
58 }
59
60 [[nodiscard]] std::string toString() const override
61 {
62 std::ostringstream result;
63 result << std::fixed << std::setprecision(2);
64 result << "Parameters: ["
65 << "Amplitude: " << amplitude << ", "
66 << "Decay: " << decay << ", "
67 << "Zero crossings: " << zeroCrossings << ", "
68 << "Amplitude global: " << amplitudeGlobal << ", "
69 << "Circular: " << (circular ? "true" : "false") << ", "
70 << "Normalized: " << (normalized ? "true" : "false") << "]";
71 return result.str();
72 }
73 };
74
87 class OscillatoryKernel2D final : public Kernel
88 {
89 private:
91 std::array<int, 2> kernelRange_x{};
92 std::array<int, 2> kernelRange_y{};
93 std::vector<int> extIndex_x;
94 std::vector<int> extIndex_y;
95 std::vector<double> kernel_1d_x;
96 std::vector<double> kernel_1d_y;
97 std::vector<double> scratchTmp_;
98 std::vector<double> scratchConvolution_;
99 public:
100 OscillatoryKernel2D(const ElementCommonParameters& elementCommonParameters,
101 const OscillatoryKernel2DParameters& parameters);
102
103 void init() override;
104 void step(double t, double deltaT) override;
105 [[nodiscard]] std::string toString() const override;
106 [[nodiscard]] std::shared_ptr<Element> clone() const override;
107
108 void setParameters(const OscillatoryKernel2DParameters& parameters);
109 [[nodiscard]] OscillatoryKernel2DParameters getParameters() const;
110 };
111}
Abstract base class for all convolution-based interaction kernels.
Definition kernel.h:17
2D oscillatory lateral-interaction kernel using separable convolution.
Definition oscillatory_kernel_2d.h:88
void step(double t, double deltaT) override
Advance the element by one time step.
Definition oscillatory_kernel_2d.cpp:87
void setParameters(const OscillatoryKernel2DParameters &parameters)
Definition oscillatory_kernel_2d.cpp:118
std::shared_ptr< Element > clone() const override
Definition oscillatory_kernel_2d.cpp:113
void init() override
Initialize the element (called once before the simulation loop).
Definition oscillatory_kernel_2d.cpp:17
OscillatoryKernel2DParameters getParameters() const
Definition oscillatory_kernel_2d.cpp:127
std::string toString() const override
Definition oscillatory_kernel_2d.cpp:105
Definition element_parameters.h:10
Definition element_parameters.h:188
Definition element_parameters.h:206
Parameters for OscillatoryKernel2D.
Definition oscillatory_kernel_2d.h:29
double amplitude
Definition oscillatory_kernel_2d.h:30
OscillatoryKernel2DParameters(double amplitude=1.0, double decay=0.08, double zeroCrossings=0.3, double amplitudeGlobal=-0.01, bool circular=true, bool normalized=true)
Definition oscillatory_kernel_2d.h:37
bool circular
Definition oscillatory_kernel_2d.h:34
double zeroCrossings
Definition oscillatory_kernel_2d.h:32
double amplitudeGlobal
Definition oscillatory_kernel_2d.h:33
bool normalized
Definition oscillatory_kernel_2d.h:35
std::string toString() const override
Definition oscillatory_kernel_2d.h:60
double decay
Definition oscillatory_kernel_2d.h:31
bool operator==(const OscillatoryKernel2DParameters &other) const
Definition oscillatory_kernel_2d.h:49