本文整理匯總了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;
}
示例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;
}
示例3: minimize
import edu.stanford.nlp.optimization.Function; //導入依賴的package包/類
public double[] minimize(Function function, double functionTolerance,
double[] initial) {
return minimize(function, functionTolerance, initial, 0);
}