ghc: panic! (the 'impossible' happened) (GHC version 8.2.1 for x86_64-apple-darwin): stack depth overflow
I created a neural network library within haskell. I was able to create, test, and train the net (using data from the mNist dataset). I could only test manually (try one input at a time and compare the two outputs), so i made a function which allowed me to test many test inputs on the net at once.
Recreating bug: first, load main.hs in ghci (duh) then, run the entirety of trainedNetwork.txt as a command to initialise the network (i.e. copy paste the file into the ghci command line) then run the entirety of test.txt as a command. Here you will get the error. To test with different input values for the function "test" (the function whose being run caused the crash), you can open the jupyter notebook and run the function mnistTest with higher or lower values (higher using more test cases, lower using less) and run the output of that function as a command in haskell. (i know from testing that 41 inputs does not cause a crash, but 42 does (seriously, this is not a joke)) .
What i know is not the problem/probably causes: I know that y was initiliased correctly. The function being run here is :
--takes in a network and an array of test inputs and their corresponding outputs and returns the accuracy of the network --only works for classification networks testClassification :: [Layer] -> [[Double]] -> [[Double]] -> Double testClassification net inputs outputs = testClassificationHelper net inputs outputs 0 0 testClassificationHelper :: [Layer] -> [[Double]] -> [[Double]] -> Double -> Double -> Double testClassificationHelper _  _ correct incorrect = (correct/(correct+incorrect)) testClassificationHelper net (input:inputs) (output:outputs) correct incorrect | netMax == outMax = next (correct+1) incorrect | otherwise = next correct (incorrect+1) where next = testClassificationHelper net inputs outputs netMax = greatestIndex (getOutput net input) outMax = greatestIndex output
I know that getOutput and greatestIndex work\\ I know that it works with a small amount of inputs (test3.txt is essentially the same command except instead of using the first 100 test examples of the mnist data set, it uses the first 3)\\ I know that it works when using the first 30 data points, but not with the first 50.\\ I know that doing it for the first 30 inputs only takes 2 seconds and 270 MB, while training the network took 40 minutes and 820GB, take from that what you will\\
Note: trainedNetwork.txt is too large to upload, so it is available at https://drive.google.com/open?id=1HfCNknZ9AfJauQoNwzhlEwsQfcHTya0t