diff options
Diffstat (limited to 'core/bootstrap.cpp')
-rw-r--r-- | core/bootstrap.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/core/bootstrap.cpp b/core/bootstrap.cpp new file mode 100644 index 0000000..092d0f2 --- /dev/null +++ b/core/bootstrap.cpp @@ -0,0 +1,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; +} |