?? abstractcachingdifffunction.java
字號:
package edu.stanford.nlp.optimization;import java.util.*;/** @author Dan Klein */public abstract class AbstractCachingDiffFunction implements DiffFunction, HasInitial { double[] lastX = null; protected double[] derivative = null; protected double value = 0.0; abstract public int domainDimension(); abstract protected void calculate(double[] x); public double[] initial() { double[] initial = new double[domainDimension()]; Arrays.fill(initial, 0.0); return initial; } void copy(double[] y, double[] x) { System.arraycopy(x, 0, y, 0, x.length); } void ensure(double[] x) { if (Arrays.equals(x, lastX)) return; if (lastX == null) lastX = new double[domainDimension()]; if (derivative == null) derivative = new double[domainDimension()]; copy(lastX, x); calculate(x); } public double valueAt(double[] x) { ensure(x); return value; } double norm2(double[] x) { double sum = 0.0; for (int i=0; i<x.length; i++) sum += x[i]*x[i]; return Math.sqrt(sum); } public double[] derivativeAt(double[] x) { ensure(x); return derivative; }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -