Package de.jungblut.math.squashing

Source Code of de.jungblut.math.squashing.HammingLossFunctionTest

package de.jungblut.math.squashing;

import org.junit.Assert;
import org.junit.Test;

import de.jungblut.math.sparse.SparseDoubleRowMatrix;

public class HammingLossFunctionTest {

  @Test
  public void testSingleHammingLoss() {
    SparseDoubleRowMatrix groundTruth = new SparseDoubleRowMatrix(
        new double[][] { { 1, 1, 1, 1 } });

    SparseDoubleRowMatrix hypo = new SparseDoubleRowMatrix(new double[][] { {
        0, 1, 1, 1 } });

    HammingLossFunction fnc = new HammingLossFunction(0.5d);

    double err = fnc.calculateError(groundTruth, hypo);
    Assert.assertEquals(0.25, err, 0.1d);

  }

  @Test
  public void testMultiHammingLoss() {
    SparseDoubleRowMatrix groundTruth = new SparseDoubleRowMatrix(
        new double[][] { { 1d, 0d }, { 0d, 1d } });

    SparseDoubleRowMatrix hypo = new SparseDoubleRowMatrix(new double[][] {
        { 1d, 0d }, { 0d, 0d } });

    HammingLossFunction fnc = new HammingLossFunction(0.5d);

    double err = fnc.calculateError(groundTruth, hypo);
    Assert.assertEquals(0.5, err, 0.1d);
  }

}
TOP

Related Classes of de.jungblut.math.squashing.HammingLossFunctionTest

TOP
Copyright © 2018 www.massapi.com. 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.