Last change
on this file since 295 was
193,
checked in by Maciej Komosinski, 11 years ago
|
Set svn:eol-style native for all textual files
|
-
Property svn:eol-style set to
native
|
File size:
1.1 KB
|
Rev | Line | |
---|
[37] | 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 | |
---|
| 13 | my $num = shift @ARGV; |
---|
| 14 | |
---|
| 15 | my $geno; |
---|
| 16 | if (@ARGV) { |
---|
| 17 | $geno = "@ARGV"; |
---|
| 18 | } else { |
---|
| 19 | $geno = (<STDIN>); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | my @out; |
---|
| 23 | my $idx = 0; |
---|
| 24 | my $ratio = 1; |
---|
| 25 | for (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 | |
---|
| 49 | printf "%s\n", join('[', @out); |
---|
| 50 | |
---|
Note: See
TracBrowser
for help on using the repository browser.