public void testResolveType_parameterizedType() {
   @SuppressWarnings("rawtypes") // trying to test raw type
   Parameterized<?, ?, ?> parameterized =
       new Parameterized<TypeTokenResolutionTest, Bar, String>() {};
   TypeResolver typeResolver = TypeResolver.accordingTo(parameterized.getClass());
   ParameterizedType resolved =
       (ParameterizedType) typeResolver.resolveType(parameterized.parameterizedType());
   assertEquals(TypeTokenResolutionTest.class, resolved.getOwnerType());
   assertEquals(Bar.class, resolved.getRawType());
   assertThat(resolved.getActualTypeArguments()).asList().contains(String.class);
 }
示例#2
0
  /**
   * This method will automatically populate the search space with parameters based on which
   * Parameter objects return non-null distributions.<br>
   * <br>
   * Note, using this method with Cross Validation has the potential for over-estimating the
   * accuracy of results if the data set is actually used to for parameter guessing.
   *
   * @param data the data set to get parameter estimates from
   * @param paramsEach the number of parameters value to try for each parameter found
   * @return the number of parameters added
   */
  public int autoAddParameters(DataSet data, int paramsEach) {
    Parameterized obj;
    if (baseClassifier != null) obj = (Parameterized) baseClassifier;
    else obj = (Parameterized) baseRegressor;
    int totalParms = 0;
    for (Parameter param : obj.getParameters()) {
      Distribution dist;
      if (param instanceof DoubleParameter) {
        dist = ((DoubleParameter) param).getGuess(data);
        if (dist != null) totalParms++;
      } else if (param instanceof IntParameter) {
        dist = ((IntParameter) param).getGuess(data);
        if (dist != null) totalParms++;
      }
    }
    if (totalParms < 1) return 0;

    double[] quantiles = new double[paramsEach];
    for (int i = 0; i < quantiles.length; i++) quantiles[i] = (i + 1.0) / (paramsEach + 1.0);
    for (Parameter param : obj.getParameters()) {
      Distribution dist;
      if (param instanceof DoubleParameter) {
        dist = ((DoubleParameter) param).getGuess(data);
        if (dist == null) continue;
        double[] vals = new double[paramsEach];
        for (int i = 0; i < vals.length; i++) vals[i] = dist.invCdf(quantiles[i]);

        addParameter((DoubleParameter) param, vals);

      } else if (param instanceof IntParameter) {
        dist = ((IntParameter) param).getGuess(data);
        if (dist == null) continue;
        int[] vals = new int[paramsEach];
        for (int i = 0; i < vals.length; i++) vals[i] = (int) Math.round(dist.invCdf(quantiles[i]));

        addParameter((IntParameter) param, vals);
      }
    }

    return totalParms;
  }