|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcodesimian.CS<CSGeneric>
codesimian.DefaultCS
codesimian.BayesNode
public class BayesNode
ERROR IN JAVADOC 7/05:
Executing this BayesNode does not add to the HISTORY (in param2). That is instead done externally by the bayesnet.
I'm a NODE (in a BAYESIAN NETWORK) with 2 or 3 params (each is a list),
each with a different purpose (described below).
This default implementation uses NAIVE BAYES,
which means all nodes assume their inputs are independent,
but subclasses or other CSs used with BayesNodes do not have to assume that.
Executing this BayesNode returns this BayesNode's CHANCE (0.0 to 1) based on the executes/chances
of this node's params and the conditional-probabilities. If there is a param2,
then param2 is a history list, and DForProxy() saves exec's returned value at the end of it.
HOW TO USE:
To make a normal bayesian network,
connect many BayesNode's to each other, in a directed graph with no cycles,
set all their myFuel's to 1,
set the input values (input nodes should be leafs),
and execute the top (output) node(s).
AVOIDING REDUNDANT OVERLAPPING RECURSIVE CALLS:
It can cause exponential slowness, and infinite loops if you have cycles in your network.
All BayesNode's must remember their own previous values of DForProxy() (their chances),
so they can be used to calculate bayesian chances later. "Dynamic Programming".
That remembering is a standard option that can be enabled in any CS object.
Redundant recursive calls calculate the data only once if CS.myFuel() > 0
and that CS checks myFuel.
When myFuel is finally decremented to 0,
CS.D() returns the last double value again instead of calling CS.DForProxy() again,
but only if you have that option turned on (see Exec.java).
WHICH PARAMS DO WHAT?:
Param0 contains a list of CSs that will be interpreted as bayesian nodes,
the nodes whose chances I use to calculate my chance.
These nodes can be almost any type of CS that has 3 params and
lets them be manipulated like bayesian nodes.
It does not matter if they give correct bayesian chances.
For example, you might want to evolve something similar to a BayesNode
but weirder and smarter, and use it with the normal BayesNodes.
Param1 contains a list of CONDITIONAL-PROBABILITIES, with size: 2 << param0.countP().
They should all sum to 1. A very small amount of error from 1 is allowed,
but a lot more than roundoff error (6/05 it was .000001).
They are interpreted as their absolute value. No negatives are summed.
The list uses the constant-pool (example Const.pool(.422124)) for efficiency.
It is 2 times as big as you'd expect because the chance of THIS NODE is included.
Example: If there are 3 child nodes, thats 2^(3+1)=16 condProb[] size.
It contains the chance of each of the 16 possibilities of the 4 booleans.
Each node's DForProxy() returns a chance describing that node's boolean value.
An event either occurs or it does not, but we predict with chances.
The indexs for conditional-probabilities represent the combinations
of the child nodes's being true or false. The 0s and 1s in the index
are falses and trues. There is 1 more bit than childs.
The last bit is for this (parent) node's chance.
8/05 I DONT THINK THIS PARAGRAPH IS ACCURATE ANYMORE:
Param2 contains a (partial) list of
the previous DForProxy() values of this BayesNode, the history,
which is later used to calculate new conditional-probabilities.
Param2 is optional. If countP()==2 then history of my chance is not saved.
To start using history again, put any CS in my param2 (third param).
If that CS can not store numbers, it will be replaced by a CS that can.
If that CS contained some numbers, those numbers are copied to the new CS.
To learn, a bayesian network's nodes must ALL have the same size histories.
All numbers from a certain index in all
histories (in the same bayesian network) are from the same calculation.
ERRORS:
The bayesian-network may contain any types of CSs, not just BayesNodes,
therefore if a chance is not in range 0.0 to 1, wrap it around that range.
If any other error occurs, assume that one chance is .5,
or better: use the last known non-weird estimate of that chance,
and continue the calculations. The system should be fuzzy and error-tolerant.
CONDITIONAL-CHANCE BITS AND PARAM-INDEXS:
The highest half of indexs in condChanceValues[] are all for THIS NODE being true
because this node is represented by the highest bit in the indexs.
The highest bit has position P(0).countP().
All nodes are represented by the bit number equal to their
param-index in my param0 (their parent). The first bit
is for param0.param0 and has position 0. Second bit for param0.param1...
Nested Class Summary | |
---|---|
static class |
BayesNode.VerifyCountP
|
Field Summary | |
---|---|
static CS |
TYPE
fuzzy-type of a bayes node. |
Fields inherited from class codesimian.CS |
---|
DESCRIPTION, END, EXECPROXY, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS |
Constructor Summary | |
---|---|
BayesNode()
|
Method Summary | |
---|---|
boolean |
addToHistory(double addThisChance)
adds a CS (from the constant-pool) with the value addThisChance to the end of the history list contained in param2. |
static void |
adjustBitChance(double[] conditionalChances,
int bitNum,
double newChance)
Changes all values in conditionalChances[] so bitChance(conditionalChances,bitNum) would return approximately newChance. |
static double |
bitChance(double[] conditionalChances,
int bitNum)
Returns the CHANCE that the bayes-node represented by bitNum is true. |
static int |
childCountForCondProbSize(int condProbSize)
condProbSize is exponentially bigger than childCount. |
double |
cost()
Returns size of conditional-probability table in param1, which is EXPONENTIALLY bigger than quantity of child nodes and anything else in this BayesNode. |
java.lang.String |
description()
a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for. |
double |
DForProxy()
returns this node's CHANCE (0.0 to 1) based on the DForProxy()s/chances of param0's params and the conditional-probabilities in param1. |
java.lang.String |
keyword()
For the CodeSimian language as a String. CodeSimian language keyword, like "+" "*" "max" ">" etc. Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add. Some CSs might never be intended to be used in the language by their keyword. The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()". |
static void |
makeArraySumTo1(double[] d)
assumes the array contains no negatives, and |
int |
maxP()
Maximum quantity of Params |
int |
minP()
For DForProxy(). Minimum number of parameters in param[] needed to call DForProxy(). Defines which indexs of param[] DForProxy() can use. Functions with a different number of parameters must override this. OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS. Default is 1. |
CS |
PType(int index)
This must always be true of a bayesnode: P(0).countP() + 1 == 2 exponent P(1).countP() therefore PType(int) returns Need to test the log/exponential calculations against bayes countP requirements |
boolean |
setD(double execValue)
Removes all child bayes-nodes and all conditional-probabilities. |
static double |
sum(double[] d)
|
Methods inherited from class codesimian.DefaultCS |
---|
B, C, countP, decrementMyFuel, deleteP, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, javaCode, LForProxy, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, S, setB, setC, setCountP, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, setName, setObject, setP, setPrevExec, setPType, setS, setZ, start, toString, V, Z |
Methods inherited from class codesimian.CS |
---|
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addP, addS, addZ, BForProxy, CForProxy, clone, D, deleteP, FForProxy, GETB, GETC, GETD, GETF, GETI, GETJ, GETL, GETS, GETZ, IForProxy, isIllusion, JForProxy, L, L, L, L, L, maxD, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, reflect6, setB, SETB, setC, SETC, setCost, SETD, setDescription, setF, SETF, setHeap, setI, SETI, setJ, SETJ, SETL, setL, setL, setParent, setParsePriority, setProxyOf, setS, SETS, setTester, setZ, SETZ, SForProxy, tester, toJavaCode, VForProxy, voidReflect, ZForProxy |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static CS TYPE
Constructor Detail |
---|
public BayesNode()
Method Detail |
---|
public double DForProxy()
DForProxy
in class DefaultCS
public static double bitChance(double[] conditionalChances, int bitNum)
public static int childCountForCondProbSize(int condProbSize)
public static void adjustBitChance(double[] conditionalChances, int bitNum, double newChance)
public static void makeArraySumTo1(double[] d)
public static double sum(double[] d)
public boolean addToHistory(double addThisChance)
public int minP()
DefaultCS
minP
in class DefaultCS
public int maxP()
CS
maxP
in class CS
public java.lang.String keyword()
DefaultCS
keyword
in class DefaultCS
CS.parent()
,
CS.newInstance()
,
CS.name()
public java.lang.String description()
CS
description
in class DefaultCS
public double cost()
cost
in class CS
public boolean setD(double execValue)
setD
in class DefaultCS
public CS PType(int index)
PType
in class DefaultCS
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |