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

com.joliciel.talismane.machineLearning.features.InverseFeature 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;

/**
 * Inverts a normalised double feature (whose values go from 0 to 1), giving
 * 1-result. If the result is < 0, returns 0.
 * 
 * @author Assaf Urieli
 *
 */
public class InverseFeature extends AbstractCachableFeatureimplements DoubleFeature {

  Feature valueFeature;

  public InverseFeature(Feature feature) {
    super();
    this.valueFeature = feature;
    this.setName(this.getName() + "(" + this.valueFeature.getName() + ")");
  }

  @Override
  public FeatureResult checkInternal(T context, RuntimeEnvironment env) throws TalismaneException {
    FeatureResult rawOutcome = valueFeature.check(context, env);
    FeatureResult outcome = null;
    if (rawOutcome != null) {
      double weight = rawOutcome.getOutcome();
      double inverseWeight = 1 - weight;
      if (inverseWeight < 0)
        inverseWeight = 0;
      outcome = this.generateResult(inverseWeight);
    }
    return outcome;
  }

  public Feature getValueFeature() {
    return valueFeature;
  }

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy