I want to use PB for AI projects

Everything else that doesn't fall into one of the other PB categories.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

I want to use PB for AI projects

Post by Psychophanta »

I have been searching info about AI and neuronal networks in the web, and all sites sell it, sell AI related courses, or give book titles. So then, secret continues for people who don't want to waste money for knowledge. Any help will be grateful!



AL
BalrogSoft
Enthusiast
Enthusiast
Posts: 203
Joined: Sat Apr 26, 2003 6:33 pm
Location: Spain
Contact:

Post by BalrogSoft »

hi, i make a little dll library, to use basic neural networks on pb, the source code is included, it could help you...

http://www.balrogsoftware.com/kosas/nnwork.zip

bye...
DominiqueB
Enthusiast
Enthusiast
Posts: 103
Joined: Fri Apr 25, 2003 4:00 pm
Location: France

hi

Post by DominiqueB »

In the sample, you forgot to change the dll name from purebasic.dll to nmwork.dll .
Thank's for sharing.

Dominique.
Dominique

Windows 10 64bits. Pure basic 32bits
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Thank you for share it, Balrog.

It is useful for me.


AL
LJ
Enthusiast
Enthusiast
Posts: 177
Joined: Wed Apr 30, 2003 4:00 pm

Neural Net Programming

Post by LJ »

@Balrog:

A PC computer is not a neural net, I often find educated programmers making this error. Your PC is an evolved Turing machine. A neural net is a neural network.

A neural network is a collection of electronic neurons which mimic the behavior of the brain. Each time a neural network makes a correct choice, the circuits are reinforced by changing the "weights" of each neuron. Each time it makes an error, the connections are deemphasized.

Neural networks still have a long way to go before they can model the human brain.

At MIT, Hopfield found that where the atoms are tightly bound in a lattice structure, there are simple organizing priciples given by the quantum theory. Hopfield asked himself whether the array of atoms found in a solid are smiliar to the neurons in the brain. Can a neuron in the brain be treated like an atom in a lattice? Hopfield when on to refute the top-down school that the "mind" was an incredibly complicated program inserted into a large computer. Hopfield suggested that intelligence might arise from the quantum theory of mindless atoms, without any programs whatsoever!

Hopfield's research showed that each atom in a solid is spinning and can exist in a few discrete states, such as spin up or down. Similarly, the neuron also exists in discrete states: it can fire or not fire. In a quantum solid, there is a universal principle that determines which state the system prefers--i.e. the atoms arrange themselves so that the energy is minimized. Hopfield's discovered that a neural network circuit must also minimize its energy.

Hopfield, using the broad principles of the quantum theory, found that all neurons in the brain would fire in such a way as to minimize the "energy" of the net. "Learning" is the process of finding the lowest energy.

Hopfield went on to find that his neural nets exhibited unexpected behavior which mimicked actual brain functions. He found, for example, that even after the removal of many neurons, the neural network behaved pretty much the same.

Another by-product was that it neural nets gave an interpretation for obsessions. Sometimes, if you weren't careful in preparing a neural net, a particular valley might become so large that it ate up all the neighboring valleys. Then the signal would inevitably fall into this gaping hole. This may be just what happens in the case of an obsession.

The strangest by-product of neural nets was totally unexpected. He found that his neural nets began to dream.

To Hopfield, dreams are fluctuating energy states in a quantum mechanical system. Hopfield discovered that his neural networks reproduced many of the properties of dreams identified long ago be psychologists, who found that we need to sleep and dream after a series of exhausting experiences. He foudn that if he filled a neural net with too many overload i.e, (valleys), then the system began to malfunction from overload-- i.e, the amount of time it took to access different memories began to become increasingly unequal. It began to malfunction in recalling previously learned memories. In fact, unwanted ripples began to form on the surface of the terrain that did not correspond to any real memories at all. These ripples are called "spurious memories" and correspond to dreams.

One of the first commercial applications of neural network theory is a bomb detector for airlines that can seek out certain chemicals, like plastic explosives, which are usually invisible to X-rays. Luggage is first flooded with neutron radiation, which is absorbed by the explosive. When the explosive then emits a distinctive gamma ray, the neural network machine can recognize that pattern and sound an alarm.

In contrast to the traditional top-down computers (i.e., using IF statements) you do not program these machines. "You train the system rather than program it" says Barbara Yoon, program manager for artificial neural network technology at the Defense Advanced Research Projects Agency.

Mead was the first to put a Hopfield neural net on a silicon chip. Using transistors and standard chip-making devices, he crafted a 22 neuron chip that demonstrated Hopfields ideas.

At MIT, what is done with those green to the study of A.I. (i.e. Top Down versus Down UP), is that the instructor gives students 1 week to debate the different approaches.

There are always a few students who refuse to except that a PC (evolved turing machine) with it's 0 and 1's can't simulate a neural network. Grounded in their own individuality and desire to be unique, with their almost religious belief that a computer can simulate with 0 and 1's anything reality has to offer, they are humiliated when forced to put up or shut up as the instructor now desires to move the class forward into the advanced studies of top down, bottom up schools of thought, complete with a tour of the MIT "Things that Think" lab. The instructors achieve this by simply asking these delusional students to create a program that learns without any IF statements. Some stay stubborn and drop the class and start their own web sites claiming to have code that perfectly emulates a neural net, of course using IF statements..lol..

Suffice to say, you don't need a neural net to have A.I. like responses in your game/program. As long as a language allows you to manipulate GATES (AND,IF,OR,NOT,NOR,etc..) you should be able to create some great A.I. programs.

We must be correct when we use the term neural net that we do not use it interchangeably with the term A.I., for while few on this web site would notice, should you produce a commercial program and advertise it as a neural net, you will surely be scorned to death, and probably sued if you were not to refund your customers.

As far as purchasing Neural Net chip sets, check this out:
www.citi.qut.edu.au/research/sdl/projects/lcnn_chip.jsp

This is cool as well:
www.musicindustries.com/axon/neuralnet.htm

And please, no flames. You probably need to read this message at least 3 times before you even think of responding to it. Remember, neural nets learn without any programming at all. How? Atoms are tightly bound in a lattice structure and their behaviours are simple organizing priciples given by the quantum theory without any programs whatsoever! (This is the "bottom up" approach to AI theory.)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Hello, LJ, and Balrog.

What about an small tutorial about AI and neuronal networks in order to beginners in that matter to know enought to be able to start programming something with it? For example OCR, etc...

A PC is not a neuronal network, but some of newest games for PSX2, XBOX, etc. include AI staff.
So then, neuronal networks can be "emulated" or "simulated" by a PC, don't?


AL
BalrogSoft
Enthusiast
Enthusiast
Posts: 203
Joined: Sat Apr 26, 2003 6:33 pm
Location: Spain
Contact:

Post by BalrogSoft »

hi...

first, i only make a implementation of the neural networks to Pure basic, i dont say nothing about AI, i dont say AI as neural networks.... please read the previous posts, only a user ask about AI and neural networks and i post a little program that show simple perceptron neural network...
A PC computer is not a neural net, I often find educated programmers making this error. Your PC is an evolved Turing machine. A neural net is a neural network.
yes, its right, silize, the material of computers are made dont are carbono that have some chemical propieties that other elements dont have... and brain works with chemical reactions... about Turing machine, i dont understand very well what are you saying...
Neural networks still have a long way to go before they can model the human brain.
well, i dont want to model the human brain, and think that neurones exist on ALL animals... a neural network dont must think to be usefull...

about hopfield, i dont say anything because you are using some technicals words, im spanish i dont understand very well....
Suffice to say, you don't need a neural net to have A.I. like responses in your game/program. As long as a language allows you to manipulate GATES (AND,IF,OR,NOT,NOR,etc..) you should be able to create some great A.I. programs.
yes, its right, you dot need nnworks to have ai, but neural networks have the facility to generalize patterns... is very usefull for pattern recognition... a lot of OCR programs use neural networks... in another sites i read that on a experiment with neural network was able to learn grammar as a children of 6 years old... my example show how make the recognition of a logic gate, but can be used to some pattern recognition... i dont say that its the best method to make something, i only a coder that read something about nnworks, and make a version for PB...
kns
User
User
Posts: 54
Joined: Sat Apr 26, 2003 2:06 am

Post by kns »

As this is a Basic forum, you may wish to have a look at
Neurobasic (http://www.ife.ee.ethz.ch/neuro/).

Additionally, tutorial material may be found with any number
of freely available simulators (e.g., SNNS, PDP++). Presumably,
with some work the compiled libraries from the mentioned simulators
may be accessible from Purebasic. I don't know for certain. I do know
however that the kernel from SNNS can be compiled with at the very
least any GCC port to DOS/Windows.

A postscript version of Kevin Gurney's book is available at
http://www.shef.ac.uk/psychology/gurney/notes/.

KS
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

@LJ
Nice reading, thanks. :)
LJ
Enthusiast
Enthusiast
Posts: 177
Joined: Wed Apr 30, 2003 4:00 pm

Psycho

Post by LJ »

@Psycho,

AI is an art form and teaching art is very challenging. AI simply stands for artificial intelligence, so anything is exceptable as long as it falls under this very broad definition.

I'm going to make something up here. I'm going to add AI to a program I wrote. The program is a process thread lister. One of the AI features I'm going to add to it is that I'm going to have the program attempt to ascertain if the user is becoming frustrated with a certain instruction, and if so, I'm going to attempt to calm them down by fixing the problem.

Here is the art form of AI, how I do it. Using my imagination like an artist painting on a canvass, I come up with one AI routine. The purpose of this routine is to monitor the keyboard. If lots of keys are pushed at the same time, I'm going to make the assumption the user is pounding the keyboard. But it could be my cat walking across the keyboard, or my dust cover stuck to one edge of the keyboard. So I'm going to add 1 to the frustration variable and then I'm going to have another AI routine watch the mouse. If the mouse goes up to the toolbar on the Window and the user selects at least 3 different categories, I'm going to make the assumption that the user is searching/scanning for some information and so I'm going to add another 1 to the frustration variable. I'm going to create another AI routine that monitors the Help selection. If the frustration variable is greater than 1, and if the user selects Help, then exists, then selects help again within 1 minute, I'm going to add another 1 to the frustration variable. My final AI routine is going to monitor the frustration variable, if the frustration variable is greater than 3, I'm going to make the assumption I have a frustrated user and I'm going to pop up a little help wizard that Lists the topics closest to the input from the keyboard the user put in the last 2 times they went into the Help selection.

Now of course I just made this all up, I probably wouldn't really do this. But this is the revolution that is taking place in the computer programming industry, namely to use AI to make the computer fit the user rather than the approach of 20 years ago which was the opposite --to make the user fit the computer.

This is possible because of the vast amount of memory and processing power we programmers now have at our disposal.

And so the art of my AI, the foundation of my AI came not from learning programming code, but instead from my imagination in creating an ever greater user friendly, artificially intelligent product.

Everything I mentioned above can be done with simple IF statements and has nothing to do with neural networks.

Another form of AI is game AI. The movement of computer controlled characters in a FPS game. Games of old had limited memory and so programmers created characters (like Doom) that got stuck on the corners of walls, etc... Now computer controlled characters don't get stuck on walls and in fact move very much like a human would control them, like Quake 4. And so the art in this becomes how do you make a computer controlled character move like a human was controlling it? Use your imagination. How would you do it? Perhaps create an AI routine that monitors the position of the computer player in comparison to x,y, and z world coordinates of the map. If the computer player gets very close to a wall, increase the x movement, decrease the y, and hold the z value if the last movement was a y movement that caused the player to strike the wall: x = x + 1: y = y - 1. Is there another way to have a computer controlled character move like a human? Use your imagination, can you come up with another way? What about having a motion spline pre-set for the computer player? This way the character always moves along a spline path and that path never brings the computer character to close to a wall. Create a AI routine that has 10 or 20 spline paths and depending upon the location of the computer character, load that spline path into the characters future motion buffer. Is the character at world location x, y, and z? If so, load motion spline 7 into the computer character. Is there another way to have a computer controlled character move around like a human and not get stuck on any walls? What about nodes that are invisible and scattered around the world. The computer character randomly moves in some direction by always does a SIN curve to the next node. Once a character reaches the node, there is another node it begins to move toward. These nodes are invisible to other characters in the game and act like destination beacons and are only there for the AI routine to control the motion of the computer controlled characters. Is there another way to do this? You bet. I challenge that there is almost an infinite number of approaches that can be used, or combinations of approaches.

What about AI security routines? Can you do AI for an e-mail program? Sure. AI can be done for anything. What about an AI program that filters out spam? Or what about an AI program that automatically loads your e-mail program into a hidden Window when you load your browser and then the AI monitors your browser to see if you click on the E-mail button. If you click on the E-mail button, the hidden Window becomes visible and POOF, instant e-mail: in essence an AI cache.

Or how about AI in this very message you are reading on this message forum. How about instead of having to click on Code to insert your code, the AI routine running on the web site that hosts this message board scans your message for all of the recognizable Purebasic code and automatically puts the code brackets around your code in your message for you. Can you think of some ways this might be done?

And so, AI is not so much about neural nets, or lots of IF statements, rather it is an art form of perspective based on the endless limits of the human imagination. As the painter needs to learn to use his paints and canvas, so does a programmer need to learn to use his computer language, but what happens next is the magic of the imagination, and that is when the artwork becomes complete.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

o)_o)


I have been reading docs about AI and introductions for neural nets courses.
I have tested Balrogs dll, and i've read carefully his .txt
Result: I don't understand a word of all. :!:


I remember a silly man who defined intelligence as the ability of adapt to external medium. 8O
Haha! then, if all the people was intelligent, who could change values on the world?
That is a perfect definition of a herd, not of intelligence.

Intelligence has no goals in itself.
Intelligence definition is the ability to understand; that's all.
After this, of course, different ways of interpretation of an intelligent organism can be found depending on considerations of other intelligent organisms.

When a programmer do something with a computer, he is looking for a goal to do with that tool (the computer).
To look for a goal each moment is not the mission of intelligence.
Intelligence has no missions. It is a capacity, a talent, a character.
How can i do a not biological machine learn and reason "freely"?
How can i do a not biological machine build its own goals "knowing" and "processing" (interpreting) as much as possible external data?


AL
LJ
Enthusiast
Enthusiast
Posts: 177
Joined: Wed Apr 30, 2003 4:00 pm

Hmmm...

Post by LJ »

Alright now you just plain getting psycho Psycho :D

You write this:
To look for a goal each moment is not the mission of intelligence.
Intelligence has no missions. It is a capacity, a talent, a character.

We are not talking about a mission of intelligence, that's non-sense. We are talking about ARTIFICIAL intelligence.

Second, what you are talking about above has nothing to do with artifical intelligence but instead consciousness. You want code to make a computer conscious, hence you write:
How can i do a not biological machine learn and reason "freely"?
How can i do a not biological machine build its own goals "knowing" and "processing" (interpreting) as much as possible external data?

Now you are talking pie in the sky, earth to Psycho, come in Psycho. Ground your thoughts my friend, bring it down to earth, to practical reality.

I'm out of this silly conversation, you guys have fun.
Lj
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Unfortunately you are right, i must be defeated to the real evidence of nowadays.

Intelligence might or might have not goals, and anyway goals would be a consequence of it.
But some people "put" on intelligence an obligatory goal. :x

Well, lets leave this conversation, because this is the PB forum.
Lets resign to try to do what is in our hands (which is enought). :?

Anyway, any other AI code in PB like Balrog's one should be welcomed by me. :D

AL
BalrogSoft
Enthusiast
Enthusiast
Posts: 203
Joined: Sat Apr 26, 2003 6:33 pm
Location: Spain
Contact:

Post by BalrogSoft »

hi...

Im sorry for the documents of the library, but im spanish, and write a technic documment on a foreignlanguage can be dificult... but i will try again...

Neural networks

Neural networws is a system to simulate a neuron behavior, a neurone is a cell that transfer information inside animals brain and nerves, all neurons compose the nervous system.

On the year 1948, Warren Mc Colluch and Walter Pitts, made a mathematic model of a neuron. This mathematic neuron have a group of line inputs for information (dentrites, see picture 1), and one line for output(axon, see picture 1), every input have an associated 'weight', that means the importance of this line. See figure 1, it shows a neuron scheme, where 'w' represent the weights of every dentrite.

Image

How work a neuron?

How to know if a input of information gets an answer? to know this(see code *), you must multiply the dentrite input with its weight, then we must add this values, if the result is greater that a value(called U), we get an answer on the axon(see code **)... with this algorithm you can simule any logic function, such as OR, or AND, but a artificial neuron can learn at the moment (later i explain how to make learn to a neural network). To simulate AND function you must set inputs only binary values (0 or 1), and set U=1 and w1=w2=0.5, with this values we get an output when the two inputs are 1, otherwise we get a 0.

How neural networks learn...

On 1949, Donnald Hebb exposed the Learning law. It says when two connected neurons are activated at the same time, the weight of the conexion between this neurons grows, otherwhise decrease.

Single layer perceptron...

A single layer perceptron its a group for artificial neurons not connected, it means that every input of the system are connected to all neurones getting an independent output (see image 2).

Image 2
Image


To make learn to a single layer perceptron, we can use three learning methods: supervised learning, by refoircement, and not supervised, i use supervised mode on my library.

Supervised learning:

This method set inputs to perceptron, getting an ouput, and knowing the correct input, we must adjust the weights to get the correct output, if the difference between the neural network output, and the correct output is null, the weights arent modified(see code ***).

When the outputs are aproximated to the outputs that we need, you must save the values of the weights, and the use this
weights on the program that you will use, but an high number of inputs isnt recommended, because then the neural network dont
learn only memorize, the neural networks are good to generalize any unkowned input to a similar knowed input...

The source code of a neural network learning AND function:

Code: Select all


; First we initialize the variables

MaxNeuralNetNumber=1
MaxInputNumber=2
InputNumbers=2
InputComb=Pow(MaxInputNumber,2)
Dim W(MaxNeuralNetNumber,MaxInputNumber)          ; this is the weights
Dim Net(MaxNeuralNetNumber)                       ; this is the output for the neurals network
Dim Output(MaxNeuralNetNumber)                    ; if the Net is greater than 0 the output gets 1
Dim Inputs(MaxNeuralNetNumber,MaxInputNumber)     ; this set the inputs for the neural networks
Dim InputImportance.s(MaxNeuralNetNumber,Inputcomb) ; input importance is for the supervised learning
                                                  ; and say to the neural network that this input 
                                                  ; must gets an output

W(1,0)=1                                          ; we set a first values for neural networks
For Weights=1 To InputNumbers                     ; exist also W(1,0) but this line is only to make more easy
  W(1,Weights)=Random(5)-3                        ; calculations
Next Weights

Ta.f=0.8                                          ; Ta.f is the learning constant, and must be between 0 and 1
                                                  ; you can think that when this value was higher would be 
                                                  ; better, because you can think that it can learn more faster
                                                  ; but usually not, a high value can make that weights of the 
                                                  ; neural networks change very faster, and dont get the 
                                                  ; optimal value.

InputImportance(1,1)="000"                        ; We set the input importance to learn AND function, it have 
InputImportance(1,2)="010"                        ; this form "IIO" where I are the inputs bits, two in this case
InputImportance(1,3)="100"                        ; and O the correct output, its like teach a dog
InputImportance(1,4)="111"                        ; to make something, we give two bits, you try that the dog
                                                  ; make something and if it made correct we give a cookie
                                                  ; but we give to the neural network 1( a binary cookie ),
                                                  ; the correct output.
OpenConsole()
For Rep=1 To 80
Inputs(1,1)=Random(1)                             ; set random inputs for two bits
Inputs(1,2)=Random(1)


; *
Net(1)=W(1,0)                                     ; and we get an output for the net
For In=1 To InputNumbers
  Net(1)+(Inputs(1,In)*W(1,In))
Next In

; **
If Net(1)=>0                                      ; and if Net its greater than 0 we get an output
  Output(1)=#TRUE
Else
  Output(1)=#FALSE
EndIf

PrintN(Str(Inputs(1,1))+Str(Inputs(1,2))+" - "+Str(Output(1)))

; ***

InputComb=Pow(InputNumbers,2)                                  ; this is the learning part, first we get all input posibilities
Input.s=""
For In=1 To InputNumbers                            ; we get a string with the inputs like in input importance
  Input.s+Str(Inputs(1,In))
Next In
For In=1 To InputComb                                   ; and we check with our predefined inputimportance to 
  If Input.s=Left(InputImportance(1,In),InputNumbers)              ; get the correct defined ouput
    InputImportance=Val(Right(InputImportance(1,In),1))
  EndIf
Next In
Increment=InputImportance-Output(1)                     ; get the difference of the output of the net and the correct output
For In=1 To InputNumbers
  W(1,In)=W(1,In)+Ta.f*Increment*Inputs(1,In)           ; and get the new weights
Next In
W(1,0)=W(1,0)+Ta.f*Increment

Input()
Next Rep
CloseConsole()
Bye...
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Theres a nice Neural Network tutorial here. Nice and simple for the beginner.

The examples are in Python, but you should be able to convert to PB easy enough.

http://gnosis.cx/publish/programming/ne ... tworks.htm
Post Reply