當前位置: 首頁>>代碼示例>>Java>>正文


Java Function類代碼示例

本文整理匯總了Java中edu.stanford.nlp.optimization.Function的典型用法代碼示例。如果您正苦於以下問題:Java Function類的具體用法?Java Function怎麽用?Java Function使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Function類屬於edu.stanford.nlp.optimization包,在下文中一共展示了Function類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: calculateValues

import edu.stanford.nlp.optimization.Function; //導入依賴的package包/類
/**
 * Calculate the values of function at points
 * 
 * @param function
 * @param points
 */
private double[] calculateValues(Function function, double[][] points) {
  double values[] = new double[points.length];
  for (int i = 0; i < points.length; i++) {
    values[i] = function.valueAt(points[i]);
  }
  return values;
}
 
開發者ID:stanfordnlp,項目名稱:phrasal,代碼行數:14,代碼來源:DownhillSimplexMinimizer.java

示例2: optimize

import edu.stanford.nlp.optimization.Function; //導入依賴的package包/類
@Override
public Counter<String> optimize(Counter<String> initialWts) {
  Counter<String> wts = new ClassicCounter<String>(initialWts);
      
  // create a mapping between weight names and optimization
  // weight vector positions
  String[] weightNames = new String[initialWts.size()];
  double[] initialWtsArr = new double[initialWts.size()];

  int nameIdx = 0;
  for (String feature : wts.keySet()) {
    initialWtsArr[nameIdx] = wts.getCount(feature);
    weightNames[nameIdx++] = feature;
  }

  Minimizer<Function> dhsm = new DownhillSimplexMinimizer();

  MERTObjective mo = new MERTObjective(weightNames);
  
  double initialValueAt = mo.valueAt(initialWtsArr);
  if (initialValueAt == Double.POSITIVE_INFINITY
      || initialValueAt != initialValueAt) {
    System.err
        .printf("Initial Objective is infinite/NaN - normalizing weight vector");
    double normTerm = Counters.L2Norm(wts);
    for (int i = 0; i < initialWtsArr.length; i++) {
      initialWtsArr[i] /= normTerm;
    }
  }
  
  double initialObjValue = mo.valueAt(initialWtsArr);

  System.err.println("Initial Objective value: " + initialObjValue);
  double newX[] = dhsm.minimize(mo, 1e-6, initialWtsArr); // new
                                                         // double[wts.size()]

  Counter<String> newWts = new ClassicCounter<String>();
  for (int i = 0; i < weightNames.length; i++) {
    newWts.setCount(weightNames[i], newX[i]);
  }

  double finalObjValue = mo.valueAt(newX);
  
  System.err.println("Final Objective value: " + finalObjValue);
  double metricEval = MERT.evalAtPoint(nbest, newWts, emetric);
  MERT.updateBest(newWts, metricEval);
  return newWts;
}
 
開發者ID:stanfordnlp,項目名稱:phrasal,代碼行數:49,代碼來源:DownhillSimplexOptimizer.java

示例3: minimize

import edu.stanford.nlp.optimization.Function; //導入依賴的package包/類
public double[] minimize(Function function, double functionTolerance,
    double[] initial) {
  return minimize(function, functionTolerance, initial, 0);
}
 
開發者ID:stanfordnlp,項目名稱:phrasal,代碼行數:5,代碼來源:DownhillSimplexMinimizer.java


注:本文中的edu.stanford.nlp.optimization.Function類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。