All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.joliciel.talismane.machineLearning.features.GraduateFeature Maven / Gradle / Ivy

There is a newer version: 6.1.8
Show newest version
///////////////////////////////////////////////////////////////////////////////
//Copyright (C) 2014 Joliciel Informatique
//
//This file is part of Jochre.
//
//Jochre is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//Jochre is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU Affero General Public License for more details.
//
//You should have received a copy of the GNU Affero General Public License
//along with Jochre.  If not, see .
//////////////////////////////////////////////////////////////////////////////
package com.joliciel.talismane.machineLearning.features;

import com.joliciel.talismane.TalismaneException;

/**
 * Takes a feature with a value from 0 to 1, and converts it to a graduated
 * value of 0, 1/n, 2/n, 3/n, ..., 1
 * 
 * @author Assaf Urieli
 *
 */
public class GraduateFeature extends AbstractCachableFeatureimplements DoubleFeature {
  private DoubleFeature valueFeature;
  private IntegerFeature nFeature;

  public GraduateFeature(DoubleFeature valueFeature, IntegerFeature nFeature) {
    super();
    this.valueFeature = valueFeature;
    this.nFeature = nFeature;
    this.setName(this.getName() + "(" + valueFeature.getName() + "," + nFeature.getName() + ")");
  }

  @Override
  public FeatureResult checkInternal(T context, RuntimeEnvironment env) throws TalismaneException {
    FeatureResult rawResult = valueFeature.check(context, env);
    FeatureResult nResult = nFeature.check(context, env);
    FeatureResult result = null;
    if (rawResult != null && nResult != null) {
      double weight = rawResult.getOutcome();
      int n = nResult.getOutcome();
      double graduatedWeight = (1.0 / n) * Math.round(weight * (n - 1));
      result = this.generateResult(graduatedWeight);
    }
    return result;
  }

  public DoubleFeature getValueFeature() {
    return valueFeature;
  }

  public void setValueFeature(DoubleFeature valueFeature) {
    this.valueFeature = valueFeature;
  }

  public IntegerFeature getnFeature() {
    return nFeature;
  }

  public void setnFeature(IntegerFeature nFeature) {
    this.nFeature = nFeature;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy