E
ela
I tried to add one more variable to print by using our previous programmer's
program but failed. I tried using pointer variable but also failed. the
compilable codes are as follows and
lines following the comment
"/////////////// I want to print MCC so I add this variable here"
were added by me.
Sorry but unable to provide the ana files to test but I wish this problem
can still be solved by somebody.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <map>
#include <vector>
#include <set>
using namespace std;
const char* anaFilename = "%d.txt";
char buffer[65536];
char buffer2[65536];
void wrongArgv(char **argv){
fprintf(stderr,
"Usage: %s [select how many] [total # model] \n",\
*argv);
exit(1);
}
int main(int argc, char **argv){
map<char*, vector<double> > tptable;
if(argc != 3)
wrongArgv(argv);
int select = atoi(argv[1]);
int all = atoi(argv[2]);
if(select<=0 || all<=0 || select > all)
wrongArgv(argv);
// use map for priority queue
map<double, int> mcc; //matthews correlation coefficient
for(int i=0; i<all; ++i){
sprintf(buffer,anaFilename, i);
FILE *ana = fopen(buffer, "r");
for(int j=1; j<=17; ++j)
fgets(buffer, sizeof(buffer), ana);
double TP, TN, FP, FN, MCC;
{
int zero, one;
fgets(buffer, sizeof(buffer), ana);
assert(3==sscanf(buffer," %d %lf %lf",&zero, &TN, &FP));
assert(0==zero);
fgets(buffer, sizeof(buffer), ana);
assert(3==sscanf(buffer," %d %lf %lf",&one, &FN, &TP));
assert(1==one);
/////////////// I want to print MCC so I add this variable here
MCC = (TP*TN-FP*FN)/ sqrt((TP+FP)*(TP+FN)*(TN+FP)*(TN+FN));
tptable["TP"].push_back(TP);
tptable["TN"].push_back(TN);
tptable["FP"].push_back(FP);
tptable["FN"].push_back(FN);
/////////////// I want to print MCC so I add this variable here
tptable["MCC"].push_back(MCC);
}
assert(mcc.find(MCC)==mcc.end());
mcc[MCC] = i;
fclose(ana);
}
set<int> top;
map<double,int>::reverse_iterator riter=mcc.rbegin();
for(int i=0;
i<select;
++i, ++riter){
top.insert((*riter).second);
}
{
FILE *file = fopen("Eval.txt","w");
fprintf(file,"PPV\tNPV\tSP\tSE\tMCC\n");
for(int i=0; i<all; ++i){
double tp = tptable["TP"];
double fp = tptable["FP"];
double tn = tptable["TN"];
double fn = tptable["FN"];
/////////////// I want to print MCC so I add this variable here
double tpmcc = tptable["MCC"];
fprintf(file,"%1.3f \t%1.3f\t%1.3f\t%1.3f\n",ppv,npv,sp,se,tpmcc);
}
freopen("SEL.txt","w",file);
fprintf(file,"%d",*top.begin());
for(set<int>::iterator it = ++top.begin();
it!=top.end();
++it){
fprintf(file," %d",*it);
}
fclose(file);
}
return 0;
}
program but failed. I tried using pointer variable but also failed. the
compilable codes are as follows and
lines following the comment
"/////////////// I want to print MCC so I add this variable here"
were added by me.
Sorry but unable to provide the ana files to test but I wish this problem
can still be solved by somebody.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <map>
#include <vector>
#include <set>
using namespace std;
const char* anaFilename = "%d.txt";
char buffer[65536];
char buffer2[65536];
void wrongArgv(char **argv){
fprintf(stderr,
"Usage: %s [select how many] [total # model] \n",\
*argv);
exit(1);
}
int main(int argc, char **argv){
map<char*, vector<double> > tptable;
if(argc != 3)
wrongArgv(argv);
int select = atoi(argv[1]);
int all = atoi(argv[2]);
if(select<=0 || all<=0 || select > all)
wrongArgv(argv);
// use map for priority queue
map<double, int> mcc; //matthews correlation coefficient
for(int i=0; i<all; ++i){
sprintf(buffer,anaFilename, i);
FILE *ana = fopen(buffer, "r");
for(int j=1; j<=17; ++j)
fgets(buffer, sizeof(buffer), ana);
double TP, TN, FP, FN, MCC;
{
int zero, one;
fgets(buffer, sizeof(buffer), ana);
assert(3==sscanf(buffer," %d %lf %lf",&zero, &TN, &FP));
assert(0==zero);
fgets(buffer, sizeof(buffer), ana);
assert(3==sscanf(buffer," %d %lf %lf",&one, &FN, &TP));
assert(1==one);
/////////////// I want to print MCC so I add this variable here
MCC = (TP*TN-FP*FN)/ sqrt((TP+FP)*(TP+FN)*(TN+FP)*(TN+FN));
tptable["TP"].push_back(TP);
tptable["TN"].push_back(TN);
tptable["FP"].push_back(FP);
tptable["FN"].push_back(FN);
/////////////// I want to print MCC so I add this variable here
tptable["MCC"].push_back(MCC);
}
assert(mcc.find(MCC)==mcc.end());
mcc[MCC] = i;
fclose(ana);
}
set<int> top;
map<double,int>::reverse_iterator riter=mcc.rbegin();
for(int i=0;
i<select;
++i, ++riter){
top.insert((*riter).second);
}
{
FILE *file = fopen("Eval.txt","w");
fprintf(file,"PPV\tNPV\tSP\tSE\tMCC\n");
for(int i=0; i<all; ++i){
double tp = tptable["TP"];
double fp = tptable["FP"];
double tn = tptable["TN"];
double fn = tptable["FN"];
/////////////// I want to print MCC so I add this variable here
double tpmcc = tptable["MCC"];
fprintf(file,"%1.3f \t%1.3f\t%1.3f\t%1.3f\n",ppv,npv,sp,se,tpmcc);
}
freopen("SEL.txt","w",file);
fprintf(file,"%d",*top.begin());
for(set<int>::iterator it = ++top.begin();
it!=top.end();
++it){
fprintf(file," %d",*it);
}
fclose(file);
}
return 0;
}