source: scripts/neurons_in_f1/add_neuro.pl @ 123

Last change on this file since 123 was 37, checked in by Maciej Komosinski, 14 years ago

added scripts that help handle relative neural connections in f1 genotypes when adding/deleting neurons

File size: 1.1 KB
Line 
1#!/usr/bin/perl
2
3# This script makes it easier to handle relative neural connections in f1 genotypes when adding/deleting neurons.
4# Usage:
5#   perl add_neuro.pl <neuron_number> <f1_genotype>
6# If not provided, the <f1_genotype> will be read from stdin.
7# <neuron_number> is 1-based.
8
9# TODO: handle bounds (1..N) of <neuron_number> and display a warning when exceeded
10# TODO: test thoroughly
11# TODO: consider joining with del_neuro.pl or including a common part - 80% of the code is the same.
12
13my $num = shift @ARGV;
14
15my $geno;
16if (@ARGV) {
17        $geno = "@ARGV";
18} else {
19        $geno = (<STDIN>);
20}
21
22my @out;
23my $idx = 0;
24my $ratio = 1;
25for (split /\[/, $geno) {
26        if ($idx == 0) {
27                push @out, $_;
28                $idx++;
29                next;
30        }
31        if ($idx == $num) {
32                push @out, "NEW]";
33                $idx++;
34                $ratio *= -1;
35        }
36        my ($neuro, $rest) = split /\]/;
37        my @neuroOut;
38        foreach (split /,/, $neuro) {
39                if (/([-0-9]+):(.*)/ && ($ratio * ($1 + $idx) >= $ratio * ($num))) {
40                        push @neuroOut, join (':', ($1 + $ratio, $2));
41                } else {
42                        push @neuroOut, $_;
43                }
44        }
45        push @out, join(',', @neuroOut) . ']' . $rest;
46        $idx++;
47}
48
49printf "%s\n", join('[', @out);
50
Note: See TracBrowser for help on using the repository browser.