| | |
| | | free(m.vals); |
| | | } |
| | | |
| | | float matrix_accuracy(matrix truth, matrix guess) |
| | | float matrix_topk_accuracy(matrix truth, matrix guess, int k) |
| | | { |
| | | int k = truth.cols; |
| | | int i; |
| | | int count = 0; |
| | | int *indexes = calloc(k, sizeof(int)); |
| | | int n = truth.cols; |
| | | int i,j; |
| | | int correct = 0; |
| | | for(i = 0; i < truth.rows; ++i){ |
| | | int class = max_index(guess.vals[i], k); |
| | | if(truth.vals[i][class]) ++count; |
| | | top_k(guess.vals[i], n, k, indexes); |
| | | for(j = 0; j < k; ++j){ |
| | | int class = indexes[j]; |
| | | if(truth.vals[i][class]){ |
| | | ++correct; |
| | | break; |
| | | } |
| | | return (float)count/truth.rows; |
| | | } |
| | | } |
| | | free(indexes); |
| | | return (float)correct/truth.rows; |
| | | } |
| | | |
| | | void matrix_add_matrix(matrix from, matrix to) |