Exemplo n.º 1
0
int read_module_settings(const char *filename, const char *module, settings_callback fcn, void *data)
{
	config_t cfg;
	config_setting_t *elem;

	if (!fcn || !filename)
		return -EINVAL;

	memset(&cfg, 0, sizeof(cfg));
	config_init(&cfg);

	/* Read the file. If there is an error, report it and exit. */
	if (read_settings_file(&cfg, filename) != CONFIG_TRUE) {
		config_destroy(&cfg);
		ERROR("Error reading configuration file, skipping....");
		return -EINVAL;
	}

	elem = find_settings_node(&cfg, module);

	if (!elem) {
		config_destroy(&cfg);
		return -ENODATA;
	}

	fcn(elem, data);

	config_destroy(&cfg);

	return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	double** g; //PF firings vector
	int timestep; // timestep i++ = + 1 msec
	
	//PF synapces weights vector
	double *sigma, *vector_e;//, **eligibility_exp;
	double scalar_Purkinje_presynap, sigma_sum;
	//full time fo running
	int fulltime;// = 200000;//100000;//40000;

	//Purkinje summation window parameter
	double T_p = 20; //msec (while dt = 1 msec)
	
	double Liana_buf = 0;
	double CSpikeTime = 0;

	//initial Purkinje firing frequency
	double Purkinje = 0;

	//number of PF synapces on Purkinje cell
	int N;// = 2000;//1000;
	double epsilon;// = 0.000001;//0.000001;//0.0000001;
	int L;// = 1000;//2000; //lenght of "snake-in-a-box"
	//input_alpha(t): alpha-atm - static, alpha(timestep) - dynamic
	//double alpha_atm = 5;

	//read settings (N,L, alpha parameters) from file
	double a_amp, a_period, sigma_init;
	int gen_snake, alpha_mode;

	read_settings_file(N,L,a_amp,a_period, fulltime, gen_snake, epsilon, sigma_init, alpha_mode);
	
	//random numbers generator
	srand(time(NULL));
	vector_e = generate_eligibility(N);
	//eligibility_exp = gen_elig_exp(N);
	sigma = generate_vect_sigma(N, sigma_init);
	if (gen_snake == 1)g = generate_vect_g(N,L); //slow cause of snake/////// Write snake's file
	else if (gen_snake == 0) g = vector_g_from_file(N,L); //quick
	else if (gen_snake == 2) g = generate_random_g(N,L);
	else {printf("wrong 'gen_snake' value"); getchar();exit(-1);}

	FILE* myfile1, *myfile2, *myfile3, *myfile4, *myfile5;

	myfile1 = create_output_file("1");
	myfile2 = create_output_file("2");
	myfile3 = create_output_file("3");
	myfile4 = create_output_file("4");
	myfile5 = create_output_file("5");

	for (timestep = 0; timestep < fulltime; timestep++)
	{
		
		if (LianaCellFiringFunction(alpha(timestep,a_amp,a_period, alpha_mode), Purkinje, Liana_buf) == true) CSpikeTime = 0;
		eligibility(g, vector_e/*, eligibility_exp*/, timestep, N, L);
		changing_weights(sigma, vector_e, CSpikeTime, N, L, epsilon);
				
		//calculating of Purkinje output
		scalar_Purkinje_presynap = 0;
		sigma_sum = 0;
		for (int k = 0; k < N; k++)
		{
			scalar_Purkinje_presynap = scalar_Purkinje_presynap + sigma[k]*g[timestep%L][k];
			sigma_sum = sigma_sum + sigma[k];
		}

		//Purkinje = Purkinje*exp(-1/T_p)+scalar_Purkinje_presynap;
		Purkinje = Purkinje*0.5*0+scalar_Purkinje_presynap;
		if (timestep<200000)fprintf(myfile1, "%d %f %f %f %f %f\n",
			timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode));
		else if (timestep<400000)fprintf(myfile2, "%d %f %f %f %f %f\n",
			timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode));
		else if (timestep<600000)fprintf(myfile3, "%d %f %f %f %f %f\n",
			timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode));
		else if (timestep<800000)fprintf(myfile4, "%d %f %f %f %f %f\n",
			timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode));
		else if (timestep<1000000)fprintf(myfile5, "%d %f %f %f %f %f\n",
			timestep, sigma[0], sigma_sum, Liana_buf, Purkinje, alpha(timestep, a_amp, a_period, alpha_mode));
		else {printf("\ntimestep is out of range\n"); getchar();exit(-1);}

		CSpikeTime++;
	}

	fclose(myfile1);
	for (int i = 0; i<L; i++) free(g[i]);
	free(g);
	free(vector_e);
	fclose(myfile1); fclose(myfile2); fclose(myfile3); fclose(myfile4); fclose(myfile5);
	//free(eligibility_exp[1]);free(eligibility_exp[0]);free(eligibility_exp);
	free(sigma);

	return 0;
}