-
Notifications
You must be signed in to change notification settings - Fork 1
/
mec.h
122 lines (95 loc) · 3.09 KB
/
mec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Navigating with grid and place cells in cluttered environments
// Edvardsen et al. (2020). Hippocampus, 30(3), 220-232.
//
// Licensed under the EUPL-1.2-or-later.
// Copyright (c) 2019 NTNU - Norwegian University of Science and Technology.
// Author: Vegard Edvardsen (https://github.com/evegard).
#ifndef MEC_H_INCLUDED
#define MEC_H_INCLUDED
#include <tuple>
#include "network.h"
#include "plot.h"
#include "main.h"
class MecRecurrentInput;
enum MecDirectionality { west, north, south, east };
class NeuralSheetNetwork : public Network
{
public:
NeuralSheetNetwork(real gain);
real gain;
real lambda, beta, gamma;
inline int neuron_index_to_x(int i) { return i % MEC_SIZE; }
inline int neuron_index_to_y(int i) { return i / MEC_SIZE; }
inline int coords_to_neuron_index(int x, int y) { return y * MEC_SIZE + x; }
int bump_x, bump_y;
int bump_total_dx = 0, bump_total_dy = 0;
bool bump_tracker_initialized;
void initialize_bump_tracker();
void update_bump_tracker();
protected:
std::tuple<real, int, int> calculate_disc_mass(int center_x, int center_y);
};
class MecNetwork : public NeuralSheetNetwork
{
public:
MecNetwork(real gain, MecGainMode gain_mode);
MecGainMode gain_mode;
real activation_probability;
void update();
bool should_update_neuron(int neuron_index);
inline MecDirectionality directionality(int x, int y) {
return (MecDirectionality)(2 * (y % 2) + (x % 2)); }
protected:
void update_neuron_values();
MecRecurrentInput *recurrent_input;
bool neurons_enabled[MEC_SIZE * MEC_SIZE];
};
class ConvolvedMecNetwork : public NeuralSheetNetwork
{
public:
ConvolvedMecNetwork(MecNetwork *afferent);
protected:
void update_neuron_values();
};
class MecConvolveInput : public Input
{
public:
MecConvolveInput(ConvolvedMecNetwork *efferent, MecNetwork *afferent);
void add_inputs();
protected:
ConvolvedMecNetwork *efferent;
MecNetwork *afferent;
};
class MecShiftedMaskInput : public Input
{
public:
MecShiftedMaskInput(Network *efferent, NeuralSheetNetwork *afferent);
void initialize();
void add_inputs();
protected:
NeuralSheetNetwork *afferent;
Matrix *weights;
std::pair<int, int> *shifts;
real cached_sums[MEC_SIZE][MEC_SIZE];
bool cached_sum_valid[MEC_SIZE][MEC_SIZE];
virtual real get_weight(int x, int y) = 0;
virtual std::pair<int, int> get_shift(int neuron_index) = 0;
};
class MecRecurrentInput : public MecShiftedMaskInput
{
public:
MecRecurrentInput(MecNetwork *network);
protected:
MecNetwork *afferent;
real get_weight(int x, int y);
std::pair<int, int> get_shift(int neuron_index);
};
class MecNetworkPlot : public Plot
{
public:
MecNetworkPlot(NeuralSheetNetwork *network, int number);
protected:
void dump_plot_commands(std::ostream &gnuplot);
NeuralSheetNetwork *network;
};
#endif