Permalink
Browse files

fixed a bug in some code involving compartments

  • Loading branch information...
1 parent 420a385 commit 44c7abb9777d2c4c1b7032c3d12085f5de043189 Anastas committed Aug 1, 2010
Showing with 40 additions and 13 deletions.
  1. +3 −1 main.c
  2. +26 −2 neuron.c
  3. +1 −0 neuron.h
  4. +9 −8 ode.c
  5. +1 −2 template.txt
View
4 main.c
@@ -17,7 +17,9 @@ int main(int argc, char** argv)
assoc_network_params(network, params);
link_neurons(network, input_filename);
- ode_run(network, 0, 350.0, 1.0e-6, 1.0e-6);
+ ode_run(network, 0, 50.0, 1.0e-6, 1.0e-6);
+
+ print_network(network);
if(argc > 2) output_state(network, init_compartment_state, params, argv[2]);
else if(argc < 2) free(input_filename);
View
28 neuron.c
@@ -15,7 +15,7 @@ struct network * create_network(char * filename)
fclose(fp);
if(DEBUG > 0)
- printf("* network->size set to %ld\n",network->size);
+ printf("* network->size set to %ld, %ld compartments each\n",network->size, network->compartments);
network->neurons = malloc(network->size*sizeof(struct neuron *));
for(i = 0; i < network->size; i++)
@@ -29,6 +29,13 @@ struct network * create_network(char * filename)
void create_neuron_compartments(struct neuron * neuron, long n)
{
long i;
+
+ if(n < 1)
+ {
+ printf("Error: number of compartments per neuron was %ld, must be poitive\n",n);
+ exit(-1);
+ }
+
neuron->compartments = (struct neuron_compartment **)malloc(n * sizeof(struct neuron_compartment *));
for(i = 0; i < n; i++)
{
@@ -45,7 +52,6 @@ struct neuron * create_neuron()
{
struct neuron * new_neuron = malloc(sizeof(struct neuron));
new_neuron->num_links = 0;
- //new_neuron->state = NULL;
new_neuron->params = NULL;
new_neuron->links = NULL;
return new_neuron;
@@ -622,3 +628,21 @@ void write_to_file(FILE * fp, char * line)
{
fwrite(line, sizeof(char), strlen(line), fp);
}
+
+// self-explanatory
+void print_network(struct network * network)
+{
+ long i,j,k;
+ for(i = 0; i < network->size; i++)
+ {
+ printf("\n=================\n\n* * NEURON %ld\n", i);
+ for(j = 0; j < network->compartments; j++)
+ {
+ printf("\n* COMPARTMENT %ld\n", j);
+ for(k = 0; k < network->neurons[i]->compartments[j]->state->num_params; k++)
+ {
+ printf("* %s = %f\n",network->neurons[i]->compartments[j]->state->names[k], network->neurons[i]->compartments[j]->state->values[k]);
+ }
+ }
+ }
+}
View
1 neuron.h
@@ -85,5 +85,6 @@ void create_queued_links(struct network * network, struct link_queue * link_queu
void output_state(struct network * network, struct compartment_state * state, struct neuron_params * params, char * filename);
void write_to_file(FILE * fp, char * line);
void init_nondefault_states(struct network * network, char * filename);
+void print_network(struct network * network);
#endif
View
17 ode.c
@@ -76,11 +76,11 @@ void ode_update_neurons(struct network * network, long start, long num, const do
for(i = start; i < limit; i++)
{
- offset = num_state_params * i;
+ offset = num_state_params * network->compartments * i;
// update params in neuron_state
- for(j = 0; j < network->neurons[i]->compartments[1]->state->num_params; j++)
- network->neurons[i]->compartments[1]->state->values[j] = y[num_state_params*i + j];
+ for(j = 0; j < network->neurons[i]->compartments[0]->state->num_params; j++)
+ network->neurons[i]->compartments[0]->state->values[j] = y[offset + j];
// potassium, from Dayan & Abbott
alpha_n = 0.02*(y[offset] + 45.7)/(1.0 - exp(-0.1*(y[offset]+45.7)));
@@ -205,8 +205,8 @@ void ode_update_neurons(struct network * network, long start, long num, const do
int ode_run(struct network * network, double t, double t1, double step_size, double error)
{
const gsl_odeiv_step_type * T = gsl_odeiv_step_rk8pd;
- long i, j, num_state_params = network->neurons[0]->compartments[0]->state->num_params;;
- long dimension = network->size * num_state_params;
+ long i, j, k, num_state_params = network->neurons[0]->compartments[0]->state->num_params;;
+ long dimension = network->size * network->compartments * num_state_params;
int status;
gsl_odeiv_step * s = gsl_odeiv_step_alloc(T, dimension);
@@ -222,10 +222,11 @@ int ode_run(struct network * network, double t, double t1, double step_size, dou
// set up ode system, four odes per neuron
// 0 = V, 1 = n, 2 = m, 3 = h
- double y[num_state_params * network->size];
+ double y[num_state_params * network->size * network->compartments];
for(i = 0; i < network->size; i++)
- for(j = 0; j < network->neurons[i]->compartments[1]->state->num_params; j++)
- y[num_state_params*i + j] = network->neurons[i]->compartments[1]->state->values[j];
+ for(j = 0; j < network->compartments; j++)
+ for(k = 0; k < num_state_params; k++)
+ y[num_state_params * network->compartments * i + num_state_params * j + k] = network->neurons[i]->compartments[j]->state->values[k];
while (t < t1)
{
View
3 template.txt
@@ -1,5 +1,5 @@
@NETWORK_SIZE
-2 2
+2 1
@PARAMS
36
@@ -62,7 +62,6 @@ s_AMPA_slow 0.0
@INIT_STATES
-
@LINKS
defined
0 1 1 0 0.5 0.5

0 comments on commit 44c7abb

Please sign in to comment.