Created
September 7, 2019 18:22
-
-
Save IntegerMan/0cc757c4bfc0de80d3b2e5341b06c828 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
/// Represents a node in a Neural Network | |
and Neuron ([<Optional>] ?initialValue: decimal) = | |
let mutable value = defaultArg initialValue 0M; | |
let mutable inputs: NeuronConnection seq = Seq.empty; | |
/// Exposes the current calculated amount of the Neuron | |
member this.Value | |
with get () = value | |
and set (newValue) = value <- newValue | |
/// Incoming connections from other Neurons (if any) | |
member this.Inputs: NeuronConnection seq = inputs; | |
/// Adds an incoming connection from another Neuron | |
member this.AddIncomingConnection c = inputs <- Seq.append this.Inputs [c]; | |
/// Adds all connections together, stores the result in Value, and returns the value | |
member this.Evaluate(): decimal = | |
if not (Seq.isEmpty this.Inputs) then do | |
let numInputs = Seq.length this.Inputs |> decimal | |
value <- Seq.sumBy (fun (c:NeuronConnection) -> c.Evaluate()) this.Inputs / numInputs; | |
value; | |
/// Connects this neuron to another and returns the connection | |
member this.Connect(target: Neuron) = | |
let connection = new NeuronConnection(this); | |
target.AddIncomingConnection(connection); | |
connection; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment