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];
|
||||
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_term("GO:0040007"));
|
||||
|
@ -155,10 +158,12 @@ float go_distance(char *term1, char *term2) {
|
|||
}
|
||||
|
||||
void clear_flags(struct node *n) {
|
||||
int i;
|
||||
for (i=0; i<n->childrenc; i++)
|
||||
clear_flags(n->children[i]);
|
||||
n->visited = 0;
|
||||
int i, j;
|
||||
for (i=0; i<term_array_size; i++) {
|
||||
term_array[i]->visited = 0;
|
||||
for (j=0; j<12; j++)
|
||||
term_array[i]->temp_acc[j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
if (n->visited)
|
||||
return;
|
||||
n->visited = 1;
|
||||
|
||||
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++) {
|
||||
if (!n->children[i]->visited) {
|
||||
accumulate_evidence(n->children[i]);
|
||||
acc_ev(n->children[i]);
|
||||
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)
|
||||
ann += (float) n->acc_evidence[i];
|
||||
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) {
|
||||
|
@ -288,7 +301,7 @@ struct node *common_subsumer(struct node *n1, struct node *n2) {
|
|||
if ((!retval) || (anc1[i]->ic > retval->ic))
|
||||
retval = anc1[i];
|
||||
if (retval)
|
||||
printf("Retval: %s\n", retval->term);
|
||||
;// printf("Retval: %s\n", retval->term);
|
||||
else
|
||||
printf("No value to return");
|
||||
return retval;
|
||||
|
@ -313,9 +326,13 @@ float resnik(struct node *n1, struct node *n2) {
|
|||
int read_terms(FILE *fd, struct node *terms[], int *termc) {
|
||||
char term[11];
|
||||
int retval;
|
||||
printf("read_terms\n");
|
||||
retval = fscanf(fd, " %10s ", term);
|
||||
while (retval != EOF) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
terms[(*termc)++] = get_term(term);
|
||||
retval = fscanf(fd, " %10s ", term);
|
||||
if (retval != EOF) {
|
||||
terms[*termc++] = get_term(term);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
@ -326,11 +343,15 @@ void build_dataset() {
|
|||
int i, j;
|
||||
|
||||
FILE *fd = fopen("dimension", "r");
|
||||
|
||||
read_terms(fd, terms, &termc);
|
||||
|
||||
for (int i=0; i<termc; i++) {
|
||||
for (int j=0; j<termc; j++) {
|
||||
|
||||
for (i=0; i<termc; i++) {
|
||||
for (j=0; j<termc; j++) {
|
||||
printf("%f ", resnik(terms[i], terms[j]));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
fclose(fd);
|
||||
|
|
|
@ -33,6 +33,9 @@ struct node {
|
|||
/* Accumulated evidence codes */
|
||||
int acc_evidence[12];
|
||||
|
||||
/* Working memory */
|
||||
int temp_acc[12];
|
||||
|
||||
/* Parent count and parents */
|
||||
int parentc;
|
||||
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 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
|
||||
|
||||
|
|
Reference in New Issue