[libfann] 167/242: Added Delphi bindings

Christian Kastner chrisk-guest at moszumanska.debian.org
Sat Oct 4 21:10:39 UTC 2014


This is an automated email from the git hooks/post-receive script.

chrisk-guest pushed a commit to tag Version2_0_0
in repository libfann.

commit e103eec3ab2cec52c8dc8e7bd9014987051ded50
Author: Steffen Nissen <lukesky at diku.dk>
Date:   Tue Nov 2 10:55:14 2004 +0000

    Added Delphi bindings
---
 Delphi/Files/FannNetwork.pas             | 264 ++++++++++++++++++
 Delphi/Files/fann.dcr                    | Bin 0 -> 480 bytes
 Delphi/Files/fann.pas                    | 463 +++++++++++++++++++++++++++++++
 Delphi/README.txt                        |  89 ++++++
 Delphi/Samples/Xor/ProjectXor.dpr        |  13 +
 Delphi/Samples/Xor/XorSample.dfm         |  88 ++++++
 Delphi/Samples/Xor/XorSample.pas         | 100 +++++++
 Delphi/Samples/XorConsole/XorConsole.dpr |  34 +++
 8 files changed, 1051 insertions(+)

diff --git a/Delphi/Files/FannNetwork.pas b/Delphi/Files/FannNetwork.pas
new file mode 100644
index 0000000..42ec4c8
--- /dev/null
+++ b/Delphi/Files/FannNetwork.pas
@@ -0,0 +1,264 @@
+unit FannNetwork;
+
+interface
+
+{$R fann.dcr}
+
+
+uses
+  Windows, Messages, SysUtils, Classes,Fann;
+
+type CardinalArray = array [0..1023] of Cardinal;
+     PCardinalArray = ^CardinalArray;
+
+
+type
+  TFannNetwork = class(TComponent)
+  private
+    ann: PFann;
+    pBuilt: boolean;
+    pLayers: TStrings;
+    pLearningRate: Single;
+    pConnectionRate: Single;
+    procedure SetLayers(const Value: TStrings);
+
+  protected
+    { Protected declarations }
+  public
+    { Public declarations }
+    constructor Create(Aowner: TComponent); override;
+    destructor Destroy(); override;
+    procedure Build();
+    function Train(Input: array of fann_type; Output: array of fann_type): single;
+    procedure TrainOnFile(FileName: String; MaxEpochs: Cardinal; DesiredError: Single);
+    procedure Run(Inputs: array of fann_type; var Outputs: array of fann_type);
+    function GetMSE(): Single;
+    procedure SaveToFile(FileName: String);
+    procedure LoadFromFile(Filename: string);
+
+  published
+
+    {** Network Layer Structure. Each line need to have the number of neurons
+        of the layer.
+        2
+        4
+        1
+        Will make a three layered network with 2 input neurons, 4 hidden neurons
+        and 1 output neuron.
+    }
+    property Layers: TStrings read PLayers write SetLayers;
+
+    {** Network Learning Rate.
+    }
+    property LearningRate: Single read pLearningRate write pLearningRate;
+    {** Network Connection Rate. See the FANN docs for more info.
+    }
+    property ConnectionRate: Single read pConnectionRate write pConnectionRate;
+end;
+
+procedure Register;
+
+implementation
+
+procedure Register;
+begin
+  RegisterComponents('FANN', [TFannNetwork]);
+end;
+
+{ TFannNetwork }
+
+
+{** Builds a Fann neural nerwork.
+    Layers property must be set to work.
+
+    @param      none
+}
+procedure TFannNetwork.Build;
+var l: PCardinalArray; //Pointer to number of neurons on each layer
+    nl: integer; //Number of layers
+    i: integer;
+begin
+
+        nl:=pLayers.Count;
+
+        if nl=0 then
+                Exception.Create('You need to specify the Layers property');
+
+        GetMem(l,nl*sizeof(Cardinal)); //Alloc mem for the array
+
+        for i:=0 to nl-1 do
+        begin
+
+                l[i]:=StrtoInt(pLayers.Strings[i]);
+                
+        end;
+
+        ann:=fann_create_array(PConnectionRate,PLearningRate,nl,l[0]);
+        pbuilt:=true;
+
+        FreeMem(l);
+
+
+
+end;
+
+{** Creates an instance of TFannNetwork
+
+    @param      AOwner Owner Component
+}
+constructor TFannNetwork.Create(Aowner: TComponent);
+begin
+        inherited Create(Aowner);
+        
+        pBuilt:=false;
+        pConnectionRate:=1;
+        pLearningRate:=0.7;
+        pLayers:=TStringList.Create;
+
+
+end;
+
+{** Destroys the TFannNetwork object and frees its memory.
+
+    @param      none
+}
+destructor TFannNetwork.Destroy;
+begin
+  If pBuilt then fann_destroy(ann);
+
+  FreeAndNil(pLayers);
+  inherited;
+end;
+
+{** Returns the Mean Square Error of the Network.
+
+    @param      none
+    @return             Mean Square Error
+}
+function TFannNetwork.GetMSE: Single;
+begin
+        if not pBuilt then
+               raise Exception.Create('The nework has not been built');
+
+        result:=fann_get_mse(ann);
+
+end;
+
+{** Loads a network from a file.
+
+    @param  Filename    File that contains the network
+    @see                SavetoFile
+}
+procedure TFannNetwork.LoadFromFile(Filename: string);
+begin
+
+        If pBuilt then fann_destroy(ann);
+
+        fann_create_from_file(PChar(Filename));
+
+        pBuilt:=true;
+
+end;
+
+{** Executes the network.
+
+    @param  Inputs      Array with the value of each input
+    @param  Ouputs      Will receive the output of the network. Need to be
+                        allocated before the Run function call with the number
+                        of outputs on the network.
+}
+procedure TFannNetwork.Run(Inputs: array of fann_type;
+  var Outputs: array of fann_type);
+var O: Pfann_type_array;
+    i: integer;
+begin
+        if not pBuilt then
+               raise Exception.Create('The nework has not been built');
+
+        O:=fann_run(ann,Inputs[0]);
+
+        for i:=0 to High(outputs) do
+        begin
+            Outputs[i]:=O[i];
+        end;
+
+        
+
+end;
+
+{** Saves the current network to the specified file.
+
+    @param  Filename    Filename of the network
+
+    @see                LoadFromFile
+}
+procedure TFannNetwork.SaveToFile(FileName: String);
+begin
+        if not pBuilt then exit;
+
+
+        fann_save(ann,PChar(Filename));
+        
+
+end;
+
+{** Train the network and returns the Mean Square Error.
+
+    @param  Input       Array with the value of each input of the network
+    @param  Output      Array with the value of each desired output of the network
+    @return             Mean Square Error after the training
+
+    @see                TrainOnFile
+}
+procedure TFannNetwork.SetLayers(const Value: TStrings);
+begin
+
+   if Value.Count < 2 then
+      raise Exception.Create('The network should have at least two layers')
+   else
+      pLayers.Assign(Value);
+
+end;
+
+{** Will train one iteration with a set of inputs, and a set of desired outputs.
+
+    @param  Input   Network inputs
+    @param  Output  Network Desired Outputs
+
+    @see                TrainOnFile
+}
+function TFannNetwork.Train(Input, Output: array of fann_type): single;
+begin
+
+        if not pBuilt then
+                raise Exception.Create('The nework has not been built');
+
+        fann_reset_mse(ann);
+        fann_train(ann,Input[0],Output[0]);
+
+        result:=fann_get_mse(ann);
+        
+end;
+
+{** Trains the network using the data in filename until desirederror is reached
+    or until maxepochs is surpassed.
+
+    @param  FileName    Training Data File.
+    @param  MaxEpochs   Maximum number of epochs to train
+    @param  DesiredError Desired Error of the network after the training
+
+    @see                Train
+}
+procedure TFannNetwork.TrainOnFile(FileName: String; MaxEpochs: Cardinal;
+  DesiredError: Single);
+begin
+
+        if not pBuilt then
+                raise Exception.Create('The nework has not been built');
+
+        fann_train_on_file(ann,PChar(FileName),MaxEpochs,1000,DesiredError);
+
+end;
+
+end.
+ 
\ No newline at end of file
diff --git a/Delphi/Files/fann.dcr b/Delphi/Files/fann.dcr
new file mode 100644
index 0000000..e579baf
Binary files /dev/null and b/Delphi/Files/fann.dcr differ
diff --git a/Delphi/Files/fann.pas b/Delphi/Files/fann.pas
new file mode 100644
index 0000000..375aee3
--- /dev/null
+++ b/Delphi/Files/fann.pas
@@ -0,0 +1,463 @@
+unit fann;
+
+interface
+
+{$IFNDEF FIXEDFANN}
+const DLL_FILE = 'fannfloat.dll';
+{$ELSE}
+const DLL_FILE = 'fannfixed.dll';
+{$ENDIF}
+
+
+{$IFDEF VER150}
+   {$DEFINE VARIABLE_ARGUMENTS}
+{$ENDIF}
+
+{$IFDEF VER140}
+   {$DEFINE VARIABLE_ARGUMENTS}
+{$ENDIF}
+
+//Only Delphi 6 and 7 supports the varargs directive
+
+
+type
+
+
+        fann_type = single;
+
+        Pfann_type = ^fann_type;
+
+        PPfann_type = ^pfann_type;
+
+        fann_type_array = array [0..32767] of fann_type;
+
+        Pfann_type_array = ^fann_type_array;
+
+        (* MICROSOFT VC++ STDIO'S FILE DEFINITION*)
+        _iobuf = packed record
+                _ptr: Pchar;
+                _cnt: integer;
+                _base: Pchar;
+                _flag: integer;
+                _file: integer;
+                _charbuf: integer;
+                _bufsiz: integer;
+                _tmpfname: Pchar;
+        end;
+
+
+        PFile = ^TFile;
+        TFile = _iobuf;
+
+
+        PPFann_Neuron = ^PFann_Neuron;
+        PFann_Neuron = ^TFann_Neuron;
+        TFann_Neuron = packed record
+                weights: PFann_type;
+                connected_neurons: PPFann_Neuron;
+                num_connections: cardinal;
+                value: fann_type;
+        end;
+
+
+        PFann_Layer = ^TFann_Layer;
+        TFann_Layer = packed record
+                first_neuron: PFann_Neuron;
+                last_neuron: PFann_Neuron;
+        end;
+
+        PFann = ^TFann;
+        TFann = packed record
+                errno_f: cardinal;
+                error_log: PFile;
+                errstr: Pchar;
+                learning_rate: single;
+                connection_rate: single;
+                shortcut_connections: cardinal;
+                first_layer: PFann_Layer;
+                last_layer: PFann_Layer;
+                total_neurons: cardinal;
+                num_input: cardinal;
+                num_output: cardinal;
+                train_errors: Pfann_type;
+                activation_function_hidden,activation_function_output: cardinal;
+                activation_steepness_hidden: fann_type;
+                activation_steepness_output: fann_type;
+                training_algorithm: cardinal;
+                {$IFDEF FIXEDFANN}
+                 decimal_point: cardinal;
+                 multiplier: cardinal;
+                {$ENDIF}
+                activation_results_hidden: array [0..5] of fann_type;
+                activation_values_hidden: array [0..5] of fann_type;
+                activation_results_output: array [0..5] of fann_type;
+                activation_values_output: array [0..5] of fann_type;
+
+                total_connections: cardinal;
+                output: pfann_type;
+                num_MSE: cardinal;
+                MSE_value: single;
+                train_error_function: cardinal;
+                quickprop_decay: single;
+                quickprop_mu: single;
+                rprop_increase_factor: single;
+                rprop_decrease_factor: single;
+                rprop_delta_min: single;
+                rprop_delta_max: single;
+                train_slopes: pfann_type;
+                prev_steps: pfann_type;
+                prev_train_slopes: pfann_type;
+        end;
+
+        PFann_Train_Data = ^TFann_Train_Data;
+        TFann_Train_Data = packed record
+                errno_f: cardinal;
+                erro_log: PFile;
+                errstr: Pchar;
+                num_data: cardinal;
+                num_input: cardinal;
+                num_ouput: cardinal;
+                input: PPFann_Type;
+                output: PPFann_Type;
+        end;
+
+        PFann_Error = ^TFann_Error;
+        TFann_Error = packed record
+                error_log: PFile;
+                errstr: PChar;
+        end;
+
+        _Fann_Train =
+        (
+          	FANN_TRAIN_INCREMENTAL = 0,
+	        FANN_TRAIN_BATCH,
+	        FANN_TRAIN_RPROP,
+                FANN_TRAIN_QUICKPROP
+        );
+
+        _Fann_Error_Func =
+        (
+                FANN_ERRORFUNC_LINEAR = 0,
+	        FANN_ERRORFUNC_TANH
+        );
+
+        TFann_Report_CallBack = function(epochs: cardinal;error: single): integer; stdcall;
+
+var
+        FANN_ERRORFUNC_NAMES: array [0..1] of string = (
+        	'FANN_ERRORFUNC_LINEAR',
+	        'FANN_ERRORFUNC_TANH'
+        );
+
+        FANN_TRAIN_NAMES: array [0..3] of string =
+        (
+	        'FANN_TRAIN_INCREMENTAL',
+	        'FANN_TRAIN_BATCH',
+	        'FANN_TRAIN_RPROP',
+	        'FANN_TRAIN_QUICKPROP'
+        );
+
+        {$IFDEF VARIABLE_ARGUMENTS}
+
+        function fann_create(connection_rate: single; learning_rate: single;
+                                num_layers: cardinal): PFann; cdecl; varargs;
+
+        function fann_create_shortcut(learning_rate: single;num_layers: cardinal): PFann; cdecl; varargs;
+
+        {$ENDIF}
+
+        function fann_create_array(connection_rate: single; learning_rate: single;
+                                num_layers: cardinal;var layers: cardinal): PFann; stdcall;
+
+
+
+        function fann_create_shortcut_array(learning_rate: single; num_layers: cardinal;var layers: cardinal): PFann; stdcall;
+
+        function fann_run(ann: PFann;var input: Fann_Type): Pfann_type_array; stdcall;
+
+        procedure fann_destroy(Ann: PFann); stdcall;
+
+        procedure fann_randomize_weights(Ann: PFann; Min_weight: fann_type; Max_weight: fann_type); stdcall;
+
+        procedure fann_init_weights(Ann: PFann;var train_data: TFann_Train_Data); stdcall;
+
+        procedure fann_print_connections(ann: PFann);stdcall;
+
+        function fann_create_from_file(const configuration_file: PChar): PFann; stdcall;
+
+        procedure fann_save(Ann: PFann; Const Configuration_File: PChar);stdcall;
+
+        function fann_save_to_fixed(Ann: PFann; Const Configuration_File: PChar): integer;stdcall;
+
+        {$IFNDEF FIXEDFANN}
+                procedure fann_train(Ann: PFann;var Input: Fann_Type;var Desired_Output: Fann_Type);stdcall;
+        {$ENDIF}
+
+        function fann_test(Ann: PFann; var Input: Fann_Type; var Desired_Output: fann_Type): Pfann_type_array;stdcall;
+
+        function fann_get_MSE(Ann: PFann): single;stdcall;
+
+        procedure fann_reset_MSE(Ann: Pfann); stdcall;
+
+        function fann_read_train_from_file(filename: PChar): PFann_Train_Data; stdcall;
+
+        procedure fann_destroy_train(var Train_Data: TFann_Train_Data);stdcall;
+
+        {$IFNDEF FIXEDFANN}
+              function fann_train_epoch(Ann: PFann;var data: TFann_Train_Data): single;
+              function fann_test_data(Ann: PFann;var data: TFann_Train_Data): single;
+              procedure fann_train_on_data(Ann: PFann; var Data: TFann_Train_Data;max_epochs: cardinal;epochs_between_reports: cardinal; desired_error: single);stdcall;
+
+              procedure fann_train_on_data_callback(Ann: PFann; var Data: TFann_Train_Data; max_epochs: cardinal;epochs_between_reports: cardinal; desired_error: single;CallBack: TFann_Report_Callback); stdcall;
+
+              procedure fann_train_on_file(Ann: PFann; Filename: Pchar;max_epochs: cardinal;epochs_between_reports: cardinal; desired_error: single); stdcall;
+
+              procedure fann_train_on_file_callback(Ann: PFann; Filename: Pchar;max_epochs: cardinal;epochs_between_reports: cardinal; desired_error: single; CallBack: TFann_Report_Callback);stdcall;
+
+              procedure fann_shuffle_train_data(var Train_Data: TFann_Train_Data);stdcall;
+
+              function fann_merge_train_data(var Data1: TFann_Train_Data;var Data2: TFann_Train_Data): PFann_Train_Data; stdcall;
+
+              function fann_duplicate_train_data(var Data: TFann_Train_Data): PFann_Train_Data;stdcall;
+
+        {$ENDIF}
+
+        procedure fann_save_train(var Data: TFann_train_Data; Filename: PChar);stdcall;
+
+        procedure fann_save_train_to_fixed(var Data: TFann_train_Data; FileName: Pchar; decimal_point: cardinal);stdcall;
+
+        procedure fann_print_parameters(Ann: PFann); stdcall;
+
+        function fann_get_training_algorithm(Ann: Pfann): cardinal;stdcall;
+
+        procedure fann_set_training_algorithm(Ann: PFann; Training_Algorithm: cardinal);stdcall;
+
+        function fann_get_learning_rate(Ann: PFann): single;stdcall;
+
+        procedure fann_set_learning_rate(Ann: PFann; Learning_Rate: Single); stdcall;
+
+        function fann_get_activation_function_hidden(Ann: PFann): cardinal;stdcall;
+
+        procedure fann_set_activation_function_hidden(Ann: Pfann; Activation_function: cardinal); stdcall;
+
+        function fann_get_activation_function_output(Ann: Pfann): cardinal;stdcall;
+
+        procedure fann_set_activation_function_output(Ann: Pfann; Activation_Function: cardinal); stdcall;
+
+        function fann_get_activation_steepness_hidden(Ann: PFann): fann_type; stdcall;
+
+        procedure fann_set_activation_steepness_hidden(Ann: PFann; SteepNess: Fann_Type); stdcall;
+
+        function fann_get_activation_steepness_output(Ann: PFann): fann_type;stdcall;
+
+        procedure fann_set_activation_steepness_output(Ann: PFann; SteepNess: Fann_Type);stdcall;
+
+        procedure fann_set_train_error_function(Ann: PFann; Train_Error_Function: cardinal); stdcall;
+
+        function fann_get_train_error_function(Ann: PFann): cardinal;stdcall;
+
+        function fann_get_quickprop_decay(Ann: PFann): single;stdcall;
+
+        procedure fann_set_quickprop_decay(Ann: Pfann; quickprop_decay: Single);stdcall;
+
+        function fann_get_quickprop_mu(Ann: PFann): single;stdcall;
+
+        procedure fann_set_quickprop_mu(Ann: PFann; Mu: Single);stdcall;
+
+        function fann_get_rprop_increase_factor(Ann: PFann): single;stdcall;
+
+        procedure fann_set_rprop_increase_factor(Ann: PFann;rprop_increase_factor: single);stdcall;
+
+        function fann_get_rprop_decrease_factor(Ann: PFann): single;stdcall;
+
+        procedure fann_set_rprop_decrease_factor(Ann: PFann;rprop_decrease_factor: single); stdcall;
+
+        function fann_get_rprop_delta_min(Ann: PFann): single; stdcall;
+
+        procedure fann_set_rprop_delta_min(Ann: PFann; rprop_delta_min: Single); stdcall;
+
+        function fann_get_rprop_delta_max(Ann: PFann): single;stdcall;
+
+        procedure fann_set_rprop_delta_max(Ann: PFann; rprop_delta_max: Single); stdcall;
+
+        function fann_get_num_input(Ann: PFann): cardinal;stdcall;
+
+        function fann_get_num_output(Ann: PFann): cardinal;stdcall;
+
+        function fann_get_total_neurons(Ann: PFann): cardinal; stdcall;
+
+        function fann_get_total_connections(Ann: PFann): cardinal; stdcall;
+
+        {$IFDEF FIXEDFANN}
+
+                function fann_get_decimal_point(Ann: Pfann): cardinal; stdcall;
+
+                function fann_get_multiplier(Ann: PFann): cardinal;stdcall;
+
+        {$ENDIF}
+
+        procedure fann_set_error_log(errdat: PFann_Error; Log_File: PFile);stdcall;
+
+        function fann_get_errno(errdat: PFann_Error): cardinal;stdcall;
+
+        procedure fann_reset_errno(errdat: PFann_Error);stdcall;
+
+        procedure fann_reset_errstr(errdat: PFann_Error);stdcall;
+
+        function fann_get_errstr(errdat: PFann_Error): PChar;stdcall;
+
+        procedure fann_print_error(Errdat: PFann_Error);stdcall;
+
+
+implementation
+
+        {$IFDEF VARIABLE_ARGUMENTS}
+        function fann_create;external DLL_FILE;
+
+        function fann_create_shortcut;external DLL_FILE;
+        {$ENDIF}
+        
+        
+        function fann_create_array;external DLL_FILE name '_fann_create_array at 16';
+
+
+
+        function fann_create_shortcut_array;external DLL_FILE name '_fann_create_shortcut_array at 12';
+
+        function fann_run;external DLL_FILE name '_fann_run at 8';
+
+        procedure fann_destroy;external DLL_FILE name '_fann_destroy at 4';
+
+        procedure fann_randomize_weights;external DLL_FILE name '_fann_randomize_weights at 12';
+
+        procedure fann_init_weights;external DLL_FILE name '_fann_init_weights at 8';
+
+        procedure fann_print_connections;external DLL_FILE name '_fann_print_connections at 4';
+
+        function fann_create_from_file;external DLL_FILE name '_fann_create_from_file at 4';
+
+        procedure fann_save;external DLL_FILE name '_fann_save at 8';
+
+        function fann_save_to_fixed;external DLL_FILE name '_fann_save_to_fixed at 8';
+
+        {$IFNDEF FIXEDFANN}
+                procedure fann_train;external DLL_FILE name '_fann_train at 12';
+        {$ENDIF}
+
+        function fann_test;external DLL_FILE name '_fann_test at 12';
+
+        function fann_get_MSE;external DLL_FILE name '_fann_get_MSE at 4';
+
+        procedure fann_reset_MSE;external DLL_FILE name '_fann_reset_MSE at 4';
+
+        function fann_read_train_from_file;external DLL_FILE name '_fann_read_train_from_file at 4';
+
+        procedure fann_destroy_train;external DLL_FILE name '_fann_destroy_train at 4';
+
+        {$IFNDEF FIXEDFANN}
+              function fann_train_epoch;external DLL_FILE name '_fann_train_epoch at 8';
+
+              function fann_test_data;external DLL_FILE name '_fann_test_data at 8';
+
+              procedure fann_train_on_data;external DLL_FILE name '_fann_train_on_data at 20';
+
+              procedure fann_train_on_data_callback;external DLL_FILE name '_fann_train_on_data_callback at 24';
+
+              procedure fann_train_on_file;external DLL_FILE name '_fann_train_on_file at 20'
+
+              procedure fann_train_on_file_callback;external DLL_FILE name '_fann_train_on_file_callback at 24';
+
+              procedure fann_shuffle_train_data;external DLL_FILE name '_fann_shuffle_train_data at 4';
+
+              function fann_merge_train_data;external DLL_FILE name '_fann_merge_train_data at 8';
+
+              function fann_duplicate_train_data;external DLL_FILE name '_fann_duplicate_train_data at 4';
+
+        {$ENDIF}
+
+        procedure fann_save_train;external DLL_FILE name '_fann_save_train at 8';
+
+        procedure fann_save_train_to_fixed;external DLL_FILE name '_fann_save_train_to_fixed at 12';
+
+        procedure fann_print_parameters;external DLL_FILE name '_fann_print_parameters at 4';
+
+        function fann_get_training_algorithm;external DLL_FILE name '_fann_get_training_algorithm at 4';
+
+        procedure fann_set_training_algorithm;external DLL_FILE name '_fann_set_training_algorithm at 8';
+
+        function fann_get_learning_rate;external DLL_FILE name '_fann_get_learning_rate at 4';
+
+        procedure fann_set_learning_rate;external DLL_FILE name '_fann_set_learning_rate at 8';
+
+        function fann_get_activation_function_hidden;external DLL_FILE name '_fann_get_activation_function_hidden at 4';
+
+        procedure fann_set_activation_function_hidden;external DLL_FILE name '_fann_set_activation_function_hidden at 8';
+
+        function fann_get_activation_function_output;external DLL_FILE name '_fann_get_activation_function_output at 4';
+
+        procedure fann_set_activation_function_output;external DLL_FILE name '_fann_set_activation_function_output at 8';
+
+        function fann_get_activation_steepness_hidden;external DLL_FILE name '_fann_get_activation_steepness_hidden at 4';
+
+        procedure fann_set_activation_steepness_hidden;external DLL_FILE name '_fann_set_activation_steepness_hidden at 8';
+
+        function fann_get_activation_steepness_output;external DLL_FILE name '_fann_get_activation_steepness_output at 4';
+
+        procedure fann_set_activation_steepness_output;external DLL_FILE name '_fann_set_activation_steepness_output at 8';
+
+        procedure fann_set_train_error_function;external DLL_FILE name '_fann_set_train_error_function at 8';
+
+        function fann_get_train_error_function;external DLL_FILE name '_fann_get_train_error_function at 4';
+
+        function fann_get_quickprop_decay;external DLL_FILE name '_fann_get_quickprop_decay at 4';
+
+        procedure fann_set_quickprop_decay;external DLL_FILE name '_fann_set_quickprop_decay at 8';
+
+        function fann_get_quickprop_mu;external DLL_FILE name '_fann_get_quickprop_mu at 4';
+
+        procedure fann_set_quickprop_mu;external DLL_FILE name '_fann_set_quickprop_mu at 8';
+
+        function fann_get_rprop_increase_factor;external DLL_FILE name '_fann_get_rprop_increase_factor at 4';
+
+        procedure fann_set_rprop_increase_factor;external DLL_FILE name '_fann_set_rprop_increase_factor at 8';
+
+        function fann_get_rprop_decrease_factor;external DLL_FILE name '_fann_get_rprop_decrease_factor at 4';
+
+        procedure fann_set_rprop_decrease_factor;external DLL_FILE name '_fann_set_rprop_decrease_factor at 8';
+
+        function fann_get_rprop_delta_min;external DLL_FILE name '_fann_get_rprop_delta_min at 4';
+
+        procedure fann_set_rprop_delta_min;external DLL_FILE name '_fann_set_rprop_delta_min at 8';
+
+        function fann_get_rprop_delta_max;external DLL_FILE name '_fann_get_rprop_delta_max at 4';
+
+        procedure fann_set_rprop_delta_max;external DLL_FILE name '_fann_set_rprop_delta_max at 8';
+
+        function fann_get_num_input;external DLL_FILE name '_fann_get_num_input at 4';
+
+        function fann_get_num_output;external DLL_FILE name '_fann_get_num_output at 4';
+
+        function fann_get_total_neurons;external DLL_FILE name '_fann_get_total_neurons at 4';
+
+        function fann_get_total_connections;external DLL_FILE name '_fann_get_total_connections at 4';
+
+        {$IFDEF FIXEDFANN}
+
+                function fann_get_decimal_point;external DLL_FILE name '_fann_get_decimal_point at 4';
+                function fann_get_multiplier;external DLL_FILE name '_fann_get_decimal_point at 4';
+
+        {$ENDIF}
+
+        procedure fann_set_error_log;external DLL_FILE name '_fann_set_error_log at 8';
+
+        function fann_get_errno;external DLL_FILE name '_fann_get_errno at 4';
+
+        procedure fann_reset_errno;external DLL_FILE name '_fann_reset_errno at 4';
+
+        procedure fann_reset_errstr;external DLL_FILE name '_fann_reset_errstr at 4';
+
+        function fann_get_errstr;external DLL_FILE name '_fann_get_errstr at 4';
+
+        procedure fann_print_error;external DLL_FILE name '_fann_print_error at 4';
+
+end.
diff --git a/Delphi/README.txt b/Delphi/README.txt
new file mode 100644
index 0000000..b78100a
--- /dev/null
+++ b/Delphi/README.txt
@@ -0,0 +1,89 @@
+FANN Delphi Binding
+===================
+
+These files are distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+Author: Mauricio Pereira Maia <mauricio at uaisol.com.br>
+Version: 1.0
+
+
+Version History
+===============
+
+10 Oct 2004 - First Version released.
+
+
+Requeriments
+============
+
+- FANN Library Version 1.2.0
+- Delphi 6 or 7. Prior Delphi versions should work too, but without the functions 
+fann_create and fann_create_shorcut because of the variable argument list.)
+
+
+HOW TO USE IT
+=============
+
+- Download the fann_win32_dll-1.2.0.zip file
+- Put the file fannfloat.dll in your PATH. (If you want to use the fixed version
+you should define FIXEDFANN on fann.pas)
+- include fann.pas in your project and in your unit uses clause, and have fun!
+- See the XorConsole sample for more details.
+
+
+INSTALLING THE TFannNetwork
+===========================
+
+TFannNetwork is a Delphi component that encapsulates the Fann Library.
+You do not have to install TFannNetwork to use Fann on Delphi, 
+but it will make the library more Delphi friendly.
+Currently it has only a small subset of all the library functions, but I 
+hope that will change in the near future.
+
+To install TFannNetwork you should follow all the previous steps and
+- Copy the FannNetwork.pas and Fann.dcr to your Delphi Library PATH.
+- Choose Component/Install Component.
+- In the Unit file name field, click on Browse and point to the fannnetwork.pas file.
+By default Delphi will install in the Borland User Components package, 
+it might be changed using Package file name field or Into new package page.
+- Click on Ok 
+- A confirmation dialog will be shown asking if you want to build the package. Click on Yes.
+- You have just installed TFannNetwork, now close the package window 
+(Don't forget to put Yes when it ask if you want to save the package). 
+- See the FannNetwork.pas file or the Xor Sample.
+
+KNOWN PROBLEMS
+==============
+
+If you are getting in trouble to use your own compiled FANN DLL with Delphi that might be
+because of the C++ naming mangle that changes between C++ compilers. 
+You will need to make a TDUMP on your dll and changes all the name directives on fann.pas to 
+the correct function names on your dll.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Delphi/Samples/Xor/ProjectXor.dpr b/Delphi/Samples/Xor/ProjectXor.dpr
new file mode 100644
index 0000000..573ba3b
--- /dev/null
+++ b/Delphi/Samples/Xor/ProjectXor.dpr
@@ -0,0 +1,13 @@
+program ProjectXor;
+
+uses
+  Forms,
+  XorSample in 'XorSample.pas' {Form1};
+
+{$R *.res}
+
+begin
+  Application.Initialize;
+  Application.CreateForm(TForm1, Form1);
+  Application.Run;
+end.
diff --git a/Delphi/Samples/Xor/XorSample.dfm b/Delphi/Samples/Xor/XorSample.dfm
new file mode 100644
index 0000000..773235e
--- /dev/null
+++ b/Delphi/Samples/Xor/XorSample.dfm
@@ -0,0 +1,88 @@
+object Form1: TForm1
+  Left = 192
+  Top = 107
+  Width = 276
+  Height = 170
+  Caption = 'Delphi FANN Xor Demo'
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'MS Sans Serif'
+  Font.Style = []
+  OldCreateOrder = False
+  PixelsPerInch = 96
+  TextHeight = 13
+  object LblError: TLabel
+    Left = 104
+    Top = 36
+    Width = 111
+    Height = 13
+    Caption = 'Mean Square Error:'
+    Font.Charset = DEFAULT_CHARSET
+    Font.Color = clWindowText
+    Font.Height = -11
+    Font.Name = 'MS Sans Serif'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object lblMSE: TLabel
+    Left = 216
+    Top = 36
+    Width = 5
+    Height = 13
+    Font.Charset = DEFAULT_CHARSET
+    Font.Color = clRed
+    Font.Height = -11
+    Font.Name = 'MS Sans Serif'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object btnTrain: TButton
+    Left = 0
+    Top = 32
+    Width = 97
+    Height = 25
+    Caption = 'Train'
+    Enabled = False
+    TabOrder = 0
+    OnClick = btnTrainClick
+  end
+  object btnRun: TButton
+    Left = 0
+    Top = 64
+    Width = 97
+    Height = 25
+    Caption = 'Run'
+    Enabled = False
+    TabOrder = 1
+    OnClick = btnRunClick
+  end
+  object memoXor: TMemo
+    Left = 104
+    Top = 64
+    Width = 113
+    Height = 73
+    Lines.Strings = (
+      '')
+    TabOrder = 2
+  end
+  object btnBuild: TButton
+    Left = 0
+    Top = 0
+    Width = 97
+    Height = 25
+    Caption = 'Build'
+    TabOrder = 3
+    OnClick = btnBuildClick
+  end
+  object NN: TFannNetwork
+    Layers.Strings = (
+      '2'
+      '4'
+      '1')
+    LearningRate = 0.699999988079071
+    ConnectionRate = 1
+    Top = 104
+  end
+end
diff --git a/Delphi/Samples/Xor/XorSample.pas b/Delphi/Samples/Xor/XorSample.pas
new file mode 100644
index 0000000..7449efd
--- /dev/null
+++ b/Delphi/Samples/Xor/XorSample.pas
@@ -0,0 +1,100 @@
+unit XorSample;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, FannNetwork, StdCtrls;
+
+type
+  TForm1 = class(TForm)
+    NN: TFannNetwork;
+    btnTrain: TButton;
+    LblError: TLabel;
+    lblMSE: TLabel;
+    btnRun: TButton;
+    memoXor: TMemo;
+    btnBuild: TButton;
+    procedure btnTrainClick(Sender: TObject);
+    procedure btnRunClick(Sender: TObject);
+    procedure btnBuildClick(Sender: TObject);
+  private
+    { Private declarations }
+  public
+    { Public declarations }
+  end;
+
+var
+  Form1: TForm1;
+
+implementation
+
+{$R *.dfm}
+
+procedure TForm1.btnTrainClick(Sender: TObject);
+var inputs: array [0..1] of single;
+    outputs: array [0..0] of single;
+    e,i,j: integer;
+    mse: single;
+begin
+
+
+        //Train the network
+        for e:=1 to 10000 do //Train 10000 epochs
+        begin
+
+                for i:=0 to 1 do
+                begin
+                        for j:=0 to 1 do
+                        begin
+                            inputs[0]:=i;
+                            inputs[1]:=j;
+                            outputs[0]:=i Xor j;
+
+                            mse:=NN.Train(inputs,outputs);
+                            lblMse.Caption:=Format('%.4f',[mse]);
+                            Application.ProcessMessages;
+
+                        end;
+                end;
+        end;
+
+        
+
+
+end;
+
+procedure TForm1.btnRunClick(Sender: TObject);
+var i,j: integer;
+    output: array [0..0] of single;
+    inputs: array [0..1] of single;
+
+begin
+
+     MemoXOR.Lines.Clear;
+
+     for i:=0 to 1 do
+     begin
+        for j:=0 to 1 do
+        begin
+
+                inputs[0]:=i;
+                inputs[1]:=j;
+                NN.Run(inputs,output);
+                MemoXor.Lines.Add(Format('%d XOR %d = %f',[i,j,Output[0]]));
+        end;
+     end;
+
+
+end;
+
+procedure TForm1.btnBuildClick(Sender: TObject);
+begin
+        NN.Build;
+        btnBuild.Enabled:=false;
+        BtnTrain.Enabled:=true;
+        btnRun.Enabled:=true;
+
+end;
+
+end.
diff --git a/Delphi/Samples/XorConsole/XorConsole.dpr b/Delphi/Samples/XorConsole/XorConsole.dpr
new file mode 100644
index 0000000..bdd9bfa
--- /dev/null
+++ b/Delphi/Samples/XorConsole/XorConsole.dpr
@@ -0,0 +1,34 @@
+program XorConsole;
+
+{$APPTYPE CONSOLE}
+
+uses
+  SysUtils,fann;
+
+var ann: PFann;
+    inputs: array [0..1] of fann_type;
+    calc_out: PFann_Type_array;
+    i,j: integer;
+
+begin
+        ann:=fann_create(1,0.7,3,2,4,1);
+
+
+        fann_train_on_file(ann, 'xor.data', 500000,
+                1000, 0.00001);
+
+        fann_save(ann, 'xor_float.net');
+
+        for i:=0 to 1 do
+                for j:=0 to 1 do
+                begin
+                        inputs[0]:=j;
+                        inputs[1]:=i;
+                        calc_out:= fann_run(ann, inputs[0]);
+                        writeln(Format('%d Xor %d = %f',[i,j,Calc_Out[0]]));
+                end;
+        readln;
+
+        fann_destroy(ann);
+
+end.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/libfann.git



More information about the debian-science-commits mailing list