Debian Codegraph @

train.sh

raw symbols SCIP
1 #!/bin/bash
2
3 usage(){
4 echo "
5 Written by Brian Bushnell
6 Last modified Jan 25, 2024
7
8 Description: Trains or evaluates neural networks.
9
10 Usage: train.sh in=<data> dims=<X,Y,Z> out=<trained network>
11
12 train.sh in=<data> netin=<network> evaluate
13
14 Input may be fasta or fastq, compressed or uncompressed.
15
16
17 I/O parameters:
18 in=<file> Tab-delimited data vectors. The first line should look like
19 '#dims 5 1' with the number of inputs and outputs; the
20 first X columns are inputs, and the last Y the desired result.
21 Subsequent lines are tab-delimited floating point numbers.
22 Can be created via seqtovec.sh.
23 validate=<file> Optional validation dataset used exclusively for evaluation.
24 net=<file> Optional input network to train.
25 out=<file> Final output network after the last epoch.
26 outb=<file> Best discovered network according to evaluation metrics.
27 overwrite=f (ow) Set to false to force the program to abort rather than
28 overwrite an existing file.
29
30 Processing parameters:
31 evaluate=f Don't do any training, just evaluate the network.
32 dims= Set network dimensions. E.g. dims=5,12,7,1
33 mindims,maxdims These allow random dimensions, but the number of inputs and
34 outputs must agree. e.g. mindims=5,6,3,1 maxdims=5,18,15,1
35 batches=400k Number of batches to train.
36 alpha=0.08 Amount to adjust weights during backpropagation. Larger
37 numbers train faster but may not converge.
38 balance=0.2 If the positive and negative samples are unequal, make copies
39 of whichever has fewer until this ratio is met. 1.0 would
40 make an equal number of positive and negative samples.
41 density=1.0 Retain at least this fraction of edges.
42 edges=-1 If positive, cap the maximum number of edges.
43 dense=t Set dense=f (or sparse) to process as a sparse network.
44 Dense mode is fastest for fully- or mostly-connected networks;
45 sparse becomes faster below 0.25 density or so.
46
47 Advanced training parameters
48 seed=-1 A positive seed will yield deterministic output;
49 negative will use a random seed. For multiple networks,
50 each gets a different seed but you only need to set it once.
51 nets=1 Train this many networks concurrently (per cycle). Only the
52 best network will be reported, so training more networks will
53 yield give a better result. Higher increases memory use, but
54 also can improve CPU utilization on many-threaded CPUs.
55 cycles=1 Each cycle trains 'nets' networks in parallel.
56 setsize=60000 Iterate through subsets of at most this size while training;
57 larger makes batches take longer.
58 fpb=0.08 Only train this fraction of the subset per batch, prioritizing
59 samples with the most error; larger is slower.
60
61 Evaluation parameters
62 vfraction=0.1 If no validation file is given, split off this fraction of the
63 input dataset to use exclusively for validation.
64 inclusive=f Use the full training dataset for validation. Note that
65 'evaluate' mode automatically used the input for validation.
66 cutoffeval= Set the evaluation cutoff directly; any output above this
67 cutoff will be considered positive, and below will be
68 considered negative, when evaluating a sample. This does not
69 affect training other than the printed results and the best
70 network selection. Overrides fpr, fnr, and crossover.
71 crossover=1 Set 'cutoffeval' dynamically using the intersection of the
72 FPR and FNR curves. If false positives are 3x as detrimental
73 as false negatives, set this at 3.0; if false negatives are 2x
74 as bad as false positives, set this at 0.5, etc.
75 fpr= Set 'cutoffeval' dynamically using this false positive rate.
76 fnr= Set 'cutoffeval' dynamically using this false negative rate.
77
78 Activation functions; fractions are relative and don't need to add to 1.
79 sig=0.6 Fraction of nodes using sigmoid function.
80 tanh=0.4 Fraction of nodes using tanh function.
81 rslog=0.02 Fraction of nodes using rotationally symmetric log.
82 msig=0.02 Fraction of nodes using mirrored sigmoid.
83 swish=0.0 Fraction of nodes using swish.
84 esig=0.0 Fraction of nodes using extended sigmoid.
85 emsig=0.0 Fraction of nodes using extended mirrored sigmoid.
86 bell=0.0 Fraction of nodes using a bell curve.
87 max=0.0 Fraction of nodes using a max function (TODO).
88 final=rslog Type of function used in the final layer.
89
90 Exotic parameters
91 scan=0 Test this many seeds initially before picking one to train.
92 scanbatches=1k Evaluate scanned seeds at this point to choose the best.
93 simd=f Use SIMD instructions for greater speed; requires Java 18+.
94 cutoffbackprop=0.5 Optimize around this point for separating positive and
95 negative results. Unrelated to cutoffeval.
96 pem=1.0 Positive error mult; when value>target, multiply the error
97 by this number to adjust the backpropagation penalty.
98 nem=1.0 Negative error mult; when value<target, multiply the error
99 by this number to adjust the backpropagation penalty.
100 fpem=10.5 False positive error mult; when target<cutoffbackprop
101 value>(cutoffbackprop-spread), multiply error by this.
102 fnem=10.5 False negative error mult; when target>cutoffbackprop
103 value<(cutoffbackprop+spread), multiply error by this.
104 spread=0.05 Allows applying fnem/fpem multipliers to values that
105 are barely onsides, but too close to the cutoff.
106 epem=0.2 Excess positive error mult; error multiplier when
107 target>cutoff and value>target (overshot the target).
108 enem=0.2 Error multiplier when target<cutoff and value<target.
109 epm=0.2 Excess pivot mult; lower numbers give less priority to
110 training samples that are excessively positive or negative.
111 cutoff= Set both cutoffbackprop and cutoffeval.
112 ptriage=0.0001 Ignore this fraction of positive samples as untrainable.
113 ntriage=0.0005 Ignore this fraction of negative samples as untrainable.
114 anneal=0.003 Randomize weights by this much to avoid local minimae.
115 annealprob=.225 Probability of any given weight being annealed per batch.
116 ebs=1 (edgeblocksize) 8x gives best performance with AVX256 in
117 sparse networks. 4x may be useful for raw sequence.
118
119 Java Parameters:
120 -Xmx This will set Java's memory usage, overriding autodetection.
121 -Xmx20g will specify 20 gigs of RAM, and -Xmx200m will
122 specify 200 megs. The max is typically 85% of physical memory.
123 -eoom This flag will cause the process to exit if an out-of-memory
124 exception occurs. Requires Java 8u92+.
125 -da Disable assertions.
126
127 Please contact Brian Bushnell at [email protected] if you encounter any problems.
128 "
129 }
130
131 #This block allows symlinked shellscripts to correctly set classpath.
132 pushd . > /dev/null
133 DIR="${BASH_SOURCE[0]}"
134 while [ -h "$DIR" ]; do
135 cd "$(dirname "$DIR")"
136 DIR="$(readlink "$(basename "$DIR")")"
137 done
138 cd "$(dirname "$DIR")"
139 DIR="$(pwd)/"
140 popd > /dev/null
141
142 #DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
143 CP="$DIR""current/"
144
145 z="-Xmx8g"
146 z2="-Xms8g"
147 set=0
148
149 if [ -z "$1" ] || [[ $1 == -h ]] || [[ $1 == --help ]]; then
150 usage
151 exit
152 fi
153
154 calcXmx () {
155 source "$DIR""/calcmem.sh"
156 setEnvironment
157 parseXmx "$@"
158 if [[ $set == 1 ]]; then
159 return
160 fi
161 freeRam 8000m 42
162 z="-Xmx${RAM}m"
163 z2="-Xms${RAM}m"
164 }
165 calcXmx "$@"
166
167 train() {
168 local CMD="java $EA $EOOM $z $z2 $SIMD -cp $CP ml.Trainer $@"
169 echo $CMD >&2
170 eval $CMD
171 }
172
173 train "$@"