Class NeatChromosomeSpec
- All Implemented Interfaces:
ChromosomeSpec
- Direct Known Subclasses:
ImmutableNeatChromosomeSpec
A specification defines the stable identities and vector order of the network's input and output nodes, the
namespace available to hidden nodes, and the bounds applied to connection weights. Chromosome factories and genetic
operators use the same NeatNodeLayout throughout an evolutionary run so structural mutations do not relabel
existing nodes.
Contiguous layouts preserve the traditional NEAT numbering scheme. Inputs start at zero, outputs immediately follow the inputs, and hidden-node IDs start after the outputs:
NeatChromosomeSpec xorSpec = NeatChromosomeSpec.of(
2, // input IDs [0, 1]
1, // output ID [2]
-1.0f, // minimum connection weight
1.0f); // maximum connection weight
Explicit layouts support stable, ordered, non-contiguous external IDs and a dedicated hidden-node range:
NeatNodeLayout layout = NeatNodeLayout.explicit(
List.of(10, 1_000, 1_001), // ordered input IDs
List.of(102_000), // ordered output IDs
1_000_000, // hidden range start, inclusive
2_000_000); // hidden range end, exclusive
NeatChromosomeSpec sparseSpec = new NeatChromosomeSpec.Builder().nodeLayout(layout)
.minWeightValue(-2.0f)
.maxWeightValue(2.0f)
.build();
Declaration order is significant: it defines how input and output vectors map to node IDs. Node IDs themselves are opaque identities and need not be contiguous. A valid layout contains at least one input and one output, uses unique non-negative external IDs, keeps input and output IDs disjoint, and reserves a non-empty hidden-node range that does not overlap external IDs.
The minimum connection weight must be strictly less than the maximum. Factories use these bounds when creating initial connections, and mutation operators use them when changing connection weights.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilds immutable NEAT chromosome specifications. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheck()abstract floatReturns the maximum allowed connection weight.abstract floatReturns the minimum allowed connection weight.abstract NeatNodeLayoutReturns the stable external node identities and hidden-node namespace for chromosomes created from this specification.intReturns the number of input nodes declared bynodeLayout().intReturns the number of output nodes declared bynodeLayout().static NeatChromosomeSpecof(int numInputs, int numOutputs, float minWeightValue, float maxWeightValue) Creates a specification using the traditional contiguous node layout.static NeatChromosomeSpecof(NeatNodeLayout nodeLayout, float minWeightValue, float maxWeightValue) Creates a specification using the supplied node layout and connection-weight bounds.
-
Constructor Details
-
NeatChromosomeSpec
public NeatChromosomeSpec()
-
-
Method Details
-
nodeLayout
Returns the stable external node identities and hidden-node namespace for chromosomes created from this specification.- Returns:
- the node layout
-
minWeightValue
@Parameter public abstract float minWeightValue()Returns the minimum allowed connection weight.- Returns:
- the inclusive lower bound for connection weights
-
maxWeightValue
@Parameter public abstract float maxWeightValue()Returns the maximum allowed connection weight.- Returns:
- the inclusive upper bound for connection weights
-
numInputs
public int numInputs()Returns the number of input nodes declared bynodeLayout().- Returns:
- the positive number of input nodes
-
numOutputs
public int numOutputs()Returns the number of output nodes declared bynodeLayout().- Returns:
- the positive number of output nodes
-
check
@Check protected void check() -
of
public static NeatChromosomeSpec of(NeatNodeLayout nodeLayout, float minWeightValue, float maxWeightValue) Creates a specification using the supplied node layout and connection-weight bounds.- Parameters:
nodeLayout- stable external IDs and hidden-node namespaceminWeightValue- minimum allowed connection weightmaxWeightValue- maximum allowed connection weight- Returns:
- a validated immutable chromosome specification
- Throws:
NullPointerException- ifnodeLayoutisnullIllegalArgumentException- ifminWeightValueis not less thanmaxWeightValue
-
of
public static NeatChromosomeSpec of(int numInputs, int numOutputs, float minWeightValue, float maxWeightValue) Creates a specification using the traditional contiguous node layout.Input IDs are
[0, numInputs), output IDs are[numInputs, numInputs + numOutputs), and the hidden-node namespace starts atnumInputs + numOutputs.- Parameters:
numInputs- number of input nodes; must be positivenumOutputs- number of output nodes; must be positiveminWeightValue- minimum allowed connection weightmaxWeightValue- maximum allowed connection weight- Returns:
- a validated immutable chromosome specification
- Throws:
IllegalArgumentException- if either node count is not positive or the weight bounds are not ordered
-