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
mexican_hat_kernel.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <string>
5#include <array>
6
7#include "kernel.h"
8#include "tools/math.h"
9
10#ifdef max
11#undef max
12#endif
13
14#ifdef min
15#undef min
16#endif
17
18
20{
29 struct MexicanHatKernelParameters final : ElementSpecificParameters
30 {
31 double widthExc;
32 double amplitudeExc;
33 double widthInh;
34 double amplitudeInh;
36 bool circular;
37 bool normalized;
38
39 explicit MexicanHatKernelParameters(const double widthExc = 2.5, const double amplitudeExc = 11.0,
40 const double widthInh = 5.0, const double amplitudeInh = 15.0,
41 const double amplitudeGlobal = -0.1,
42 const bool circular = true, const bool normalized = true)
47 {}
48
49 bool operator==(const MexicanHatKernelParameters& other) const
50 {
51 constexpr double epsilon = 1e-6;
52
53 return std::abs(widthExc - other.widthExc) < epsilon &&
54 std::abs(amplitudeExc - other.amplitudeExc) < epsilon &&
55 std::abs(widthInh - other.widthInh) < epsilon &&
56 std::abs(amplitudeInh - other.amplitudeInh) < epsilon &&
57 std::abs(amplitudeGlobal - other.amplitudeGlobal) < epsilon &&
58 circular == other.circular &&
59 normalized == other.normalized;
60 }
61
62 [[nodiscard]] std::string toString() const override
63 {
64 std::ostringstream result;
65 result << std::fixed << std::setprecision(2);
66 result << "Parameters: ["
67 << "Width exc.: " << widthExc << ", "
68 << "Amplitude exc.: " << amplitudeExc << ", "
69 << "Width inh.: " << widthInh << ", "
70 << "Amplitude inh.: " << amplitudeInh << ", "
71 << "Amplitude glob.: " << amplitudeGlobal << ", "
72 << "Circular: " << (circular ? "true" : "false") << ", "
73 << "Normalized: " << (normalized ? "true" : "false") << "]";
74 return result.str();
75 }
76 };
77
84 class MexicanHatKernel final : public Kernel
85 {
86 private:
88 std::vector<double> scratchExtended;
89 std::vector<double> scratchConvolution;
90 public:
94 MexicanHatKernel(const ElementCommonParameters& elementCommonParameters,
95 MexicanHatKernelParameters mhk_parameters);
96
97 void init() override;
98 void step(double t, double deltaT) override;
99 std::string toString() const override;
100 std::shared_ptr<Element> clone() const override;
101
102 void setParameters(const MexicanHatKernelParameters& mhk_parameters);
104 };
105}
Abstract base class for all convolution-based interaction kernels.
Definition kernel.h:17
Difference-of-Gaussians convolution kernel for DFT lateral interactions.
Definition mexican_hat_kernel.h:85
void setParameters(const MexicanHatKernelParameters &mhk_parameters)
Definition mexican_hat_kernel.cpp:91
MexicanHatKernelParameters getParameters() const
Definition mexican_hat_kernel.cpp:97
std::shared_ptr< Element > clone() const override
Definition mexican_hat_kernel.cpp:85
void step(double t, double deltaT) override
Advance the element by one time step.
Definition mexican_hat_kernel.cpp:56
std::string toString() const override
Definition mexican_hat_kernel.cpp:77
void init() override
Initialize the element (called once before the simulation loop).
Definition mexican_hat_kernel.cpp:13
Definition element_parameters.h:10
Definition element_parameters.h:188
Parameters for a Mexican-hat lateral interaction kernel.
Definition mexican_hat_kernel_parameters.h:10
bool operator==(const MexicanHatKernelParameters &other) const
Definition mexican_hat_kernel.h:49
double widthInh
σ of the inhibitory Gaussian.
Definition mexican_hat_kernel_parameters.h:13
bool circular
Enable circular (toroidal) convolution.
Definition mexican_hat_kernel_parameters.h:15
std::string toString() const override
Definition mexican_hat_kernel.h:62
bool normalized
Normalise both Gaussians before differencing.
Definition mexican_hat_kernel_parameters.h:16
double amplitudeExc
Peak amplitude of the excitatory Gaussian.
Definition mexican_hat_kernel_parameters.h:12
double amplitudeGlobal
Spatially uniform inhibition added after convolution.
Definition mexican_hat_kernel.h:35
MexicanHatKernelParameters(const double widthExc=2.5, const double amplitudeExc=11.0, const double widthInh=5.0, const double amplitudeInh=15.0, const double amplitudeGlobal=-0.1, const bool circular=true, const bool normalized=true)
Definition mexican_hat_kernel.h:39
double amplitudeInh
Peak amplitude of the inhibitory Gaussian.
Definition mexican_hat_kernel_parameters.h:14
double widthExc
σ of the excitatory Gaussian.
Definition mexican_hat_kernel_parameters.h:11