Package org.apache.mahout.classifier.discriminative

Source Code of org.apache.mahout.classifier.discriminative.WinnowTrainerTest

/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.mahout.classifier.discriminative;

import org.apache.mahout.common.MahoutTestCase;
import org.apache.mahout.math.DenseMatrix;
import org.apache.mahout.math.DenseVector;
import org.apache.mahout.math.Matrix;
import org.apache.mahout.math.Vector;
import org.junit.Before;
import org.junit.Test;

@Deprecated
public final class WinnowTrainerTest extends MahoutTestCase {

  private WinnowTrainer trainer;

  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
    trainer = new WinnowTrainer(3);
  }

  @Test
  public void testUpdate() throws Exception {
    double[] labels = { 0.0, 0.0, 0.0, 1.0 };
    Vector labelset = new DenseVector(labels);
    double[][] values = new double[3][4];
    for (int i = 0; i < 3; i++) {
      values[i][0] = 1.0;
      values[i][1] = 1.0;
      values[i][2] = 1.0;
      values[i][3] = 1.0;
    }
    values[1][0] = 0.0;
    values[2][0] = 0.0;
    values[1][1] = 0.0;
    values[2][2] = 0.0;

    Matrix dataset = new DenseMatrix(values);
    trainer.train(labelset, dataset);
    assertTrue(trainer.getModel().classify(dataset.viewColumn(3)));
    assertFalse(trainer.getModel().classify(dataset.viewColumn(0)));
  }

}
TOP

Related Classes of org.apache.mahout.classifier.discriminative.WinnowTrainerTest

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.