Zen of self-adaptive code-jitsu
So, we're mad scientists in search for final question of life,
universe, and everything, and we're gonna build ourseves a big and smart machine to aid us
in our quest.
Where to start?
Let's see how human brain
works, say... S. Haykin: neural networks, a comprehensive foundation,
chapter 1.2, human brain:
The human nervous system may be viewed as a three-stage
system... Central to the system is the brain, represented by the neural
(nerve) net, which cointinually receives information, percieves it, and
makes appropriate decissions. ... The receptors
convert convert stimuli from the human body or the external environment
into electrical impulses that convey information to the neural net
(brain). The effectors
convert electrical impulses generated by the neural net into
discernible responses as system outputs.
... blah, blah...
In the brain there are both small-scale and large-scale
anatomical organizations, and different functions take place at lower
and higher levels...
The synapses represent the
most fundamental level, depending on molecules and ions for their
action. At the next levels we have neural microcircuits, dendritic
trees, and then neurons. A neural
microcircuit refers to an assembly of synapses organized into
patterns of connectivity to produce a functional operation of
interest... neural microcircuits are grouped to form dendritic subunits within the dendritic trees of individual
neurons. The whole neuron...
contains several dendritic subunits. At the next level of complexity we
have local circuits made up
of neurons with similar or different properties; these neural
assemblies perform operations charactereistic of a localized region in
the brain. This is followed by interregional
circuits made up of pathways, collumns, and topographic maps,
which involve multiple regions located in different parts of the brain.
Topograpic maps are organized
to respond to icoming sensory information. These maps are often
arranged in sheets, as in the superior colliculus, where the visual,
auditory, and somatosensory maps are stacked in adjacent layers in such
a way that stimuli from corresponding points in space lie above or
below each other... At the final level of complexity, the topograpic
maps and other interregional circuits mediate specific types of
behavior in the central nervous system.
OK that's all, let's write the code.
Neuron, neuron, ommmmm... hey,
it's kinda object! Synapses, synapses, ommmmm... huh, ain't that like
object references? Nah, references are kinda neural microcircuits, I'm
gonna use method calls for synapses, let's give it a try:
public class Neuron implements Observer extends Observable {
public void update( Observable neuron, Object event ) {
// processing input
}
public void notifyObservers( Object event ) {
// send output
}
}
Hehe, I've already connected them:) And I got both receptors and
effectors.
What he said further? Sez brain's like onion, it's got layers...
public class Layer extends Neuron {
public void update( Observable neuron, Object event ) {
super.update( neuron, event );
}
}
Thus I stacked them, I can lay as many layers
as I want. Nice, I can use instanceOf operator to identify layers, it's
gonna be fast, fast, fastest;)
But it's stupid, it shouda do something...
public void update( Observable neuron, Object event ) {
super.update( neuron, event );
// processing here
}
OR
public void update( Observable neuron, Object event ) {
// processing here
super.update( neuron, event );
}
?
Smells like feedforward and backpropagation... well who cares,
let's see performance.
Worst case, everybody sees everybody, N(N-1) references, ugly... but
nice, without OOP tricks (inheritance) we'd have N(N-1)*L, where L is
class hierarchy depth. Nice, we bought us an order of magnitue or two.
But that N(N-1)... well, I don't need fully
connected network anyway, I'm gonna cut it in pieces. Say, I'm
gonna take one box. No, not box, I'm gonna call it 3-dimensional hypercube, make everyone realize
what a smart-ass I am!
And I'm gonna slice and dice these hypercubes, I'm gonna play with
intersections and unions, yummie!
But that, later.
The code still ain't fault tolerant:
public void update( Observable neuron, Object event ) {
try {
// super.update() and processing wherever
} catch (Exception e) {
// say the main man you don't feel good
}
}
Cool, I just got a synapse that may work or may not. Oh yes, I'm gonna
need the same thing in a healthy brain, but Exceptions are expensive, so
public void update( Observable neuron, Object event ) {
if ( iCanHandleIt ) {
try {
// super.update() and processing
} catch ( Exception e ) {
// super.invalidRequest() or something
}
} else {
super.cantHandle( neuron, event );
}
}
Nice. Did I miss something?
Uh, synapse has weight... it's probability that it
will pass the information further. I can't do that with references, it
would be like working with operational amplifiers in... what's the
word, saturation, overload? Well, who cares:
public void update( Observable neuron, Object event ) {
if ( iCanHandleIt ) {
if ( level >= treshold ) {
// try, super.update() & stuff
} else {
// update level somehow
}
}
}
Yeah, that's it, it's got synapses, it's got weights, it's got
tresholds, it's got layers. Of course, I'm gonna need more complex
conditions and state changes than this stupid level; if level and
treshold were enough for what I want, I'd calculate it already.
Did I miss something? Let's see... neural microcircuits, dendritic
trees... nah, it's method calls - Haykin sez 'A neural microcircuit refers to an
assembly of synapses organized into patterns of connectivity to produce
a functional operation of interest', I'm gonna hardcode this functional
operation of interest.
What's next? Local circuit: neural assemblies perform operations
characteristic of a localized region in the brain.
OK here's one:
public class LocalCircuit...
... no wait, it sounds stupid, I'm gonna call it Transform, it does
some transformations to something data anyway:
public class Transform extends Neuron {
public Neuron[] members;
}
Yeah. So, it's got input and output inherited from Neuron, and it's got
lotsa Neurons, I'm gonna connect them to perform operations
characteristic of a localized region later.
OK what's left... pathways, collumns, maps, sheets... but it doesn't
matter, I can assemble these transforms in as many sheets and columns
and maps as I want, either extending them or referencing them.
And I can add as many methods as I want.
But waitaminit, it's not a neuron anymore: I use single class to
process multiple inputs and send multiple outputs, that's OK. But I
also use a single class to represent multiple levels of complexity,
from neurons, to interregional circuits... OK I'm gonna call it VRObject.
And this stupid interregional circuit sounds stupid, these I'm gonna
call... I'm gonna call em Gates. Gates is a
nice name, full of symbolical meanings, gotta bring me loads of good
karma;)
Allright, let's test the concept. Suppose I you say something and I
hear it, here's event dataflow:
User -> Alice
Is that really all?
Let's see what happens inside Alice: in fact, she calls super.update().
Sure, not always, she's not interested in all events. Also, lot of
behaviour is hardcoded - I have no intentions to discuss commands with
robots. I ain't a pervert, I just want her to be my slave...;)
But anyway, here's how event dataflow really flows:
User ->
Alice -> User -> Client -> OwnedDBObject -> PublicDBObject
-> DBObject -> VRObject
Alice <- User <- Client <- OwnedDBObject <- PublicDBObject
<- DBObject <-
-> User and the rest of the world, all optional
Right - an event travels thru the entire class hierarchy, to the very
basic receptor, and back to
the most refined layer.
If I call super.update() first in each class, I get
receptor->abstraction dataflow.
If I call super.update() last in each class, I get
abstraction->effector dataflow.
It's cuz VRObject is both receptor and effector. And sure, I mix this
all the time.
Hey waitaminit, sez you, this ain't right! Alice gets the message, it's not a
VRObject who gets it!
Well, I cheated. I cheat all the time, and I call these cheats 'hacks'.
But the catch is, I can send a message to VRObject 1 or to Alice 1. Hyppocampus gives me the
right object anyway, based on unique ID. ID itself is generated by
hyppocampus itself; it's up to it to check whether VRObject 1 and Alice
1 are the same thing. So one
can do that and the other
can't; the later can't be used to identify patterns, only to distribute
'language' between hi-level concepts.
Yeah, pattern identification and language.
As for language, well it's not quite language, it's just a protocol
these objects/neurons/abstractions/assemblies use to exchange
information, say, to talk. And it really becomes talk in when
sofisticated speach centers like Alice communicate. Otherwise, they
just tell their 'neighbours' about changes of their own attributes,
like, I'm red.
This VRObject 1 message whatever; this gets matched against all classes
from the class tree, from VRObject to Alice. Thus, we
truly identify the pattern, in fact we do it in fastest possible way,
using instanceOf operator, direct method calls, hardcoded ifs - all
compiled. But, it's stupid; we want a smarter pattern matching, we get
ourself an AIML interpreter, say CharlieBot.
Excersize 1: build
AIML processor that spits out java source for categories; build AIML
interpreter that performs pattern mathching by using instanceOf
operator to compare these classes.
Interesting things happen in the networks of these; though: suppose
'center' A tells 'center' B about Alice, but B knows nothing about
Alice (has no appropriate class). If we send VRObject message, it will
match against closest class, probably User. It will try to evaluate; it
will, if it's about User or superclasses, it fails if it's about Alice
specifics. Therefore, if we want B to learn from A, we can't relly on
the protocol alone, we need to transfer description in a real language,
be it java, or AIML, or english. Kant was right all along;)
Excersize 2: on
ClassDefNotFoundError, ask peers for java class. Do not ask request originator; ask
trusted peers in order of confidence.
Excersize 3: on
CatchAll, ask peers for AIML category. If found, transfer entire
knowledge tree leading to that category. Do not ask request originator; ask
trusted peers in order of confidence.
Yeah, learning. And forgetting.
There's so many learning methods that I never bothered to learn even
their names. A stupid state machine learns too, but it remains stupid
forever cuz it never forgets.
We need time for that. So what do we know about time?
Time - passes. Time - has come. Time - wounds all heals.
Time - does not exist.
It's but a Average Joe's word for processing power of the universe.
Consider how universe works: everthing sees everything else. So
everything has N(N-1) references. Bundle some matter together, and poor
universe can't process all events - time slows down. Move it closer and
farther and see what happens, you always have that stupid N(N-1), be it
r^2 or sqrt( 1/(c^2 - v^2) ).
Well, to make long story shorter, I'll just state that universe's
maximum processing speed is known by the name Planck
time and Planck
length.
It's not universes clock. It processing cost of most basic instruction.
Like, NOP - idle universe.
Academic smart-asses call the thing time-frame;
I call it Checkpoint.
It runs periodically, more or less - it will delay on heavy loads. It
does two important things:
- it runs garbage collector, makes our thing forget things. This is
optional; by default our thing forgets things only when it runs out of
memory... and this sounds so stupid that I gotta leave it as is:))) And
default 24h checkpoint interval is plainly accidental;)
- it flushes the data to the database. All the data; neurons, synapses,
maps, sheets, whatever - everything. That is to say - database is orthogonal to entire network. It samples the entire network state in some time-frame.
And this is very, very important: without time
there's no causes and
consequences. As J.A. Wheeler sez, time is God's way to keep things
from happening all at once.
And only now we may have all the brain parts, Haykin wasn't enough - he
forgot brainwaves,
human time-frame implementation.
So let's get back to hypercubes.
Suppose there are two-dimensional beings, they walk around their
planes, and can't look up nor down. They probably do know that third
spatial dimension exist, as they are superintelligent grades of cyan.
And they wanna talk to us, just as we want to talk with beings from
higher dimensions.
To understand each other, we gotta leave or add some spatial dimensions
during translation. So let's talk to some hyperdimensional superbeing:
3D <-> Translator
<-> 4D
When 3D initiates communication: 4D has no problem with it. However, he
gets only a 3D image. He may, or may not, add more spatial information,
say grow mountains
from a photo.
When 4D initiates communication, more interesting things happen: poor
human can't grasp fourth Minkowski axis, he just blinks and says I
don't get it, he gets 3D projection of what's really goin on.
Still, he gets all the other stuff, he rembembers, he forgets, he's
able to see the couse and the consequence, he may be even aware
that he's missing something important. And, they are able to talk, as
long as they talk common things - hyperdimensional superbeing keeps
data related to fourth dimension to himself. In fact, it could even
forget all except spatial data, and leave all the rest to poor humans.
Big deal, so what?
So human can see the same causes and consequences, and draw the same
conclusions as the hyperdimensional superbeing, chrunching less data,
thus using less processing power AKA time. Of course - not all exactly
the same; humans just get lost when it comes to fourth dimension. But
all the rest - all the same.
Excersize 4: lay a
couple of orthogonal layers and see what happens.
Just as we crunch hypercubes, we can cut trees: peer A says VrmlFile; peer
B doesn't know VrmlFile, falls back to File, looses some
data. Peer C knows VrmlFile; hears about it from peer B, learns either
File or VrmlFile, probably distingushing by mime-type. If C learns
VrmlFile, fills in default values for unknown attributes.
In effect - self-adaptive event filtering. Distributed, spatial,
hierarchical, holographical.