Artificial Intelligence in PB?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Artificial Intelligence in PB?

Post by Caronte3D »

Since AI is awesome for some things.. I dunno why no one here (talented coders) is trying to find a way to use it the easy way in PB :?

I think the easiest way whould be using a C dll, but not sure.

I found this library:
http://leenissen.dk/fann/wp/

Do you think this can be used in PB directly?
Any other ideas?
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Artificial Intelligence in PB?

Post by jacdelad »

I'm still one of the newbies here and I wouldn't say AI is not possible with PB. But why?
I guess there's a reason why there's no real artificial intelligence out there yet. Alexa? Just a bunch of if statements and predefined internet search. Photo AI? Just selecting the predefined postprocessing algorithm by predefined choosing algorithms.

I for one neither think PB is the right language for a real approach, nor is the hardware it runs on.

But, of course, I may be horribly wrong...
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Artificial Intelligence in PB?

Post by Mijikai »

There have been several threads about neural networks (even with src) and other AI related threads.
Coding an AI with PB is ofc. possible but it all depends on time, skill and resources.
A game AI for example might be easy and way more feasable compared to a avoidance system for a car that doesnt kill people.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Artificial Intelligence in PB?

Post by infratec »

And the answer is ...

yes, it is possible to use the mentioned C library as dll directly in PB.
You need only to write a wrapper for the exported C functions.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Artificial Intelligence in PB?

Post by Caronte3D »

Mijikai wrote: Sun Jul 25, 2021 10:23 am There have been several threads about neural networks (even with src) and other AI related threads.
Coding an AI with PB is ofc. possible but it all depends on time, skill and resources.
A game AI for example might be easy and way more feasable compared to a avoidance system for a car that doesnt kill people.
Yes, I know about that threads, but they are very simplistic and obsolete. Today we need to be able to use something more robust, like TensorFlow.
infratec wrote: Sun Jul 25, 2021 10:47 am And the answer is ...
yes, it is possible to use the mentioned C library as dll directly in PB.
You need only to write a wrapper for the exported C functions.
I haven't the Know to do this mi self, but I will research about it

Thanks to evey one! :wink:
juergenkulow
Enthusiast
Enthusiast
Posts: 544
Joined: Wed Sep 25, 2019 10:18 am

Re: Artificial Intelligence in PB?

Post by juergenkulow »

Is there an easy way to connect PureBasic 6.00 Alpha with C backend with FANN without wrapper?
http://fann.sourceforge.net/fann.html
FANN-2.2.0-Source.zip️
Please ask your questions, because switch on the cognition apparatus decides on the only known life in the universe.Wersten :DDüsseldorf NRW Germany Europe Earth Solar System Flake Bubble Orionarm
Milky Way Local_Group Virgo Supercluster Laniakea Universe
User avatar
tj1010
Enthusiast
Enthusiast
Posts: 621
Joined: Mon Feb 25, 2013 5:51 pm
Location: US or Estonia
Contact:

Re: Artificial Intelligence in PB?

Post by tj1010 »

from what I've seen AI/ML is all about building neurons and synapses from big-data that is groomed by hand or automation first... It's not surprising that you don't see many threads on it...

Actually, if you go around communities that do a lot of stuff with pytorch you probably won't see much useful code either.. It's all about the data, and people aren't likely to share...

Probably the *wisest* thing that could be done on PB forum is a thread that gives source to a FNN(easiest type of neural network) that uses primitive data, so people can see what one really is. From there they could go on to learn FIS, RNN, DBN, ESN, BRNN etc...
The truth hurts.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Artificial Intelligence in PB?

Post by Caronte3D »

Python communities have lots of useful code, examples, and even entire projects.
For now, I do the AI with Python (I'm new to that language) and everything else with PB where I feel more comfortable, but it would be very interesting to be able to use powerful AI libraries in PB directly.
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Artificial Intelligence in PB?

Post by NicTheQuick »

Caronte3D wrote: Sat Jul 24, 2021 2:02 pmI found this library:
http://leenissen.dk/fann/wp/
Looking at the Changelog I don't think you wanna use that nowadays. :D
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Artificial Intelligence in PB?

Post by Caronte3D »

It's better than nothing, but anyway I don't hope a good solution for PB now, so in the mean time I try to use a mix of PB + Python 🤷🏻‍♂️
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: Artificial Intelligence in PB?

Post by Olli »

Caronte3D wrote: Sat Jul 24, 2021 2:02 pm Since AI is awesome for some things.. I dunno why no one here (talented coders) is trying to find a way to use it the easy way in PB :?

I think the easiest way whould be using a C dll, but not sure.

I found this library:
http://leenissen.dk/fann/wp/

Do you think this can be used in PB directly?
Any other ideas?
Coding section : 20+ lines can recognize handwritten characters for AI code (by MiLoo)
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Artificial Intelligence in PB?

Post by Caronte3D »

Thanks Olli, I already saw all the examples on the forum, but they are very simple far from the power available today.
Robeene
User
User
Posts: 15
Joined: Sun Aug 15, 2021 6:34 am

Re: Artificial Intelligence in PB?

Post by Robeene »

I use AI very extensively in my project, large networks and hundreds at the same time, each as a DLL loaded in a C++ console host.
They can do thousands of lookups per second.
The console host loads the DLL and it's functions along with the weight file.
Here is the C++ code for the console host without the header file code.
I had to move the loops to never execute at the bottom because it limits the lookups to a few per second.
I didn't write the code.

Code: Select all

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include "NNshell.h"

using namespace std;

enum {NSRecallNetwork, NSLearningNetwork};

int main()
{

	HINSTANCE hDLL = LoadDLLFunctions("NN.dll");
	if (hDLL)
	{

		void *nn;
		createNetwork(nn, NSRecallNetwork);

		loadWeights(nn,"Weights.nsw");

		double *inputData = new double[758];
		double *outputData = new double[2];
		string inputstring;

	for( ; ; ) {

		getline(cin,inputstring);

		int x=0;

		stringstream ss(inputstring);
		string field;

		while (getline(ss,field,','))
		{
			stringstream fs(field);
			fs >> inputData[x];
			x++;
		}

		getResponse(nn, 1, inputData, outputData);

		for (int i = 0; i < 2; ++i) {
			cout << setprecision(10) << outputData[i];
			cout << '\n';
		}
		
	}

		delete[] inputData;
		delete[] outputData;
		destroyNetwork(nn);
		FreeLibrary(hDLL);

	} 

	return 0;
}
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Artificial Intelligence in PB?

Post by Caronte3D »

Do you have a PB code we can try?
Robeene
User
User
Posts: 15
Joined: Sun Aug 15, 2021 6:34 am

Re: Artificial Intelligence in PB?

Post by Robeene »

I wanted to do it in PB but I couldn't figure it out.
I had to use a provided code in C++ instead.
It's blazing fast.
I'm sure many people here could very easily convert the code to PB.
I have no idea but I think you need to use prototypes.
Way beyond my 1980's style of programming.
I had to learn a little C++ to modify the way it did the output and waiting for each output to be read.
Post Reply