We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to take "The Nature of Code" chapter 10 example 4 and make it three dimensional, but I am having the hardest time! Does anyone have any suggestions as to how to make it easier or has anyone done it already?
Answers
Start by posting the code you have so far. I don't have that book, so I'm at a complete loss as to where you're at and what help you need.
like this example? openprocessing.org/sketch/11193
The book
book is online,
see
http://natureofcode.com/book/chapter-10-neural-networks/
look for Example 10.4 on that page
The idea
The code on openprocessing looks very good.
The idea of a neuronal network is a learning entity (e.g. recognizing hand writing). Much is said in the books chapter. I don't think that in terms of learning going 3D gains us much. It looks cool in 3D of course, when you display it. But for the learning I don't think it will bring us much...
The class Neuron
the code given in the example 10.4 is obviously building on the code in the previous examples
e.g. on the class Neuron
Good for us: PVector can be 2D, but also 3D, so we can stick with PVector when going 3D now.
When you think of it in 3D, you need all three components x,y,z (and not only x,y).
Also ellipse doesn't work in 3D
so replace it with (box or sphere)
or so...
Other adjustements
for the other stuff also do similar adjustements
e.g. line (in display()) has a version in 3D (unlike ellipse!)
so this is easy:
from
line(a.location.x, a.location.y, b.location.x, b.location.y);
to (just use z as well)
line(a.location.x, a.location.y, a.location.z, b.location.x, b.location.y, b.location.z);
The function update()
also
becomes
since PVector can just be 2D or 3D we don't need to change the occurance of sender or b
just when defining sender and b, think of defining z for both of them as well...
Greetings, Chrisir
Nothing to do with "Processing: installation, usage of the PDE", please read the To newcomers in this forum: read attentively these instructions. Thanks. (Moved.)
Thank you so much Chrisir!!!!! I'll work on it today and give an update later :)
I edited my post
please look at the openprocessing thing too, you can even rotate it with the mouse.
Hey Chrisir, so I made all the necessary changes, but an error keeps coming up saying that Component.x is not visible in my connections tab specifically under the translate in the display function. Any suggestions?
my bad
I guess it's line 25
translate (sender.x, sender.y, sender.z);
since you're replacing
Thank you again Chrisir! I've gotten it to be three dimensional and I am beyond stoked! Your help has been great! THANK YOU! :)
One last question, Chrisir. Would adding neurons via mouse interaction be asking too much? I'm trying to set it up as follows:
any suggestions? It doesn't seem to want to recognize the addSelf. I've imported the toxiclibs geometry but maybe I'm doing something wrong?
Thanks again!
hm...
as far as I understand the code in the chapter, we see
make a neuron
Neuron d = new Neuron(200,0); // or in 3D (200,0,-100)
Add the Neurons to the network.
network.addNeuron(d);
also a connection is made for that neuron
when you mouse click, you have to do the same stuff:
do some connections
does that help ?
do you know about peasy cam?
it's easy and can be a great help to view your result from different angles. -
Yeah, I have Peasy Cam set up already, I'm overlaying this network on contour lines of Mexico City. I'll give the mouse thing a try after my next class. Thank you!
I'm struggling over here. So I'm trying to add the mouse interaction, but I can't seem to understand the best step to take. Here's the code:
line 38 won't work
delete line 70
replace line 91
with
edited - you need to define b - see post below
the process is the same as in setup() but only for one node
Later
later you need an idea for a better z-pos (instead of -100) - e.g. have a zPos stored that you change with pg up/pg dn (and that is displayed as a kind of 3D cursor in space)
also now we always connect to node b. You'll need an idea how to replace b.
E.g.
connect to the last node that has been clicked before the current right click or
connect to the nearest node or to the third closest node or so.
Greetings, Chrisir
for anyone who is interested
EDITED ++++++++++++++++++++++
this version uses no libs, no images
but comes with a 3D cursor
positioning left/right and top/down
use mouse
use wasd keys
positioning depth
mouse wheel
use mouse x-pos while dragging (press and hold left mouse and move mouse left and right)
use r and f keys
use + and - keys
the new nodes are connected to two random nodes
Thank you Chrisir!
One final question/thought. Is it possible to make the neurons add themselves autonomously based on some sort of summation? I mean I figure there is a way, I guess I don't understand the math too well...
here...
Hey Chrisir, so I took your code and put it with my stuff, the only problem is that when I click the mouse, the node gets placed very far away from where the mouse is actually clicked. Any idea how that can be fixed?
I don't know
because it is in 3D space there is of course a certain gap where your mouse is and where the point is in 3D - that's why I invented the 3D cursor.
Alright, well thank you anyway.