Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
/// 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;
/// Connects this neuron to another and returns the connection
member this.Connect(target: Neuron) =
let connection = new NeuronConnection(this);
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.