当前位置: 首页>>代码示例>>Java>>正文


Java TDoubleArrayList.add方法代码示例

本文整理汇总了Java中gnu.trove.TDoubleArrayList.add方法的典型用法代码示例。如果您正苦于以下问题:Java TDoubleArrayList.add方法的具体用法?Java TDoubleArrayList.add怎么用?Java TDoubleArrayList.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnu.trove.TDoubleArrayList的用法示例。


在下文中一共展示了TDoubleArrayList.add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSample

import gnu.trove.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));
  }
 
开发者ID:mimno,项目名称:GRMM,代码行数:25,代码来源:TestNormalFactor.java

示例2: testSample

import gnu.trove.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.toNativeArray ();
  double mean = MatrixOps.mean (vals);
  double std = MatrixOps.stddev (vals);
  assertEquals (-1.0, mean, 0.025);
  assertEquals (Math.sqrt(2.0), std, 0.01);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:18,代码来源:TestUniNormalFactor.java

示例3: createDirectedModel

import gnu.trove.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.toNativeArray ()), vars[2]));

  return mdl;
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:24,代码来源:TestInference.java

示例4: make3dMatrix

import gnu.trove.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.toNativeArray (), vals.toNativeArray ());
  return a;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:17,代码来源:TestSparseMatrixn.java

示例5: readDoubleArray

import gnu.trove.TDoubleArrayList; //导入方法依赖的package包/类
public static double[] readDoubleArray(JsonReaderEx reader) {
  checkIsNull(reader, null);
  reader.beginArray();
  if (!reader.hasNext()) {
    reader.endArray();
    return new double[]{0};
  }

  TDoubleArrayList result = new TDoubleArrayList();
  do {
    result.add(reader.nextDouble());
  }
  while (reader.hasNext());
  reader.endArray();
  return result.toNativeArray();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:JsonReaders.java

示例6: retainMass

import gnu.trove.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.toNativeArray (), valList.toNativeArray ());

  TableFactor result = new TableFactor (computeVars (ptl));
  result.setValues (m);

  return result;
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:35,代码来源:Factors.java

示例7: testSample

import gnu.trove.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.toNativeArray ();
  double mean = MatrixOps.mean (vals);
  assertEquals (0.7 / (0.5 + 0.7), mean, 0.01);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:16,代码来源:TestBetaFactor.java

示例8: testSample2

import gnu.trove.TDoubleArrayList; //导入方法依赖的package包/类
public void testSample2 ()
{
  Variable var = new Variable (Variable.CONTINUOUS);
  Randoms r = new Randoms (2343);
  Factor f = new BetaFactor (var, 0.7, 0.5, 3.0, 8.0);
  TDoubleArrayList lst = new TDoubleArrayList ();
  for (int i = 0; i < 100000; i++) {
    Assignment assn = f.sample (r);
    lst.add (assn.getDouble (var));
  }

  double[] vals = lst.toNativeArray ();
  double mean = MatrixOps.mean (vals);
  assertEquals (5.92, mean, 0.01);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:16,代码来源:TestBetaFactor.java

示例9: testSample

import gnu.trove.TDoubleArrayList; //导入方法依赖的package包/类
public void testSample ()
{
  Variable var = new Variable (Variable.CONTINUOUS);
  Randoms r = new Randoms (2343);
  Factor f = new UniformFactor (var, -1.0, 1.5);
  TDoubleArrayList lst = new TDoubleArrayList ();
  for (int i = 0; i < 10000; i++) {
    Assignment assn = f.sample (r);
    lst.add (assn.getDouble (var));
  }

  double[] vals = lst.toNativeArray ();
  double mean = MatrixOps.mean (vals);
  assertEquals (0.25, mean, 0.01);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:16,代码来源:TestUniformFactor.java

示例10: removeFeatures

import gnu.trove.TDoubleArrayList; //导入方法依赖的package包/类
public void removeFeatures(IIntIterator removedFeatures) {
    for (int i = 0; i < _documentsWeights.size(); ++i) {
        TIntDoubleHashMap weigs = _documentsWeights.get(i);
        TIntArrayList feats = new TIntArrayList(weigs.size());
        TDoubleArrayList weigths = new TDoubleArrayList(weigs.size());
        TIntDoubleIterator wit = weigs.iterator();
        while (wit.hasNext()) {
            wit.advance();
            feats.add(wit.key());
            weigths.add(wit.value());
        }
        int j = 0;
        int shift = 0;
        int feat;
        int rem;
        if (j < feats.size() && removedFeatures.hasNext()) {
            feat = feats.getQuick(j);
            rem = removedFeatures.next();

            while (true) {
                if (feat == rem) {
                    feats.remove(j);
                    weigths.remove(j);
                    if (j < feats.size() && removedFeatures.hasNext()) {
                        feat = feats.getQuick(j);
                        rem = removedFeatures.next();
                        ++shift;
                    } else
                        break;
                } else if (feat > rem) {
                    if (removedFeatures.hasNext()) {
                        rem = removedFeatures.next();
                        ++shift;
                    } else
                        break;
                } else {
                    feats.setQuick(j, feat - shift);
                    ++j;
                    if (j < feats.size())
                        feat = feats.getQuick(j);
                    else
                        break;
                }
            }
            ++shift;
        }
        while (j < feats.size()) {
            feats.setQuick(j, feats.getQuick(j) - shift);
            ++j;
        }

        weigs.clear();
        for (j = 0; j < feats.size(); ++j)
            weigs.put(feats.getQuick(j), weigths.getQuick(j));

        removedFeatures.begin();
    }
}
 
开发者ID:jatecs,项目名称:jatecs,代码行数:59,代码来源:TroveWeightingDB.java


注:本文中的gnu.trove.TDoubleArrayList.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。