static void cmd_test_list(svm_model *model, WindowFile &testFile) { const QString fmt("%1: prob { %2 , %3 } @ %4 ch %5\n"); const qint32 samples = getNumSamples(testFile); float *buf = new float[samples]; SVMNodeList nodelist(samples); double probEstim[2]; while(testFile.nextChannel()) { assert(testFile.getEventSamples() == samples); testFile.read((char*)buf, samples*sizeof(float)); nodelist.fill(buf); const char subj = (svm_predict_probability(model, nodelist, probEstim) > 0) ? 'A' : 'B'; const double t = (testFile.getEventOffset() / BytesPerSample)/ (double)SamplingRate; fputs(fmt.arg(subj) .arg(probEstim[0], 0, 'f', 4) .arg(probEstim[1], 0, 'f', 4) .arg(t, 0, 'f', 6) .arg(testFile.getChannelId()) .toAscii(), stdout); } delete[] buf; }
static void populateDecisionLabelPairs(svm_model *model, QList<DecisionLabel> &list, WindowFile &file, int label) { const qint32 samples = getNumSamples(file); float *buf = new float[samples]; SVMNodeList nodelist(samples); double decision = 0.; while(file.nextChannel()) { assert(file.getEventSamples() == samples); file.read((char*)buf, samples*sizeof(float)); nodelist.fill(buf); svm_predict_values(model, nodelist, &decision); list.append(DecisionLabel(-decision, label)); } delete[] buf; file.rewind(); }
static void predictAndCount(svm_model *model, WindowFile &file, int &nA, int &nB) { const qint32 samples = getNumSamples(file); float *buf = new float[samples]; SVMNodeList nodelist(samples); nA = nB = 0; while(file.nextChannel()) { assert(file.getEventSamples() == samples); file.read((char*)buf, samples*sizeof(float)); nodelist.fill(buf); if(svm_predict(model, nodelist) > 0) ++nA; else ++nB; } delete[] buf; file.rewind(); }
int workstationinfo(Fmt *f) { return nodelist(f, ALL_LEARNT_IN_DOMAIN); }
int domaininfo(Fmt *f) { return nodelist(f, LIST_DOMAINS_ONLY); }
// create label for each vertex by Dijkstra algorithm on extended graphs; void HD::findPath(VertexID source, VertexID target, vector<VertexID>& path, double& d){ if (source == target) { path.push_back(source); return; } //cout << "Test: source = " << source << ", target = " << target << "." << endl; int nodesize = graph.num_vertices(); vector<double> dist (nodesize); for (int vid = 0; vid < nodesize; vid++) dist[vid] = DBL_INFINITY; dist[source] = 0.0; vector<VertexID> father(nodesize, numeric_limits<unsigned int>::max()); priority_queue<pair<double, VertexID>, vector<pair<double, VertexID> >, QueueComp> Queue; Queue.push(make_pair(0.0, source)); VertexList nodelist(nodesize); for (int vid = 0; vid < nodesize; vid++) { nodelist[vid].flaga = false; // nodelist[vid].rank = graph[vid].rank; } int i = 0; while (Queue.size() > 0) { //cout << i++ << endl; double min_dist = Queue.top().first; VertexID vid = Queue.top().second; //cout << "vid = " << vid << ", min_dist = " << min_dist << endl; Queue.pop(); if (min_dist > dist[vid]) {/*cout << "Greater!?" << endl;*/ continue;} // lazy update; else nodelist[vid].flaga = true; // settle vertex vid; if (vid == target) break; // find the target node; forall_outneighbors(graph, vid, eit){ if (nodelist[eit->target].flaga) continue; // settled; // if (/*vid != source &&*/ nodelist[eit->target].rank < nodelist[vid].rank) continue; if (dist[eit->target] > min_dist + eit->weight) { dist[eit->target] = min_dist + eit->weight; Queue.push(make_pair(dist[eit->target], eit->target)); father[eit->target] = vid; } } // forall_outshortcuts(graph, vid, eit){ // if (nodelist[eit->target].flaga) continue; // settled; // if (/*vid != source &&*/ nodelist[eit->target].rank < nodelist[vid].rank) continue; // if (dist[eit->target] > min_dist + eit->weight) { // dist[eit->target] = min_dist + eit->weight; // Queue.push(make_pair(dist[eit->target], eit->target)); // father[eit->target] = vid; // } // } } // create path information for unpacking path; vector<VertexID>(0).swap(path); path.push_back(target); int index = target; while (index != source){ if (father[index] != numeric_limits<unsigned int>::max()) { path.push_back(father[index]); index = father[index]; }else break; } if (path.size()==1) path.push_back(source); // for test; for (int i = path.size()-1; i > 0; i--){ int a = path[i]; int b = path[i-1]; forall_outneighbors(graph, a, eit){ if (eit->target == b){ d += eit->weight; break; } } } // cout << "d = " << d << endl; // cout << "father: " << endl; // for (int i = 0; i < father.size(); i++) { // cout << i << ": " << father[i] << endl; // } // cout << "~~~~~" << endl; // for (int i = path.size()-1; i >= 0; i--){ // cout << path[i] << " "; // } // cout << endl; }