#!/bin/sh

# performance (just go forward)
echo "Performance Test..."
time sonar -d sonar.df -f 100000

# learn
echo ""
echo "Learn..."
time sonar -l -s 4000 -t 2000 208 0.49 -d sonar.df 

# test
echo "Test..."
sonar Network.Finished -d sonar.df -E -P 0.8

# dump weights to files for plotting
sonar < sonar.cmd

# plot it with gnuplot3.0
echo This may not work if you do not have gnuplot 3.0
gnuplot sonar.gnu

# dump hidden node values to files for pca
sonar -d mines.df < mines.cmd
sonar -d rocks.df < rocks.cmd

# make master file
cp rocks.hidden hidden
cat mines.hidden >> hidden
cp rocks.targets hidden.targets
cat mines.targets >> hidden.targets

# pca
echo ""
echo "Calculating principal components..."
/bin/rm -f hidden.principal_components hidden.principal_values

pca -f hidden -i rocks.hidden -x 0 -y 1 -z 2 > pca012.rocks
pca -f hidden -i mines.hidden -x 0 -y 1 -z 2 > pca012.mines

pca -f hidden -i rocks.hidden -x 0 -y 1  > pca01.rocks
pca -f hidden -i mines.hidden -x 0 -y 1  > pca01.mines

pca -f hidden -i rocks.hidden -x 0 -y 2 > pca02.rocks
pca -f hidden -i mines.hidden -x 0 -y 2 > pca02.mines

pca -f hidden -i rocks.hidden -x 0 -y 3  > pca03.rocks
pca -f hidden -i mines.hidden -x 0 -y 3  > pca03.mines

pca -f hidden -i rocks.hidden -x 1 -y 2  > pca12.rocks
pca -f hidden -i mines.hidden -x 1 -y 2  > pca12.mines

pca -f hidden -i rocks.hidden -x 1 -y 3  > pca13.rocks
pca -f hidden -i mines.hidden -x 1 -y 3  > pca13.mines

pca -f hidden -i rocks.hidden -x 2 -y 3 > pca23.rocks
pca -f hidden -i mines.hidden -x 2 -y 3 > pca23.mines

# plot it with gnuplot3.0
# echo This may not work if you do not have gnuplot 3.0
gnuplot pca.gnu


# cda
echo ""
echo "Calculating canonical variates"
/bin/rm -f hidden.canonical_variates hidden.canonical_values

cda -f hidden -i rocks.hidden -g hidden.targets -x 0 -y 1 -z 2 > cda012.rocks
cda -f hidden -i mines.hidden -g hidden.targets -x 0 -y 1 -z 2 > cda012.mines

cda -f hidden -i rocks.hidden -g hidden.targets -x 0 -y 1  > cda01.rocks
cda -f hidden -i mines.hidden -g hidden.targets -x 0 -y 1  > cda01.mines

cda -f hidden -i rocks.hidden -g hidden.targets -x 0 -y 2 > cda02.rocks
cda -f hidden -i mines.hidden -g hidden.targets -x 0 -y 2 > cda02.mines

cda -f hidden -i rocks.hidden -g hidden.targets -x 0 -y 3  > cda03.rocks
cda -f hidden -i mines.hidden -g hidden.targets -x 0 -y 3  > cda03.mines

cda -f hidden -i rocks.hidden -g hidden.targets -x 1 -y 2  > cda12.rocks
cda -f hidden -i mines.hidden -g hidden.targets -x 1 -y 2  > cda12.mines

cda -f hidden -i rocks.hidden -g hidden.targets -x 1 -y 3  > cda13.rocks
cda -f hidden -i mines.hidden -g hidden.targets -x 1 -y 3  > cda13.mines

cda -f hidden -i rocks.hidden -g hidden.targets -x 2 -y 3 > cda23.rocks
cda -f hidden -i mines.hidden -g hidden.targets -x 2 -y 3 > cda23.mines

# plot it with gnuplot3.0
# echo This may not work if you do not have gnuplot 3.0
gnuplot cda.gnu


