public void getParameters (double[] buf) { if ( buf.length != numParameters ) throw new IllegalArgumentException("Argument is not of the " + " correct dimensions"); int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector defaults = tmpl.getDefaultWeights (); double[] values = defaults.getValues(); System.arraycopy (values, 0, buf, idx, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector[] weights = tmpl.getWeights(); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights [assn].getValues (); System.arraycopy (values, 0, buf, idx, values.length); idx += values.length; } } }
public void getParameters (double[] buf) { if ( buf.length != numParameters ) throw new IllegalArgumentException("Argument is not of the " + " correct dimensions"); int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector defaults = tmpl.getDefaultWeights (); double[] values = defaults.getValues(); System.arraycopy (values, 0, buf, idx, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector[] weights = tmpl.getWeights(); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights [assn].getValues (); System.arraycopy (values, 0, buf, idx, values.length); idx += values.length; } } }
protected void setParametersInternal (double[] params) { cachedValueStale = cachedGradientStale = true; int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector defaults = tmpl.getDefaultWeights(); double[] values = defaults.getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector[] weights = tmpl.getWeights(); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights [assn].getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } } }
public AbstractTableFactor computeFactor (UnrolledVarSet clique) { Matrix phi = createFactorMatrix(clique); SparseVector[] weights = getWeights(); // System.out.println("UnrolledClique "+clique); // System.out.println("FV : "+clique.fv); for (int loc = 0; loc < phi.numLocations(); loc++) { int idx = phi.indexAtLocation(loc); assert idx < weights.length : "Error: Instantiating "+this+" on "+clique+" : Clique has too many " +"assignments.\n # of weights = "+weights.length+" clique weight = "+clique.weight(); SparseVector w = weights[idx]; // System.out.println("Weights "+idx+" : "+w); // w.print(); double dp = w.dotProduct(clique.fv); dp += getDefaultWeight(idx); phi.setValueAtLocation(loc, dp); } AbstractTableFactor ptl = new LogTableFactor(clique); ptl.setValues(phi); return ptl; }
protected void setParametersInternal (double[] params) { cachedValueStale = cachedGradientStale = true; int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates[tidx]; SparseVector defaults = tmpl.getDefaultWeights (); double[] values = defaults.getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates[tidx]; SparseVector[] weights = tmpl.getWeights (); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights[assn].getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } } }
protected void setParametersInternal (double[] params) { cachedValueStale = cachedGradientStale = true; int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector defaults = tmpl.getDefaultWeights(); double[] values = defaults.getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector[] weights = tmpl.getWeights(); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights [assn].getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } } }
protected void setParametersInternal (double[] params) { cachedValueStale = cachedGradientStale = true; int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector defaults = tmpl.getDefaultWeights(); double[] values = defaults.getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector[] weights = tmpl.getWeights(); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights [assn].getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } } }
protected void setParametersInternal (double[] params) { cachedValueStale = cachedGradientStale = true; int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector defaults = tmpl.getDefaultWeights(); double[] values = defaults.getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector[] weights = tmpl.getWeights(); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights [assn].getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } } }
protected void setParametersInternal (double[] params) { cachedValueStale = cachedGradientStale = true; int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector defaults = tmpl.getDefaultWeights(); double[] values = defaults.getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector[] weights = tmpl.getWeights(); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights [assn].getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } } }
protected void setParametersInternal (double[] params) { cachedValueStale = cachedGradientStale = true; int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates[tidx]; SparseVector defaults = tmpl.getDefaultWeights (); double[] values = defaults.getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates[tidx]; SparseVector[] weights = tmpl.getWeights (); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights[assn].getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } } }
protected void setParametersInternal (double[] params) { cachedValueStale = cachedGradientStale = true; int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector defaults = tmpl.getDefaultWeights(); double[] values = defaults.getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector[] weights = tmpl.getWeights(); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights [assn].getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } } }
protected void setParametersInternal (double[] params) { cachedValueStale = cachedGradientStale = true; int idx = 0; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates[tidx]; SparseVector defaults = tmpl.getDefaultWeights (); double[] values = defaults.getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates[tidx]; SparseVector[] weights = tmpl.getWeights (); for (int assn = 0; assn < weights.length; assn++) { double[] values = weights[assn].getValues (); System.arraycopy (params, idx, values, 0, values.length); idx += values.length; } } }
private void initConstraintsExpectations () { // Do the defaults first defaultConstraints = new SparseVector [templates.length]; defaultExpectations = new SparseVector [templates.length]; for (int tidx = 0; tidx < templates.length; tidx++) { SparseVector defaults = templates[tidx].getDefaultWeights(); defaultConstraints[tidx] = (SparseVector) defaults.cloneMatrixZeroed (); defaultExpectations[tidx] = (SparseVector) defaults.cloneMatrixZeroed (); } // And now the others constraints = new SparseVector [templates.length][]; expectations = new SparseVector [templates.length][]; for (int tidx = 0; tidx < templates.length; tidx++) { ACRF.Template tmpl = templates [tidx]; SparseVector[] weights = tmpl.getWeights(); constraints [tidx] = new SparseVector [weights.length]; expectations [tidx] = new SparseVector [weights.length]; for (int i = 0; i < weights.length; i++) { constraints[tidx][i] = (SparseVector) weights[i].cloneMatrixZeroed (); expectations[tidx][i] = (SparseVector) weights[i].cloneMatrixZeroed (); } } }
public AbstractTableFactor computeFactor (UnrolledVarSet clique) { Matrix phi = createFactorMatrix(clique); SparseVector[] weights = getWeights(); // System.out.println("UnrolledClique "+clique); // System.out.println("FV : "+clique.fv); for (int loc = 0; loc < phi.numLocations(); loc++) { int idx = phi.indexAtLocation(loc); assert idx < weights.length : "Error: Instantiating "+this+" on "+clique+" : Clique has too many " +"assignments.\n # of weights = "+weights.length+" clique weight = "+clique.weight(); SparseVector w = weights[idx]; // System.out.println("Weights "+idx+" : "+w); // w.print(); double dp = w.dotProduct(clique.fv); dp += getDefaultWeight(idx); phi.setValueAtLocation(loc, dp); } AbstractTableFactor ptl = new LogTableFactor(clique); ptl.setValues(phi); return ptl; }
private double computePrior () { double retval = 0.0; double priorDenom = 2 * gaussianPriorVariance; for (int tidx = 0; tidx < templates.length; tidx++) { SparseVector[] weights = templates [tidx].getWeights (); for (int j = 0; j < weights.length; j++) { for (int fnum = 0; fnum < weights[j].numLocations(); fnum++) { double w = weights [j].valueAtLocation (fnum); if (weightValid (w, tidx, j)) { retval += -w*w/priorDenom; } } } } return retval; }
private double computePrior () { double retval = 0.0; double priorDenom = 2 * gaussianPriorVariance; for (int tidx = 0; tidx < templates.length; tidx++) { SparseVector[] weights = templates [tidx].getWeights (); for (int j = 0; j < weights.length; j++) { for (int fnum = 0; fnum < weights[j].numLocations(); fnum++) { double w = weights [j].valueAtLocation (fnum); if (weightValid (w, tidx, j)) { retval += -w*w/priorDenom; } } } } return retval; }
private double computePrior () { double retval = 0.0; double priorDenom = 2 * gaussianPriorVariance; for (int tidx = 0; tidx < templates.length; tidx++) { SparseVector[] weights = templates [tidx].getWeights (); for (int j = 0; j < weights.length; j++) { for (int fnum = 0; fnum < weights[j].numLocations(); fnum++) { double w = weights [j].valueAtLocation (fnum); if (weightValid (w, tidx, j)) { retval += -w*w/priorDenom; } } } } return retval; }
private double computeLogFactorValue (Assignment cliqueAssn, ACRF.Template tmpl, FeatureVector fv) { SparseVector[] weights = tmpl.getWeights (); int idx = cliqueAssn.singleIndex (); SparseVector w = weights[idx]; double dp = w.dotProduct (fv); dp += tmpl.getDefaultWeight (idx); return dp; }
private double computeLogFactorValue (Assignment cliqueAssn, ACRF.Template tmpl, FeatureVector fv) { SparseVector[] weights = tmpl.getWeights (); int idx = cliqueAssn.singleIndex (); SparseVector w = weights[idx]; double dp = w.dotProduct (fv); dp += tmpl.getDefaultWeight (idx); return dp; }
private double computeLogFactorValue (Assignment cliqueAssn, ACRF.Template tmpl, FeatureVector fv) { SparseVector[] weights = tmpl.getWeights (); int idx = cliqueAssn.singleIndex (); SparseVector w = weights[idx]; double dp = w.dotProduct (fv); dp += tmpl.getDefaultWeight (idx); return dp; }