set_genome 0.6.7

A genetic data structure for neuroevolution algorithms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
use std::{
    collections::HashSet,
    hash::{Hash, Hasher},
};

use crate::{
    genes::{Connection, Genes, Id, Node},
    parameters::Structure,
};

use rand::{rngs::SmallRng, seq::SliceRandom, thread_rng, Rng, SeedableRng};
use seahash::SeaHasher;
use serde::{Deserialize, Serialize};

mod compatibility_distance;

pub use compatibility_distance::CompatibilityDistance;

/// This is the core data structure this crate revoles around.
///
/// A genome can be changed by mutation (a random alteration of its structure) or by crossing in another genome (recombining their matching parts).
/// A lot of additional information explaining details of the structure can be found in the [thesis] that developed this idea.
/// More and more knowledge from there will find its way into this documentaion over time.
///
/// [thesis]: https://www.silvan.codes/SET-NEAT_Thesis.pdf
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct Genome {
    pub inputs: Genes<Node>,
    pub hidden: Genes<Node>,
    pub outputs: Genes<Node>,
    pub feed_forward: Genes<Connection>,
    pub recurrent: Genes<Connection>,
}

impl Genome {
    /// Creates a new genome according to the [`Structure`] it is given.
    /// It generates all necessary identities based on an RNG seeded from a hash of the I/O configuration of the structure.
    /// This allows genomes of identical I/O configuration to be crossed over in a meaningful way.
    pub fn new(structure: &Structure) -> Self {
        let mut seed_hasher = SeaHasher::new();
        structure.number_of_inputs.hash(&mut seed_hasher);
        structure.number_of_outputs.hash(&mut seed_hasher);
        structure.seed.hash(&mut seed_hasher);

        let mut rng = SmallRng::seed_from_u64(seed_hasher.finish());

        Genome {
            inputs: (0..structure.number_of_inputs)
                .map(|order| Node::input(Id(rng.gen::<u64>()), order))
                .collect(),
            outputs: (0..structure.number_of_outputs)
                .map(|order| {
                    Node::output(Id(rng.gen::<u64>()), order, structure.outputs_activation)
                })
                .collect(),
            ..Default::default()
        }
    }

    /// Returns an iterator over references to all node genes (input + hidden + output) in the genome.
    pub fn nodes(&self) -> impl Iterator<Item = &Node> {
        self.inputs
            .iter()
            .chain(self.hidden.iter())
            .chain(self.outputs.iter())
    }

    pub fn contains(&self, id: Id) -> bool {
        let fake_node = &Node::input(id, 0);
        self.inputs.contains(fake_node)
            || self.hidden.contains(fake_node)
            || self.outputs.contains(fake_node)
    }

    /// Returns an iterator over references to all connection genes (feed-forward + recurrent) in the genome.
    pub fn connections(&self) -> impl Iterator<Item = &Connection> {
        self.feed_forward.iter().chain(self.recurrent.iter())
    }

    /// Initializes a genome, i.e. connects the in the [`Structure`] configured percent of inputs to all outputs by creating connection genes with random weights.
    pub fn init(&mut self, structure: &Structure) {
        let rng = &mut SmallRng::from_rng(thread_rng()).unwrap();

        let mut possible_inputs = self.inputs.iter().collect::<Vec<_>>();
        possible_inputs.shuffle(rng);

        for input in possible_inputs.iter().take(
            (structure.percent_of_connected_inputs * structure.number_of_inputs as f64).ceil()
                as usize,
        ) {
            // connect to every output
            for output in self.outputs.iter() {
                assert!(self.feed_forward.insert(Connection::new(
                    input.id,
                    Connection::weight_perturbation(0.0, 0.1, rng),
                    output.id
                )));
            }
        }
    }

    /// Returns the sum of connection genes inside the genome (feed-forward + recurrent).
    pub fn len(&self) -> usize {
        self.feed_forward.len() + self.recurrent.len()
    }

    /// Is true when no connection genes are present in the genome.
    pub fn is_empty(&self) -> bool {
        self.feed_forward.is_empty() && self.recurrent.is_empty()
    }

    /// Cross-in another genome.
    /// For connection genes present in both genomes flip a coin to determine the weight inside the new genome.
    /// For node genes present in both genomes flip a coin to determine the activation function inside the new genome.
    /// Any structure not present in other is taken over unchanged from `self`.
    pub fn cross_in(&self, other: &Self) -> Self {
        // Instantiating an RNG for every call might slow things down.
        let mut rng = SmallRng::from_rng(thread_rng()).unwrap();

        let feed_forward = self.feed_forward.cross_in(&other.feed_forward, &mut rng);
        let recurrent = self.recurrent.cross_in(&other.recurrent, &mut rng);
        let hidden = self.hidden.cross_in(&other.hidden, &mut rng);

        Genome {
            feed_forward,
            recurrent,
            hidden,
            // use input and outputs from fitter, but they should be identical with weaker
            inputs: self.inputs.clone(),
            outputs: self.outputs.clone(),
            ..Default::default()
        }
    }

    /// Check if connecting `start_node` and `end_node` would introduce a circle into the ANN structure.
    /// Think about the ANN as a graph for this, if you follow the connection arrows, can you reach `start_node` from `end_node`?
    pub fn would_form_cycle(&self, start_node: &Node, end_node: &Node) -> bool {
        let mut to_visit = vec![end_node.id];
        let mut visited = HashSet::new();

        while let Some(node) = to_visit.pop() {
            if !visited.contains(&node) {
                visited.insert(node);
                for connection in self
                    .feed_forward
                    .iter()
                    .filter(|connection| connection.input == node)
                {
                    if connection.output == start_node.id {
                        return true;
                    } else {
                        to_visit.push(connection.output)
                    }
                }
            }
        }
        false
    }

    /// Check if a node gene has more than one connection gene pointing to it.
    pub fn has_alternative_input(&self, node: Id, exclude: Id) -> bool {
        self.connections()
            .filter(|connection| connection.output == node)
            .any(|connection| connection.input != exclude)
    }

    /// Check if a node gene has more than one connection gene leaving it.
    pub fn has_alternative_output(&self, node: Id, exclude: Id) -> bool {
        self.connections()
            .filter(|connection| connection.input == node)
            .any(|connection| connection.output != exclude)
    }

    /// Get the encoded neural network as a string in [DOT][1] format.
    ///
    /// The output can be [visualized here][2] for example.
    ///
    /// [1]: https://www.graphviz.org/doc/info/lang.html
    /// [2]: https://dreampuf.github.io/GraphvizOnline
    pub fn dot(genome: &Self) -> String {
        let mut dot = "digraph {\n".to_owned();
        dot.push_str("\tgraph [splines=curved ranksep=8]\n");

        dot.push_str("\tsubgraph cluster_inputs {\n");
        dot.push_str("\t\tgraph [label=\"Inputs\"]\n");
        dot.push_str("\t\tnode [color=\"#D6B656\", fillcolor=\"#FFF2CC\", style=\"filled\"]\n");
        dot.push_str("\n");
        for node in genome.inputs.iter() {
            // fill color: FFF2CC
            // line color: D6B656

            dot.push_str(&format!(
                "\t\t{} [label={:?}];\n",
                node.id.0, node.activation
            ));
        }
        dot.push_str("\t}\n");

        dot.push_str("\tsubgraph hidden {\n");
        dot.push_str("\t\tgraph [label=\"Hidden\" rank=\"same\"]\n");
        dot.push_str("\t\tnode [color=\"#6C8EBF\", fillcolor=\"#DAE8FC\", style=\"filled\"]\n");
        dot.push_str("\n");
        for node in genome.hidden.iter() {
            // fill color: DAE8FC
            // line color: 6C8EBF

            dot.push_str(&format!(
                "\t\t{} [label={:?}];\n",
                node.id.0, node.activation
            ));
        }
        dot.push_str("\t}\n");

        dot.push_str("\tsubgraph cluster_outputs {\n");
        dot.push_str("\t\tgraph [label=\"Outputs\" labelloc=\"b\"]\n");
        dot.push_str("\t\tnode [color=\"#9673A6\", fillcolor=\"#E1D5E7\", style=\"filled\"]\n");
        dot.push_str("\n");
        for node in genome.outputs.iter() {
            // fill color: E1D5E7
            // line color: 9673A6

            dot.push_str(&format!(
                "\t\t{} [label={:?}];\n",
                node.id.0, node.activation
            ));
        }
        dot.push_str("\t}\n");

        dot.push_str("\n");

        dot.push_str("\tsubgraph feedforward_connections {\n");
        dot.push_str("\n");
        for connection in genome.feed_forward.iter() {
            dot.push_str(&format!(
                "\t\t{0} -> {1} [label=\"\" arrowsize={3:?} penwidth={3:?} tooltip={2:?} labeltooltip={2:?}];\n",
                connection.input.0,
                connection.output.0,
                connection.weight,
                connection.weight.abs() * 0.95 + 0.05
            ));
        }
        dot.push_str("\t}\n");

        dot.push_str("\tsubgraph recurrent_connections {\n");
        dot.push_str("\t\tedge [color=\"#FF8000\"]\n");
        dot.push_str("\n");
        for connection in genome.recurrent.iter() {
            // color: FF8000

            dot.push_str(&format!(
                "\t\t{0} -> {1} [label=\"\" arrowsize={3:?} penwidth={3:?} tooltip={2:?} labeltooltip={2:?}];\n",
                connection.input.0,
                connection.output.0,
                connection.weight,
                connection.weight.abs() * 0.95 + 0.05
            ));
        }
        dot.push_str("\t}\n");

        dot.push_str("}\n");
        dot
    }
}

#[cfg(test)]
mod tests {
    use std::hash::{Hash, Hasher};

    use rand::thread_rng;
    use seahash::SeaHasher;

    use super::Genome;
    use crate::{
        genes::{Activation, Connection, Genes, Id, Node},
        Mutations, Parameters, Structure,
    };

    #[test]
    fn find_alternative_input() {
        let genome = Genome {
            inputs: Genes(
                vec![Node::input(Id(0), 0), Node::input(Id(1), 1)]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            outputs: Genes(
                vec![Node::output(Id(2), 0, Activation::Linear)]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            feed_forward: Genes(
                vec![
                    Connection::new(Id(0), 1.0, Id(2)),
                    Connection::new(Id(1), 1.0, Id(2)),
                ]
                .iter()
                .cloned()
                .collect(),
            ),
            ..Default::default()
        };

        assert!(genome.has_alternative_input(Id(2), Id(1)))
    }

    #[test]
    fn find_no_alternative_input() {
        let genome = Genome {
            inputs: Genes(vec![Node::input(Id(0), 0)].iter().cloned().collect()),
            outputs: Genes(
                vec![Node::output(Id(1), 0, Activation::Linear)]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            feed_forward: Genes(
                vec![Connection::new(Id(0), 1.0, Id(1))]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            ..Default::default()
        };

        assert!(!genome.has_alternative_input(Id(1), Id(0)))
    }

    #[test]
    fn find_alternative_output() {
        let genome = Genome {
            inputs: Genes(vec![Node::input(Id(0), 0)].iter().cloned().collect()),
            outputs: Genes(
                vec![
                    Node::output(Id(2), 0, Activation::Linear),
                    Node::output(Id(1), 0, Activation::Linear),
                ]
                .iter()
                .cloned()
                .collect(),
            ),
            feed_forward: Genes(
                vec![
                    Connection::new(Id(0), 1.0, Id(1)),
                    Connection::new(Id(0), 1.0, Id(2)),
                ]
                .iter()
                .cloned()
                .collect(),
            ),
            ..Default::default()
        };

        assert!(genome.has_alternative_output(Id(0), Id(1)))
    }

    #[test]
    fn find_no_alternative_output() {
        let genome = Genome {
            inputs: Genes(vec![Node::input(Id(0), 0)].iter().cloned().collect()),
            outputs: Genes(
                vec![Node::output(Id(1), 0, Activation::Linear)]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            feed_forward: Genes(
                vec![Connection::new(Id(0), 1.0, Id(1))]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            ..Default::default()
        };

        assert!(!genome.has_alternative_output(Id(0), Id(1)))
    }

    #[test]
    fn crossover() {
        let parameters = Parameters::default();

        let mut genome_0 = Genome::initialized(&parameters);
        let mut genome_1 = Genome::initialized(&parameters);

        let rng = &mut thread_rng();

        // mutate genome_0
        Mutations::add_node(&Activation::all(), &mut genome_0, rng);

        // mutate genome_1
        Mutations::add_node(&Activation::all(), &mut genome_1, rng);
        Mutations::add_node(&Activation::all(), &mut genome_1, rng);

        // shorter genome is fitter genome
        let offspring = genome_0.cross_in(&genome_1);

        assert_eq!(offspring.hidden.len(), 1);
        assert_eq!(offspring.feed_forward.len(), 3);
    }

    #[test]
    fn detect_no_cycle() {
        let parameters = Parameters::default();

        let genome = Genome::initialized(&parameters);

        let input = genome.inputs.iter().next().unwrap();
        let output = genome.outputs.iter().next().unwrap();

        assert!(!genome.would_form_cycle(&input, &output));
    }

    #[test]
    fn detect_cycle() {
        let parameters = Parameters::default();

        let genome = Genome::initialized(&parameters);

        let input = genome.inputs.iter().next().unwrap();
        let output = genome.outputs.iter().next().unwrap();

        assert!(genome.would_form_cycle(&output, &input));
    }

    #[test]
    fn crossover_no_cycle() {
        // assumption:
        // crossover of equal fitness genomes should not produce cycles
        // prerequisits:
        // genomes with equal fitness (0.0 in this case)
        // "mirrored" structure as simplest example

        let mut genome_0 = Genome {
            inputs: Genes(vec![Node::input(Id(0), 0)].iter().cloned().collect()),
            outputs: Genes(
                vec![Node::output(Id(1), 0, Activation::Linear)]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            hidden: Genes(
                vec![
                    Node::hidden(Id(2), Activation::Tanh),
                    Node::hidden(Id(3), Activation::Tanh),
                ]
                .iter()
                .cloned()
                .collect(),
            ),
            feed_forward: Genes(
                vec![
                    Connection::new(Id(0), 1.0, Id(2)),
                    Connection::new(Id(2), 1.0, Id(1)),
                    Connection::new(Id(0), 1.0, Id(3)),
                    Connection::new(Id(3), 1.0, Id(1)),
                ]
                .iter()
                .cloned()
                .collect(),
            ),
            ..Default::default()
        };

        let mut genome_1 = genome_0.clone();

        // insert connectio one way in genome0
        genome_0
            .feed_forward
            .insert(Connection::new(Id(2), 1.0, Id(3)));

        // insert connection the other way in genome1
        genome_1
            .feed_forward
            .insert(Connection::new(Id(3), 1.0, Id(2)));

        let offspring = genome_0.cross_in(&genome_1);

        for connection0 in offspring.feed_forward.iter() {
            for connection1 in offspring.feed_forward.iter() {
                assert!(
                    !(connection0.input == connection1.output
                        && connection0.output == connection1.input)
                )
            }
        }
    }

    #[test]
    fn hash_genome() {
        let genome_0 = Genome {
            inputs: Genes(
                vec![Node::input(Id(1), 0), Node::input(Id(0), 0)]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            outputs: Genes(
                vec![Node::output(Id(2), 0, Activation::Linear)]
                    .iter()
                    .cloned()
                    .collect(),
            ),

            feed_forward: Genes(
                vec![Connection::new(Id(0), 1.0, Id(1))]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            ..Default::default()
        };

        let genome_1 = Genome {
            inputs: Genes(
                vec![Node::input(Id(0), 0), Node::input(Id(1), 0)]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            outputs: Genes(
                vec![Node::output(Id(2), 0, Activation::Linear)]
                    .iter()
                    .cloned()
                    .collect(),
            ),

            feed_forward: Genes(
                vec![Connection::new(Id(0), 1.0, Id(1))]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            ..Default::default()
        };

        assert_eq!(genome_0, genome_1);

        let mut hasher = SeaHasher::new();
        genome_0.hash(&mut hasher);
        let genome_0_hash = hasher.finish();

        let mut hasher = SeaHasher::new();
        genome_1.hash(&mut hasher);
        let genome_1_hash = hasher.finish();

        assert_eq!(genome_0_hash, genome_1_hash);
    }

    #[test]
    fn create_dot_from_genome() {
        let genome = Genome {
            inputs: Genes(vec![Node::input(Id(0), 0)].iter().cloned().collect()),
            outputs: Genes(
                vec![Node::output(Id(1), 0, Activation::Linear)]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            hidden: Genes(
                vec![Node::hidden(Id(2), Activation::Tanh)]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            feed_forward: Genes(
                vec![
                    Connection::new(Id(0), 0.25795942718883524, Id(2)),
                    Connection::new(Id(2), -0.09736946507786626, Id(1)),
                ]
                .iter()
                .cloned()
                .collect(),
            ),
            recurrent: Genes(
                vec![Connection::new(Id(1), 0.19777863112749228, Id(2))]
                    .iter()
                    .cloned()
                    .collect(),
            ),
            ..Default::default()
        };

        // let dot = "digraph {\n\t0 [label=Linear color=\"#D6B656\" fillcolor=\"#FFF2CC\" style=\"filled\"];\n\t2 [label=Tanh color=\"#6C8EBF\" fillcolor=\"#DAE8FC\" style=\"filled\"];\n\t1 [label=Linear color=\"#9673A6\" fillcolor=\"#E1D5E7\" style=\"filled\"];\n\t0 -> 2 [label=0.25795942718883524];\n\t2 -> 1 [label=0.09736946507786626];\n\t1 -> 2 [label=0.19777863112749228 color=\"#FF8000\"];\n}\n";

        let dot = "digraph {
\tgraph [splines=curved ranksep=8]
\tsubgraph cluster_inputs {
\t\tgraph [label=\"Inputs\"]
\t\tnode [color=\"#D6B656\", fillcolor=\"#FFF2CC\", style=\"filled\"]

\t\t0 [label=Linear];
\t}
\tsubgraph hidden {
\t\tgraph [label=\"Hidden\" rank=\"same\"]
\t\tnode [color=\"#6C8EBF\", fillcolor=\"#DAE8FC\", style=\"filled\"]

\t\t2 [label=Tanh];
\t}
\tsubgraph cluster_outputs {
\t\tgraph [label=\"Outputs\" labelloc=\"b\"]
\t\tnode [color=\"#9673A6\", fillcolor=\"#E1D5E7\", style=\"filled\"]

\t\t1 [label=Linear];
\t}

\tsubgraph feedforward_connections {

\t\t0 -> 2 [label=\"\" arrowsize=0.29506145582939347 penwidth=0.29506145582939347 tooltip=0.25795942718883524 labeltooltip=0.25795942718883524];
\t\t2 -> 1 [label=\"\" arrowsize=0.14250099182397294 penwidth=0.14250099182397294 tooltip=-0.09736946507786626 labeltooltip=-0.09736946507786626];
\t}
\tsubgraph recurrent_connections {
\t\tedge [color=\"#FF8000\"]

\t\t1 -> 2 [label=\"\" arrowsize=0.23788969957111766 penwidth=0.23788969957111766 tooltip=0.19777863112749228 labeltooltip=0.19777863112749228];
\t}
}
";
        assert_eq!(&Genome::dot(&genome), dot)
    }

    #[test]
    fn print_big_dot() {
        let parameters = Parameters {
            structure: Structure {
                number_of_inputs: 10,
                number_of_outputs: 10,
                percent_of_connected_inputs: 0.2,
                ..Default::default()
            },
            mutations: vec![
                Mutations::ChangeWeights {
                    chance: 1.0,
                    percent_perturbed: 0.5,
                    standard_deviation: 0.1,
                },
                Mutations::ChangeActivation {
                    chance: 0.05,
                    activation_pool: vec![
                        Activation::Linear,
                        Activation::Sigmoid,
                        Activation::Tanh,
                        Activation::Gaussian,
                        Activation::Step,
                        Activation::Sine,
                        Activation::Cosine,
                        Activation::Inverse,
                        Activation::Absolute,
                        Activation::Relu,
                    ],
                },
                Mutations::AddNode {
                    chance: 0.005,
                    activation_pool: vec![
                        Activation::Linear,
                        Activation::Sigmoid,
                        Activation::Tanh,
                        Activation::Gaussian,
                        Activation::Step,
                        Activation::Sine,
                        Activation::Cosine,
                        Activation::Inverse,
                        Activation::Absolute,
                        Activation::Relu,
                    ],
                },
                Mutations::AddConnection { chance: 0.01 },
                Mutations::AddRecurrentConnection { chance: 0.01 },
            ],
        };
        let mut genome = Genome::initialized(&parameters);

        for _ in 0..1000 {
            genome.mutate(&parameters);
        }

        print!("{}", Genome::dot(&genome));
    }
}