// // This chop accepts a bunch of dummy channels, one for each offspring. // Their length should correspond to the number of genes. // // It has a [0..1] parameter (user controlled) that should convey roughly // the percentage of genes that should be mutated. // For genes to be mutated, a "one" value is output, a zero otherwise. // Instead of setting exactly M% of the genes to "one", it calculates the // chance of any given gene mutating, then does a "die roll" for each gene // to see if it should mutate. A seed parameter must also be provided. // #include #pragma help "This chop accepts a bunch of dummy channels, one for each offspring. Their length should correspond to the number of genes. It has a [0..1] parameter (user controlled) that should convey roughly the percentage of genes that should be mutated. For genes to be mutated, a "one" value is output, a zero otherwise. Instead of setting exactly M% of the genes to "one", it calculates the chance of any given gene mutating, then does a "die roll" for each gene to see if it should mutate. A seed parameter must also be provided." #pragma label seed "Seed" #pragma range seed 1 10000 #pragma label rate "Rate" #pragma range rate 0 1 #pragma label num_genes "Num Genes" #pragma range num_genes 1 500 chop mutate(int seed = 1; float rate = .1; int num_genes = 17) { float tot_num_genes = NC * num_genes; float num_mutations = floor(rate * tot_num_genes); float chance = num_mutations / tot_num_genes; float r = random((C+2)*(seed+I+3298)); if(r < chance) { V = 1.0; } else { V = 0.0; } }