Alexandre Patry avatar Alexandre Patry committed ae49abc

Remove cc.mallet.grmm.types.NormalFactor

This was not used and was the only class depending on mtj, a
third-party library not published in a central maven repository.

Comments (0)

Files changed (3)

     </dependency>
 
     <dependency>
-      <groupId>matrix-toolkits-java</groupId>
-      <artifactId>mtj</artifactId>
-      <version>0.9.9</version>
-    </dependency>
-
-    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.5</version>
       </plugin>
     </plugins>
   </build>
-
-
-  <repositories>
-    <!-- needed for mtj -->
-    <repository>
-      <snapshots>
-        <enabled>false</enabled>
-      </snapshots>
-      <id>cleartk-googlecode</id>
-      <name>ClearTK Google Code repository</name>
-      <url>http://cleartk.googlecode.com/svn/repo/</url>
-    </repository>
-  </repositories>
-
 </project>

src/cc/mallet/grmm/types/NormalFactor.java

-/* Copyright (C) 2006 Univ. of Massachusetts Amherst, Computer Science Dept.
-   This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).
-   http://www.cs.umass.edu/~mccallum/mallet
-   This software is provided under the terms of the Common Public License,
-   version 1.0, as published by http://www.opensource.org.  For further
-   information, see the file `LICENSE' included with this distribution. */
-package cc.mallet.grmm.types;
-
-import cc.mallet.util.Maths;
-import cc.mallet.util.Randoms;
-import no.uib.cipr.matrix.*;
-
-/**
- * Multivariate Gaussian factor.  Currently, almost all of this class
- *  is a stub, except for the sample method.
- * $Id: NormalFactor.java,v 1.1 2007/10/22 21:37:44 mccallum Exp $
- */
-public class NormalFactor extends AbstractFactor {
-
-  private Vector mean;
-  private Matrix variance;
-
-  public NormalFactor (VarSet vars, Vector mean, Matrix variance)
-  {
-    super (vars);
-    if (!isPosDef (variance)) throw new IllegalArgumentException ("Matrix "+variance+" not positive definite.");
-    this.mean = mean;
-    this.variance = variance;
-  }
-
-  private boolean isPosDef (Matrix variance)
-  {
-    try {
-      EVD evd = EVD.factorize (variance);
-      double[] vals = evd.getRealEigenvalues ();
-      return vals[vals.length - 1] > 0;
-    } catch (NotConvergedException e) {
-      throw new RuntimeException (e);
-    }
-  }
-
-
-  //
-  protected Factor extractMaxInternal (VarSet varSet)
-  {
-    throw new UnsupportedOperationException ();
-  }
-
-  public double value (Assignment assn)
-  {
-    // stub
-    return 1.0;
-  }
-
-  protected double lookupValueInternal (int i)
-  {
-    throw new UnsupportedOperationException ();
-  }
-
-  protected Factor marginalizeInternal (VarSet varsToKeep)
-  {
-    throw new UnsupportedOperationException ();
-  }
-
-  public Factor normalize ()
-  {
-    return this;
-  }
-
-  public Assignment sample (Randoms r)
-  {
-    // generate from standard normal
-    double[] vals = new double [mean.size ()];
-    for (int k = 0; k < vals.length; k++) {
-      vals[k] = r.nextGaussian ();
-    }
-
-    // and transform
-    Vector Z = new DenseVector (vals, false);
-    DenseVector result = new DenseVector (vals.length);
-    variance.mult (Z, result);
-    result = (DenseVector) result.add (mean);
-
-    return new Assignment (vars.toVariableArray (), result.getData ());
-  }
-
-  public boolean almostEquals (Factor p, double epsilon)
-  {
-    return equals (p);
-  }
-
-  public Factor duplicate ()
-  {
-    return new NormalFactor (vars, mean, variance);
-  }
-
-  public boolean isNaN ()
-  {
-    return false;
-  }
-
-  public String dumpToString ()
-  {
-    return toString ();
-  }
-
-  public String toString ()
-  {
-    return "[NormalFactor "+vars+" "+mean+" ... " +variance+" ]";
-  }
-
-  // todo
-  public Factor slice (Assignment assn)
-  {
-    if (assn.varSet ().containsAll (vars)) {
-      // special case
-      return new ConstantFactor (value (assn));
-    } else {
-      throw new UnsupportedOperationException ();
-    }
-  }
-
-  public void multiplyBy (Factor f)
-  {
-    if (f instanceof ConstantFactor) {
-      double val = f.value (new Assignment());
-      // NormalFactor must be normalized right now...
-      if (Maths.almostEquals (val, 1.0)) {
-        return;  // ok, it's an identity factor
-      }
-    }
-
-    throw new UnsupportedOperationException ("Can't multiply NormalFactor by "+f);
-  }
-
-  public void divideBy (Factor f)
-  {
-    if (f instanceof ConstantFactor) {
-      double val = f.value (new Assignment());
-      // NormalFactor must be normalized right now...
-      if (Maths.almostEquals (val, 1.0)) {
-        return;  // ok, it's an identity factor
-      }
-    }
-
-    throw new UnsupportedOperationException ("Can't divide NormalFactor by "+f);
-  }
-
-
-}

tests/cc/mallet/grmm/test/TestNormalFactor.java

-/* Copyright (C) 2006 Univ. of Massachusetts Amherst, Computer Science Dept.
-   This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).
-   http://www.cs.umass.edu/~mccallum/mallet
-   This software is provided under the terms of the Common Public License,
-   version 1.0, as published by http://www.opensource.org.  For further
-   information, see the file `LICENSE' included with this distribution. */
-
-package cc.mallet.grmm.test;
-
-import cc.mallet.grmm.types.*;
-import cc.mallet.types.MatrixOps;
-import cc.mallet.util.Randoms;
-import junit.framework.*;
-import gnu.trove.TDoubleArrayList;
-import no.uib.cipr.matrix.Vector;
-import no.uib.cipr.matrix.DenseVector;
-import no.uib.cipr.matrix.Matrix;
-import no.uib.cipr.matrix.DenseMatrix;
-
-/**
- * $Id: TestNormalFactor.java,v 1.1 2007/10/22 21:37:41 mccallum Exp $
- */
-public class TestNormalFactor extends TestCase {
-
-  public TestNormalFactor (String name)
-  {
-    super (name);
-  }
-
-  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));
-  }
-
-  void checkMeanStd (TDoubleArrayList ell, double mu, double sigma)
-  {
-    double[] vals = ell.toNativeArray ();
-    double mean1 = MatrixOps.mean (vals);
-    double std1 = MatrixOps.stddev (vals);
-    assertEquals (mu, mean1, 0.025);
-    assertEquals (sigma, std1, 0.01);
-  }
-
-
-  /**
-   * @return a <code>TestSuite</code>
-   */
-  public static TestSuite suite ()
-  {
-    return new TestSuite (TestNormalFactor.class);
-  }
-
-  public static void main (String[] args)
-  {
-    TestSuite theSuite;
-    if (args.length > 0) {
-      theSuite = new TestSuite ();
-      for (int i = 0; i < args.length; i++) {
-        theSuite.addTest (new TestNormalFactor (args[i]));
-      }
-    } else {
-      theSuite = (TestSuite) suite ();
-    }
-
-    junit.textui.TestRunner.run (theSuite);
-  }
-
-}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.