I'm doing a genetic algorithm and I'm testing out how I might create offspring from R, with each row of R corresponding to a parent and each column corresponding to a trait. In my code, I am attempting to mate parents 1 and 2, and parents 3 and 4 to give a total of two children. However, when I run the code, it inserts an extra row of zeros in between child 1 and child 2. Why is this happening?
R=[1,2,3;4,5,6;1000,2000,3000;4000,5000,6000]
for parent=1:2:3
theta=rand(1);
trait1=theta*R(0+parent,1)+(1-theta)*R(1+parent,1);
theta=rand(1);
trait2=theta*R(0+parent,2)+(1-theta)*R(1+parent,2);
theta=rand(1);
trait3=theta*R(0+parent,3)+(1-theta)*R(1+parent,3);
children(parent,:)=[trait1,trait2,trait3];
end
children
Output:
R =
1 2 3
4 5 6
1000 2000 3000
4000 5000 6000
children =
3.0837e+00 4.2959e+00 3.2356e+00
0 0 0
2.7330e+03 2.7728e+03 3.0762e+03
Thank you