Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
178 changes: 178 additions & 0 deletions include/izhikevich.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#include <deque>
#include <vector>
#include <unordered_map>
#include "framework.hpp"
#include "nlohmann/json.hpp"

namespace izhikevich {

class Synapse;
class Network;

class Neuron {
public:

double v;
double u;

double a;
double b;
double c;
double d;

double input;

int id;

bool tracking;
int last_fire_time;
int fire_count;
std::vector<double> fire_times;

neuro::Node* node;

std::vector<Synapse *> synapses;

Neuron(neuro::Node* node, int id);
~Neuron();

void update();
void fire(Network* net, int time);
void reset();
};

class Synapse {
public:
Neuron* to;
int weight;
int delay;

Synapse(Neuron* to, neuro::Edge* edge, bool exc);
};

class Network {
public:
std::vector<int> inputs;
std::vector<int> outputs;
std::vector<Neuron *> neurons;
std::unordered_map<uint32_t, int> ids;

int timestep;
long long total_fire_count;
long long total_accumulate_count;

/* Events have the form <neuron id, value>. */

std::deque< std::vector< std::pair<int, double> > > events;

Network(neuro::Network* network);
~Network();

void run(int duration);
Neuron* get_neuron(uint32_t node_id);
Neuron* get_output(int output_id);
void reset();
};

class Processor : public neuro::Processor {
public:
static nlohmann::json spec;
neuro::PropertyPack ppack;
nlohmann::json properties;
nlohmann::json params;
int input_scaling_value;

std::unordered_map<int, Network *> networks;

Processor(nlohmann::json& arg);
~Processor();

bool load_network(neuro::Network* network, int network_id = 0);
bool load_networks(std::vector<neuro::Network *> &networks);

void clear(int network_id = 0);

void apply_spike(
const neuro::Spike& spike,
bool normalized = true,
int network_id = 0
);

void apply_spike(
const neuro::Spike &spike,
const std::vector<int>& network_ids,
bool normalized = true
);

void apply_spikes(
const std::vector<neuro::Spike>& spikes,
bool normalized = true,
int network_id = 0
);

void apply_spikes(
const std::vector<neuro::Spike>& spikes,
const std::vector<int>& network_ids,
bool normalized = true
);

void run(double duration, int network_id = 0);
void run(double duration, const std::vector<int>& network_ids);

double get_time(int network_id = 0);

bool track_output_events(
int output_id,
bool track = true,
int network_id = 0
);

bool track_neuron_events(
uint32_t node_id,
bool track = true,
int network_id = 0
);

double output_last_fire(int output_id, int network_id = 0);
std::vector<double> output_last_fires(int network_id = 0);
int output_count(int output_id, int network_id = 0);
std::vector<int> output_counts(int network_id = 0);

std::vector<double> output_vector(
int output_id,
int network_id = 0
);

std::vector< std::vector<double> > output_vectors(
int network_id = 0
);

long long total_neuron_counts(int network_id = 0);
long long total_neuron_accumulates(int network_id = 0);
std::vector<int> neuron_counts(int network_id = 0);
std::vector<double> neuron_last_fires(int network_id = 0);

std::vector< std::vector<double> > neuron_vectors(
int network_id = 0
);

std::vector<double> neuron_charges(int network_id = 0);

void synapse_weights(
std::vector<uint32_t>& pres,
std::vector<uint32_t>& posts,
std::vector<double>& vals,
int network_id = 0
);

void clear_activity(int network_id = 0);

neuro::PropertyPack get_network_properties() const;
nlohmann::json get_processor_properties() const;
nlohmann::json get_params() const;

std::string get_name() const;

Network* get_network(int network_id);
};
}
13 changes: 13 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ VRISP_RVV_FULL_OBJ = obj/vrisp_rvv_full.o obj/vrisp_static.o
VRISP_RVV_FIRED_OBJ = obj/vrisp_rvv_fired.o obj/vrisp_static.o
VRISP_RVV_SYNAPSES_OBJ = obj/vrisp_rvv_synapses.o obj/vrisp_static.o

IZH_INC = include/izhikevich.hpp
IZH_OBJ = obj/izhikevich.o obj/izhikevich_static.o

all: lib/libframework.a \
bin/network_tool \
bin/compose_networks \
bin/processor_tool_risp \
bin/processor_tool_vrisp \
bin/processor_tool_izhikevich \
bin/network_to_jgraph \

riscv_vector: all \
Expand Down Expand Up @@ -84,6 +88,9 @@ bin/processor_tool_vrisp_vector_fired: src/processor_tool.cpp $(FR_INC) $(VRISP_
bin/processor_tool_vrisp_vector_synapses: src/processor_tool.cpp $(FR_INC) $(VRISP_INC) $(VRISP_RVV_SYNAPSES_OBJ) $(FR_LIB)
$(CXX) $(FR_CFLAGS) -o bin/processor_tool_vrisp_vector_synapses src/processor_tool.cpp $(VRISP_RVV_SYNAPSES_OBJ) $(FR_LIB)

bin/processor_tool_izhikevich: src/processor_tool.cpp $(FR_INC) $(IZH_INC) $(IZH_OBJ) $(FR_LIB)
$(CXX) $(FR_CFLAGS) -o bin/processor_tool_izhikevich src/processor_tool.cpp $(IZH_OBJ) $(FR_LIB)

# ------------------------------------------------------------
# Auxiliary Programs

Expand Down Expand Up @@ -123,6 +130,12 @@ obj/vrisp_rvv_synapses.o: src/vrisp.cpp $(FR_INC) $(VRISP_INC)
obj/vrisp_static.o: src/vrisp_static.cpp $(FR_INC) $(VRISP_INC)
$(CXX) -c $(FR_CFLAGS) -o obj/vrisp_static.o src/vrisp_static.cpp

obj/izhikevich.o: src/izhikevich.cpp $(FR_INC) $(IZH_INC)
$(CXX) -c $(FR_CFLAGS) -o obj/izhikevich.o src/izhikevich.cpp

obj/izhikevich_static.o: src/izhikevich_static.cpp $(FR_INC) $(IZH_INC)
$(CXX) -c $(FR_CFLAGS) -o obj/izhikevich_static.o src/izhikevich_static.cpp

obj/framework.o: src/framework.cpp $(FR_INC)
$(CXX) -c $(FR_CFLAGS) -o obj/framework.o src/framework.cpp

Expand Down
97 changes: 97 additions & 0 deletions scripts/test_izhikevich.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Script to test the network tool and RISP processor tool

if [ $# -ne 2 ]; then
echo 'usage: sh scripts/test_izhikevich.sh number('-' for all) yes|no(keep temporary files)' >&2
exit 1
fi

keep="$2"
if [ "$keep" != yes -a "$keep" != no ]; then
echo 'keep parameter must be "yes" or "no".' >&2
exit 1
fi

t="$1"

if [ T"$t" = 'T-' ]; then
t=`ls testing/izhikevich`
fi

# Make the two executables if they aren't made yet.

for i in bin/network_tool bin/processor_tool_izhikevich ; do
if [ ! -x $i ]; then make $i ; fi
done

for i in $t ; do
i=`echo $i | awk '{ printf "%02d\n", $1 }'`
if [ ! -d testing/izhikevich/$i ]; then
echo "Error -- no directory testing/izhikevich/$i" >&2
exit 1
fi

for f in label.txt network_tool.txt processor.sh processor_tool.txt correct_output.txt ; do
if [ ! -f testing/izhikevich/$i/$f ]; then
echo "Error -- no file testing/izhikevich/$i/$f" >&2
exit 1
fi
done

# Create the processor params, and then an empty network

l=`cat testing/izhikevich/$i/label.txt`
sh testing/izhikevich/$i/processor.sh > tmp_proc_params.txt

( echo M izhikevich tmp_proc_params.txt
echo EMPTYNET tmp_empty_network.txt ) | bin/processor_tool_izhikevich

# Use network_tool.txt to create the network.

bin/network_tool < testing/izhikevich/$i/network_tool.txt > tmp_nt_output.txt 2>&1
if [ `wc tmp_nt_output.txt | awk '{ print $1 }'` != 0 ]; then
echo "Test $i - $l" >&2
echo "There was an error in the network_tool command when I ran:" >&2
echo "" >&2
echo "bin/network_tool < testing/izhikevich/$i/network_tool.txt > tmp_nt_output.txt" >&2
echo "" >&2
cat tmp_nt_output.txt >&2
exit 1
fi

# Now, you'll execute the commands in processor_tool.txt and compare the output
# against known output.

cp testing/izhikevich/$i/processor_tool.txt tmp_pt_input.txt

bin/processor_tool_izhikevich < testing/izhikevich/$i/processor_tool.txt > tmp_pt_output.txt 2> tmp_pt_error.txt
if [ `wc tmp_pt_error.txt | awk '{ print $1 }'` != 0 ]; then
echo "Test $i - $l" >&2
echo "There was an error in the processor_tool_izhikevich command when I ran:" >&2
echo "" >&2
echo "bin/processor_tool_izhikevich < testing/izhikevich/$i/processor_tool.txt" >&2
echo "" >&2
cat tmp_pt_error.txt >&2
exit 1
fi

d=`diff tmp_pt_output.txt testing/izhikevich/$i/correct_output.txt | wc | awk '{ print $1 }'`
if [ $d != 0 ]; then
echo "Test $i - $l" >&2
echo "Error: Output does not match the correct output." >&2
echo " Output file is tmp_pt_output.txt" >&2
echo " Correct output file is testing/izhikevich/$i/correct_output.txt" >&2
exit 1
fi

echo "Passed Test $i - $l"
if [ $keep = no ]; then
rm -f tmp_proc_params.txt \
tmp_network.txt \
tmp_nt_output.txt \
tmp_pt_output.txt \
tmp_pt_input.txt \
tmp_pt_error.txt \
tmp_empty_network.txt
fi

done
28 changes: 14 additions & 14 deletions scripts/test_risp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi
t="$1"

if [ T"$t" = 'T-' ]; then
t=`ls testing`
t=`ls testing/risp`
fi

# Make the two executables if they aren't made yet.
Expand All @@ -25,34 +25,34 @@ done

for i in $t ; do
i=`echo $i | awk '{ printf "%02d\n", $1 }'`
if [ ! -d testing/$i ]; then
echo "Error -- no directory testing/$i" >&2
if [ ! -d testing/risp/$i ]; then
echo "Error -- no directory testing/risp/$i" >&2
exit 1
fi

for f in label.txt network_tool.txt processor.sh processor_tool.txt correct_output.txt ; do
if [ ! -f testing/$i/$f ]; then
echo "Error -- no file testing/$i/$f" >&2
if [ ! -f testing/risp/$i/$f ]; then
echo "Error -- no file testing/risp/$i/$f" >&2
exit 1
fi
done

# Create the processor params, and then an empty network

l=`cat testing/$i/label.txt`
sh testing/$i/processor.sh > tmp_proc_params.txt
l=`cat testing/risp/$i/label.txt`
sh testing/risp/$i/processor.sh > tmp_proc_params.txt

( echo M risp tmp_proc_params.txt
echo EMPTYNET tmp_empty_network.txt ) | bin/processor_tool_risp

# Use network_tool.txt to create the network.

bin/network_tool < testing/$i/network_tool.txt > tmp_nt_output.txt 2>&1
bin/network_tool < testing/risp/$i/network_tool.txt > tmp_nt_output.txt 2>&1
if [ `wc tmp_nt_output.txt | awk '{ print $1 }'` != 0 ]; then
echo "Test $i - $l" >&2
echo "There was an error in the network_tool command when I ran:" >&2
echo "" >&2
echo "bin/network_tool < testing/$i/network_tool.txt > tmp_nt_output.txt" >&2
echo "bin/network_tool < testing/risp/$i/network_tool.txt > tmp_nt_output.txt" >&2
echo "" >&2
cat tmp_nt_output.txt >&2
exit 1
Expand All @@ -61,25 +61,25 @@ for i in $t ; do
# Now, you'll execute the commands in processor_tool.txt and compare the output
# against known output.

cp testing/$i/processor_tool.txt tmp_pt_input.txt
cp testing/risp/$i/processor_tool.txt tmp_pt_input.txt

bin/processor_tool_risp < testing/$i/processor_tool.txt > tmp_pt_output.txt 2> tmp_pt_error.txt
bin/processor_tool_risp < testing/risp/$i/processor_tool.txt > tmp_pt_output.txt 2> tmp_pt_error.txt
if [ `wc tmp_pt_error.txt | awk '{ print $1 }'` != 0 ]; then
echo "Test $i - $l" >&2
echo "There was an error in the processor_tool_risp command when I ran:" >&2
echo "" >&2
echo "bin/processor_tool_risp < testing/$i/processor_tool.txt" >&2
echo "bin/processor_tool_risp < testing/risp/$i/processor_tool.txt" >&2
echo "" >&2
cat tmp_pt_error.txt >&2
exit 1
fi

d=`diff tmp_pt_output.txt testing/$i/correct_output.txt | wc | awk '{ print $1 }'`
d=`diff tmp_pt_output.txt testing/risp/$i/correct_output.txt | wc | awk '{ print $1 }'`
if [ $d != 0 ]; then
echo "Test $i - $l" >&2
echo "Error: Output does not match the correct output." >&2
echo " Output file is tmp_pt_output.txt" >&2
echo " Correct output file is testing/$i/correct_output.txt" >&2
echo " Correct output file is testing/risp/$i/correct_output.txt" >&2
exit 1
fi

Expand Down
Loading