Recent

Author Topic: Instructions and example how to use e.g. neuronal nets in Lazarus  (Read 363 times)

Muso

  • Sr. Member
  • ****
  • Posts: 362
I have been a Lazarus user for a long time. However in recent years I could not use its power because on one hand the development of the compiler is somehow stuck and on the other hand there is no toolbox available to program e.g. neuronal networks.
Now I found a solution on how to combine the power of Lazarus (IDE, LCL etc.) with the power of other programming languages and I want to share that with you:

For neuronal networks but also for plain algorithms you need to deal with tensors in many dimensions and to be fast you need to address the GPU if one is available. I saw only 2 options for a programming language that offers this, either Python or Julia. I chose Julia as I am an engineer and like its syntax and approach more than Python (just a personal preference).

Julia comes with a complete set of packages for any kind one might need (statistics, neuronal networks, machine learning etc.). There is also an active and responding community. Therefore one can easily write the code one needs, but to make it a real program (not a script), one needs a UI. And here Lazarus came into play.
To use the Julia code for Lazarus, one needs to compile the Julia code to a C-style library (e.g. a DLL). This library can be used in Lazarus. There were 2 challenges:
 
  • How to compile the library. Unfortunately the docs are sparse and apparently not many users use this feature of Julia. So I had to find it our by myself and I documented it properly here.
    (here is my announcement in the Julia forum)
    With these step-by step instructions it is easy to compile a library.
  • How to use the library in Lazarus/FreePascal.
For the Lazarus part it took me a while (for example for a strange reason the data type "longInt" is 32bit on 64bit systems (also if the compilation target is 64bit). But on all other programming languages like Julia a "long" is 64bit on 64 bit systems (Julia is 64bit-only) )
However, I found a solution and provide a small Lazarus program as generic example.

I hope this helps you as I see that for more and more programs you need machine learning stools, small neuronal networks etc. and FreePascal cannot handle tensors. I mean how can I create with FreePascal a tensor in e.g. 12, 120 or 1200 dimensions?
---------------------------------
To demonstrate why and how this is necessary, I wrote a complete (production-ready) Lazarus program that can cluster data with as many dimensions as you like. The user can read in a CSV data file in which every column represents a dimension. The clustering is done using a new algorithm I wrote (called "Iteridense") that uses no neuronal nets but tensors with as many dimensions as your data has.
The clustering algorithm is completely written in Julia, compiled as library that is used in the Lazarus program as described above.
If you are interested, you can get the Lazarus program from here.
I also provide a precompiled Windows version: take the file IteridenseClustering.zip from the release assets. There in its bin folder you find the file IteridenseClustering.exe.
« Last Edit: May 08, 2025, 04:12:33 pm by Muso »

 

TinyPortal © 2005-2018