@Override public IStructure getBestStructure(WeightVector weight, IInstance ins) throws Exception { RerankingInstance ri = (RerankingInstance) ins; int max_index = -1; double max_score = Double.NEGATIVE_INFINITY; for(int i=0; i < ri.fea_list.size(); i ++){ double score = weight.dotProduct(ri.fea_list.get(i)); if (score > max_score){ max_score = score; max_index = i; } } assert max_index != -1; return new LabeledRerankingIns(ri, max_index); }
@Override public void solveSubProblemAndUpdateW(L2SolverInfo si, WeightVector w) { double C = sC; double dot_product = w.dotProduct(fv); double xij_norm2 = fv.l2NormSqure(); double NG = 1.0 - y * dot_product - (alpha / (2.0 * C)); double PG = -NG; if (alpha == 0f) { PG = Math.min(-NG, 0); } si.PGmax_new = Math.max(si.PGmax_new, PG); si.PGmin_new = Math.min(si.PGmin_new, PG); if (Math.abs(PG) > UPDATE_CONDITION) { double step = NG / (xij_norm2 + (1.0 / (2.0 * C))); double new_alpha = Math.max(alpha + step, 0);// make sure // alpha_[i][j] // is w.addSparseFeatureVector(fv, (new_alpha - alpha) * y); alpha = new_alpha; } }
@Override public Pair<IStructure, Double> getLossSensitiveBestStructure( WeightVector weight, IInstance ins, IStructure goldStructure) throws Exception { RerankingInstance ri = (RerankingInstance) ins; LabeledRerankingIns lri = (LabeledRerankingIns) goldStructure; int max_index = -1; double max_score = Double.NEGATIVE_INFINITY; for(int i=0; i < ri.fea_list.size(); i ++){ double loss = -ri.score_list.get(i)+ ri.score_list.get(lri.pred_item); if (loss< 0){ System.out.println("-----------"); System.out.println(ri.score_list); System.out.println("best: " + lri.pred_item); } assert loss >= 0; double score = weight.dotProduct(ri.fea_list.get(i)) + loss; if (score > max_score){ max_score = score; max_index = i; } } assert max_index != -1; double loss = -ri.score_list.get(max_index)+ ri.score_list.get(lri.pred_item); LabeledRerankingIns pred = new LabeledRerankingIns(ri, max_index); //System.out.println("pred: " + max_index + " gold: " + lri.pred_item); return new Pair<IStructure, Double>(pred, loss); }
for(int i=0; i < mi.number_of_class ; i ++){ LabeledMultiClassStructure cand = new LabeledMultiClassStructure(mi, i); double score = weight.dotProduct(cand.getFeatureVector());
double dot_product = w.dotProduct(fv); double xij_norm2 = fv.l2NormSqure();
double dotProduct = wv.dotProduct(diff); double score = (loss - dotProduct) - xi; - wv.dotProduct(tmp_alpha_loss.getSecond()) - xi; if (max_score_in_cache < s) max_score_in_cache = s; + wv.dotProduct(h.getFeatureVector())); System.out.println("dotproduct on diff: " + dotProduct); System.out.println("loss: " + loss); + " loss: " + pair.getFirst()[1]); System.out.println(">>> (dot) " + wv.dotProduct(pair.getSecond())); + wv.dotProduct(gold_struct.getFeatureVector())); throw new Exception( "The inference procedure is not correct! The max solution is worse than some of the solution in the cacse! If you want to use approximated inference. Check JLISParameter.check_inference_opt ");
bestFeatures.slowAddFeature(INDIRECT_GLOBAL_BIAS, 1.0); double score = 1.0 - y * wv.dotProduct(bestFeatures) - xi; double s = 1.0 - y * wv.dotProduct(tmp_alpha_loss.getSecond()) - xi;
@Override public IStructure getBestStructure(WeightVector weight, IInstance ins) throws Exception { MultiClassInstance mi = (MultiClassInstance) ins; int best_output = -1; double best_score = Double.NEGATIVE_INFINITY; for(int i=0; i < mi.number_of_class ; i ++){ LabeledMultiClassStructure cand = new LabeledMultiClassStructure(mi, i); double score = weight.dotProduct(cand.getFeatureVector()); if (score > best_score){ best_output = i; best_score = score; } } assert best_output >= 0 ; return new LabeledMultiClassStructure(mi, best_output); }
@Override public IStructure getBestStructure(WeightVector weight, IInstance ins) throws Exception { MultiClassInstance mi = (MultiClassInstance) ins; int best_output = -1; double best_score = Double.NEGATIVE_INFINITY; for(int i=0; i < mi.number_of_class ; i ++){ LabeledMultiClassStructure cand = new LabeledMultiClassStructure(mi, i); double score = weight.dotProduct(cand.getFeatureVector()); if (score > best_score){ best_output = i; best_score = score; } } assert best_output >= 0 ; LabeledMultiClassStructure result = new LabeledMultiClassStructure(mi, best_output); result.score = best_score; return result; }
public double predictLCLRBinaryScore(IStructure is, IInstance ins){ FeatureVector fv = is.getFeatureVector(); fv.normalize(ins.size()); fv.slowAddFeature(L2LossInstanceWithAlphas.INDIRECT_GLOBAL_BIAS, 1.0); return dotProduct(fv); }
double dot_product = w.dotProduct(fv); double xij_norm2 = fv.l2NormSqure();
double dot_product = cur_wv.dotProduct(fv); sins.gold_struct); double loss = res.getSecond() + cur_wv.dotProduct(res.getFirst().getFeatureVector()) - cur_wv.dotProduct(sins.gold_struct.getFeatureVector());
double score = weight.dotProduct(cand.getFeatureVector());
double score = weight.dotProduct(cand.getFeatureVector());