|
30 | 30 | (+ 256 byte)
|
31 | 31 | byte))
|
32 | 32 |
|
33 |
| -(defn read-mnist-file [file-name] |
| 33 | +(defn read-mnist-file |
34 | 34 | "Reads the idx[x]-ubyte format and parses it into a byte array"
|
| 35 | + [file-name] |
35 | 36 | (let [file (io/file file-name)
|
36 | 37 | b-array (byte-array (.length file))]
|
37 | 38 | (with-open [stream (io/input-stream file)]
|
|
104 | 105 | "Creates a list of specified length with random decimal values between 0 to max"
|
105 | 106 | {:test (fn []
|
106 | 107 | (is= (rand-d-list 4 1 0.4)
|
107 |
| - [1961823115700386051 |
108 |
| - '(0.1430590959000676 0.8178222714074991 0.5044600700514671 0.01660157088963388)]))} |
| 108 | + [-9136436700791295257 |
| 109 | + [0.20178402802058684 0.02002609726974093 |
| 110 | + 0.006640628355853552 1.8626451500983188E-10]]))} |
109 | 111 | [length seed max]
|
110 | 112 | (reduce (fn [[seed rand-vals] _]
|
111 | 113 | (let [[next-seed rand-val] (rand seed max)]
|
|
119 | 121 | (is= (rand-list-max-mag 4 2 0)
|
120 | 122 | [-9197343212719499864 `(0 0 0 0)])
|
121 | 123 | (is= (rand-list-max-mag 3 4 23)
|
122 |
| - [-7068052242903947273 `(-6.004336956424794 13.63314510538855 -18.93359371783845)]))} |
| 124 | + [77986490623247743 |
| 125 | + [-22.18838978334721 |
| 126 | + -19.945311020568624 |
| 127 | + -22.999999914318323]]))} |
123 | 128 | [length seed max]
|
124 | 129 | (let [[new-seed rand-list] (rand-d-list length seed (* 2 max))]
|
125 | 130 | [new-seed (map (partial + (- max)) rand-list)]))
|
|
128 | 133 | "Initializes one layer of the neural network. Note the + 1 adjusts for the bias"
|
129 | 134 | ; y = Wx
|
130 | 135 | {:test (fn []
|
131 |
| - (is= (initialize-layer 1 3 1 0) [-8728512804673154413 `((0 0) (0 0) (0 0))]) |
| 136 | + (is= (initialize-layer 1 3 1 0) |
| 137 | + [-8728512804673154413 [[0 0] [0 0] [0 0]]]) |
132 | 138 | (is= (initialize-layer 3 2 24 1)
|
133 |
| - [7786394753034826687 |
134 |
| - '((-0.32256568051994106 0.5576858765248609 0.5806762038640101 -0.8371181152002505) |
135 |
| - (0.6701701863995613 0.3397951933274954 -0.48321265703216776 -0.6015623093589966))]))} |
| 139 | + [2665986749794895764 |
| 140 | + [[0.34034037279912277 |
| 141 | + -0.24479991162419323 |
| 142 | + -0.32040961334500895 |
| 143 | + -0.38945634541542096] |
| 144 | + [0.03357468593566448 |
| 145 | + -0.9542951490517217 |
| 146 | + -0.20312461871799303 |
| 147 | + -0.9999999776482582]]]))} |
136 | 148 | [input-count output-count seed max]
|
137 | 149 | (reduce (fn [[seed rand-lists] _]
|
138 | 150 | (let [[new-seed rand-list] (rand-list-max-mag (+ input-count 1) seed max)]
|
|
246 | 258 | "resources/train-labels.idx1-ubyte" 0.2 10 1))))
|
247 | 259 |
|
248 | 260 | (comment (time (train-and-test "resources/train-images.idx3-ubyte"
|
249 |
| - "resources/train-labels.idx1-ubyte" |
250 |
| - "resources/test-images.idx3-ubyte" |
251 |
| - "resources/test-labels.idx1-ubyte"))) |
| 261 | + "resources/train-labels.idx1-ubyte" |
| 262 | + "resources/test-images.idx3-ubyte" |
| 263 | + "resources/test-labels.idx1-ubyte"))) |
0 commit comments