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
|
#include <boost/mpl/list.hpp>
#include <boost/mpl/pair.hpp>
#include <iostream>
#include <inttypes.h>
#include "index.hpp"
#include "index_spike.hpp"
#include "pla_get.hpp"
#include "property_composition.hpp"
#include "pla_init_default.hpp"
#include "pla_set.hpp"
#include "sim_loop.hpp"
#include "model.hpp"
using namespace boost;
const Time startTime(0.1);
struct FakeSim {
FakeSim()
: indices(),
queues()
{
using boost::make_tuple;
}
Ptr<GlobalMsg> addGlobalMsg(RNG::seed_t seed) {
const Time gmStartTime(ModelConsts::TrainerInitialDelay);
// create an discrete quant instance
Ptr<GlobalMsg> res(indices.get<Index<GlobalMsg>>().add
(Time(0), gmStartTime, Ptr<Global>()));
// and a corresponding event occuring at time 0.1, stored in start
// interval (t=0)
queues.insert<GlobalMsg>(Time(0), gmStartTime, Event<GlobalMsg>(res));
pc.cast(PLA_Set<NextTrainer>(res, TrainerT(seed)));
return res;
}
Ptr<Spike> addSpike(Ptr<Neuron> src) {
Time eventTime = startTime + TopologicalTimeOffset<Neuron, Spike>()(topo, src);
Ptr<Spike> res(indices.get<Index<Spike>>().add(startTime, eventTime, src));
queues.insert<Spike>(Time(0), eventTime, Event<Spike>(startTime, src, res));
return res;
}
Ptr<RandomSpike> addRandomSpike(Ptr<Neuron> src, RNG::seed_t seed) {
Time eventTime = startTime + RNG::expo(seed, 1 / ModelConsts::RandomFreq);
Ptr<RandomSpike> res(indices.get<Index<RandomSpike>>().add
(startTime, eventTime, src));
queues.insert<RandomSpike>(Time(0), eventTime,
Event<RandomSpike>(eventTime, src, res));
return res;
}
// data structs
typedef SimLoop<Lists::all> sim_t;
sim_t::indices_t indices;
sim_t::queues_t queues;
sim_t::pc_t pc;
Topology topo;
};
using namespace std;
int main(int argc, char **argv) {
using boost::mpl::pair;
using boost::mpl::list;
FakeSim data;
// read cmd line arg
if (argc > 2) {
cout << "Usage: " << argv[0] << " [random-seed=0]";
}
char *tail;
RNG::seed_t rng(0);
if (argc == 2) {
rng = RNG::seed_t(strtoll(argv[1], &tail, 10));
assert(*tail == 0);
}
// init values (except weight)
data.pc.cast(PLA_Init_Default());
// init random seed (different one for every neuron)
for (Ptr<Neuron> i : Ptr<Global>().childs()) {
data.pc.cast(PLA_Set<RandomSeed>(Time(0), i, RNG::split(rng)));
rng = RNG::next(rng, 40);
}
// TODO: add a global event to start trainer
PLA_Get<NextTrainer> get(Ptr<GlobalMsg>(0));
data.addGlobalMsg(RNG::split(rng));
rng = RNG::next(rng, 40);
// add a random noise source for every neuron
for (Ptr<Neuron> i : Ptr<Global>().childs())
if (i() < ModelConsts::NumExcitatory) { // exclude special neurons
data.addRandomSpike(i, RNG::split(rng));
rng = RNG::next(rng, 40);
}
// TODO: add discrete properties to the created events
return 0;
}
|