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_2d.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <sstream>
5#include <iomanip>
6
7#include "tools/math.h"
8#include "kernel.h"
9
10//https://github.com/stevenlovegrove/Pangolin/issues/352
11#ifdef max
12#undef max
13#endif
14
15#ifdef min
16#undef min
17#endif
18
20{
22 {
23 double widthExc;
25 double widthInh;
30
31 explicit MexicanHatKernel2DParameters(double widthExc = 2.5, double amplitudeExc = 11.0,
32 double widthInh = 5.0, double amplitudeInh = 15.0,
33 double amplitudeGlobal = -0.1,
34 bool circular = true, bool normalized = true)
39 {}
40
42 {
43 constexpr double epsilon = 1e-6;
44 return std::abs(widthExc - other.widthExc) < epsilon &&
45 std::abs(amplitudeExc - other.amplitudeExc) < epsilon &&
46 std::abs(widthInh - other.widthInh) < epsilon &&
47 std::abs(amplitudeInh - other.amplitudeInh) < epsilon &&
48 std::abs(amplitudeGlobal - other.amplitudeGlobal) < epsilon &&
49 circular == other.circular &&
50 normalized == other.normalized;
51 }
52
53 [[nodiscard]] std::string toString() const override
54 {
55 std::ostringstream result;
56 result << std::fixed << std::setprecision(2);
57 result << "Parameters: ["
58 << "Width exc: " << widthExc << ", "
59 << "Amplitude exc: " << amplitudeExc << ", "
60 << "Width inh: " << widthInh << ", "
61 << "Amplitude inh: " << amplitudeInh << ", "
62 << "Amplitude global: " << amplitudeGlobal << ", "
63 << "Circular: " << (circular ? "true" : "false") << ", "
64 << "Normalized: " << (normalized ? "true" : "false") << "]";
65 return result.str();
66 }
67 };
68
69 class MexicanHatKernel2D final : public Kernel
70 {
71 private:
73 std::array<int, 2> kernelRangeExc_x{}, kernelRangeExc_y{};
74 std::array<int, 2> kernelRangeInh_x{}, kernelRangeInh_y{};
75 std::vector<int> extIndexExc_x, extIndexExc_y;
76 std::vector<int> extIndexInh_x, extIndexInh_y;
77 std::vector<double> kernelExc_x, kernelExc_y;
78 std::vector<double> kernelInh_x, kernelInh_y;
79 std::vector<double> scratchTmp_;
80 std::vector<double> scratchExcConv_;
81 std::vector<double> scratchInhConv_;
82 public:
83 MexicanHatKernel2D(const ElementCommonParameters& elementCommonParameters,
84 const MexicanHatKernel2DParameters& parameters);
85
86 void init() override;
87 void step(double t, double deltaT) override;
88 std::string toString() const override;
89 std::shared_ptr<Element> clone() const override;
90
91 void setParameters(const MexicanHatKernel2DParameters& parameters);
93 };
94}
Abstract base class for all convolution-based interaction kernels.
Definition kernel.h:17
Definition mexican_hat_kernel_2d.h:70
std::string toString() const override
Definition mexican_hat_kernel_2d.cpp:119
void step(double t, double deltaT) override
Advance the element by one time step.
Definition mexican_hat_kernel_2d.cpp:95
std::shared_ptr< Element > clone() const override
Definition mexican_hat_kernel_2d.cpp:127
void setParameters(const MexicanHatKernel2DParameters &parameters)
Definition mexican_hat_kernel_2d.cpp:132
MexicanHatKernel2DParameters getParameters() const
Definition mexican_hat_kernel_2d.cpp:138
void init() override
Initialize the element (called once before the simulation loop).
Definition mexican_hat_kernel_2d.cpp:18
Definition element_parameters.h:10
Definition element_parameters.h:188
Definition element_parameters.h:206
Definition mexican_hat_kernel_2d.h:22
double amplitudeInh
Definition mexican_hat_kernel_2d.h:26
bool operator==(const MexicanHatKernel2DParameters &other) const
Definition mexican_hat_kernel_2d.h:41
double widthExc
Definition mexican_hat_kernel_2d.h:23
bool normalized
Definition mexican_hat_kernel_2d.h:29
double widthInh
Definition mexican_hat_kernel_2d.h:25
MexicanHatKernel2DParameters(double widthExc=2.5, double amplitudeExc=11.0, double widthInh=5.0, double amplitudeInh=15.0, double amplitudeGlobal=-0.1, bool circular=true, bool normalized=true)
Definition mexican_hat_kernel_2d.h:31
double amplitudeGlobal
Definition mexican_hat_kernel_2d.h:27
bool circular
Definition mexican_hat_kernel_2d.h:28
double amplitudeExc
Definition mexican_hat_kernel_2d.h:24
std::string toString() const override
Definition mexican_hat_kernel_2d.h:53