public static WeightVector getWeightVectorBySumAlpahFv( L2LossInstanceWithAlphas[] alpha_ins_list, boolean is_extendable, int n_ex, int verbose_level) { int max_n = -1; for (int i = 0; i < n_ex; i++) { int cur_idx = alpha_ins_list[i].getMaxIdx(); if (cur_idx > max_n) max_n = cur_idx; } if (verbose_level >= JLISParameters.VLEVEL_MID) System.out.println("number of features: " + max_n); WeightVector cur_wv = new WeightVector(max_n + 1); cur_wv.setExtendable(is_extendable); // double[] cur_w = new double[max_n + 1]; for (int i = 0; i < n_ex; i++) { alpha_ins_list[i].fillWeightVector(cur_wv); } return cur_wv; }
public static double getDualObjectiveWithCurrentCuts( L2LossInstanceWithAlphas[] alpha_ins_list, WeightVector cur_wv) { double obj = 0; obj += cur_wv.getTwoNormSquare() * 0.5; for (int i = 0; i < alpha_ins_list.length; i++) { L2LossInstanceWithAlphas instanceWithAlphas = alpha_ins_list[i]; double w_sum = instanceWithAlphas.getLossWeightAlphaSum(); double sum = instanceWithAlphas.getAlphaSum(); double C = instanceWithAlphas.getC(); obj -= w_sum; obj += (1.0 / (4.0 * C)) * sum * sum; } return obj; }
protected void updateStructuresForBinaryPositiveExamples( WeightVector new_wv, L2LossInstanceWithAlphas[] alpha_ins_list, AbstractStructureFinder struct_finder) throws Exception { // update positive examples int n_p = 0; int n_p_changed = 0; int total_size = alpha_ins_list.length; for (int i = 0; i < total_size; i++) { L2LossInstanceWithAlphas p_ins = alpha_ins_list[i]; if (i % verbose_step == 0) System.out.println("positive_xi inference stage: " + i + "/" + total_size); if (p_ins.isBinary() && p_ins.getY() == 1) { n_p += 1; double updated = p_ins.updateRepresentationCollection(new_wv, struct_finder); if (updated > 0) n_p_changed += 1; } } System.out.println("Among " + n_p + " examples, " + n_p_changed + "updated "); }
WeightVector new_wv, L2LossInstanceWithAlphas[] alpha_ins_list, JLISParameters para) throws Exception { L2LossInstanceWithAlphas.setJLISParameters(para); if (alpha_ins_list[i].isBinary() && alpha_ins_list[i].getY() == 1) n_postive++; alpha_ins_list[i].cleanCache(new_wv);
protected WeightVector getJointWeightVectorFast(WeightVector old_wv, final AbstractStructureFinder struct_finder, StructuredProblem sp, BinaryProblem bp, JLISParameters para) throws Exception { L2LossInstanceWithAlphas.setJLISParameters(para); int struct_size = sp.size(); int binary_size = bp.size(); alpha_ins_list[i].cleanCache(new_wv);
final StructuredProblem sp, final JLISParameters para) throws Exception { L2LossInstanceWithAlphas.setJLISParameters(para); alpha_ins_list[j].fillWeightVector(new_wv);
assert ins.isBinary() == false; L2LossStructureInstanceWithAlphas sins = (L2LossStructureInstanceWithAlphas) ins; IStructure pre_gold = sins.gold_struct;
alpha_ins_list[idx].solveSubProblemAndUpdateW(si, cur_wv);
double dot_product = cur_wv.dotProduct(fv); double loss = 1.0 - ins.getY() * dot_product; if (loss > 0) { obj += ins.sC * loss * loss;
@Override public void run() { int index = 0; for (L2LossInstanceWithAlphas ins : alpha_ins_list) { // focus on positive know if (!ins.isBinary() || ins.getY() == -1) continue; double score = 0; try { score = ins.updateRepresentationCollection(wv, s_finder); } catch (Exception e) { e.printStackTrace(); System.exit(1); } if (score > L2LossInstanceWithAlphas.BINARY_DUAL_GAP) { n_b_new += 1; } // System.out.println("now: " + index); index++; } if (verbose_level >= JLISParameters.VLEVEL_HIGH) { System.out.println("Thread: (b) udpate = " + n_b_new); } } }
private Pair<Integer, Integer> updateStructuresforNegativeAndStructuredExamples( L2LossInstanceWithAlphas[] alpha_ins_list, WeightVector new_wv, int struct_size, AbstractStructureFinder struct_finder) throws Exception { int n_s_new = 0; int n_b_new = 0; int total_size = alpha_ins_list.length; for (int i = 0; i < total_size; i++) { // positive h has already been fixed if (alpha_ins_list[i].isBinary() && alpha_ins_list[i].getY() == 1) continue; double score = alpha_ins_list[i].updateRepresentationCollection( new_wv, struct_finder); if (i < struct_size) { if (score > L2LossInstanceWithAlphas.DUAL_GAP) { n_s_new += 1; } } else { if (score > L2LossInstanceWithAlphas.BINARY_DUAL_GAP) { n_b_new += 1; } } } return new Pair<Integer, Integer>(n_s_new, n_b_new); }
if (ins.isBinary() && ins.getY() == 1) continue; double score = 0; try { score = ins.updateRepresentationCollection(wv, s_finder); } catch (Exception e) { e.printStackTrace(); if (ins.isBinary()) { if (score > L2LossInstanceWithAlphas.BINARY_DUAL_GAP) { n_b_new += 1;