edu.umass.cs.mallet.base.maximize.tests
Class TestMaximizable

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byedu.umass.cs.mallet.base.maximize.tests.TestMaximizable
All Implemented Interfaces:
junit.framework.Test

public class TestMaximizable
extends junit.framework.TestCase

Contains static methods for testing subclasses of Maximizable and Maximizable.ByGradient. Especially useful are methods that verify the consistency of the value and gradient functions of an instance of Maximizable.ByGradient.


Constructor Summary
TestMaximizable(java.lang.String name)
           
 
Method Summary
static void main(java.lang.String[] args)
           
static void setNumComponents(int n)
          Sets the number of gradient components that will be checked.
protected  void setUp()
           
static junit.framework.Test suite()
           
static boolean testGetSetParameters(Maximizable maxable)
          Tests that parameters set by setParameters can be retrieved by getParameters.
 void testTestValueAndGradient()
           
static boolean testValueAndGradient(Maximizable.ByGradient maxable)
          Tests that getValue and getValueGradient are consistent.
static double testValueAndGradientCurrentParameters(Maximizable.ByGradient maxable)
          Tests that the value and gradient function are consistent at the current parameters.
static double testValueAndGradientInDirection(Maximizable.ByGradient maxable, double[] direction)
           
static boolean testValueAndGradientRandomParameters(Maximizable.ByGradient maxable, java.util.Random r)
          Tests that getValue and getValueGradient are consistent at a random parameter setting.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestMaximizable

public TestMaximizable(java.lang.String name)
Method Detail

setNumComponents

public static void setNumComponents(int n)
Sets the number of gradient components that will be checked. If negative, all will be checked.


testGetSetParameters

public static boolean testGetSetParameters(Maximizable maxable)
Tests that parameters set by setParameters can be retrieved by getParameters.

Parameters:
maxable - Instance of a Maximizable that should be tested. Its current parameters will be overwritten.

testValueAndGradientInDirection

public static double testValueAndGradientInDirection(Maximizable.ByGradient maxable,
                                                     double[] direction)

testValueAndGradientCurrentParameters

public static double testValueAndGradientCurrentParameters(Maximizable.ByGradient maxable)
Tests that the value and gradient function are consistent at the current parameters. Computes both the analytic gradient (the one given by maxable.getValueGradient) and the empirical gradient, which is (if x are the current parameters and f the function computed by maxable) f(x + epsilon) - f(x). Verifies that the angle between the empirical and analytic gradients are close to 0.

Throws:
java.lang.IllegalStateException - If the angle is above the tolerance
See Also:
testValueAndGradient, testValueAndGradientRandomParameters

testValueAndGradient

public static boolean testValueAndGradient(Maximizable.ByGradient maxable)
Tests that getValue and getValueGradient are consistent. Tests for consistency at params = 0 and at params = -0.0001 * grad(f)

Throws:
java.lang.IllegalStateException - If the test fails.
See Also:
testValueAndGradientCurrentParameters

testValueAndGradientRandomParameters

public static boolean testValueAndGradientRandomParameters(Maximizable.ByGradient maxable,
                                                           java.util.Random r)
Tests that getValue and getValueGradient are consistent at a random parameter setting.

Throws:
java.lang.IllegalStateException - If the test fails.
See Also:
testValueAndGradientCurrentParameters

testTestValueAndGradient

public void testTestValueAndGradient()

suite

public static junit.framework.Test suite()

setUp

protected void setUp()

main

public static void main(java.lang.String[] args)