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.h
Go to the documentation of this file.
1#pragma once
2
3#include "kernel.h"
4#include "tools/math.h"
5
6
8{
12 {
13 double amplitude;
14 double decay;
17 bool circular;
19
20 explicit OscillatoryKernelParameters(const double amplitude = 1.0, const double decay = 0.08,
21 const double zeroCrossings = 0.3, const double amplitudeGlobal = -0.01,
22 const bool circular = true, const bool normalized = false)
26 {
27 // zero crossings must be in the range [0, 1]
28 if (zeroCrossings < 0.0)
29 this->zeroCrossings = 0.0;
30 else if (zeroCrossings > 1.0)
31 this->zeroCrossings = 1.0;
32 // decay cannot be negative or zero
33 if (decay <= 0.0)
34 this->decay = 0.01;
35 }
36
37 bool operator==(const OscillatoryKernelParameters& other) const
38 {
39 constexpr double epsilon = 1e-6;
40
41 return std::abs(amplitude - other.amplitude) < epsilon &&
42 std::abs(decay - other.decay) < epsilon &&
43 std::abs(zeroCrossings - other.zeroCrossings) < epsilon &&
44 std::abs(amplitudeGlobal - other.amplitudeGlobal) < epsilon &&
45 circular == other.circular &&
46 normalized == other.normalized;
47 }
48
49 [[nodiscard]] std::string toString() const override
50 {
51 std::ostringstream result;
52 result << std::fixed << std::setprecision(2);
53 result << "Parameters: ["
54 << "Amplitude: " << amplitude << ", "
55 << "Decay: " << decay << ", "
56 << "Zero crossings: " << zeroCrossings << ", "
57 << "Amplitude global: " << amplitudeGlobal << ", "
58 << "Circular: " << (circular ? "true" : "false") << ", "
59 << "Normalized: " << (normalized ? "true" : "false") << "]";
60 return result.str();
61 }
62 };
63
71 class OscillatoryKernel final : public Kernel
72 {
73 private:
75 std::vector<double> scratchExtended;
76 std::vector<double> scratchConvolution;
77 public:
81 OscillatoryKernel(const ElementCommonParameters& elementCommonParameters,
82 OscillatoryKernelParameters ok_parameters);
83
84 void init() override;
85 void step(double t, double deltaT) override;
86 std::string toString() const override;
87 std::shared_ptr<Element> clone() const override;
88
89 void setParameters(const OscillatoryKernelParameters& ok_parameters);
91 };
92}
Abstract base class for all convolution-based interaction kernels.
Definition kernel.h:17
Damped-cosine convolution kernel for oscillatory field dynamics.
Definition oscillatory_kernel.h:72
void init() override
Initialize the element (called once before the simulation loop).
Definition oscillatory_kernel.cpp:15
void setParameters(const OscillatoryKernelParameters &ok_parameters)
Definition oscillatory_kernel.cpp:95
std::shared_ptr< Element > clone() const override
Definition oscillatory_kernel.cpp:89
OscillatoryKernelParameters getParameters() const
Definition oscillatory_kernel.cpp:109
void step(double t, double deltaT) override
Advance the element by one time step.
Definition oscillatory_kernel.cpp:60
std::string toString() const override
Definition oscillatory_kernel.cpp:81
Definition element_parameters.h:10
Definition element_parameters.h:188
Definition element_parameters.h:206
Parameters for an oscillatory (damped-cosine) convolution kernel.
Definition oscillatory_kernel.h:12
bool circular
Enable circular (toroidal) convolution.
Definition oscillatory_kernel.h:17
double amplitude
Overall kernel amplitude.
Definition oscillatory_kernel.h:13
bool operator==(const OscillatoryKernelParameters &other) const
Definition oscillatory_kernel.h:37
bool normalized
Normalise the kernel before convolution.
Definition oscillatory_kernel.h:18
double amplitudeGlobal
Spatially uniform inhibition added after convolution.
Definition oscillatory_kernel.h:16
std::string toString() const override
Definition oscillatory_kernel.h:49
double decay
Exponential envelope decay rate (must be > 0).
Definition oscillatory_kernel.h:14
OscillatoryKernelParameters(const double amplitude=1.0, const double decay=0.08, const double zeroCrossings=0.3, const double amplitudeGlobal=-0.01, const bool circular=true, const bool normalized=false)
Definition oscillatory_kernel.h:20
double zeroCrossings
Spatial frequency controlling oscillation period (clamped to [0, 1]).
Definition oscillatory_kernel.h:15