Created
September 7, 2019 18:23
-
-
Save IntegerMan/110c73255dca6b1c87a921e1434fd607 to your computer and use it in GitHub Desktop.
This file contains 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
/// A layer is just a series of Neurons in parallel that will link to every Neuron in the next layer (if any is present) | |
and NeuralNetLayer(numNeurons: int) = | |
do if numNeurons <= 0 then invalidArg "numNeurons" "There must be at least one neuron in each layer"; | |
let neurons: Neuron seq = seq [ for i in 1 .. numNeurons -> new Neuron 0M] | |
/// Layers should start with an empty collection of neurons | |
member this.Neurons: Neuron seq = neurons; | |
/// Sets the value of every neuron in the sequence to the corresponding ordered value provided | |
member this.SetValues (values: decimal seq) = | |
let assignValue (n:Neuron) (v:decimal) = n.Value <- v; | |
Seq.iter2 assignValue this.Neurons values | |
/// Evaluates the layer and returns the value of each node | |
member this.Evaluate(): decimal seq = | |
for n in this.Neurons do n.Evaluate() |> ignore; | |
Seq.map (fun (n:Neuron) -> n.Value) this.Neurons; | |
/// Connects every node in this layer to the target layer | |
member this.Connect(layer: NeuralNetLayer): unit = | |
for nSource in neurons do | |
for nTarget in layer.Neurons do | |
nSource.Connect(nTarget) |> ignore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment