diff --git a/src/signature/ref/lvlx/ml_predict.c b/src/signature/ref/lvlx/ml_predict.c index 6d0af71..195b5aa 100644 --- a/src/signature/ref/lvlx/ml_predict.c +++ b/src/signature/ref/lvlx/ml_predict.c @@ -78,47 +78,47 @@ double ml_predict_success(long norm_val, int trace_val, int kernel_order) { // 日志函数:记录一次理想尝试 // 记录到 CSV 文件,包含时间戳 -// void ml_log_ideal_attempt(int attempt, -// const quat_left_ideal_t *lideal_com, -// int kernel_order, -// int success_flag) -// { -// const char *dir_path = "./dataset"; -// struct stat st = {0}; +void ml_log_ideal_attempt(int attempt, + const quat_left_ideal_t *lideal_com, + int kernel_order, + int success_flag) +{ + const char *dir_path = "./dataset"; + struct stat st = {0}; -// if (stat(dir_path, &st) == -1) { -// mkdir(dir_path, 0755); -// } + if (stat(dir_path, &st) == -1) { + mkdir(dir_path, 0755); + } -// // 使用固定文件名,避免频繁创建文件 -// char csv_path[512]; -// snprintf(csv_path, sizeof(csv_path), "%s/ideal_data.csv", dir_path); + // 使用固定文件名,避免频繁创建文件 + char csv_path[512]; + snprintf(csv_path, sizeof(csv_path), "%s/ideal_data.csv", dir_path); -// // 使用追加模式,避免覆盖 -// FILE *logfile = fopen(csv_path, "a+"); -// if (!logfile) { -// perror("无法打开 ideal_data CSV 文件"); -// return; -// } + // 使用追加模式,避免覆盖 + FILE *logfile = fopen(csv_path, "a+"); + if (!logfile) { + perror("无法打开 ideal_data CSV 文件"); + return; + } -// // 如果是第一次写入,添加表头 -// if (ftell(logfile) == 0) { -// fprintf(logfile, "Timestamp,Attempt,Norm,Trace,KernelOrder,Prob,Success\n"); -// } + // 如果是第一次写入,添加表头 + if (ftell(logfile) == 0) { + fprintf(logfile, "Timestamp,Attempt,Norm,Trace,KernelOrder,Prob,Success\n"); + } -// // 提取特征和记录 -// long norm_val = ibz_to_long_safe(&lideal_com->norm); -// int trace_val = quat_ideal_trace(lideal_com); -// double prob = ml_predict_success(norm_val, trace_val, kernel_order); + // 提取特征和记录 + long norm_val = ibz_to_long_safe(&lideal_com->norm); + int trace_val = quat_ideal_trace(lideal_com); + double prob = ml_predict_success(norm_val, trace_val, kernel_order); -// time_t t = time(NULL); -// struct tm tm_info; -// localtime_r(&t, &tm_info); -// char time_str[32]; -// strftime(time_str, sizeof(time_str), "%Y-%m-%d-%H-%M-%S", &tm_info); + time_t t = time(NULL); + struct tm tm_info; + localtime_r(&t, &tm_info); + char time_str[32]; + strftime(time_str, sizeof(time_str), "%Y-%m-%d-%H-%M-%S", &tm_info); -// fprintf(logfile, "%s,%d,%ld,%d,%d,%.3f,%d\n", -// time_str, attempt, norm_val, trace_val, kernel_order, prob, success_flag); + fprintf(logfile, "%s,%d,%ld,%d,%d,%.3f,%d\n", + time_str, attempt, norm_val, trace_val, kernel_order, prob, success_flag); -// fclose(logfile); -// } \ No newline at end of file + fclose(logfile); +} \ No newline at end of file