Skip to content

Instantly share code, notes, and snippets.

@paralax
Created March 9, 2016 20:21
Show Gist options
  • Save paralax/0bd26338ca8807d363bf to your computer and use it in GitHub Desktop.
Save paralax/0bd26338ca8807d363bf to your computer and use it in GitHub Desktop.
DeepBeliefNetwork in F#
#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