annotate libtests/0028/prog1.c @ 755:37c2b9cce23a multiprobeLSH

Adding mkc_lsh_update branch, trunk candidate with improved LSH: merged trunk 1095 and branch multiprobe_lsh
author mas01mc
date Thu, 25 Nov 2010 13:42:40 +0000
parents 342822c2d49a
children bcc7a6ddb2c8
rev   line source
mas01cr@498 1 #include "audioDB_API.h"
mas01cr@498 2 #include "test_utils_lib.h"
mas01ik@355 3
mas01cr@498 4 int main(int argc, char **argv) {
mas01cr@498 5 adb_t *adb;
mas01cr@498 6 adb_insert_t batch[1]={{0}};
mas01ik@355 7
mas01cr@498 8 clean_remove_db(TESTDB);
mas01cr@498 9 if(!(adb = audiodb_create(TESTDB,0,0,0)))
mas01cr@498 10 return 1;
mas01ik@355 11
mas01cr@498 12 maketestfile("testfeature", 2, (double[4]){0, 1, 1, 0}, 4);
mas01cr@498 13 maketestfile("testpower", 1, (double[2]) {-0.5, -1}, 2);
mas01ik@355 14
mas01cr@498 15 batch[0].features="testfeature";
mas01cr@498 16 batch[0].power="testpower";
mas01cr@498 17 if(!audiodb_batchinsert(adb, batch, 1))
mas01cr@498 18 return 1;
mas01ik@355 19
mas01cr@498 20 if(audiodb_power(adb))
mas01cr@498 21 return 1;
mas01ik@355 22
mas01cr@498 23 batch[0].power=NULL;
mas01cr@498 24 if(!audiodb_batchinsert(adb, batch, 1))
mas01cr@498 25 return 1;
mas01ik@355 26
mas01cr@498 27 batch[0].power="testpower";
mas01cr@498 28 if(audiodb_batchinsert(adb, batch, 1))
mas01cr@498 29 return 1;
mas01ik@355 30
mas01cr@498 31 if(audiodb_l2norm(adb))
mas01cr@498 32 return 1;
mas01ik@355 33
mas01cr@498 34 adb_datum_t query = {1, 2, "testquery", (double[2]) {0, 0.5}};
mas01cr@498 35 adb_query_id_t qid = {0};
mas01cr@498 36 qid.datum = &query;
mas01cr@498 37 qid.sequence_length = 1;
mas01cr@498 38 qid.sequence_start = 0;
mas01cr@498 39 adb_query_parameters_t parms =
mas01cr@498 40 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_EUCLIDEAN_NORMED, 10, 10};
mas01cr@498 41 adb_query_refine_t refine = {0};
mas01cr@498 42 refine.hopsize = 1;
mas01ik@355 43
mas01cr@498 44 adb_query_spec_t spec;
mas01cr@498 45 spec.qid = qid;
mas01cr@498 46 spec.params = parms;
mas01cr@498 47 spec.refine = refine;
mas01ik@355 48
mas01cr@498 49 adb_query_results_t *results = audiodb_query_spec(adb, &spec);
mas01cr@498 50 if(!results || results->nresults != 2) return 1;
mas01cr@498 51 result_present_or_fail(results, "testfeature", 0, 0, 0);
mas01cr@498 52 result_present_or_fail(results, "testfeature", 2, 0, 1);
mas01cr@498 53 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 54
mas01cr@498 55 spec.params.npoints = 1;
mas01cr@498 56 results = audiodb_query_spec(adb, &spec);
mas01cr@498 57 if(!results || results->nresults != 1) return 1;
mas01cr@498 58 result_present_or_fail(results, "testfeature", 0, 0, 0);
mas01cr@498 59 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 60
mas01cr@498 61 spec.qid.datum->data = (double [2]) {0.5, 0};
mas01cr@498 62 spec.params.npoints = 10;
mas01cr@498 63 results = audiodb_query_spec(adb, &spec);
mas01cr@498 64 if(!results || results->nresults != 2) return 1;
mas01cr@498 65 result_present_or_fail(results, "testfeature", 0, 0, 1);
mas01cr@498 66 result_present_or_fail(results, "testfeature", 2, 0, 0);
mas01cr@498 67 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 68
mas01cr@498 69 spec.params.npoints = 1;
mas01cr@498 70 results = audiodb_query_spec(adb, &spec);
mas01cr@498 71 if(!results || results->nresults != 1) return 1;
mas01cr@498 72 result_present_or_fail(results, "testfeature", 0, 0, 1);
mas01cr@498 73 audiodb_query_free_results(adb, &spec, results);
mas01cr@498 74
mas01cr@498 75 /* queries with associated power data */
mas01cr@498 76 spec.qid.datum->data = (double [2]) {0, 0.5};
mas01cr@498 77 spec.qid.datum->power = (double [1]) {-0.5};
mas01cr@498 78 spec.params.npoints = 10;
mas01cr@498 79 spec.refine.flags = ADB_REFINE_ABSOLUTE_THRESHOLD;
mas01cr@498 80 spec.refine.absolute_threshold = -1.4;
mas01cr@498 81 results = audiodb_query_spec(adb, &spec);
mas01cr@498 82 if(!results || results->nresults != 2) return 1;
mas01cr@498 83 result_present_or_fail(results, "testfeature", 0, 0, 0);
mas01cr@498 84 result_present_or_fail(results, "testfeature", 2, 0, 1);
mas01cr@498 85 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 86
mas01cr@498 87 spec.refine.absolute_threshold = -0.6;
mas01cr@498 88 results = audiodb_query_spec(adb, &spec);
mas01cr@498 89 if(!results || results->nresults != 1) return 1;
mas01cr@498 90 result_present_or_fail(results, "testfeature", 0, 0, 0);
mas01cr@498 91 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 92
mas01cr@498 93 spec.refine.absolute_threshold = -0.2;
mas01cr@498 94 results = audiodb_query_spec(adb, &spec);
mas01cr@498 95 if(!results || results->nresults != 0) return 1;
mas01cr@498 96 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 97
mas01cr@498 98 spec.refine.absolute_threshold = 0;
mas01cr@498 99 spec.refine.flags = ADB_REFINE_RELATIVE_THRESHOLD;
mas01cr@498 100 spec.refine.relative_threshold = 1;
mas01cr@498 101 results = audiodb_query_spec(adb, &spec);
mas01cr@498 102 if(!results || results->nresults != 2) return 1;
mas01cr@498 103 result_present_or_fail(results, "testfeature", 0, 0, 0);
mas01cr@498 104 result_present_or_fail(results, "testfeature", 2, 0, 1);
mas01cr@498 105 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 106
mas01cr@498 107 spec.refine.relative_threshold = 0.2;
mas01cr@498 108 results = audiodb_query_spec(adb, &spec);
mas01cr@498 109 if(!results || results->nresults != 1) return 1;
mas01cr@498 110 result_present_or_fail(results, "testfeature", 0, 0, 0);
mas01cr@498 111 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 112
mas01cr@498 113 spec.qid.datum->data = (double [2]) {0.5, 0};
mas01cr@498 114 spec.refine.flags = ADB_REFINE_ABSOLUTE_THRESHOLD;
mas01cr@498 115 spec.refine.absolute_threshold = -1.4;
mas01cr@498 116 results = audiodb_query_spec(adb, &spec);
mas01cr@498 117 if(!results || results->nresults != 2) return 1;
mas01cr@498 118 result_present_or_fail(results, "testfeature", 0, 0, 1);
mas01cr@498 119 result_present_or_fail(results, "testfeature", 2, 0, 0);
mas01cr@498 120 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 121
mas01cr@498 122 spec.refine.absolute_threshold = -0.6;
mas01cr@498 123 results = audiodb_query_spec(adb, &spec);
mas01cr@498 124 if(!results || results->nresults != 1) return 1;
mas01cr@498 125 result_present_or_fail(results, "testfeature", 2, 0, 0);
mas01cr@498 126 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 127
mas01cr@498 128 spec.refine.absolute_threshold = -0.2;
mas01cr@498 129 results = audiodb_query_spec(adb, &spec);
mas01cr@498 130 if(!results || results->nresults != 0) return 1;
mas01cr@498 131 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 132
mas01cr@498 133 spec.refine.absolute_threshold = 0;
mas01cr@498 134 spec.refine.flags = ADB_REFINE_RELATIVE_THRESHOLD;
mas01cr@498 135 spec.refine.relative_threshold = 1;
mas01cr@498 136 results = audiodb_query_spec(adb, &spec);
mas01cr@498 137 if(!results || results->nresults != 2) return 1;
mas01cr@498 138 result_present_or_fail(results, "testfeature", 0, 0, 1);
mas01cr@498 139 result_present_or_fail(results, "testfeature", 2, 0, 0);
mas01cr@498 140 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 141
mas01cr@498 142 spec.refine.relative_threshold = 0.2;
mas01cr@498 143 results = audiodb_query_spec(adb, &spec);
mas01cr@498 144 if(!results || results->nresults != 1) return 1;
mas01cr@498 145 result_present_or_fail(results, "testfeature", 2, 0, 0);
mas01cr@498 146 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 147
mas01cr@498 148 audiodb_close(adb);
mas01ik@355 149
mas01cr@498 150 return 104;
mas01ik@355 151 }