本文整理汇总了Java中gnu.trove.list.array.TDoubleArrayList.add方法的典型用法代码示例。如果您正苦于以下问题:Java TDoubleArrayList.add方法的具体用法?Java TDoubleArrayList.add怎么用?Java TDoubleArrayList.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.list.array.TDoubleArrayList
的用法示例。
在下文中一共展示了TDoubleArrayList.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseToken
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
void parseToken(int i, String token) {
if (dataTypes[i - 2] == null) {
// test double parsing, in case of error we consider it a string time series
if (Doubles.tryParse(token) != null) {
dataTypes[i - 2] = TimeSeriesDataType.DOUBLE;
TDoubleArrayList doubleValues = createDoubleValues();
doubleValues.add(parseDouble(token));
values[i - 2] = doubleValues;
} else {
dataTypes[i - 2] = TimeSeriesDataType.STRING;
List<String> stringValues = createStringValues();
stringValues.add(checkString(token));
values[i - 2] = stringValues;
}
} else {
if (dataTypes[i - 2] == TimeSeriesDataType.DOUBLE) {
((TDoubleArrayList) values[i - 2]).add(parseDouble(token));
} else if (dataTypes[i - 2] == TimeSeriesDataType.STRING) {
((List<String>) values[i - 2]).add(checkString(token));
} else {
throw assertDataType(dataTypes[i - 2]);
}
}
}
示例2: computeCPFs
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
private void computeCPFs ()
{
isFactorsAdded = true;
TDoubleArrayList residTmp = new TDoubleArrayList ();
for (Iterator it = cliques.iterator(); it.hasNext();) {
UnrolledVarSet clique = (UnrolledVarSet) it.next();
AbstractTableFactor ptl = clique.tmpl.computeFactor (clique);
addFactorInternal (clique, ptl);
clique.tmpl.modifyPotential (this, clique, ptl);
uvsMap.put (ptl, clique);
// sigh
LogTableFactor unif = new LogTableFactor (clique);
residTmp.add (Factors.distLinf (unif, ptl));
}
lastResids = residTmp.toArray();
}
示例3: readSparseVector
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
private SparseVector readSparseVector (String str, Alphabet dict) throws IOException
{
TIntArrayList idxs = new TIntArrayList ();
TDoubleArrayList vals = new TDoubleArrayList ();
String[] lines = str.split ("\n");
for (int li = 0; li < lines.length; li++) {
String line = lines[li];
if (Pattern.matches ("^\\s*$", line)) continue;
String[] fields = line.split ("\t");
int idx;
if (dict != null) {
idx = dict.lookupIndex (fields[0]);
} else {
idx = Integer.parseInt (fields[0]);
}
double val = Double.parseDouble (fields[1]);
idxs.add (idx);
vals.add (val);
}
return new SparseVector (idxs.toArray(), vals.toArray());
}
示例4: testSample
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
public void testSample ()
{
Variable v1 = new Variable (Variable.CONTINUOUS);
Variable v2 = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Vector mu = new DenseVector (new double[] { 1.0, 2.0 });
Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 0, 1 }});
// Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 2.0, 0.75 }});
VarSet vars = new HashVarSet (new Variable[] { v1, v2 });
Factor f = new NormalFactor (vars, mu, var);
TDoubleArrayList v1lst = new TDoubleArrayList();
TDoubleArrayList v2lst = new TDoubleArrayList ();
for (int i = 0; i < 100000; i++) {
Assignment assn = f.sample (r);
v1lst.add (assn.getDouble (v1));
v2lst.add (assn.getDouble (v2));
}
checkMeanStd (v1lst, 1.0, Math.sqrt (1/0.5));
checkMeanStd (v2lst, 2.0, Math.sqrt (1/0.75));
}
示例5: testSample
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
public void testSample ()
{
Variable var = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Factor f = new UniNormalFactor (var, -1.0, 2.0);
TDoubleArrayList lst = new TDoubleArrayList();
for (int i = 0; i < 10000; i++) {
Assignment assn = f.sample (r);
lst.add (assn.getDouble (var));
}
double[] vals = lst.toArray ();
double mean = MatrixOps.mean (vals);
double std = MatrixOps.stddev (vals);
assertEquals (-1.0, mean, 0.025);
assertEquals (Math.sqrt(2.0), std, 0.01);
}
示例6: createDirectedModel
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
private DirectedModel createDirectedModel ()
{
int NUM_OUTCOMES = 2;
cc.mallet.util.Randoms random = new cc.mallet.util.Randoms (13413);
Dirichlet dirichlet = new Dirichlet (NUM_OUTCOMES, 1.0);
double[] pA = dirichlet.randomVector (random);
double[] pB = dirichlet.randomVector (random);
TDoubleArrayList pC = new TDoubleArrayList (NUM_OUTCOMES * NUM_OUTCOMES * NUM_OUTCOMES);
for (int i = 0; i < (NUM_OUTCOMES * NUM_OUTCOMES); i++) {
pC.add (dirichlet.randomVector (random));
}
Variable[] vars = new Variable[] { new Variable (NUM_OUTCOMES), new Variable (NUM_OUTCOMES),
new Variable (NUM_OUTCOMES) };
DirectedModel mdl = new DirectedModel ();
mdl.addFactor (new CPT (new TableFactor (vars[0], pA), vars[0]));
mdl.addFactor (new CPT (new TableFactor (vars[1], pB), vars[1]));
mdl.addFactor (new CPT (new TableFactor (vars, pC.toArray ()), vars[2]));
return mdl;
}
示例7: make3dMatrix
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
private SparseMatrixn make3dMatrix ()
{
int[] sizes = new int[]{2, 3, 4};
TIntArrayList idxs = new TIntArrayList ();
TDoubleArrayList vals = new TDoubleArrayList ();
for (int i = 0; i < 24; i++) {
if (i % 3 != 0) {
idxs.add (i);
vals.add (2.0 * i);
}
}
SparseMatrixn a = new SparseMatrixn (sizes, idxs.toArray (), vals.toArray ());
return a;
}
示例8: recomputeBias
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
public void recomputeBias(double[][] datai, double[][] dataj, boolean[] same) {
final TDoubleArrayList posDistances = new TDoubleArrayList();
final TDoubleArrayList negDistances = new TDoubleArrayList();
for (int i = 0; i < datai.length; i++) {
final Matrix diff = diff(datai[i], dataj[i]);
final Matrix diffProj = W.times(diff);
final double dist = sumsq(diffProj);
if (same[i]) {
posDistances.add(dist);
} else {
negDistances.add(dist);
}
}
b = computeOptimal(posDistances, negDistances);
}
示例9: updateInhibitionRadius
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
/**
* Update the inhibition radius. The inhibition radius is a measure of the
* square (or hypersquare) of columns that each a column is "connected to"
* on average. Since columns are are not connected to each other directly, we
* determine this quantity by first figuring out how many *inputs* a column is
* connected to, and then multiplying it by the total number of columns that
* exist for each input. For multiple dimension the aforementioned
* calculations are averaged over all dimensions of inputs and columns. This
* value is meaningless if global inhibition is enabled.
*
* @param c the {@link Connections} (spatial pooler memory)
*/
public void updateInhibitionRadius(Connections c) {
if(c.getGlobalInhibition()) {
c.setInhibitionRadius(ArrayUtils.max(c.getColumnDimensions()));
return;
}
TDoubleArrayList avgCollected = new TDoubleArrayList();
int len = c.getNumColumns();
for(int i = 0;i < len;i++) {
avgCollected.add(avgConnectedSpanForColumnND(c, i));
}
double avgConnectedSpan = ArrayUtils.average(avgCollected.toArray());
double diameter = avgConnectedSpan * avgColumnsPerInput(c);
double radius = (diameter - 1) / 2.0d;
radius = Math.max(1, radius);
c.setInhibitionRadius((int)(radius + 0.5));
}
示例10: calculateLScores
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
private double[][] calculateLScores(DensityManager dm)
{
TDoubleArrayList x = new TDoubleArrayList();
TDoubleArrayList y = new TDoubleArrayList();
x.add(0.0);
y.add(0.0);
for (double r = minR; r < maxR; r += incrementR)
{
double l = dm.ripleysLFunction(r);
x.add(r);
double score = (r > 0) ? (l - r) / r : 0;
y.add(score);
}
double[][] values = new double[2][];
values[0] = x.toArray();
values[1] = y.toArray();
return values;
}
示例11: findCutPoint
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
public TreeNode findCutPoint() {
List<TreeNode> _children = new ArrayList<TreeNode>();
TDoubleArrayList scores = new TDoubleArrayList();
Queue<TreeNode> q = new ArrayDeque<TreeNode>();
q.add(this);
while (!q.isEmpty()) {
TreeNode c = q.poll();
q.addAll(c.children);
TreeNode p = c.getParent();
if (p == null) {
continue;
}
double aboveSize = fragment_size - c.size;
if (aboveSize >= 3d || c.size >= 3d) {
_children.add(c);
scores.add(c.d / Math.min(aboveSize, c.size));
}
}
TreeNode minc = null;
double minScore = Double.MAX_VALUE;
for (int i = 0; i < scores.size(); i++) {
if (scores.get(i) < minScore) {
minScore = scores.get(i);
minc = _children.get(i);
}
}
return minc;
}
示例12: _findCutPoint
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
public TreeNode _findCutPoint() {
List<TreeNode> _children = new ArrayList<TreeNode>();
TDoubleArrayList scores = new TDoubleArrayList();
Queue<TreeNode> q = new ArrayDeque<TreeNode>();
q.add(this);
while (!q.isEmpty()) {
TreeNode c = q.poll();
q.addAll(c.children);
TreeNode p = c.getParent();
if (p == null) {
continue;
}
double aboveSize = fragment_size - c.size;
if (aboveSize >= minModuleSize || c.size >= minModuleSize) {
_children.add(c);
scores.add(c.d / Math.max(aboveSize, c.size));
}
}
TreeNode maxc = null;
double maxScore = Double.MIN_VALUE;
for (int i = 0; i < scores.size(); i++) {
if (scores.get(i) > maxScore) {
maxScore = scores.get(i);
maxc = _children.get(i);
}
}
return maxc;
}
示例13: calculateNDCG
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
/**
* Calculate NDCG.
* blatantly refactored from galago
*/
public static double calculateNDCG(List<ScoredDate> rankedDates, Set<Integer> relYears) {
if(relYears.isEmpty()) return 0.0;
// parameters
final double IdealScore = 1.0;
int numRetrieved = rankedDates.size();
// compute dcg:
TDoubleArrayList actualGain = new TDoubleArrayList(numRetrieved);
for (ScoredDate doc : rankedDates) {
double value = 0.0;
if(relYears.contains(doc.year)) { value = IdealScore; }
actualGain.add(value);
}
double dcg = computeDCG(actualGain, numRetrieved);
TDoubleArrayList idealGain = new TDoubleArrayList(numRetrieved);
for(int i=0; i<relYears.size(); i++) {
idealGain.add(IdealScore);
}
// put the best ones at the beginning
idealGain.sort(); idealGain.reverse();
double max = computeDCG(idealGain, numRetrieved);
return dcg / max;
}
示例14: retainMass
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
public static TableFactor retainMass (DiscreteFactor ptl, double alpha)
{
int[] idxs = new int [ptl.numLocations ()];
double[] vals = new double [ptl.numLocations ()];
for (int i = 0; i < idxs.length; i++) {
idxs[i] = ptl.indexAtLocation (i);
vals[i] = ptl.logValue (i);
}
RankedFeatureVector rfv = new RankedFeatureVector (new Alphabet(), idxs, vals);
TIntArrayList idxList = new TIntArrayList ();
TDoubleArrayList valList = new TDoubleArrayList ();
double mass = Double.NEGATIVE_INFINITY;
double logAlpha = Math.log (alpha);
for (int rank = 0; rank < rfv.numLocations (); rank++) {
int idx = rfv.getIndexAtRank (rank);
double val = rfv.value (idx);
mass = Maths.sumLogProb (mass, val);
idxList.add (idx);
valList.add (val);
if (mass > logAlpha) {
break;
}
}
int[] szs = computeSizes (ptl);
SparseMatrixn m = new SparseMatrixn (szs, idxList.toArray (), valList.toArray ());
TableFactor result = new TableFactor (computeVars (ptl));
result.setValues (m);
return result;
}
示例15: testSample
import gnu.trove.list.array.TDoubleArrayList; //导入方法依赖的package包/类
public void testSample ()
{
Variable var = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Factor f = new BetaFactor (var, 0.7, 0.5);
TDoubleArrayList lst = new TDoubleArrayList ();
for (int i = 0; i < 100000; i++) {
Assignment assn = f.sample (r);
lst.add (assn.getDouble (var));
}
double[] vals = lst.toArray ();
double mean = MatrixOps.mean (vals);
assertEquals (0.7 / (0.5 + 0.7), mean, 0.01);
}