While looking for Delphi Firemonkey projects I found a Delphi Science blog which has a post up about neural networks. It includes a demo for Delphi XE5 Firemonkey that contains a TNeuron object. If you’re looking for some code to get you started with artificial intelligence and neural networks in Delphi this might be a good starting spot. The blog post goes into detail on what a neuron is and the math behind a neuron. The demo should run on Android and IOS and there isn’t any platform specific code. Here is a code snippet that defines the TNeuron object:
TNeuron = class(TObject)
private
FThreshold: Single;
FInputCount: Integer;
FInputs:TSingleDynArray;
FWeights:TSingleDynArray;
FAnalogOutput:Boolean;
function GetInput(Index: Integer): Single;
function GetOutput: Single;
function GetWeight(Index: Integer): Single;
procedure SetInput(Index: Integer; const Value: Single);
procedure SetWeight(Index: Integer; const Value: Single);
procedure SetInputCount(const Value: Integer);
function GetLoad: Single;
public
Constructor Create(aInputCount:Integer);
procedure RandomInitialize;
Property Load:Single read GetLoad;
property Output:Single read GetOutput;
property Threshold:Single read FThreshold write FThreshold;
property Inputs[Index: Integer]: Single read GetInput write SetInput;
property Weights[Index: Integer]: Single read GetWeight write SetWeight;
property InputCount:Integer read FInputCount write SetInputCount;
property AnalogOutput read FAnalogOutput write FAnalogOutput;
end;
Download the updated TNeuron project for Delphi XE5 Firemonkey.
Head over and read the full blog post about the Delphi XE5 neuron object.
Great post! I’ve been interested in neural networks for quite some time and can still remember writing my first neural network code during a slow day as a part-time college computer lab assistant with Turbo Pascal for DOS. 🙂
The neuron object presented here is OK, but readers may be interested in the much more fleshed-out and mature FANN library which has good documentation and bindings for many languages including Delphi:
http://leenissen.dk/fann/wp/