|
1
|
|
package net.bmahe.genetics4j.neat.mutation.chromosome; |
|
2
|
|
|
|
3
|
|
import java.util.List; |
|
4
|
|
import java.util.Objects; |
|
5
|
|
import java.util.random.RandomGenerator; |
|
6
|
|
|
|
7
|
|
import net.bmahe.genetics4j.core.spec.mutation.RandomMutation; |
|
8
|
|
import net.bmahe.genetics4j.neat.Connection; |
|
9
|
|
import net.bmahe.genetics4j.neat.chromosomes.NeatChromosome; |
|
10
|
|
|
|
11
|
|
/** |
|
12
|
|
* Mutation handler that applies random weight replacement to NEAT chromosomes using the core |
|
13
|
|
* {@link RandomMutation} policy. Each mutated connection receives a new weight sampled uniformly |
|
14
|
|
* from the chromosome's valid weight range. |
|
15
|
|
* |
|
16
|
|
* <p>For distribution-controlled weight mutation (e.g. Gaussian perturbation, configurable |
|
17
|
|
* perturbation ratio), use {@link net.bmahe.genetics4j.neat.spec.mutation.NeatConnectionWeight} |
|
18
|
|
* with {@link NeatChromosomeConnectionWeightMutationHandler} instead. |
|
19
|
|
*/ |
|
20
|
|
public class NeatChromosomeRandomMutationHandler |
|
21
|
|
extends AbstractNeatChromosomeConnectionMutationHandler<RandomMutation> |
|
22
|
|
{ |
|
23
|
|
|
|
24
|
|
public NeatChromosomeRandomMutationHandler(final RandomGenerator _randomGenerator) { |
|
25
|
|
super(RandomMutation.class, _randomGenerator); |
|
26
|
|
} |
|
27
|
|
|
|
28
|
|
@Override |
|
29
|
|
protected List<Connection> mutateConnection(final RandomMutation randomMutation, final NeatChromosome neatChromosome, |
|
30
|
|
final Connection oldConnection, final int i) { |
|
31
|
|
Objects.requireNonNull(randomMutation); |
|
32
|
|
Objects.requireNonNull(neatChromosome); |
|
33
|
|
Objects.requireNonNull(oldConnection); |
|
34
|
|
|
|
35
|
3
1. mutateConnection : replaced call to net/bmahe/genetics4j/neat/Connection$Builder::from with receiver → KILLED
2. mutateConnection : removed call to net/bmahe/genetics4j/neat/Connection::builder → KILLED
3. mutateConnection : removed call to net/bmahe/genetics4j/neat/Connection$Builder::from → KILLED
|
final var connectionBuilder = Connection.builder().from(oldConnection); |
|
36
|
|
|
|
37
|
1
1. mutateConnection : removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getMinWeightValue → KILLED
|
final var minValue = neatChromosome.getMinWeightValue(); |
|
38
|
1
1. mutateConnection : removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getMaxWeightValue → SURVIVED
|
final var maxValue = neatChromosome.getMaxWeightValue(); |
|
39
|
|
|
|
40
|
1
1. mutateConnection : removed call to net/bmahe/genetics4j/neat/mutation/chromosome/NeatChromosomeRandomMutationHandler::getRandomGenerator → KILLED
|
final var randomGenerator = getRandomGenerator(); |
|
41
|
|
|
|
42
|
4
1. mutateConnection : Replaced float subtraction with addition → SURVIVED
2. mutateConnection : removed call to java/util/random/RandomGenerator::nextFloat → KILLED
3. mutateConnection : Replaced float addition with subtraction → KILLED
4. mutateConnection : replaced call to java/util/random/RandomGenerator::nextFloat with argument → KILLED
|
float newWeight = randomGenerator.nextFloat(maxValue - minValue) + minValue; |
|
43
|
2
1. mutateConnection : replaced call to net/bmahe/genetics4j/neat/Connection$Builder::weight with receiver → KILLED
2. mutateConnection : removed call to net/bmahe/genetics4j/neat/Connection$Builder::weight → KILLED
|
connectionBuilder.weight(newWeight); |
|
44
|
3
1. mutateConnection : replaced return value with Collections.emptyList for net/bmahe/genetics4j/neat/mutation/chromosome/NeatChromosomeRandomMutationHandler::mutateConnection → KILLED
2. mutateConnection : removed call to net/bmahe/genetics4j/neat/Connection$Builder::build → KILLED
3. mutateConnection : removed call to java/util/List::of → KILLED
|
return List.of(connectionBuilder.build()); |
|
45
|
|
} |
|
46
|
|
} |
| | Mutations |
| 35 |
|
1.1 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] replaced call to net/bmahe/genetics4j/neat/Connection$Builder::from with receiver → KILLED
2.2 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] removed call to net/bmahe/genetics4j/neat/Connection::builder → KILLED
3.3 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] removed call to net/bmahe/genetics4j/neat/Connection$Builder::from → KILLED
|
| 37 |
|
1.1 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getMinWeightValue → KILLED
|
| 38 |
|
1.1 Location : mutateConnection Killed by : none removed call to net/bmahe/genetics4j/neat/chromosomes/NeatChromosome::getMaxWeightValue → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()]
|
| 40 |
|
1.1 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] removed call to net/bmahe/genetics4j/neat/mutation/chromosome/NeatChromosomeRandomMutationHandler::getRandomGenerator → KILLED
|
| 42 |
|
1.1 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] removed call to java/util/random/RandomGenerator::nextFloat → KILLED
2.2 Location : mutateConnection Killed by : none Replaced float subtraction with addition → SURVIVED
Covering tests
Covered by tests:
- net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()]
3.3 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] Replaced float addition with subtraction → KILLED
4.4 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] replaced call to java/util/random/RandomGenerator::nextFloat with argument → KILLED
|
| 43 |
|
1.1 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] replaced call to net/bmahe/genetics4j/neat/Connection$Builder::weight with receiver → KILLED
2.2 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] removed call to net/bmahe/genetics4j/neat/Connection$Builder::weight → KILLED
|
| 44 |
|
1.1 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] replaced return value with Collections.emptyList for net/bmahe/genetics4j/neat/mutation/chromosome/NeatChromosomeRandomMutationHandler::mutateConnection → KILLED
2.2 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] removed call to net/bmahe/genetics4j/neat/Connection$Builder::build → KILLED
3.3 Location : mutateConnection Killed by : net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest.[engine:junit-jupiter]/[class:net.bmahe.genetics4j.neat.mutation.chromosome.NeatChromosomeRandomMutationHandlerTest]/[method:mutateConnection()] removed call to java/util/List::of → KILLED
|