Changing Network

Blitz3D Forums/Blitz3D Programming/Changing Network

Heliotrope(Posted 2013) [#1]
I have being looking at tree networks in university maths, and I was looking at writing some code that can change and self-regulate a large network. The rules are ...

1. The more a path is used the more weight that it is given and the more connections it can make.
2. The less a path is used the weight is taken away.
3. The weight and connections in a path equal the likelihood of it being used.

Does anyone have an idea or be able to refer me to anything that has already being done.


Yasha(Posted 2013) [#2]
Sounds like you should start by reading about neural networks, natural and artificial. There's some simple code for B3D in the code archives, although I don't know how good it is (it was written by a known AI crank, so probably not); at lest one person - NateTheGreat I think - has made working learning bots with BlitzMax too.

There is a vast amount written on this subject, but little for the BRL languages since they have no dedicated features for this kind of work (and the strong focus on games means usually you don't want a learning system in B3D).


Kryzon(Posted 2013) [#3]
I hope these are useful:

Evolution of Corridor Following Behavior in a Noisy World

Motion Planning Using Potential Fields

(GameDev.Net Artificial Intelligence - Archive)


Heliotrope(Posted 2013) [#4]
Yasha, if BB isn't good for this, then what language do you suggest.

Kryzon, I wasn't thinking of path finding but rather a program that mimics the neuro-plasticity of the brain. The program is meant to control a bunch of text files than mimic the connections of the neurons.


Yasha(Posted 2013) [#5]
Oh I don't think it requires special languages features that B3D doesn't have as such, just that you'll need to be willing to at least read other languages in order to understand the work that's been done on this in the past. There's more than you can read in one lifetime, but none of it's been done in Blitz. Yet.

Traditionally AI work has usually involved Lisp or Scheme. I don't think there's any specific reason for this other than that the people who like AI work tended to also like writing in Lisp.


You should look at this chap's code: http://www.blitzbasic.com/codearcs/codearcs.php?code=2609

It actually works, which is always a fine start. The original is in BlitzMax, but if you don't have access to that someone did a B3D conversion further down the thread.


Heliotrope(Posted 2013) [#6]
I've had a bit of a look around, and I get that the output is f times the sum of the weights and the inputs.
But how are the inputs determined, what is f and how does the output feed into the inputs of the next node. Or have I got it wrong.

I think the main problem is that there is no practical code demonstrations in sight. If you know of any pseudo-code can you please show me. Thanks.


Yasha(Posted 2013) [#7]
f is a function to be applied to the sum of the weighted inputs.

How the inputs (to the starting nodes) are determined? Magic. This is application-specific. There is no guideline for this and it is not a part of the network. Simple examples might be pixels, if processing an image, or bits, if processing a binary value.

What is f? Again, magic. Usually a sigmoid function. It could be something else, or it could even vary per-node. Hell, it could be a learning network of its own. The simplest starting point might be to simply use a rounding function.

How output feeds into the inputs of the next node? Directly, usually. The output value is just sent directly to the input slots of whatever it's connected to. Multiple nodes using it as input mean it gets copied (this means the total "value" of the network increases; imagine it as a pulse propagating).

Simple neural networks tend to be static; how to choose when to drop connections and when to form new ones is a whole additional layer of complexity. There's also the issue of learning (weight/connection adjustment), which is also a separate mechanism from simply producing a result.


Practical code demonstrations of this are difficult because it's not an algorithm, it's just an extremely loose mathematical concept. Actually seeing pseudocode likely wouldn't help you at all, because there isn't "a way" to do this; all the pseudocode would tell you is stuff about how it was integrated into some other application that you don't want and will then have to unpick the abstracts from. The magic lies in the math, not in the code.


Best I can suggest is to start at Wikipedia and go from there. There's no shortage of material; millions of pages have been written on this subject.


Heliotrope(Posted 2013) [#8]
using - http://www.idsia.ch/NNcourse/linear1.html and http://www.idsia.ch/NNcourse/ann-overview.html
Can you explain how I would input milk prices and volumes, then determine the best one to buy.


http://www.cse.msu.edu/~cse802/notes/ArtificialNeuralNetworks.pdf
On page 34 can you please explain the placement of the operators in the equation that has the sigma in it. I dont get the second half of the equation - ((sum of input > j = 1) x weightj x inputj).


Yasha(Posted 2013) [#9]
Sigma is the summation operator. The expression means something like:

for j=1 to n
    sum = sum + (weight(j) * input(j) - THRESHOLD)
next
y = step(sum)


(The capital sigma used in this notation has no connection to the "sigmoid function" referred to further down; just a coincidence that they're both named after the same Greek letter.)


Heliotrope(Posted 2013) [#10]
Is this it.

Graphics 640,480
SeedRnd MilliSecs ()
inp1 = Rnd (-5,5)
inp2 = Rnd (-5,5)
wgh1 = Rnd (-5,5)
wgh2 = Rnd (-5,5)
threshold = 4
fired = 0

sum = (inp1 * wgh1) + (inp2 *wgh2)

Print sum
If sum > threshold Then fired = 1

If fired = 0 Then Print "Not Fired!"
If fired = 1 Then Print "Fired!"
WaitKey ()

End


the sum of the inputs and weights is checked against the threshold.


Yasha(Posted 2013) [#11]
That's one way of doing things.

However, you're using "threshold" as an activation check - in the example, it's being used to modify each input as they come in. Doing it that way makes it possible for inputs below the threshold to have a negative effect on the whole node, rather than just failing to help it fire. The activation function is then a separate thing that might be a simple threshold test, or might be something more complicated (and could potentially output floats).


Heliotrope(Posted 2013) [#12]
So the threshold function changes the inputs.
Am i correct?
If so can you give an example.


Yasha(Posted 2013) [#13]
Actually now that I look at your version more closely you don't need it because you're generating random numbers that could be negative: the equivalent using the threshold constant would be to generate them between 0 and 10 with a threshold of 5, and you'd get the same values out. The example in the article is assuming only input values between 0 and 1, so it needs a modifier to get negative values - yours already has that.

(However since your output is always 0 or 1, you can see that you'd need to add this step explicitly if you were to link two nodes together.)


Heliotrope(Posted 2013) [#14]
A network that uses two nodes in each layer.


Graphics 640,480
SeedRnd MilliSecs ()
;the values
inp1 = Rnd (-5,5)
inp2 = Rnd (-5,5)
node3 = 0
node4 = 0
node5 = 0
node6 = 0
wgh1 = Rnd (-5,5)
wgh2 = Rnd (-5,5)
wgh3 = Rnd (-5,5)
wgh4 = Rnd (-5,5)
wgh5 = Rnd (-5,5)
wgh6 = Rnd (-5,5)
wgh7 = Rnd (-5,5)
wgh8 = Rnd (-5,5)

;through the network
;layer 1
node3 = (inp1 * wgh2) + (inp2 * wgh4) + 2
node4 = (inp1 * wgh1) + (inp2 * wgh3) + 5
;layer 2
node5 = (node4 * wgh5) + (node3 * wgh7) - 2
node6 = (node4 * wgh6) + (node3 * wgh8) - 5

;output
Print node5
Print node6
WaitKey ()

End