Пример #1
0
  public static Double processValue(Target target, Double value) {
    double result = value.doubleValue();

    Double min = target.getMin();
    if (min != null) {
      result = Math.max(result, min.doubleValue());
    }

    Double max = target.getMax();
    if (max != null) {
      result = Math.min(result, max.doubleValue());
    }

    result = (result * target.getRescaleFactor()) + target.getRescaleConstant();

    Target.CastInteger castInteger = target.getCastInteger();
    if (castInteger == null) {
      return result;
    }

    switch (castInteger) {
      case ROUND:
        return (double) Math.round(result);
      case CEILING:
        return Math.ceil(result);
      case FLOOR:
        return Math.floor(result);
      default:
        throw new UnsupportedFeatureException(target, castInteger);
    }
  }
Пример #2
0
  private static ProbabilityDistribution getPriorProbabilities(Target target) {
    ProbabilityDistribution result = new ProbabilityDistribution();

    List<TargetValue> values = target.getTargetValues();
    for (TargetValue value : values) {

      // "The defaultValue attribute is used only if the optype of the field is continuous"
      if (value.getDefaultValue() != null) {
        throw new InvalidFeatureException(value);
      }

      String targetCategory = value.getValue();
      Double probability = value.getPriorProbability();

      if (targetCategory == null || probability == null) {
        continue;
      }

      result.put(targetCategory, probability);
    }

    if (result.isEmpty()) {
      return null;
    }

    return result;
  }
Пример #3
0
  public static TargetValue getTargetValue(Target target, Object value) {
    DataType dataType = TypeUtil.getDataType(value);

    List<TargetValue> targetValues = target.getTargetValues();
    for (TargetValue targetValue : targetValues) {

      if (TypeUtil.equals(
          dataType, value, TypeUtil.parseOrCast(dataType, targetValue.getValue()))) {
        return targetValue;
      }
    }

    return null;
  }
Пример #4
0
  private static Double getDefaultValue(Target target) {
    List<TargetValue> values = target.getTargetValues();

    if (values.isEmpty()) {
      return null;
    } // End if

    if (values.size() != 1) {
      throw new InvalidFeatureException(target);
    }

    TargetValue value = values.get(0);

    // "The value and priorProbability attributes are used only if the optype of the field is
    // categorical or ordinal"
    if (value.getValue() != null || value.getPriorProbability() != null) {
      throw new InvalidFeatureException(value);
    }

    return value.getDefaultValue();
  }