CPP处理实验数据脚本
scanf yyds
//input: multi line with pattern dims=%d,accuracy=%lf,std=%lf\n
//output: format that can be copied to excel
#include<bits/stdc++.h>
using namespace std;
int main(){
int dim;
double acc,std;
FILE *f=fopen("citeseer_acc.txt","r");
while(fscanf(f,"dims=%d,accuracy=%lf,std=%lf\n",&dim,&acc,&std)!=EOF)
cout<<dim<<' '<<acc<<' '<<std<<endl;
}
//input: multi line with format [xxxxx] s
//output: format that can be copied to excel
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]){
for(int i=16;i<=144;i+=16){
string filename=argv[1];
int dim;
double acc,std;
filename+='_'+to_string(i)+'_'+"acc.txt";
ifstream fin(filename);
//cout<<filename<<endl;
string input;
char buf[1024]={0};
while(fin>>input){
if(input.back()==']')break;
}
fin>>std>>acc;
auto s_std=to_string(std).substr(0,3);
cout<<i<<' '<<acc<<' '<<std<<endl;
//cout<<i<<' '<<acc<<"±"<<s_std<<endl;
/* FILE *f=fopen(filename.c_str(),"r");
fscanf(f,"dims=%d,accuracy=%lf,std=%lf\n",&dim,&acc,&std)!=EOF);
cout<<dim<<' '<<acc<<' '<<std<<endl; */
}
}
//参数直接写在程序后面就行。文件读错会报dump
//input: multi line with pattern dim,std
//output: acc+/-std
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int dim;
double acc, std;
//FILE* f = fopen("pubmed_result.txt", "r");
FILE* f = fopen(argv[1], "r");
vector<pair<int, string> > v;
while (fscanf(f, "%d,%lf,%lf\n", &dim, &acc, &std) != EOF) {
acc = round(acc * 10000) / 100;
std = round(std * 1000) / 10;
string a = to_string(acc);while (a.back() == '0') a.pop_back();
string b = to_string(std);while (b.back() == '0') b.pop_back();
auto y = a + "±" +b;
//x=dim;
if (dim % 10 == 0)v.push_back({ dim,y });
}
sort(v.begin(), v.end());
int cnt = 0;
for (auto t : v) {
cout << t.second << endl;
cnt++;
if (cnt == 18)break;
}
//cout << dim << ' ' << acc << ' ' << std << endl;
}
python 处理
#比较蠢的四舍五入 用f''就行
from decimal import Decimal, Context, ROUND_HALF_UP
with open('result.txt','r') as f:
for line in f:
line=line.strip().split('\t')
std=line[-1].strip()
acc=line[-2].strip()
std=Decimal(std)*100
std=Context(3,ROUND_HALF_UP).create_decimal(str(std))
acc=Decimal(acc)*100
acc=Context(3,ROUND_HALF_UP).create_decimal(str(acc))
print(f"{acc}±{std}")
import os
import json
os.chdir(f"/home/dell/src/su/SDE/origin_env/SubGNN/dataset/tensorboard")
for i in range(3,9):
os.chdir(f"component_{i*10}") #修改当前工作目录
with open('experiment_results.json','r') as f:
x=json.load(f)
acc=x['test_micro_f1_mean']
std=x['test_micro_f1_sd']
print(f'{acc*100:.1f}+{std*100:.1f}')
os.chdir('..')
#print(os.getcwd())
SubGNN配合tensorboard
import os
import json
os.chdir(f"/home/dell/src/su/SDE/origin_env/SubGNN/dataset/tensorboard")
for i in range(3,9):
os.chdir(f"component_{i*10}") #修改当前工作目录
with open('experiment_results.json','r') as f:
x=json.load(f)
acc=x['test_micro_f1_mean']
std=x['test_micro_f1_sd']
print(f'{acc*100:.1f}+{std*100:.1f}')
os.chdir('..')
#print(os.getcwd())