Weather casting with Machine Learning (SVM and SRNN).
Dependencies: EthernetInterface GraphicHandler NTPClient SRNN SVM SensorModule mbed-rtos mbed
Diff: setup.cpp
- Revision:
- 5:b61f3f5b0fc8
- Parent:
- 4:00da8e8c7e2a
- Child:
- 6:29d393d430d0
--- a/setup.cpp Thu Feb 19 13:53:12 2015 +0000 +++ b/setup.cpp Thu Feb 19 19:21:16 2015 +0000 @@ -74,9 +74,11 @@ FILE* srnn_setup_fp; int ret; float buf_data[DIM_SIGNAL]; - float sample[LEN_DATA_SEQUENCE * DIM_SIGNAL]; float sample_maxmin[DIM_SIGNAL * 2]; char buf_str[20]; + + // グローバルなサンプルキューを**ここで**アロケート + srnn_sample_queue = new float[DIM_SIGNAL * LEN_DATA_SEQUENCE]; // 信号の正規化のために, 信号の最大値と最小値を決めてやる必要がある. sample_maxmin[0] = 50; @@ -95,18 +97,15 @@ int line = 0; while( ( ret = fscanf( srnn_setup_fp, " %[^\n,],%f,%f,%f", buf_str, &(buf_data[0]), &(buf_data[1]), &(buf_data[2])) ) != EOF ) { if ( line == LEN_DATA_SEQUENCE ) break; - memcpy(&(sample[line * DIM_SIGNAL]), buf_data, sizeof(float) * DIM_SIGNAL); - // printf("sample %d : %f %f %f \r\n", line, MATRIX_AT(sample,DIM_SIGNAL,line,0), MATRIX_AT(sample,DIM_SIGNAL,line,1), MATRIX_AT(sample,DIM_SIGNAL,line,2)); + memcpy(&(srnn_sample_queue[line * DIM_SIGNAL]), buf_data, sizeof(float) * DIM_SIGNAL); + // printf("sample %d : %f %f %f \r\n", line, MATRIX_AT(srnn_sample_queue,DIM_SIGNAL,line,0),MATRIX_AT(srnn_sample_queue,DIM_SIGNAL,line,1), MATRIX_AT(srnn_sample_queue,DIM_SIGNAL,line,2)); line++; } fclose( srnn_setup_fp ); /* アドバイス:RNNにおいては,ダイナミクス(中間層のニューロン数)は多いほど良い */ - srnn = new SRNN(DIM_SIGNAL, 20, LEN_DATA_SEQUENCE, PREDICT_LENGTH, sample, sample_maxmin); - - // delete [] sample; - // delete [] sample_maxmin; + srnn = new SRNN(DIM_SIGNAL, 20, LEN_DATA_SEQUENCE, PREDICT_LENGTH, srnn_sample_queue, sample_maxmin); } @@ -116,7 +115,7 @@ sensor_module = new SensorModule(5); } -/* // ネットワークのセットアップ +// ネットワークのセットアップ static void network_setup(void) { // セットアップ, 最初の時間取得 @@ -131,8 +130,8 @@ if ( eth_if.connect() < 0 ) { // (offlineが確定する -> offline modeへ). - fprintf( stderr, "%s Ethernet connect failed. \r\n", prefix_net_str); - exit(1); + fprintf( stderr, "%s Ethernet connect failed. Go To offline \r\n", prefix_net_str); + return; } // init time @@ -149,10 +148,8 @@ // http_server = new HTTPServer(80, "/local/"); printf("%s IP Address : %s \r\n", prefix_net_str, eth_if.getIPAddress()); - printf("%s Network setup finished! \r\n", prefix_net_str); } -*/ // グラフィックハンドラの初期化 static void graphic_handler_setup(void) @@ -173,7 +170,6 @@ static void jst_setup(int year, int month, int day, int hour, int min) { // setup time structure - if ( time(NULL) == 0 ) { struct tm t; t.tm_sec = 0; // 0-59 t.tm_min = min; // 0-59 @@ -185,7 +181,6 @@ // convert to timestamp and set time_t seconds = mktime(&t); set_time(seconds); - } } // セットアップ. @@ -200,8 +195,8 @@ sensor_setup(); printf("SENSOR ...OK \r\n"); // network_setup(); - jst_setup(2015, 2, 19, 21, 30); - // printf("NETWORK ...NO(offline) \r\n"); + jst_setup(2015, 2, 20, 4, 0); + printf("NETWORK ...NO(offline) \r\n"); graphic_handler_setup(); printf("GRAPHIC ...OK \r\n"); data_setup();