Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/// 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
You can’t perform that action at this time.