Package cc.mallet.types

Examples of cc.mallet.types.SparseMatrixn


      int[] oneIdx = new int [sizes.length];
      Arrays.fill (oneIdx, i);
      idxs[i] = Matrixn.singleIndex (sizes, oneIdx);
    }

    return new SparseMatrixn (sizes, idxs, vals);
  }
View Full Code Here


    }

    double[] vals = new double [singleSize];
    Arrays.fill (vals, v);

    return new SparseMatrixn (sizes, vals);
  }
View Full Code Here

  public void testIndexing1d ()
  {
    double m1[] = new double[]{1.0, 2.0, 3.0, 4.0};
    int idx1[] = new int[1];
    SparseMatrixn a = new SparseMatrixn (m1);
    a.singleToIndices (3, idx1);
    assertEquals (3, idx1[0]);
    assertEquals (3, a.singleIndex (idx1));
  }
View Full Code Here

    int[] sizes = new int[]{2, 3};
    double[] m1 = new double[6];
    for (int i = 0; i < 6; i++) {
      m1[i] = 2.0 * i;
    }
    SparseMatrixn a = new SparseMatrixn (sizes, m1);
    int[] idx1 = new int[2];
    a.singleToIndices (5, idx1);
    System.out.println (idx1[0]+" , "+idx1[1]);

    int[] trueIdx = new int[] {1, 2};
    assertTrue (Arrays.equals (trueIdx, idx1));
    assertEquals (5, a.singleIndex (idx1));
    assertEquals (10.0, a.value (idx1), 1e-12);
  }
View Full Code Here

    assertEquals (10.0, a.value (idx1), 1e-12);
  }

  public void testIndexing3d ()
  {
    SparseMatrixn a = make3dMatrix ();
    int[] idx1 = new int[3];
    a.singleToIndices (21, idx1);

    int[] trueIdx = new int[]{1, 2, 1};
    assertTrue (Arrays.equals (trueIdx, idx1));
    assertEquals (21, a.singleIndex (idx1));
    assertEquals (0, a.value (idx1), 1e-12);

    int[] idx2 = new int[]{1, 2, 2};
    assertEquals (22, a.singleIndex (idx2));
    assertEquals (44.0, a.value (idx2), 1e-12);
  }
View Full Code Here

        idxs.add (i);
        vals.add (2.0 * i);
      }
    }

    SparseMatrixn a = new SparseMatrixn (sizes, idxs.toNativeArray (), vals.toNativeArray ());
    return a;
  }
View Full Code Here

    return a;
  }

  public void testSparseMatrixnSerializable () throws IOException, ClassNotFoundException
  {
    SparseMatrixn a = make3dMatrix ();
    SparseMatrixn b = (SparseMatrixn) TestSerializable.cloneViaSerialization (a);

    assertEquals (a.singleSize(), b.singleSize());
    for (int i = 0; i < a.singleSize (); i++) {
      int[] idxa = new int [a.getNumDimensions ()];
      int[] idxb = new int [a.getNumDimensions ()];

      a.singleToIndices (i, idxa);
      b.singleToIndices (i, idxb);

      assertTrue (Arrays.equals (idxa, idxb));
      assertEquals (a.value (idxa), b.value (idxb), 1e-12);
    }
  }
View Full Code Here

    double[] vals = new double[numRows ()];
    for (int ri = 0; ri < numRows (); ri++) {
      idxs[ri] = singleIndex (ri);
      vals[ri]++;
    }
    SparseMatrixn matrix = new SparseMatrixn (Utils.toSizesArray (varr), idxs, vals);
    return new TableFactor (varr, matrix);
  }
View Full Code Here

    double[] vals2 = new double [] { 0.5, 0.5 };

    double[] vals3 = new double [] { 1.0, 0, 4.0 };

    TableFactor ptl1 = new TableFactor (vars);
    ptl1.setValues (new SparseMatrixn (szs, idxs1, vals1));

    TableFactor ptl2 = new TableFactor (vars);
    ptl2.setValues (new SparseMatrixn (szs, idxs2, vals2));

    TableFactor ans = new TableFactor (vars);
    ans.setValues (new SparseMatrixn (szs, idxs1, vals3));

    Factor ptl3 = ptl1.multiply (ptl2);

    assertTrue ("Tast failed! Expected: "+ans+" Actual: "+ptl3, ans.almostEquals (ptl3));
  }
View Full Code Here

    double[] vals2 = new double [] { 0.5, 0.5 };

    double[] vals3 = new double [] { 4.0, 0, 16.0 };

    TableFactor ptl1 = new TableFactor (vars);
    ptl1.setValues (new SparseMatrixn (szs, idxs1, vals1));

    TableFactor ptl2 = new TableFactor (vars);
    ptl2.setValues (new SparseMatrixn (szs, idxs2, vals2));

    TableFactor ans = new TableFactor (vars);
    ans.setValues (new SparseMatrixn (szs, idxs1, vals3));

    ptl1.divideBy (ptl2);

    assertTrue ("Tast failed! Expected: "+ans+" Actual: "+ptl1, ans.almostEquals (ptl1));
  }
View Full Code Here

TOP

Related Classes of cc.mallet.types.SparseMatrixn

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.