Package gnu.trove

Examples of gnu.trove.TDoubleArrayList


//    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));
  }
View Full Code Here


  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;
  }
View Full Code Here

  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);
  }
View Full Code Here

  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);
  }
View Full Code Here

      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;
View Full Code Here

  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);
  }
View Full Code Here

  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);
  }
View Full Code Here

    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;
  }
View Full Code Here

    this.numLabels = numLabels;
    this.useValues = useValues;
    this.normalize = normalize;
    this.constraints = new TIntObjectHashMap<MaxEntL2IndGEConstraint>();
    this.indexCache = new TIntArrayList();
    this.valueCache = new TDoubleArrayList();
  }
View Full Code Here

    this.numFeatures = numFeatures;
    this.numLabels = numLabels;
    this.useValues = useValues;
    this.constraints = new TIntObjectHashMap<MaxEntFLGEConstraint>();
    this.indexCache = new TIntArrayList();
    this.valueCache = new TDoubleArrayList();
  }
View Full Code Here

TOP

Related Classes of gnu.trove.TDoubleArrayList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.