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
gauss_kernel.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4
5#include "tools/math.h"
6#include "kernel.h"
7
9{
12 struct GaussKernelParameters final : ElementSpecificParameters
13 {
14 double width;
15 double amplitude;
17 bool circular;
18 bool normalized;
19
20 explicit GaussKernelParameters(const double width = 3.0, const double amp = 3.0, const double ampGlobal = -0.01,
21 const bool circular = true, const bool normalized = true)
22 : width(width), amplitude(amp), amplitudeGlobal(ampGlobal),
24 {}
25
26 bool operator==(const GaussKernelParameters& other) const {
27 constexpr double epsilon = 1e-6;
28
29 return std::abs(width - other.width) < epsilon &&
30 std::abs(amplitude - other.amplitude) < epsilon &&
31 std::abs(amplitudeGlobal - other.amplitudeGlobal) < epsilon &&
32 circular == other.circular &&
33 normalized == other.normalized;
34 }
35
36 [[nodiscard]] std::string toString() const override
37 {
38 std::ostringstream result;
39 result << std::fixed << std::setprecision(2); // Ensures numbers have 2 decimal places
40 result << "Parameters: ["
41 << "Width: " << width << ", "
42 << "Amplitude: " << amplitude << ", "
43 << "Amplitude global: " << amplitudeGlobal << ", "
44 << "Circular: " << (circular ? "true" : "false") << ", "
45 << "Normalized: " << (normalized ? "true" : "false") << "]";
46 return result.str();
47 }
48 };
49
58 class GaussKernel final : public Kernel
59 {
60 private:
61 GaussKernelParameters parameters;
62 std::vector<double> scratchExtended;
63 std::vector<double> scratchConvolution;
64 public:
68 GaussKernel(const ElementCommonParameters& elementCommonParameters, GaussKernelParameters parameters);
69
70 void init() override;
71 void step(double t, double deltaT) override;
72 std::string toString() const override;
73 std::shared_ptr<Element> clone() const override;
74
75 void setParameters(const GaussKernelParameters& gk_parameters);
77 };
78}
Gaussian convolution kernel providing local excitation and optional global inhibition.
Definition gauss_kernel.h:59
void init() override
Initialize the element (called once before the simulation loop).
Definition gauss_kernel.cpp:15
void setParameters(const GaussKernelParameters &gk_parameters)
Definition gauss_kernel.cpp:87
void step(double t, double deltaT) override
Advance the element by one time step.
Definition gauss_kernel.cpp:52
std::string toString() const override
Definition gauss_kernel.cpp:73
GaussKernelParameters getParameters() const
Definition gauss_kernel.cpp:93
std::shared_ptr< Element > clone() const override
Definition gauss_kernel.cpp:81
Abstract base class for all convolution-based interaction kernels.
Definition kernel.h:17
Definition element_parameters.h:10
Definition element_parameters.h:188
Parameters for a Gaussian lateral interaction kernel.
Definition gauss_kernel_parameters.h:10
bool normalized
If true, the Gaussian is area-normalised.
Definition gauss_kernel_parameters.h:14
bool circular
If true, convolution wraps around (toroidal boundary).
Definition gauss_kernel_parameters.h:13
double amplitudeGlobal
Spatially uniform inhibition added after convolution.
Definition gauss_kernel.h:16
bool operator==(const GaussKernelParameters &other) const
Definition gauss_kernel.h:26
double amplitude
Peak amplitude of the excitatory Gaussian.
Definition gauss_kernel_parameters.h:12
std::string toString() const override
Definition gauss_kernel.h:36
double width
Standard deviation (σ) of the Gaussian.
Definition gauss_kernel_parameters.h:11
GaussKernelParameters(const double width=3.0, const double amp=3.0, const double ampGlobal=-0.01, const bool circular=true, const bool normalized=true)
Definition gauss_kernel.h:20