Created
March 9, 2016 20:21
-
-
Save paralax/0bd26338ca8807d363bf to your computer and use it in GitHub Desktop.
DeepBeliefNetwork in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #r "Debug/Accord.dll" | |
| #r "Debug/Accord.Math.dll" | |
| #r "Debug/Accord.Neuro.dll" | |
| #I "Debug" | |
| // based on C# from http://whoopsidaisies.hatenablog.com/entry/2014/08/19/015420 | |
| open Accord.Neuro | |
| open Accord.Neuro.Networks | |
| open Accord.Neuro.Learning | |
| open AForge.Neuro.Learning | |
| open Accord.Neuro.ActivationFunctions | |
| open Accord.Math | |
| let inputs = [| | |
| [|1.;1.;1.;0.;0.;0.;|]; | |
| [|1.;0.;1.;0.;0.;0.;|]; | |
| [|1.;1.;1.;0.;0.;0.;|]; | |
| [|0.;0.;1.;1.;1.;0.;|]; | |
| [|0.;0.;1.;1.;0.;0.;|]; | |
| [|0.;0.;1.;1.;1.;0.;|]; | |
| |] | |
| let outputs = [| | |
| [|1.;0.|]; | |
| [|1.;0.|]; | |
| [|1.;0.|]; | |
| [|0.;1.|]; | |
| [|0.;1.|]; | |
| [|0.;1.|]; | |
| |] | |
| let network = new DeepBeliefNetwork(inputs.Length, [|4;2|]) | |
| (new GaussianWeights(network)).Randomize() | |
| let teacher = new BackPropagationLearning(network) | |
| [ for _ in [0 .. 5000] -> teacher.RunEpoch(inputs, outputs) ] | |
| network.UpdateVisibleWeights() | |
| let input = [| 1.; 1.;1.;1.;0.;0. |] | |
| let output = network.Compute(input) | |
| let imax = output |> Array.max |> int | |
| printfn "%A" output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment