random = new Random(m_Seed); data = m_CostMatrix.applyCostMatrix(data, random);
random = new Random(m_Seed); data = m_CostMatrix.applyCostMatrix(data, random);
/** * Tests creating a 3x3 cost matrix and applying it to 2 class data. An * execption is expected in this case * * @throws Exception if a problem occurs */ public void testIncorrectSize() throws Exception { CostMatrix matrix = new CostMatrix(3); Instances data = getData(); try { matrix.applyCostMatrix(data, null); fail("Was expecting an exception as the cost matrix represents more classes than " + "are present in the data"); } catch (Exception ex) { // expected } }
/** * Tests creating a 3x3 cost matrix and applying it to 2 class data. An * execption is expected in this case * * @throws Exception if a problem occurs */ public void testIncorrectSize() throws Exception { CostMatrix matrix = new CostMatrix(3); Instances data = getData(); try { matrix.applyCostMatrix(data, null); fail("Was expecting an exception as the cost matrix represents more classes than " + "are present in the data"); } catch (Exception ex) { // expected } }
/** * Tests a simple 2 class cost matrix with fixed costs * * @throws Exception if a problem occurs */ public void test2ClassCostMatrixNoExpressions() throws Exception { CostMatrix matrix = get2ClassCostMatrixNoExpressions(2, 6); Instances data = getData(); Instances weighted = matrix.applyCostMatrix(data, null); assertEquals(0.5, weighted.instance(0).weight()); assertEquals(1.5, weighted.instance(1).weight()); }
/** * Tests a simple 2 class cost matrix with fixed costs * * @throws Exception if a problem occurs */ public void test2ClassCostMatrixNoExpressions() throws Exception { CostMatrix matrix = get2ClassCostMatrixNoExpressions(2, 6); Instances data = getData(); Instances weighted = matrix.applyCostMatrix(data, null); assertEquals(0.5, weighted.instance(0).weight()); assertEquals(1.5, weighted.instance(1).weight()); }
/** * Tests a 2 class cost matrix with one simple expression * * @throws Exception if a problem occurs */ public void test2ClassCostMatrixOneSimpleExpression() throws Exception { CostMatrix matrix = get2ClassCostMatrixNoExpressions(2, 6); matrix.setCell(0, 1, "a2"); Instances data = getData(); Instances weighted = matrix.applyCostMatrix(data, null); assertEquals(5.0, weighted.instance(0).weight()); assertEquals(6.0, weighted.instance(1).weight()); }
/** * Tests a 2 class cost matrix with one more complex expression * * @throws Exception if a problem occurs */ public void test2ClassCostMatrixOneExpression() throws Exception { CostMatrix matrix = get2ClassCostMatrixNoExpressions(2, 6); matrix.setCell(0, 1, "log(a2^2)*a1-1"); Instances data = getData(); Instances weighted = matrix.applyCostMatrix(data, null); assertEquals(-4.218876, weighted.instance(0).weight(), 1e-6); assertEquals(6.0, weighted.instance(1).weight()); }
/** * Tests a 2 class cost matrix with one simple expression * * @throws Exception if a problem occurs */ public void test2ClassCostMatrixOneSimpleExpression() throws Exception { CostMatrix matrix = get2ClassCostMatrixNoExpressions(2, 6); matrix.setCell(0, 1, "a2"); Instances data = getData(); Instances weighted = matrix.applyCostMatrix(data, null); assertEquals(5.0, weighted.instance(0).weight()); assertEquals(6.0, weighted.instance(1).weight()); }
/** * Tests a 2 class cost matrix with one more complex expression * * @throws Exception if a problem occurs */ public void test2ClassCostMatrixOneExpression() throws Exception { CostMatrix matrix = get2ClassCostMatrixNoExpressions(2, 6); matrix.setCell(0, 1, "log(a2^2)*a1-1"); Instances data = getData(); Instances weighted = matrix.applyCostMatrix(data, null); assertEquals(-4.218876, weighted.instance(0).weight(), 1e-6); assertEquals(6.0, weighted.instance(1).weight()); }
/** * Tests a 2 class cost matrix with two expressions * * @throws Exception if a problem occurs */ public void test2ClassCostMatrixTwoExpressions() throws Exception { CostMatrix matrix = get2ClassCostMatrixNoExpressions(2, 6); matrix.setCell(0, 1, "log(a2^2)*a1-1"); matrix.setCell(1, 0, "exp(a1*cos(a2))/sqrt(a1/2)"); Instances data = getData(); Instances weighted = matrix.applyCostMatrix(data, null); assertEquals(-4.218876, weighted.instance(0).weight(), 1e-6); assertEquals(0.241157, weighted.instance(1).weight(), 1e-6); }
CostMatrix normMatrix = new CostMatrix(this); normMatrix.normalize(); return normMatrix.applyCostMatrix(data, random);
CostMatrix normMatrix = new CostMatrix(this); normMatrix.normalize(); return normMatrix.applyCostMatrix(data, random);
/** * Tests a 2 class cost matrix with two expressions * * @throws Exception if a problem occurs */ public void test2ClassCostMatrixTwoExpressions() throws Exception { CostMatrix matrix = get2ClassCostMatrixNoExpressions(2, 6); matrix.setCell(0, 1, "log(a2^2)*a1-1"); matrix.setCell(1, 0, "exp(a1*cos(a2))/sqrt(a1/2)"); Instances data = getData(); Instances weighted = matrix.applyCostMatrix(data, null); assertEquals(-4.218876, weighted.instance(0).weight(), 1e-6); assertEquals(0.241157, weighted.instance(1).weight(), 1e-6); }