PageRenderTime 48ms CodeModel.GetById 2ms app.highlight 40ms RepoModel.GetById 2ms app.codeStats 0ms

/read_datasets.h

https://github.com/lionelc/ANN-TrCL
C++ Header | 804 lines | 706 code | 94 blank | 4 comment | 190 complexity | 67f59a649d759f2b82e85d1e8972e317 MD5 | raw file
  1//read hurricane-related data into neural network
  2//written by Lei Jiang, Center for Computation and Technology, Louisiana State University
  3
  4//the code is now for testbed only. The robustness of functionality is not guaranteed. The original author is glad to know any major modification of key functionality
  5//by the user of codes.
  6
  7#define LEARNING_FILE_PATH_RBF  ".\\learning_error_archive\\learning_error_RBF.txt"
  8#define VALIDATION_OUT_FILE_PATH_RBF  ".\\learning_error_archive\\validation_error_RBF.txt"
  9
 10#define LEARNING_FILE_PATH   ".\\learning_error_archive\\learning_error.txt"
 11#define VALIDATION_OUT_FILE_PATH1  ".\\learning_error_archive\\tf_validation_error_counter.txt"
 12
 13#define WEIGHT_I_H_FILE ".\\learning_error_archive\\weight_i_h_counter.txt"
 14#define WEIGHT_H_O_FILE ".\\learning_error_archive\\weight_h_o_counter.txt"
 15
 16#define WEIGHT_I_H_FILE_RBF ".\\learning_error_archive\\weight_i_h_rbf_counter.txt"
 17#define WEIGHT_H_O_FILE_RBF ".\\learning_error_archive\\weight_h_o_rbf_counter.txt"
 18
 19#define TRAINING_FILE_PATH_TEST  ".\\learning_error_archive\\test.txt"
 20#define VALIDATION_FILE_PATH_TEST  ".\\learning_error_archive\\test.txt"
 21
 22#define LEARNING_CURVE_PATH ".\\learning_error_archive\\learning_curve_counter.txt"
 23
 24
 25void read_output_file(char* in_filename, int start, int end, double* obs, double* pred)
 26{
 27	int i=0, j=0; 
 28	int count =0, timecount=0; //count the num of edges
 29	int firstmark =0;
 30	char tempstr[MAX_LINE_LENGTH];
 31	char  tempchar[LINE_THRESHOLD];
 32	for(i=0;i< MAX_LINE_LENGTH;i++)
 33		tempstr[i] = '\0';
 34	
 35	bool startmark = false;
 36	int startcount =0;
 37	
 38	FILE *file;
 39	file = fopen (in_filename, "r");
 40	if (!file)
 41	{
 42		printf ("Error opening %s\n", in_filename);
 43		exit(0);
 44	}
 45	
 46	while(fgets(tempstr,MAX_LINE_LENGTH,file))
 47	{
 48		i = 0;
 49		firstmark = 0;
 50		
 51		for(j=0; j< LINE_THRESHOLD; j++)
 52			tempchar[j] = '\0';
 53		
 54		if(tempstr[0] == '"' || tempstr[0] == '#')
 55			continue;
 56		
 57		if(!startmark)
 58		{
 59			if(startcount< start-1)
 60			{
 61				startcount++;
 62				continue;
 63			}
 64			else
 65				startmark = true; 
 66		}
 67		
 68		while(tempstr[i] != ' ' && tempstr[i] != 9)
 69		{
 70			tempchar[firstmark] = tempstr[i];
 71			i++;
 72			firstmark++;
 73		}
 74
 75		//added May 21
 76        timecount = atoi(tempchar);
 77
 78		for(j=0; j< firstmark; j++)
 79			tempchar[j] = '\0';
 80		firstmark = 0;
 81		
 82		while(tempstr[i] == ' ' || tempstr[i] == 9)
 83		{
 84			i++;
 85		}
 86        
 87		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
 88		{
 89			tempchar[firstmark] = tempstr[i];
 90			i++;
 91			firstmark++;
 92		}
 93		
 94		obs[count] = atof(tempchar);
 95		
 96		for(j=0; j< firstmark; j++)
 97			tempchar[j] = '\0';
 98		firstmark = 0;
 99		
100		while(tempstr[i] == ' ' || tempstr[i] == 9)
101		{
102			i++;
103		}
104        
105		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
106		{
107			tempchar[firstmark] = tempstr[i];
108			i++;
109			firstmark++;
110		}
111		
112		pred[count] = atof(tempchar);
113		count++;
114		
115		if(count>= end-start+1)
116			break;
117	}
118	
119    fclose(file);
120	return;
121}
122
123void read_max_wave_file(char* in_filename, int start, int end)
124{
125	int i=0, j=0; 
126	int count =0; //count the num of edges
127	int firstmark =0;
128	char tempstr[MAX_LINE_LENGTH];
129	char  tempchar[LINE_THRESHOLD];
130	for(i=0;i< MAX_LINE_LENGTH;i++)
131		tempstr[i] = '\0';
132	
133	bool startmark = false;
134	int startcount =0;
135	
136	FILE *file;
137	file = fopen (in_filename, "r");
138	if (!file)
139	{
140		printf ("Error opening %s\n", in_filename);
141		exit(0);
142	}
143	
144	while(fgets(tempstr,MAX_LINE_LENGTH,file))
145	{
146		i = 0;
147		firstmark = 0;
148		
149		for(j=0; j< LINE_THRESHOLD; j++)
150			tempchar[j] = '\0';
151		
152		if(tempstr[0] == '"' || tempstr[0] == '#')
153			continue;
154		
155		if(!startmark)
156		{
157			if(startcount< start-1)
158			{
159				startcount++;
160				continue;
161			}
162			else
163				startmark = true; 
164		}
165		
166		while(tempstr[i] != ' ' && tempstr[i] != 9)
167		{
168			tempchar[firstmark] = tempstr[i];
169			i++;
170			firstmark++;
171		}
172		
173		omega_c[count] = atof(tempchar);
174		
175		for(j=0; j< firstmark; j++)
176			tempchar[j] = '\0';
177		firstmark = 0;
178		
179		while(tempstr[i] == ' ' || tempstr[i] == 9)
180		{
181			i++;
182		}
183        
184		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
185		{
186			tempchar[firstmark] = tempstr[i];
187			i++;
188			firstmark++;
189		}
190		
191		size_c[count] = atof(tempchar);
192
193		for(j=0; j< firstmark; j++)
194			tempchar[j] = '\0';
195		firstmark = 0;
196		
197		while(tempstr[i] == ' ' || tempstr[i] == 9)
198		{
199			i++;
200		}
201        
202		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
203		{
204			tempchar[firstmark] = tempstr[i];
205			i++;
206			firstmark++;
207		}
208		
209		radius_c[count] = atof(tempchar);
210
211		for(j=0; j< firstmark; j++)
212			tempchar[j] = '\0';
213		firstmark = 0;
214		
215		while(tempstr[i] == ' ' || tempstr[i] == 9)
216		{
217			i++;
218		}
219        
220		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
221		{
222			tempchar[firstmark] = tempstr[i];
223			i++;
224			firstmark++;
225		}
226		
227		maxw_c[count] = atof(tempchar);
228
229		count++;
230		
231		if(count>= end-start+1)
232			break;
233	}
234	
235    fclose(file);
236	return;
237}
238
239void read_cos_file(char* in_filename, int start, int end)
240{
241	int i=0, j=0; 
242	int count =0; //count the num of edges
243	int firstmark =0;
244	char tempstr[MAX_LINE_LENGTH];
245	char  tempchar[LINE_THRESHOLD];
246	for(i=0;i< MAX_LINE_LENGTH;i++)
247		tempstr[i] = '\0';
248	
249	bool startmark = false;
250	int startcount =0;
251	
252	FILE *file;
253	file = fopen (in_filename, "r");
254	if (!file)
255	{
256		printf ("Error opening %s\n", in_filename);
257		exit(0);
258	}
259	
260	while(fgets(tempstr,MAX_LINE_LENGTH,file))
261	{
262		i = 0;
263		firstmark = 0;
264		
265		for(j=0; j< LINE_THRESHOLD; j++)
266			tempchar[j] = '\0';
267		
268		if(tempstr[0] == '"' || tempstr[0] == '#')
269			continue;
270		
271		if(!startmark)
272		{
273			if(startcount< start-1)
274			{
275				startcount++;
276				continue;
277			}
278			else
279				startmark = true; 
280		}
281		
282		while(tempstr[i] != ' ' && tempstr[i] != 9)
283		{
284			tempchar[firstmark] = tempstr[i];
285			i++;
286			firstmark++;
287		}
288		
289		toy_input[count] = atof(tempchar);
290		
291		for(j=0; j< firstmark; j++)
292			tempchar[j] = '\0';
293		firstmark = 0;
294		
295		while(tempstr[i] == ' ' || tempstr[i] == 9)
296		{
297			i++;
298		}
299        
300		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
301		{
302			tempchar[firstmark] = tempstr[i];
303			i++;
304			firstmark++;
305		}
306		
307		toy_output[count] = atof(tempchar);
308
309		count++;
310		
311		if(count>= end-start+1)
312			break;
313	}
314	
315    fclose(file);
316	return;
317}
318
319void read_unary_file(char* in_filename, int start, int end)
320{
321	int i=0, j=0; 
322	int count =0; //count the num of edges
323	int firstmark =0;
324	char tempstr[MAX_LINE_LENGTH];
325	char  tempchar[LINE_THRESHOLD];
326	for(i=0;i< MAX_LINE_LENGTH;i++)
327		tempstr[i] = '\0';
328	
329	bool startmark = false;
330	int startcount =0;
331	
332	FILE *file;
333	file = fopen (in_filename, "r");
334	if (!file)
335	{
336		printf ("Error opening %s\n", in_filename);
337		exit(0);
338	}
339	
340	while(fgets(tempstr,MAX_LINE_LENGTH,file))
341	{
342		i = 0;
343		firstmark = 0;
344		
345		for(j=0; j< LINE_THRESHOLD; j++)
346			tempchar[j] = '\0';
347		
348		if(tempstr[0] == '"' || tempstr[0] == '#')
349			continue;
350		
351		if(!startmark)
352		{
353			if(startcount< start-1)
354			{
355				startcount++;
356				continue;
357			}
358			else
359				startmark = true; 
360		}
361
362		while(tempstr[i] == ' ' || tempstr[i] == 9)
363		{
364			i++;
365		}
366
367		while(tempstr[i] != ' ' && tempstr[i] != 9)
368		{
369			tempchar[firstmark] = tempstr[i];
370			i++;
371			firstmark++;
372		}
373		
374		omega_c[count] = atof(tempchar);
375
376		for(j=0; j< firstmark; j++)
377			tempchar[j] = '\0';
378		firstmark = 0;
379		
380		while(tempstr[i] == ' ' || tempstr[i] == 9)
381		{
382			i++;
383		}
384        
385		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
386		{
387			tempchar[firstmark] = tempstr[i];
388			i++;
389			firstmark++;
390		}
391		
392		radius_c[count] = atof(tempchar);
393
394		for(j=0; j< firstmark; j++)
395			tempchar[j] = '\0';
396		firstmark = 0;
397		
398		while(tempstr[i] == ' ' || tempstr[i] == 9)
399		{
400			i++;
401		}
402        
403		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
404		{
405			tempchar[firstmark] = tempstr[i];
406			i++;
407			firstmark++;
408		}
409		
410		size_c[count] = atof(tempchar);
411		
412		for(j=0; j< firstmark; j++)
413			tempchar[j] = '\0';
414		firstmark = 0;
415		
416		while(tempstr[i] == ' ' || tempstr[i] == 9)
417		{
418			i++;
419		}
420        
421		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
422		{
423			tempchar[firstmark] = tempstr[i];
424			i++;
425			firstmark++;
426		}
427		
428		max_wave_sim[count][0] = atof(tempchar);
429
430		for(j=0; j< firstmark; j++)
431			tempchar[j] = '\0';
432		firstmark = 0;
433		
434		while(tempstr[i] == ' ' || tempstr[i] == 9)
435		{
436			i++;
437		}
438        
439		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
440		{
441			tempchar[firstmark] = tempstr[i];
442			i++;
443			firstmark++;
444		}
445		
446		max_wave_sim[count][1] = atof(tempchar);
447
448		for(j=0; j< firstmark; j++)
449			tempchar[j] = '\0';
450		firstmark = 0;
451		
452		while(tempstr[i] == ' ' || tempstr[i] == 9)
453		{
454			i++;
455		}
456        
457		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
458		{
459			tempchar[firstmark] = tempstr[i];
460			i++;
461			firstmark++;
462		}
463		
464		max_wave_sim[count][2] = atof(tempchar);
465
466		for(j=0; j< firstmark; j++)
467			tempchar[j] = '\0';
468		firstmark = 0;
469		
470		while(tempstr[i] == ' ' || tempstr[i] == 9)
471		{
472			i++;
473		}
474        
475		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10)
476		{
477			tempchar[firstmark] = tempstr[i];
478			i++;
479			firstmark++;
480		}
481		
482		max_wave_sim[count][3] = atof(tempchar);
483
484		count++;
485		
486		if(count>= end-start+1)
487			break;
488	}
489	
490    fclose(file);
491	return;
492}
493
494
495void read_letter_file(char* in_filename, int start, int end)
496{
497	int i=0, j=0; 
498	int count =0; //count the num of edges
499	int firstmark =0;
500	char tempstr[MAX_LINE_LENGTH];
501	char  tempchar[LINE_THRESHOLD];
502	for(i=0;i< MAX_LINE_LENGTH;i++)
503		tempstr[i] = '\0';
504	
505	bool startmark = false;
506	int startcount =0;
507	
508	FILE *file;
509	file = fopen (in_filename, "r");
510	if (!file)
511	{
512		printf ("Error opening %s\n", in_filename);
513		exit(0);
514	}
515	
516	while(fgets(tempstr,MAX_LINE_LENGTH,file))
517	{
518		i = 0;
519		firstmark = 0;
520		
521		for(j=0; j< LINE_THRESHOLD; j++)
522			tempchar[j] = '\0';
523		
524		if(tempstr[0] == '"' || tempstr[0] == '#')
525			continue;
526		
527		if(!startmark)
528		{
529			if(startcount< start-1)
530			{
531				startcount++;
532				continue;
533			}
534			else
535				startmark = true; 
536		}
537		
538		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i]!=',')
539		{
540			tempchar[firstmark] = tempstr[i];
541			i++;
542			firstmark++;
543		}
544		
545		letter_class[count] = (int)tempchar[0]-65;
546		
547		for(int s=0; s<= 15; s++)
548		{
549			for(j=0; j< firstmark; j++)
550			tempchar[j] = '\0';
551		firstmark = 0;
552		while(tempstr[i] == ' ' || tempstr[i] == 9 ||tempstr[i]==',')
553		{
554			i++;
555		}
556        
557		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10 && tempstr[i]!=',')
558		{
559			tempchar[firstmark] = tempstr[i];
560			i++;
561			firstmark++;
562		}
563		
564		input_letter[count][s] = atoi(tempchar);
565		}
566
567		count++;
568		
569		if(count>= end-start+1)
570			break;
571	}
572	
573    fclose(file);
574	return;
575}
576
577void read_mushroom_file(char* in_filename, int start, int end)
578{
579	int i=0, j=0; 
580	int count =0; //count the num of edges
581	int firstmark =0;
582	char tempstr[MAX_LINE_LENGTH];
583	char  tempchar[LINE_THRESHOLD];
584	for(i=0;i< MAX_LINE_LENGTH;i++)
585		tempstr[i] = '\0';
586	
587	bool startmark = false;
588	int startcount =0;
589	
590	FILE *file;
591	file = fopen (in_filename, "r");
592	if (!file)
593	{
594		printf ("Error opening %s\n", in_filename);
595		exit(0);
596	}
597	
598	while(fgets(tempstr,MAX_LINE_LENGTH,file))
599	{
600		i = 0;
601		firstmark = 0;
602		
603		for(j=0; j< LINE_THRESHOLD; j++)
604			tempchar[j] = '\0';
605		
606		if(tempstr[0] == '"' || tempstr[0] == '#')
607			continue;
608		
609		if(!startmark)
610		{
611			if(startcount< start-1)
612			{
613				startcount++;
614				continue;
615			}
616			else
617				startmark = true; 
618		}
619		
620		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i]!=',')
621		{
622			tempchar[firstmark] = tempstr[i];
623			i++;
624			firstmark++;
625		}
626		
627		if(tempchar[0] == 'p')
628	 	     mushroom_class[count] = 0;
629		else if (tempchar[0] == 'e')
630			 mushroom_class[count] = 1;
631		
632		for(int s=0; s< 10; s++)
633		{
634			for(j=0; j< firstmark; j++)
635				tempchar[j] = '\0';
636			firstmark = 0;
637			while(tempstr[i] == ' ' || tempstr[i] == 9 ||tempstr[i]==',')
638			{
639				i++;
640			}
641
642			while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10 && tempstr[i]!=',')
643			{
644				tempchar[firstmark] = tempstr[i];
645				i++;
646				firstmark++;
647			}
648
649			input_mushroom[count][s] = (int)tempchar[0]-97;
650		}
651        	for(j=0; j< firstmark; j++)
652				tempchar[j] = '\0';
653			firstmark = 0;
654			while(tempstr[i] == ' ' || tempstr[i] == 9 ||tempstr[i]==',')
655			{
656				i++;
657			}
658
659			while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10 && tempstr[i]!=',')
660			{
661				tempchar[firstmark] = tempstr[i];
662				i++;
663				firstmark++;
664			}
665         for(int s=10; s< 21; s++)
666		{
667			for(j=0; j< firstmark; j++)
668				tempchar[j] = '\0';
669			firstmark = 0;
670			while(tempstr[i] == ' ' || tempstr[i] == 9 ||tempstr[i]==',')
671			{
672				i++;
673			}
674
675			while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10 && tempstr[i]!=',')
676			{
677				tempchar[firstmark] = tempstr[i];
678				i++;
679				firstmark++;
680			}
681
682			input_mushroom[count][s] = (int)tempchar[0]-97;
683		}
684
685		count++;
686		
687		if(count>= end-start+1)
688			break;
689	}
690	
691    fclose(file);
692	return;
693}
694
695void read_aus_file(char* in_filename, int start, int end)
696{
697	int i=0, j=0, temp; 
698	int count =0; //count the num of edges
699	int firstmark =0;
700	char tempstr[MAX_LINE_LENGTH];
701	char  tempchar[LINE_THRESHOLD];
702	for(i=0;i< MAX_LINE_LENGTH;i++)
703		tempstr[i] = '\0';
704	
705	bool startmark = false;
706	int startcount =0;
707	
708	FILE *file;
709	file = fopen (in_filename, "r");
710	if (!file)
711	{
712		printf ("Error opening %s\n", in_filename);
713		exit(0);
714	}
715	
716	while(fgets(tempstr,MAX_LINE_LENGTH,file))
717	{
718		i = 0; temp=0;
719		firstmark = 0;
720		
721		for(j=0; j< LINE_THRESHOLD; j++)
722			tempchar[j] = '\0';
723		
724		if(tempstr[0] == '"' || tempstr[0] == '#')
725			continue;
726		
727		if(!startmark)
728		{
729			if(startcount< start-1)
730			{
731				startcount++;
732				continue;
733			}
734			else
735				startmark = true; 
736		}
737		
738		while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i]!=',')
739		{
740			tempchar[firstmark] = tempstr[i];
741			i++;
742			firstmark++;
743		}
744		
745		if(tempchar[0] == '-')
746	 	     aus_class[count] = 0;
747		else if (tempchar[0] == '+')
748			 aus_class[count] = 1;
749
750		for(int s=0; s<14 ;s++)
751			input_aus[count][s] = 0.0;
752		
753		for(int s=0; s< 14; s++)
754		{
755			if(tempstr[i] == '\0' || tempstr[i] == 9 || tempstr[i]==10)
756				break;
757
758			for(j=0; j< firstmark; j++)
759				tempchar[j] = '\0';
760			firstmark = 0;
761			while(tempstr[i] == ' '|| tempstr[i] == 9 ||tempstr[i]==',')
762			{
763				i++;
764			}
765
766			while(tempstr[i] != ' ' && tempstr[i]!=':' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10 )
767			{
768				tempchar[firstmark] = tempstr[i];
769				i++;
770				firstmark++;
771			}
772			temp = atoi(tempchar);
773			if(temp <1)
774				break;
775
776			for(j=0; j< firstmark; j++)
777				tempchar[j] = '\0';
778			firstmark=0;
779
780			i++;  //for the colon
781
782			while(tempstr[i] != ' ' && tempstr[i] != 9 && tempstr[i] != '\0' && tempstr[i] != 10 && tempstr[i]!=',' && tempstr[i]!=':')
783			{
784				tempchar[firstmark] = tempstr[i];
785				i++;
786				firstmark++;
787			}
788
789			input_aus[count][temp-1] = atof(tempchar);
790
791			if(temp == 14)
792				break;
793		}
794        	
795		count++;
796		
797		if(count>= end-start+1)
798			break;
799	}
800	
801    fclose(file);
802	return;
803}
804