(Luận văn thạc sĩ hcmute) điều khiển và giám sát mô hình nhà kính thông minh ứng dụng iot (internet of things) và thuật toán support vector machines

161 5 0
(Luận văn thạc sĩ hcmute) điều khiển và giám sát mô hình nhà kính thông minh ứng dụng iot (internet of things) và thuật toán support vector machines

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH LUẬN VĂN THẠC SĨ TRƯƠNG NGỌC HẢI NAM ÐIỀU KHIỂN VÀ GIÁM SÁT MƠ HÌNH NHÀ KÍNH THƠNG MINH ỨNG DỤNG IOT( INTERNET OF THINGS) VÀ THUẬT TOÁN SUPPORT VECTOR MACHINES NGÀNH: KỸ THUẬT CƠ ÐIỆN TỬ - 8520114 S K C0 Tp Hồ Chí Minh, tháng 04/2018 Luan van BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH LUẬN VĂN THẠC SỸ TRƯƠNG NGỌC HẢI NAM ĐIỀU KHIỂN VÀ GIÁM SÁT MƠ HÌNH NHÀ KÍNH THƠNG MINH ỨNG DỤNG IOT( INTERNET OF THINGS) VÀ THUẬT TOÁN SUPPORT VECTOR MACHINES NGÀNH: KỸ THUẬT CƠ ĐIỆN TỬ- 8520114 Tp Hồ Chí Minh, tháng 4/ 2018 Luan van BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH LUẬN VĂN THẠC SỸ TRƯƠNG NGỌC HẢI NAM ĐIỀU KHIỂN VÀ GIÁM SÁT MÔ HÌNH NHÀ KÍNH THƠNG MINH ỨNG DỤNG IOT( INTERNET OF THINGS) VÀ THUẬT TOÁN SUPPORT VECTOR MACHINES NGÀNH: KỸ THUẬT CƠ ĐIỆN TỬ- 8520114 Hướng dẫn khóa học: TS VŨ QUANG HUY Tp Hồ Chí Minh, tháng 4/ 2018 Luan van Luan van Luan van Luan van Luan van Luan van Luan van Luan van uint32_t blk_number = 1; COM_StatusTypeDef result = COM_OK; PACKET_StatusTydeDef infPk = START_PACKET; uint32_t size_, packet_size; p_buf_int = psource; size = packet_length; String lenPacket = String(packet_length); /// add start send packet debug("address source: 0X%x length packet: %d\n", (uint32_t*)p_buf_int, size); uint16_t crc = esp_core.Cmd_response( CMD_FOTA_UPGRADE, esp_core.fota_Cb.fotaCb, 0, ); crc = esp_core.Cmd_response(crc, (uint8_t*)&packet_length , 4); crc = esp_core.Cmd_response(crc, (uint8_t*)&infPk, 1); esp_core.Cmd_response(crc); esp_core.fota_Cb.valueAck = ACK_NOT; while (!esp_core.fota_Cb.valueAck ) { esp_core.waitReturnAck(TIMEOUT_ACK); debug("value ack start packet cb: %d\n", esp_core.fota_Cb.valueAck); if (esp_core.fota_Cb.valueAck == ACK_NOT) { errors0++; if (errors0 >= MAX_ERRORS) { debug("error ack\n"); return false; } } } /*Here 256 byte used to send packet*/ while ( (size) && (result == COM_OK) ){ /* Make first three packet */ packet_size = size >= PACKET_256_SIZE ? PACKET_256_SIZE : PACKET_SIZE; size_ = size < packet_size ? size : packet_size; memset(PacketData, '\0', sizeof(PacketData)); debug("address p_buf_int 0X%x size packet %d\n",(uint32_t*)p_buf_int,size_); uint32_t pp_buf_int = (uint32_t)p_buf_int; if(!spiffs_hal_read(pp_buf_int,size_, PacketData)) { debug("string:: "); for (int i = 0; i < size_; i++) { debugx("%c",PacketData[i]); } esp_core.fota_Cb.valueAck = ACK_NOT; while ((!esp_core.fota_Cb.valueAck) && (result == COM_OK) ){ /* Send next packet */ uint16_t crc = esp_core.Cmd_response(CMD_FOTA_UPGRADE, esp_core.fota_Cb.fotaCb, 0, ); crc = esp_core.Cmd_response(crc, (uint8_t*)&blk_number, 4); crc = esp_core.Cmd_response(crc, (uint8_t*)&PacketData[0], size_); 124 Luan van esp_core.Cmd_response(crc); /*Wait for Ack*/ esp_core.waitReturnAck(TIMEOUT_ACK); if ((esp_core.fota_Cb.valueAck == ACK_OK) && ( esp_core.fota_Cb.numberPk == blk_number) ) { if (size > size_) { debug("size of p_buf_int befor: 0X%x : ",(uint32_t*)p_buf_int); p_buf_int += size_; debug("size of p_buf_int after: 0X%x\n",(uint32_t*)p_buf_int); size -= size_; if (blk_number == ((uint32_t)spiffsSize / PACKET_256_SIZE)) { result = COM_LIMIT; /* boundary error */ } else { blk_number++; } } else { p_buf_int += size_; size = 0; } } else { errors++; } if (errors >= MAX_ERRORS) { debug("error ack\n"); result = COM_ERROR; } } } } if (result == COM_ERROR) { return false; } // add stop send packet infPk = END_PACKET; esp_core.fota_Cb.valueAck = ACK_NOT; while (!esp_core.fota_Cb.valueAck ) { crc = esp_core.Cmd_response(CMD_FOTA_UPGRADE, esp_core.fota_Cb.fotaCb, 0, ); crc = esp_core.Cmd_response(crc, (uint8_t*)&blk_number, 4); crc = esp_core.Cmd_response(crc, (uint8_t*)&infPk, 1); esp_core.Cmd_response(crc); esp_core.waitReturnAck(TIMEOUT_ACK); debug("value ack end packet cb: %d\n", esp_core.fota_Cb.valueAck); if (esp_core.fota_Cb.valueAck == ACK_NOT) { errors0++; if (errors0 >= MAX_ERRORS) { debug("error ack\n"); return false; } } } return true; } static bool protocolSizeData(uint8_t *psource, uint8_t *dsource, uint32_t packet_length) { 125 Luan van uint32_t errors0 = 0,errors = 0, ack_recpt = 0, size = 0; uint8_t *p_buf_int, *p_buf_out; uint32_t size_, packet_size; p_buf_int = psource; p_buf_out = dsource; size = packet_length; while (size) { packet_size = size >= PACKET_256_SIZE ? PACKET_256_SIZE : PACKET_SIZE; size_ = size < packet_size ? size : packet_size; uint32_t pp_buf_int = (uint32_t)p_buf_int; uint32_t pp_buf_out = (uint32_t)p_buf_out; if(!spiffs_hal_read(pp_buf_int,size_, PacketData)) { debug("string:: "); for (int i = 0; i < size_; i++) { debugx("%c",PacketData[i]); } if(!spiffs_hal_write(pp_buf_out, size_, PacketData)) { if (size > size_){ debug("size of p_buf_int befor: 0X%x : ",(uint32_t*)p_buf_int); p_buf_int += size_; p_buf_out += size_; debug("size of p_buf_int after: 0X%x\n",(uint32_t*)p_buf_int); size -= size_; } else { p_buf_int += size_; p_buf_out += size_; size = 0; } } else { return false; } } } return true; } static bool protocolSizeData_(uint8_t *psource, const char *pdata, uint32_t packet_length){ uint32_t errors0 = 0,errors = 0, ack_recpt = 0, size = 0; uint8_t *p_buf_int; const char *p_buf_data; uint32_t size_, packet_size; p_buf_int = psource; p_buf_data = pdata; size = packet_length; File fwrite_ = SPIFFS.open(p_buf_data, "w"); while (size) { packet_size = size >= PACKET_256_SIZE ? PACKET_256_SIZE : PACKET_SIZE; size_ = size < packet_size ? size : packet_size; uint32_t pp_buf_int = (uint32_t)p_buf_int; if(!spiffs_hal_read(pp_buf_int,size_, PacketData)){ debug("string:: "); for (int i = 0; i < size_; i++) { debugx("%c",PacketData[i]); } debug("\n"); if (fwrite_.write(PacketData, size_)) { if (size > size_) { 126 Luan van debug("size of p_buf_int befor: 0X%x : ",(uint32_t*)p_buf_int); p_buf_int += size_; debug("size of p_buf_int after: 0X%x\n",(uint32_t*)p_buf_int); size -= size_; } else { p_buf_int += size_; size = 0; } } else { return false; } } } return true; } Code thuật toán Support Vector Machines 4.1 Code tập huấn #include #include #include #include #include #include "svm.h" #define Malloc(type,n) (type *)malloc((n)*sizeof(type)) void print_null(const char *s) {} void exit_with_help() { printf( "Usage: svm-train [options] training_set_file [model_file]\n" "options:\n" "-s svm_type : set type of SVM (default 0)\n" " C-SVC (multi-class classification)\n" " nu-SVC (multi-class classification)\n" " one-class SVM\n" " epsilon-SVR (regression)\n" " nu-SVR (regression)\n" "-t kernel_type : set type of kernel function (default 2)\n" " linear: u'*v\n" " polynomial: (gamma*u'*v + coef0)^degree\n" " radial basis function: exp(-gamma*|u-v|^2)\n" " sigmoid: tanh(gamma*u'*v + coef0)\n" " precomputed kernel (kernel values in training_set_file)\n" "-d degree : set degree in kernel function (default 3)\n" "-g gamma : set gamma in kernel function (default 1/num_features)\n" "-r coef0 : set coef0 in kernel function (default 0)\n" "-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)\n" "-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)\n" "-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)\n" "-m cachesize : set cache memory size in MB (default 100)\n" "-e epsilon : set tolerance of termination criterion (default 0.001)\n" "-h shrinking : whether to use the shrinking heuristics, or (default 1)\n" "-b probability_estimates : whether to train a SVC or SVR model for probability estimates, or (default 0)\n" "-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)\n" "-v n: n-fold cross validation mode\n" "-q : quiet mode (no outputs)\n" 127 Luan van ); exit(1); } void exit_input_error(int line_num) { fprintf(stderr,"Wrong input format at line %d\n", line_num); exit(1); } void parse_command_line(int argc, char **argv, char *input_file_name, char *model_file_name); void read_problem(const char *filename); void do_cross_validation(); struct svm_parameter param; struct svm_problem prob; struct svm_model *model; struct svm_node *x_space; int cross_validation; int nr_fold; // set by parse_command_line // set by read_problem static char *line = NULL; static int max_line_len; static char* readline(FILE *input) { int len; if(fgets(line,max_line_len,input) == NULL) return NULL; while(strrchr(line,'\n') == NULL) { max_line_len *= 2; line = (char *) realloc(line,max_line_len); len = (int) strlen(line); if(fgets(line+len,max_line_len-len,input) == NULL) break; } return line; } int main(int argc, char **argv) { char input_file_name[1024]; char model_file_name[1024]; const char *error_msg; parse_command_line(argc, argv, input_file_name, model_file_name); read_problem(input_file_name); error_msg = svm_check_parameter(&prob,¶m); if(error_msg) { fprintf(stderr,"ERROR: %s\n",error_msg); exit(1); } if(cross_validation) { do_cross_validation(); } else 128 Luan van { model = svm_train(&prob,¶m); if(svm_save_model(model_file_name,model)) { fprintf(stderr, "can't save model to file %s\n", model_file_name); exit(1); } svm_free_and_destroy_model(&model); } svm_destroy_param(¶m); free(prob.y); free(prob.x); free(x_space); free(line); return 0; } void do_cross_validation() { int i; int total_correct = 0; double total_error = 0; double sumv = 0, sumy = 0, sumvv = 0, sumyy = 0, sumvy = 0; double *target = Malloc(double,prob.l); svm_cross_validation(&prob,¶m,nr_fold,target); if(param.svm_type == EPSILON_SVR || param.svm_type == NU_SVR) { for(i=0;i=argc) exit_with_help(); strcpy(input_file_name, argv[i]); if(i

Ngày đăng: 02/02/2023, 09:43

Tài liệu cùng người dùng

Tài liệu liên quan