コード例 #1
0
  public void setup(final EvolutionState state, final Parameter base) {
    // very important, remember this
    super.setup(state, base);

    // set up our input -- don't want to use the default base, it's unsafe here
    input =
        (DoubleData)
            state.parameters.getInstanceForParameterEq(base.push(P_DATA), null, DoubleData.class);
    input.setup(state, base.push(P_DATA));
  }
コード例 #2
0
  public void setup(final EvolutionState state, final Parameter base) {
    super.setup(state, base);

    Parameter def = defaultBase();

    // we use size distributions -- did the user specify any?
    if (!canPick())
      state.output.fatal(
          "PTC2 needs a distribution of tree sizes to pick from.  You can do this by either setting a distribution (with "
              + P_NUMSIZES
              + ") or with "
              + P_MINSIZE
              + " and "
              + P_MAXSIZE
              + ".",
          base,
          def);

    maxDepth = state.parameters.getInt(base.push(P_MAXDEPTH), def.push(P_MAXDEPTH), 1);
    if (maxDepth < 1)
      state.output.fatal("Maximum depth must be >= 1", base.push(P_MAXDEPTH), def.push(P_MAXDEPTH));
  }
コード例 #3
0
ファイル: KozaNodeSelector.java プロジェクト: swapon15/ecj-1
  public void setup(final EvolutionState state, final Parameter base) {
    Parameter def = defaultBase();

    terminalProbability =
        state.parameters.getDoubleWithMax(
            base.push(P_TERMINAL_PROBABILITY), def.push(P_TERMINAL_PROBABILITY), 0.0, 1.0);
    if (terminalProbability == -1.0)
      state.output.fatal(
          "Invalid terminal probability for KozaNodeSelector ",
          base.push(P_TERMINAL_PROBABILITY),
          def.push(P_TERMINAL_PROBABILITY));

    nonterminalProbability =
        state.parameters.getDoubleWithMax(
            base.push(P_NONTERMINAL_PROBABILITY), def.push(P_NONTERMINAL_PROBABILITY), 0.0, 1.0);
    if (nonterminalProbability == -1.0)
      state.output.fatal(
          "Invalid nonterminal probability for KozaNodeSelector ",
          base.push(P_NONTERMINAL_PROBABILITY),
          def.push(P_NONTERMINAL_PROBABILITY));

    rootProbability =
        state.parameters.getDoubleWithMax(
            base.push(P_ROOT_PROBABILITY), def.push(P_ROOT_PROBABILITY), 0.0, 1.0);

    if (rootProbability == -1.0)
      state.output.fatal(
          "Invalid root probability for KozaNodeSelector ",
          base.push(P_ROOT_PROBABILITY),
          def.push(P_ROOT_PROBABILITY));

    if (rootProbability + terminalProbability + nonterminalProbability > 1.0f)
      state.output.fatal(
          "The terminal, nonterminal, and root for KozaNodeSelector"
              + base
              + " may not sum to more than 1.0. ("
              + terminalProbability
              + " "
              + nonterminalProbability
              + " "
              + rootProbability
              + ")",
          base);

    reset();
  }
コード例 #4
0
  public void setup(final EvolutionState state, final Parameter base) {
    super.setup(state, base);

    Parameter def = defaultBase();
    Parameter p = base.push(P_NODESELECTOR).push("0");
    Parameter d = def.push(P_NODESELECTOR).push("0");

    nodeselect1 =
        (GPNodeSelector) (state.parameters.getInstanceForParameter(p, d, GPNodeSelector.class));
    nodeselect1.setup(state, p);

    p = base.push(P_NODESELECTOR).push("1");
    d = def.push(P_NODESELECTOR).push("1");

    if (state.parameters.exists(p, d) && state.parameters.getString(p, d).equals(V_SAME))
      // can't just copy it this time; the selectors
      // use internal caches.  So we have to clone it no matter what
      nodeselect2 = (GPNodeSelector) (nodeselect1.clone());
    else {
      nodeselect2 =
          (GPNodeSelector) (state.parameters.getInstanceForParameter(p, d, GPNodeSelector.class));
      nodeselect2.setup(state, p);
    }

    numTries = state.parameters.getInt(base.push(P_NUM_TRIES), def.push(P_NUM_TRIES), 1);
    if (numTries == 0)
      state.output.fatal(
          "GPCrossover Pipeline has an invalid number of tries (it must be >= 1).",
          base.push(P_NUM_TRIES),
          def.push(P_NUM_TRIES));

    maxDepth = state.parameters.getInt(base.push(P_MAXDEPTH), def.push(P_MAXDEPTH), 1);
    if (maxDepth == 0)
      state.output.fatal(
          "GPCrossover Pipeline has an invalid maximum depth (it must be >= 1).",
          base.push(P_MAXDEPTH),
          def.push(P_MAXDEPTH));

    maxSize = NO_SIZE_LIMIT;
    if (state.parameters.exists(base.push(P_MAXSIZE), def.push(P_MAXSIZE))) {
      maxSize = state.parameters.getInt(base.push(P_MAXSIZE), def.push(P_MAXSIZE), 1);
      if (maxSize < 1) state.output.fatal("Maximum tree size, if defined, must be >= 1");
    }

    tree1 = TREE_UNFIXED;
    if (state.parameters.exists(base.push(P_TREE).push("" + 0), def.push(P_TREE).push("" + 0))) {
      tree1 =
          state.parameters.getInt(base.push(P_TREE).push("" + 0), def.push(P_TREE).push("" + 0), 0);
      if (tree1 == -1) state.output.fatal("Tree fixed value, if defined, must be >= 0");
    }

    tree2 = TREE_UNFIXED;
    if (state.parameters.exists(base.push(P_TREE).push("" + 1), def.push(P_TREE).push("" + 1))) {
      tree2 =
          state.parameters.getInt(base.push(P_TREE).push("" + 1), def.push(P_TREE).push("" + 1), 0);
      if (tree2 == -1) state.output.fatal("Tree fixed value, if defined, must be >= 0");
    }
    tossSecondParent = state.parameters.getBoolean(base.push(P_TOSS), def.push(P_TOSS), false);
  }
コード例 #5
0
  public void setup(final EvolutionState state, final Parameter base) {
    super.setup(state, base);

    Parameter def = defaultBase();
    Parameter p = base.push(P_NODESELECTOR).push("0");
    Parameter d = def.push(P_NODESELECTOR).push("0");

    nodeselect1 =
        (GPNodeSelector) (state.parameters.getInstanceForParameter(p, d, GPNodeSelector.class));
    nodeselect1.setup(state, p);

    p = base.push(P_NODESELECTOR).push("1");
    d = def.push(P_NODESELECTOR).push("1");

    if (state.parameters.exists(p, d) && state.parameters.getString(p, d).equals(V_SAME))
      // can't just copy it this time; the selectors
      // use internal caches.  So we have to clone it no matter what
      nodeselect2 = (GPNodeSelector) (nodeselect1.clone());
    else {
      nodeselect2 =
          (GPNodeSelector) (state.parameters.getInstanceForParameter(p, d, GPNodeSelector.class));
      nodeselect2.setup(state, p);
    }

    numTries = state.parameters.getInt(base.push(P_NUM_TRIES), def.push(P_NUM_TRIES), 1);
    if (numTries == 0)
      state.output.fatal(
          "GPCrossover Pipeline has an invalid number of tries (it must be >= 1).",
          base.push(P_NUM_TRIES),
          def.push(P_NUM_TRIES));

    maxDepth = state.parameters.getInt(base.push(P_MAXDEPTH), def.push(P_MAXDEPTH), 1);
    if (maxDepth == 0)
      state.output.fatal(
          "GPCrossover Pipeline has an invalid maximum depth (it must be >= 1).",
          base.push(P_MAXDEPTH),
          def.push(P_MAXDEPTH));

    maxSize = NO_SIZE_LIMIT;
    if (state.parameters.exists(base.push(P_MAXSIZE), def.push(P_MAXSIZE))) {
      maxSize = state.parameters.getInt(base.push(P_MAXSIZE), def.push(P_MAXSIZE), 1);
      if (maxSize < 1) state.output.fatal("Maximum tree size, if defined, must be >= 1");
    }

    tree1 = TREE_UNFIXED;
    if (state.parameters.exists(base.push(P_TREE).push("" + 0), def.push(P_TREE).push("" + 0))) {
      tree1 =
          state.parameters.getInt(base.push(P_TREE).push("" + 0), def.push(P_TREE).push("" + 0), 0);
      if (tree1 == -1) state.output.fatal("Tree fixed value, if defined, must be >= 0");
    }

    tree2 = TREE_UNFIXED;
    if (state.parameters.exists(base.push(P_TREE).push("" + 1), def.push(P_TREE).push("" + 1))) {
      tree2 =
          state.parameters.getInt(base.push(P_TREE).push("" + 1), def.push(P_TREE).push("" + 1), 0);
      if (tree2 == -1) state.output.fatal("Tree fixed value, if defined, must be >= 0");
    }
    tossSecondParent = state.parameters.getBoolean(base.push(P_TOSS), def.push(P_TOSS), false);

    GPInitializer initializer = ((GPInitializer) state.initializer);
    fs = initializer.treeConstraints[0].functionset;

    templateTree = (GPNode) (((GPNode[]) fs.nodesByName.get("+"))[0]).lightClone();
    GPNode left = (GPNode) (((GPNode[]) fs.nodesByName.get("*"))[0]).lightClone();
    GPNode right = (GPNode) (((GPNode[]) fs.nodesByName.get("*"))[0]).lightClone();
    // RegERC ercNode1 = (RegERC)((((GPNode[])fs.nodesByName.get("ERC"))[0]).lightClone());
    //
    // generate TR node that will be replated by random tree
    // GPNode TRNode = new GPNode();
    // ercNode.constraints = 6;
    // ercNode.children = new GPNode[0];

    templateTree.children = new GPNode[2];
    templateTree.children[0] = left;
    templateTree.children[1] = right;

    left.children = new GPNode[2];
    left.children[0] = null;
    left.children[1] = null;

    right.children = new GPNode[2];
    right.children[0] = null;
    right.children[1] = null;
  }