Fixed resnik distances.
This commit is contained in:
parent
335efe231a
commit
c7bfefe358
|
@ -71,6 +71,9 @@ int godist_init() {
|
||||||
total_ann += n->acc_evidence[i];
|
total_ann += n->acc_evidence[i];
|
||||||
printf("Using %d annotations.\n", total_ann);
|
printf("Using %d annotations.\n", total_ann);
|
||||||
|
|
||||||
|
print_term(get_term("GO:0006006"));
|
||||||
|
print_term(get_term("GO:0019318"));
|
||||||
|
print_term(get_term("GO:0005996"));
|
||||||
print_term(get_bp());
|
print_term(get_bp());
|
||||||
/*
|
/*
|
||||||
print_term(get_term("GO:0040007"));
|
print_term(get_term("GO:0040007"));
|
||||||
|
@ -155,10 +158,12 @@ float go_distance(char *term1, char *term2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_flags(struct node *n) {
|
void clear_flags(struct node *n) {
|
||||||
int i;
|
int i, j;
|
||||||
for (i=0; i<n->childrenc; i++)
|
for (i=0; i<term_array_size; i++) {
|
||||||
clear_flags(n->children[i]);
|
term_array[i]->visited = 0;
|
||||||
n->visited = 0;
|
for (j=0; j<12; j++)
|
||||||
|
term_array[i]->temp_acc[j] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_link(char *parent_id, char *child_id) {
|
void add_link(char *parent_id, char *child_id) {
|
||||||
|
@ -210,19 +215,27 @@ struct node *get_term(char *term) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void accumulate_evidence(struct node *n) {
|
void accumulate_evidence(struct node *n) {
|
||||||
|
int i;
|
||||||
|
acc_ev(n);
|
||||||
|
for (i=0; i<12; i++) {
|
||||||
|
n->acc_evidence[i] = n->temp_acc[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void acc_ev(struct node *n) {
|
||||||
int i, j;
|
int i, j;
|
||||||
if (n->visited)
|
if (n->visited)
|
||||||
return;
|
return;
|
||||||
n->visited = 1;
|
n->visited = 1;
|
||||||
|
|
||||||
for (i=0; i<12; i++)
|
for (i=0; i<12; i++)
|
||||||
n->acc_evidence[i] = n->evidence[i];
|
n->temp_acc[i] = n->evidence[i];
|
||||||
|
|
||||||
for (i=0; i<(n->childrenc); i++) {
|
for (i=0; i<(n->childrenc); i++) {
|
||||||
if (!n->children[i]->visited) {
|
if (!n->children[i]->visited) {
|
||||||
accumulate_evidence(n->children[i]);
|
acc_ev(n->children[i]);
|
||||||
for (j=0; j<12; j++)
|
for (j=0; j<12; j++)
|
||||||
n->acc_evidence[j] += n->children[i]->acc_evidence[j];
|
n->temp_acc[j] += n->children[i]->temp_acc[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +283,7 @@ void calc_ic(struct node *n, unsigned int evidence) {
|
||||||
if (evidence & 1<<i)
|
if (evidence & 1<<i)
|
||||||
ann += (float) n->acc_evidence[i];
|
ann += (float) n->acc_evidence[i];
|
||||||
n->ic = -log(ann/total_ann);
|
n->ic = -log(ann/total_ann);
|
||||||
printf("%f\n", n->ic);
|
/* printf("%f\n", n->ic);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
struct node *common_subsumer(struct node *n1, struct node *n2) {
|
struct node *common_subsumer(struct node *n1, struct node *n2) {
|
||||||
|
@ -288,7 +301,7 @@ struct node *common_subsumer(struct node *n1, struct node *n2) {
|
||||||
if ((!retval) || (anc1[i]->ic > retval->ic))
|
if ((!retval) || (anc1[i]->ic > retval->ic))
|
||||||
retval = anc1[i];
|
retval = anc1[i];
|
||||||
if (retval)
|
if (retval)
|
||||||
printf("Retval: %s\n", retval->term);
|
;// printf("Retval: %s\n", retval->term);
|
||||||
else
|
else
|
||||||
printf("No value to return");
|
printf("No value to return");
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -313,9 +326,13 @@ float resnik(struct node *n1, struct node *n2) {
|
||||||
int read_terms(FILE *fd, struct node *terms[], int *termc) {
|
int read_terms(FILE *fd, struct node *terms[], int *termc) {
|
||||||
char term[11];
|
char term[11];
|
||||||
int retval;
|
int retval;
|
||||||
|
printf("read_terms\n");
|
||||||
retval = fscanf(fd, " %10s ", term);
|
retval = fscanf(fd, " %10s ", term);
|
||||||
if (retval != EOF) {
|
while (retval != EOF) {
|
||||||
terms[*termc++] = get_term(term);
|
printf(".");
|
||||||
|
fflush(stdout);
|
||||||
|
terms[(*termc)++] = get_term(term);
|
||||||
|
retval = fscanf(fd, " %10s ", term);
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -326,11 +343,15 @@ void build_dataset() {
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
FILE *fd = fopen("dimension", "r");
|
FILE *fd = fopen("dimension", "r");
|
||||||
|
|
||||||
read_terms(fd, terms, &termc);
|
read_terms(fd, terms, &termc);
|
||||||
|
|
||||||
for (int i=0; i<termc; i++) {
|
for (i=0; i<termc; i++) {
|
||||||
for (int j=0; j<termc; j++) {
|
for (j=0; j<termc; j++) {
|
||||||
|
printf("%f ", resnik(terms[i], terms[j]));
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
|
|
@ -33,6 +33,9 @@ struct node {
|
||||||
/* Accumulated evidence codes */
|
/* Accumulated evidence codes */
|
||||||
int acc_evidence[12];
|
int acc_evidence[12];
|
||||||
|
|
||||||
|
/* Working memory */
|
||||||
|
int temp_acc[12];
|
||||||
|
|
||||||
/* Parent count and parents */
|
/* Parent count and parents */
|
||||||
int parentc;
|
int parentc;
|
||||||
struct node *parents[MAX_PARENTS];
|
struct node *parents[MAX_PARENTS];
|
||||||
|
@ -65,5 +68,10 @@ void calc_ic(struct node *n, unsigned int evidence);
|
||||||
void clear_flags(struct node *n);
|
void clear_flags(struct node *n);
|
||||||
void print_term(struct node *n);
|
void print_term(struct node *n);
|
||||||
|
|
||||||
|
void add_ancestors(int *ancc, struct node *anc[], struct node *n);
|
||||||
|
|
||||||
|
void calculate_ics(unsigned int);
|
||||||
|
void acc_ev(struct node*);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Reference in New Issue