// Code for : x->x() {x->cond()} x->y() ? x->tval() : x->fval() void LIRGenerator::do_IfOp(IfOp* x) { #ifdef ASSERT { ValueTag xtag = x->x()->type()->tag(); ValueTag ttag = x->tval()->type()->tag(); assert(xtag == intTag || xtag == objectTag, "cannot handle others"); assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others"); assert(ttag == x->fval()->type()->tag(), "cannot handle others"); } #endif LIRItem left(x->x(), this); LIRItem right(x->y(), this); left.load_item(); right.load_item(); emit()->ifop_phase1(x->cond(), left.result(), right.result()); LIRItem t_val(x->tval(), this); LIRItem f_val(x->fval(), this); t_val.dont_load_item(); f_val.dont_load_item(); RInfo reg; if (x->fval()->type()->tag() == longTag) { // must lock before releasing reg = rlock_result(x)->rinfo(); } if (x->fval()->type()->tag() != longTag) { reg = rlock_result(x)->rinfo(); } emit()->ifop_phase2(reg, t_val.result(), f_val.result(), x->cond()); }
void NuSVC::train_binary(const DataSet &dataset, int i, int j, SyncArray<float_type> &alpha, float_type &rho) { DataSet::node2d ins = dataset.instances(i, j);//get instances of class i and j int n_pos = dataset.count()[i]; int n_neg = dataset.count()[j]; SyncArray<int> y(ins.size()); alpha.resize(ins.size()); SyncArray<float_type> f_val(ins.size()); alpha.mem_set(0); f_val.mem_set(0); float_type sum_pos = param.nu * ins.size() / 2; float_type sum_neg = sum_pos; int *y_data = y.host_data(); float_type *alpha_data = alpha.host_data(); for (int l = 0; l < n_pos; ++l) { y_data[l] = +1; alpha_data[l] = min(1., sum_pos); sum_pos -= alpha_data[l]; } for (int l = 0; l < n_neg; ++l) { y_data[n_pos + l] = -1; alpha_data[n_pos + l] = min(1., sum_neg); sum_neg -= alpha_data[n_pos + l]; } vector<int> ori = dataset.original_index(i, j); KernelMatrix k_mat(ins, param); int ws_size = get_working_set_size(ins.size(), k_mat.n_features()); NuSMOSolver solver(false); solver.solve(k_mat, y, alpha, rho, f_val, param.epsilon, 1, 1, ws_size, max_iter); LOG(INFO)<<"rho = "<<rho; int n_sv = 0; alpha_data = alpha.host_data(); for (int l = 0; l < alpha.size(); ++l) { alpha_data[l] *= y_data[l]; if (alpha_data[l] != 0) n_sv++; } LOG(INFO)<<"#sv = "<<n_sv; }
void HeapContainer<NodeType,CostType,PlannerSpecificVariables>::update (heapItem_p np, BubbleDirection bubdir) { // Does both bubble up and down if (!(np->inHeap)) return; int currentPos = np->heapArrayPos; // Bubble up if (bubdir != DOWNONLY_BUBDIR) { int parentPos = (currentPos - 1) / 2; // position of parent if ( f_val(heapArray[parentPos]) > f_val(np) ) { heapArray[currentPos] = heapArray[parentPos]; heapArray[parentPos] = np; heapArray[currentPos]->heapArrayPos = currentPos; heapArray[parentPos]->heapArrayPos = parentPos; update(heapArray[parentPos], UPONLY_BUBDIR); // recursive call. If heap, downward bubbling won't be needed. return; // no need to check children, since chilren will have higher values } if (bubdir == UPONLY_BUBDIR) return; } // Bubble down int leftChildPos = 2*currentPos + 1; int rightChildPos = 2*currentPos + 2; int exchangeChildPos; if (leftChildPos<heapArray.size() && rightChildPos<heapArray.size()) exchangeChildPos = ( f_val(heapArray[leftChildPos]) > f_val(heapArray[rightChildPos]) ) ? rightChildPos : leftChildPos; else if (leftChildPos<heapArray.size()) exchangeChildPos = leftChildPos; else if (rightChildPos<heapArray.size()) exchangeChildPos = rightChildPos; else return; if ( f_val(np) > f_val(heapArray[exchangeChildPos]) ) { heapArray[currentPos] = heapArray[exchangeChildPos]; heapArray[exchangeChildPos] = np; heapArray[currentPos]->heapArrayPos = currentPos; heapArray[exchangeChildPos]->heapArrayPos = exchangeChildPos; update(heapArray[exchangeChildPos], DOWNONLY_BUBDIR); // recursive call. If heap, upward bubbling won't be needed. return; } }