Skip to content

Commit

Permalink
add c elegans model
Browse files Browse the repository at this point in the history
  • Loading branch information
Auxilus committed Jul 9, 2019
1 parent 50563dd commit caa6766
Show file tree
Hide file tree
Showing 8 changed files with 4,406 additions and 13 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
C_SOURCES = $(wildcard src/*.c)
HEADERS = $(wildcard src/*.h)
HEADERS += $(wildcard src/models/*.h)
OBJ = ${C_SOURCES:.c=.o}
CFLAGS = -Wall
CC=gcc
Expand Down
1 change: 1 addition & 0 deletions src/brain.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void neuron_fire(struct neuron* n, struct brain* b)
for (int i = 0; i < p; i++) {
assert(n->links[i] <= (b->nc - 1));
assert(n->wts[i]);
cbrain_print(4, "sending weight to %d\n", n->links[i]);
b->neurons[n->links[i]]->nextstate += n->wts[i];
}
}
Expand Down
25 changes: 15 additions & 10 deletions src/cbrain.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ int main(int argc, char* argv[])
}
int neurons_no = atoi(argv[1]);
uint sleep_t;
sleep_t = (argc < 3) ? SLEEP_T : atoi(argv[2]);
sleep_t = (argc < 3) ? SLEEP_T : strtof(argv[2], NULL);

struct brain* b = brain_init((uint)neurons_no);
neuron_link_random(b);
cbrain_print(0, "%d neurons generated and randomly linked\n", neurons_no);
struct nthread* nt1 = thread_struct_new(0, neurons_no-1);
struct nthread* at = thread_struct_new(0, 0);
thread_create(nt1, b, 0, sleep_t);
thread_create(at, b, 1, sleep_t);
pthread_join(nt1->tid, NULL);
pthread_join(at->tid, NULL);
struct brain* b = parse_model_csv("src/models/conn.txt");

//struct brain* b = brain_init((uint)neurons_no);
//neuron_link_random(b);
cbrain_print(0, "%d neurons generated and randomly linked\n", b->nc);
neuron_fire(b->neurons[172], b);
neuron_fire(b->neurons[173], b);
neuron_update_range(0, 499, b);
//struct nthread* nt1 = thread_struct_new(0, neurons_no-1);
//thread_create(nt1, b, 0, sleep_t);
//struct nthread* at = thread_struct_new(0, 0);
//thread_create(at, b, 1, sleep_t);
//pthread_join(nt1->tid, NULL);
//pthread_join(at->tid, NULL);
return 0;
}
6 changes: 3 additions & 3 deletions src/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ SOFTWARE.
#include <assert.h>
#include <pthread.h>


/* control constants */
#define DEBUG 1
#define DEBUG 4
#define THRESHOLD 20
#define MAX_WT_DIFF 5
#define SLEEP_T 0
#define MUTATE_PROB 0.0001
#define MUTATE_PROB 0.00001
#define WEIGHT_MIN 1
#define WEIGHT_MAX 20

Expand Down Expand Up @@ -120,4 +119,5 @@ void save_brain(struct brain*, char*);
struct brain* gen_brain(char*);
int file_num_lines(char*);
int cbrain_print(int, const char*, ...)__attribute__((format(printf, 2, 3)));
struct brain* parse_model_csv(char*);
#endif
Loading

0 comments on commit caa6766

Please sign in to comment.