Esempio n. 1
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;
  }
Esempio n. 2
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;
  }
Esempio n. 3
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();
  }