public CRFOptimizableByKL(CRF crf, InstanceList trainingSet, PRAuxiliaryModel auxModel, double[][][][] cachedDots, int numThreads, double weight) { this.crf = crf; this.trainingSet = trainingSet; this.numParameters = crf.getParameters().getNumFactors(); this.cachedGradient = new double[numParameters]; this.cachedValueWeightsStamp = -1; this.cachedGradientWeightsStamp = -1; assert(weight > 0); this.weight = weight; gatherConstraints(auxModel, cachedDots); this.numThreads = numThreads; this.executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(numThreads); }
public CRFOptimizableByKL(CRF crf, InstanceList trainingSet, PRAuxiliaryModel auxModel, double[][][][] cachedDots, int numThreads, double weight) { this.crf = crf; this.trainingSet = trainingSet; this.numParameters = crf.getParameters().getNumFactors(); this.cachedGradient = new double[numParameters]; this.cachedValueWeightsStamp = -1; this.cachedGradientWeightsStamp = -1; assert(weight > 0); this.weight = weight; gatherConstraints(auxModel, cachedDots); this.numThreads = numThreads; this.executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(numThreads); }
public CRFOptimizableByKL(CRF crf, InstanceList trainingSet, PRAuxiliaryModel auxModel, double[][][][] cachedDots, int numThreads, double weight) { this.crf = crf; this.trainingSet = trainingSet; this.numParameters = crf.getParameters().getNumFactors(); this.cachedGradient = new double[numParameters]; this.cachedValueWeightsStamp = -1; this.cachedGradientWeightsStamp = -1; assert(weight > 0); this.weight = weight; gatherConstraints(auxModel, cachedDots); this.numThreads = numThreads; this.executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(numThreads); }
public CRFOptimizableByLabelLikelihood (CRF crf, InstanceList ilist) { // Set up this.crf = crf; this.trainingSet = ilist; //cachedGradient = new DenseVector (numParameters); cachedGradient = new double[crf.parameters.getNumFactors()]; constraints = new CRF.Factors(crf.parameters); expectations = new CRF.Factors(crf.parameters); // This resets and values that may have been in expectations and constraints //reallocateSufficientStatistics(); // This is unfortunately necessary, b/c cachedValue & cachedValueStale not in same place! cachedValueWeightsStamp = -1; cachedGradientWeightsStamp = -1; gatherConstraints (ilist); }
public void setParameters (double [] buff) { assert (buff.length == getNumFactors()); int pi = 0; for (int i = 0; i < initialWeights.length; i++) { initialWeights[i] = buff[pi++]; finalWeights[i] = buff[pi++]; } for (int i = 0; i < weights.length; i++) { this.defaultWeights[i] = buff[pi++]; int nl = weights[i].numLocations(); for (int j = 0; j < nl; j++) weights[i].setValueAtLocation (j, buff[pi++]); } }
public int getNumParameters() { return crf.getParameters().getNumFactors(); }
public int getNumParameters () { return crf.parameters.getNumFactors(); }
public int getNumParameters () { return crf.parameters.getNumFactors(); }
/** * @param crf CRF whose parameters we wish to estimate. * @param opts Optimizable.ByGradientValue objective functions. * * Parameters are estimated by maximizing the sum of the individual * objective functions. */ public CRFOptimizableByGradientValues (CRF crf, Optimizable.ByGradientValue[] opts) { this.crf = crf; this.optimizables = opts; this.cachedGradient = new double[crf.parameters.getNumFactors()]; this.cachedValueWeightsStamp = -1; this.cachedGradientWeightsStamp = -1; }
/** * Adds gradients from all batches. <p> * <b>Note:</b> assumes buffer is already initialized. */ public void combineGradients(Collection<double[]> batchGradients, double[] buffer) { assert(buffer.length == crf.parameters.getNumFactors()) : "Incorrect buffer length: " + buffer.length + ", expected: " + crf.parameters.getNumFactors(); Arrays.fill(buffer, 0); for (double[] gradient : batchGradients) { MatrixOps.plusEquals(buffer, gradient); } // -(...) from getBatchValueGradient MatrixOps.timesEquals(buffer, -1.0); }
public int getNumParameters() { return crf.getParameters().getNumFactors(); }
public int getNumParameters() { return crf.getParameters().getNumFactors(); }
/** * Initializes the structures. */ public CRFOptimizableByEntropyRegularization(CRF crf, InstanceList ilist, double scalingFactor) { data = ilist; this.crf = crf; this.scalingFactor = scalingFactor; // initialize the expectations using the model expectations = new CRF.Factors(crf); incrementor = expectations.new Incrementor(); cachedValue = 0.0; cachedGradient = new double[crf.getParameters().getNumFactors()]; }
public int getNumParameters () { return crf.parameters.getNumFactors(); }
/** * @param crf CRF whose parameters we wish to estimate. * @param opts Optimizable.ByGradientValue objective functions. * * Parameters are estimated by maximizing the sum of the individual * objective functions. */ public CRFOptimizableByGradientValues (CRF crf, Optimizable.ByGradientValue[] opts) { this.crf = crf; this.optimizables = opts; this.cachedGradient = new double[crf.parameters.getNumFactors()]; this.cachedValueWeightsStamp = -1; this.cachedGradientWeightsStamp = -1; }
/** * @param crf CRF whose parameters we wish to estimate. * @param opts Optimizable.ByGradientValue objective functions. * * Parameters are estimated by maximizing the sum of the individual * objective functions. */ public CRFOptimizableByGradientValues (CRF crf, Optimizable.ByGradientValue[] opts) { this.crf = crf; this.optimizables = opts; this.cachedGradient = new double[crf.parameters.getNumFactors()]; this.cachedValueWeightsStamp = -1; this.cachedGradientWeightsStamp = -1; }
public int getNumParameters () { return crf.parameters.getNumFactors(); }
protected OptimizableCRF (CRF crf, InstanceList ilist) { // Set up this.crf = crf; this.trainingSet = ilist; this.opts = optimizableByValueGradientObjects; cachedGradie = new double[crf.parameters.getNumFactors()]; cachedValueWeightsStamp = -1; cachedGradientWeightsStamp = -1; }
protected OptimizableCRF (CRF crf, InstanceList ilist) { // Set up this.crf = crf; this.trainingSet = ilist; this.opts = optimizableByValueGradientObjects; cachedGradie = new double[crf.parameters.getNumFactors()]; cachedValueWeightsStamp = -1; cachedGradientWeightsStamp = -1; }
protected OptimizableCRF (CRF crf, InstanceList ilist) { // Set up this.crf = crf; this.trainingSet = ilist; this.opts = optimizableByValueGradientObjects; cachedGradie = new double[crf.parameters.getNumFactors()]; cachedValueWeightsStamp = -1; cachedGradientWeightsStamp = -1; }