Skip to content

Commit

Permalink
increased max size, added log info
Browse files Browse the repository at this point in the history
  • Loading branch information
mhwombat committed May 27, 2016
1 parent 123fd42 commit 865028e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
33 changes: 29 additions & 4 deletions run.sh
Expand Up @@ -7,14 +7,39 @@ testDir=$HOME/mnist/testData

function runit {
echo $*
time (~/nosync/sandboxes/exp-som-comparison/bin/exp-som-comparison-sgm \
$trainingDir $testDir $1 $2 $3) >sgm-$1-$2-$3.log 2>&1
# time (~/nosync/sandboxes/exp-som-comparison/bin/exp-som-comparison-sgm \
# $trainingDir $testDir $1 $2 $3) >sgm-$1-$2-$3.log 2>&1
time (~/nosync/sandboxes/exp-som-comparison/bin/exp-som-comparison-som \
$trainingDir $testDir $4 $2 $3 $5 $6) >som-$4-$2-$3-$5-$6.log 2>&1
}

# arg 1 2 3 4 5 6
# threshold r0 rf s w0 wf

runit 0.10 0.1 0.0001 32 2 0.0001
runit 0.165 0.1 0.0001 10 2 0.0001
#runit 0.10 0.1 0.0001 55 2 0.0001
runit 0.11 0.1 0.0001 41 2 0.0001
runit 0.115 0.1 0.0001 36 2 0.0001
runit 0.116 0.1 0.0001 35 2 0.0001
runit 0.117 0.1 0.0001 34 2 0.0001
runit 0.118 0.1 0.0001 33 2 0.0001
runit 0.119 0.1 0.0001 32 2 0.0001
runit 0.12 0.1 0.0001 31 2 0.0001
runit 0.13 0.1 0.0001 24 2 0.0001
runit 0.14 0.1 0.0001 18 2 0.0001
runit 0.15 0.1 0.0001 14 2 0.0001
runit 0.16 0.1 0.0001 11 2 0.0001
runit 0.17 0.1 0.0001 9 2 0.0001
runit 0.18 0.1 0.0001 7 2 0.0001
runit 0.19 0.1 0.0001 6 2 0.0001
runit 0.2 0.1 0.0001 5 2 0.0001

runit 0.10 0.1 0.0001 55 2 0.0001

#runit 0.11 0.1 0.0001 32 2 0.0001
#runit 0.115 0.1 0.0001 32 2 0.0001
#runit 0.116 0.1 0.0001 32 2 0.0001
#runit 0.117 0.1 0.0001 32 2 0.0001
#runit 0.118 0.1 0.0001 32 2 0.0001
#runit 0.119 0.1 0.0001 32 2 0.0001
#runit 0.12 0.1 0.0001 32 2 0.0001
#runit 0.165 0.1 0.0001 10 2 0.0001
13 changes: 7 additions & 6 deletions src/SGMMain.hs
Expand Up @@ -28,21 +28,22 @@ testClassifier threshold r0 rf = makeSGM (sgmLearningFunction r0 rf) maxSGMSize

trainOne :: (ClassifierType, [(Label,Numeral)], [(Label, Numeral)]) -> (FilePath, Image) -> IO (ClassifierType, [(Label, Numeral)], [(Label, Numeral)])
trainOne (c, modelCreationData, stats) (f, p) = do
let (bmu, _, _, c') = trainAndClassify c p
let (bmu, bmuDiff, _, c') = trainAndClassify c p
let numeral = head f
putStrLn $ f ++ "," ++ numeral : "," ++ show bmu
putStrLn $ f ++ "," ++ numeral : "," ++ show bmu ++ "," ++ show bmuDiff
let modelCreationData' = case lookup bmu modelCreationData of
Just _ -> modelCreationData
Nothing -> (bmu, numeral):modelCreationData
-- putImageGrid 10 (M.elems . modelMap $ c')
return (c', modelCreationData', (bmu, numeral):stats)

testOne :: [(Label, Numeral)] -> ClassifierType -> [(Numeral, Bool)] -> (FilePath, Image) -> IO [(Numeral, Bool)]
testOne key c stats (f, p) = do
let (bmu, _, _) = classify c p
let (bmu, bmuDiff, _) = classify c p
let numeral = head f
let answer = safeLookup bmu key
let correct = answer == numeral
putStrLn $ f ++ "," ++ numeral : "," ++ show bmu ++ "," ++ show answer ++ "," ++ show correct
putStrLn $ f ++ "," ++ numeral : "," ++ show bmu ++ "," ++ show bmuDiff ++ "," ++ show answer ++ "," ++ show correct
return $ (numeral, correct):stats

main :: IO ()
Expand All @@ -59,7 +60,7 @@ main = do
putStrLn "Training"
putStrLn "====="
trainingImages <- readImages trainingDir
putStrLn "filename,numeral,label"
putStrLn "filename,numeral,label,diff"
(trainedClassifier, modelCreationData, stats) <- foldM trainOne (testClassifier threshold r0 rf, [], []) trainingImages
let answers = makeAnswerKey stats
putStrLn ""
Expand All @@ -80,7 +81,7 @@ main = do
putStrLn "====="
putStrLn "Testing"
putStrLn "====="
putStrLn "filename,numeral,label,answer,correct"
putStrLn "filename,numeral,label,diff,answer,correct"
stats2 <- foldM (testOne answers trainedClassifier') [] testImages
putStrLn ""
putStrLn "====="
Expand Down
1 change: 1 addition & 0 deletions src/SOMMain.hs
Expand Up @@ -41,6 +41,7 @@ trainOne (c, modelCreationData, stats) (f, p) = do
let modelCreationData' = case lookup bmu modelCreationData of
Just _ -> modelCreationData
Nothing -> (bmu, numeral):modelCreationData
-- putImageGrid 10 (models c')
return (c', modelCreationData', (bmu, numeral):stats)

testOne :: [(Label, Numeral)] -> ClassifierType -> [(Numeral, Bool)] -> (FilePath, Image) -> IO [(Numeral, Bool)]
Expand Down
2 changes: 1 addition & 1 deletion src/Util.hs
Expand Up @@ -156,7 +156,7 @@ tf = 60000
-- somGrid = rectSquareGrid 32 32

maxSGMSize :: Int
maxSGMSize = 1024
maxSGMSize = 2000

-- threshold :: Double
-- -- threshold = 0.16
Expand Down

0 comments on commit 865028e

Please sign in to comment.