Tuesday, January 19, 2010

Forming Sphere with Self-Learning Particle-Bots.

This simple program (with VB6 source code and compiled exe) sets the Confidence of the system on how well it keeps a radius of 4 from center of its 3D world.  It quickly learns to wander a sphere, or "sherical orbital" but these electrons do not travel as in an atom it is one step at a time on its surface.

Friday, July 4, 2008

Modeling ATOMS

Particles that flow with each others movement is nice, but not what an atom is. So here is the newest of the computer models, for our first simple atom!

Here we see a much better defined orbital, in this case a for the most part circular orbit in the particles innermost shell.

To achive this, paticles were made stationary so they did not move. Their rounded cube visual area (see below) was also divided internally into three shell areas as shown below, which in 2 and 3 are spherically calculated to remove squareness of cube from their path.

After the first shell shown in the first picture making more spherical shells does not leave a path all around due to edges being removed, but that is solved by later combining shell 2 and 3, or 1 and 2, depending on how you want to use them.

The loop is made confident going into the other particles inner shell, but not back out again. So it's drawn into its shell to for the most part stay. This way we make a very simple model of an atom with these If..Then.. statements.

'INSTINCTS are described by the following If..Then.. statements.
CnfChange = -1
'Is confident when moving through the three shells into 1.
If Dist1(N, 0) = 3 And Dist1(N, 1) = 0 Then CnfChange = 1
If Dist1(N, 0) = 2 And Dist1(N, 1) = 3 Then CnfChange = 1
If Dist1(N, 0) = 1 And Dist1(N, 1) = 2 Then CnfChange = 1
'Is confident when the second angle moving into shell 1.
If Dist2(N, 0) = 3 And Dist2(N, 1) = 0 Then CnfChange = 1
If Dist2(N, 0) = 2 And Dist2(N, 1) = 3 Then CnfChange = 1
If Dist2(N, 0) = 1 And Dist2(N, 1) = 2 Then CnfChange = 1
'Is confident when following the same shell around for some distance.
If Dist1(N, 0) = 1 And Dist1(N, 1) = 1 Then CnfChange = 1
If Dist2(N, 0) = 1 And Dist2(N, 1) = 1 Then CnfChange = 1
If Dist1(N, 0) = 2 And Dist1(N, 1) = 2 Then CnfChange = 1
If Dist2(N, 0) = 2 And Dist2(N, 1) = 2 Then CnfChange = 1
If Dist1(N, 0) = 3 And Dist1(N, 1) = 3 Then CnfChange = 1
If Dist2(N, 0) = 3 And Dist2(N, 1) = 3 Then CnfChange = 1
'Not confident when both distances are zero, meaning it sees nothing else
If Dist1(N, 0) = 0 And Dist2(N, 0) = 0 Then CnfChange = -1
'Loses Confidence when it is sitting still.
If Abs(XMR(N) - XMF(N)) + Abs(YMR(N) - YMF(N)) + Abs(ZMR(N) - ZMF(N)) = 0 Then CnfChange = -1
'Loses Confidence when hits the Wall, they Bump, or more than 2 neighbors.
If Wall(N) = 1 Or Bump(N) = 1 Or Greater2 = 1 Then CnfChange = -1

We can predict what that should do, and the model did it, which means we're already at a milestone. We have made our first simple atom, of hydrogen!

The next step is a matter of adding repulsion, to what is at the moment all attraction. Adding one more moving particle, to the one already there, has them meeting up then they go off dancing together. Atoms do have electrons that do this, they repel, so that must be added for the model to add more electrons in orbit, which could get interesting after the first two occupy the inner shell leaving the rest to find a less than circular orbit through, for more complex orbital geometries typical of atoms. Are one step at a time,

It uses 26 bits of RAM memory for the Main Memory, 67 megs total, which is not much for program size but be be patient if you save main memory since it's large for a disk file that comes out twice that in size due to how it saves the array. Or try to draw many at a time, since Visual Basic is wasting a great deal of CPU time doing 32 bit divison and more just to shift a bit that can be coded in Assembler to do superfast.

For highest speed possible, you need a MASM32 editor like this free one.

It is what the Intel (or clone) chip communicates in. Not another layer of software in between such as Visual Basic, C++, or others which can speed up development time by making writing and debugging easier. But the program runs slower since you're not directly communicating to the CPU, are going through the VB editor that goes through Windows to get to the CPU.

MASM32 is worth learning, coded for years in it. Easy one to learn. In the above download has a tutorial, data on all the instructions, and plenty of sample code to try out. Makes learning how to code in it, rather easy. In case you're interested in rewriting the Atom3D.frm program Visual Basic reads into Assembler, to see how fast it can go. With no super number crunching math like the physicists use in supercomputers, it should be like having a supercomputer inside our PC, with atoms that at times kinda have a mind all their own but are otherwise amusing. In time, possibly a better way to model some things.

Sunday, June 29, 2008

Particle In A Box Bots, Self-Learning 3D Lab with Visual Basic source

Virtual particles in a box are here shown coalescing into swirling entites where sometimes photons can be ejected out of orbits to become like a photon, or be in the form of a visibly oscillating wave with a frequency that depends on shape of the orbital. This program is actually beginning to model what it is that makes matter itself possible!

The zip file has all the files including including ParticlesInABoxBots.exe that will run on Windows PC just by clicking on it so you don't need Visual Basic to try it.
The code is in ParticlesInABoxBots.frm but begins with code that describes what's on the form like command buttons and picture box it draws in, with the Main Loop that everything happens in, at the very end of the file to be easy to find.A trained memory is not included due it being 16 megs which even zipped is too big to be worth waiting for. Have to wait a few days or more to even know what fully trained might be like, all that is known for sure is that what has been seen so far is awesome. And half the fun is in seeing the particles self-learn particle motion, which would not be seen happen if the program then started up fully trained. Would not display the many behaviors that can be trained into it, that are shown along the way sometimes by accident. For example what happens when unstable but still holding orbital configurations all at once fly apart ejecting each other into everything else for a major fission reaction that has all of them full speed bouncing from wall to wall over and over again and straight line at each other the chaos in the middle slows down projectiles trying to get through an increaingly swirling mass that in a sense swirls itself back to orbitals then it all goes relatively still again.
Might be that how they end up, reflects our personality. Someone aggressive might take their frustions out on the particles by sqeezing them in a world size so small they're like in an infinite horse power trash compactor. While some who are very peaceful might give them plenty of room so they make nice freeful orbits, not ones that look all squished.

A particle such as an electron would not be randomly bouncing off the walls or moving in regular straight lines. Be impossible to say for sure where it is, but what it is shaped like can still be mapped out as in Schrödinger's equation by showing where the probability of finding an electron in orbit would be, by drawing dots where it more likely to be at any given moment. From that these drawings are made showing orbital shapes like these.

Wikipedia helps say in their page on atomic orbitals that these pictures do not accurately depict reality, where the orbits are being stretched, bent and twisted all the time. And there are electrons being shared sometimes in very complex and like in metals constantly flowing around in an organized chaos. The Particle In A Box Bots learn this organized chaos. Not by crunching Schrödinger's equation. The particles self-learn the behavior of particles in motion. All of the complicated math governing motion of particles in 3D space, is this in the start of the RunMotors subroutine with these three equations:

Xm = Xbot(N) + YMF(N) - YMR(N)
Ym = Ybot(N) + XMF(N) - XMR(N)
Zm = Zbot(N) + ZMF(N) - ZMR(N)

Xm,Ym,Zm is the variable the calculation is first being stored in. The X,Y,Zbot(N) is it's current location in 3D cube. The other two variables in each of the three equations end up adding or subtracting one, or doing nothing. Since there are 3 axis in the 3D system Motor Forward and Reverse bits X,Y,ZMF(N) and X,Y,ZMR(N) are either a 1 or a 0. Stopped is when both are either a 0 or a 1 because 0-0=0 and 1-1=0 so either way the current bot location remains unchanged. Direction is then a matter of whether it was 1-0=+1 or 0-1=-1 and since it exists in a on a grid like array the fastest an ejected electron (photon) can travel in such a virtual reality is exactly 1 or -1 which makes the math in this case easy to remember. Since there are two codes to stop the motor, either 00 or 11, the 11 can be used for the bot to do something instead of stop. I am not sure what use it might have, but otherwise, having two codes for Stop is an unnecessary waste of a good amount of memory space. And you can't make a 3 code Forward-Stop-Reverse with less than two bits without compressing all three axis which total bits, into 5 bits, which helps save memory but the 5 bit is not used up either so there is still wasted space. Is best to look for something in the physics of particles in motion where there is something in addition to Forward-Stop-Reverse to hook up to it. The Memory Address that it hooks in to, is shown below.

Private Sub FormMemoryAddress(N As Long)
Addr(N) = XMR(N) + (XMF(N) * 2) + (YMR(N) * 4) + (YMF(N) * 8) + (ZMR(N) *
16) + (ZMF(N) * 32) + (Wall(N) * 64) + (At1 * 128) + (At2 * 32768) + (Greater2 *
End Sub

Setting XMR() and XMF() both to 1 whenever the condition to be added is detected, brings it into the Address, which by nature of it always changing in response to environment, can be thought of as generating a sequential experience of one memory at a time. Yet there is no counter to count through each experience one frame at a time, it's in the environmental sensors constantly changing. Even though this is a simple model with a modest one byte per address 16 megs of memory space it's surprising how long it will go on forming new memories. It has nothing in comparison to the number of networked neurons in a brain, but the 24 bit Address space the PC uses, results in a very large number of experiences. That's about 6 days at 32 frames per second, not counting confidence changes and trying something new with a new guess in response to confidence in a memory declining to zero.

And even though to some, the entities formed inside the 3D cube might look more like another Flying Spaghetti Monster Sighting, it has the Particle In A Box analogy right down to infinitely impenetrable. Can either stick, or bounce off. The Wall(N) bit which is 1 when hitting, 0 when No Wall, has to be included in the Address to prevent particles from turning into forever flashing red circles that never go anywhere after that. With the Wall(N) bit included in the memory addressing, a unique Data byte for every time that happens, is there to be taken in response to it. The Environmental Input influences the Action Output then back again in a way that it stimulates its own learning.
Each particle senses up to 2 other particles around itself in 1 of 250 locations inside a spherical field as shown below.

Even though looking at this much of an array space on each move is a slow process with Visual Basic in comparison to what is fastest, he program can still do a good number of particles at a time. You will have to keep the number down to how fast your computer and graphics are or it can become very slow. Large numbers meant to run without trying to draw it to screen. Visual Basic is ideal for showing how this self-assembly works, but will need to rewite in MASM32 to go as fast as a CPU can go, which should be around 1000 times faster. Is still fast enough, even a surprise Visual Basic does as well as it is, even if it's then in the future possible to go much much faster. You can save your own BotMemory.bot memory file so the program will load what you trained, before starting back up again. Rename or delete BotMemory.bot if you later want to retrain the Particle In A Box Bots from scratch all over again.


Wednesday, June 4, 2008

Self-Learning in 2D


A very fast (computing time) self-learning mechanism is here taught the basic behavior of interacting particles such as atoms or molecules. Running on one of the first GHZ Pentiums, even written in BASIC, the model achieved 22500 moves per second. It was written in Visual Basic VB6 with the source code available by emailing GaryGaulin@aol.com for latest version. May in time include here.


Shown below are 500 constantly moving "Bots" as they are called due to their being most like a robot in the way they navigate their environment, after first being introduced to their virtual 2D World.

There is an invisible wall (shown in Red) that contains them. Hitting the wall sets a bit which is used as part of the Address at which each Memory is stored. Bumping another bot already there, is trying to occupy the same space as something already there. Unless this is detected then applied to its learning it will do this. Therefore this is one of the behaviors that must be self-learned for it to successfully model particles which cannot occupy the same space at the same time.

The behavior is defined by this If..Then.. sentence.

If Wall(N) = 0 And Bump(N) = 0 Then CnfChange = 1 Else CnfChange = -1

When not hitting or bumping another the Bot has a positive confidence which can keep rising until it reaches the max of 3. When it goes down to zero it takes a random guess what to do next, until it finds a solution or gives up after 50 guesses in which case it is stuck and cannot move anywhere.After several
hours of training they began to aggregate into groups that together maintain complex motions that more or less allows them to stay in one place.

What it learns is stored in a 65 megabyte array, with one 8 bit byte of data at each memory location. The memory is addressed by combining the environmental conditions that it can sense into a 26 bit number (hence 65 meg required) with the following code. The lowest Environment bits see other Bots around itself, in a 5x5 cube (except four corner location to make more circular) which each Bot updates its position in, every time it moves to a new location. In this way they see the other Bots that are around them.

'Form unique number corresponding to positions of other Bots seen.
E1(N) = Bot3D(Xm + 0, Ym - 1, Zm)
E2(N) = Bot3D(Xm + 1, Ym - 1, Zm)
E3(N) = Bot3D(Xm + 1, Ym + 0, Zm)
E4(N) = Bot3D(Xm + 1, Ym + 1, Zm)
E5(N) = Bot3D(Xm + 0, Ym + 1, Zm)
E6(N) = Bot3D(Xm - 1, Ym + 1, Zm)
E7(N) = Bot3D(Xm - 1, Ym + 0, Zm)
E8(N) = Bot3D(Xm - 1, Ym - 1, Zm)
E9(N) = Bot3D(Xm + 0, Ym - 2, Zm)
E10(N) = Bot3D(Xm + 1, Ym - 2, Zm)
E11(N) = Bot3D(Xm + 2, Ym - 1, Zm)
E12(N) = Bot3D(Xm + 2, Ym + 0, Zm)
E13(N) = Bot3D(Xm + 2, Ym + 1, Zm)
E14(N) = Bot3D(Xm + 1, Ym + 2, Zm)
E15(N) = Bot3D(Xm + 0, Ym + 2, Zm)
E16(N) = Bot3D(Xm - 1, Ym + 2, Zm)
E17(N) = Bot3D(Xm - 2, Ym + 1, Zm)
E18(N) = Bot3D(Xm - 2, Ym + 0, Zm)
E19(N) = Bot3D(Xm - 2, Ym - 1, Zm)
E20(N) = Bot3D(Xm - 1, Ym - 2, Zm)
'Add the motor direction to the number. Two bits each for X, Y.
E21(N) = LMR(N)
E22(N) = LMF(N)
E23(N) = RMR(N)
E24(N) = RMF(N)
'Add unique experience for Bumping and hitting Wall to memory.
E25(N) = Bump(N)
E26(N) = Wall(N)

All of the above Environment bits are turned into a single Address:

MemAddr(N) = E1(N) + (E2(N) * 2) + (E3(N) * 4) + (E4(N) * 8) + (E5(N) * 16) + (E6(N) * 32) + (E7(N) * 64) + (E8(N) * 128) + (E9(N) * 256) + (E10(N) * 512) + (E11(N) * 1024) + (E12(N) * 2048) + (E13(N) * 4096) + (E14(N) * 8192) + (E15(N) * 16384) + (E16(N) * 32768) + (E17(N) * 65536) + (E18(N) * 131072) + (E19(N) * 262144) + (E20(N) * 524288) + (E21(N) * 1048576) + (E22(N) * 2097152) + (E23(N) * 4194304) + (E24(N) * 8388608) + (E25(N) * 16777216) + (E26(N) * 33554432)

It adds them together, in power of twos, to derive a number from 0 to 67108863 that describes what it is sensing from its Environment.

Since 26 bits is a large number of different experiences, it can take days for it to have seen everything. After that, memory changes as it may find a new strategy used what once didn't work.

There is no mechanism for taking one memory at a time, yet the large number of possible memories gives it an experience that changes over time. It may after long get set in its ways, do the same thing over in an endless loop that keeps the bots in the center not hitting each other or the walls. But otherwise, it achieves an experience over time in the process of new sensory information being presented over a long period of time.

At some point there will be a trained memory that can be saved with a new file name, to be used as a read-only to model that behavior. In this example they only have to not hit walls or each other to demonstrate the most basic behavior of this mechanism. But the If..Then.. shown above can be added to, for other behaviors.

Shown below is an electronic schematic circuit of the bot this (group intelligence) version started from.


This 2D vrsion showed that this self-learning mechanism works well for what can best be described as moving particles. With a large number being possible at a time, 3D is now being attempted to model Atoms. At that level, there are a small number of atoms that need to be simulated for it to form any molecule, wjhich reduces number of behaviors needing to be taught to a small a number as possible. With their being trillions of different kinds of molecules, a memory for each one is not even possible. But having a large number of realistic atoms running at a time.

One bot will represent one electron in the outer shell. The shape/size of the confinment space it is trained in, will reflect the actual radius of each atom. The path that the internal bots take, reflect energy state, valence, spin up or down, etc.. Bond sites bots that appear at the surface, conforming to a behavior that makes them attractive to what is in a condition to bond to it.

Photon or electron bombardment would be bots (already seen is behavior) that travel in a straight line that can be captured in the swirl of a group (atom), raising its energy state by it being present in the moving configuration, to at some point be released which brings atom back to the stable ground state.