|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcodesimian.CS<CSGeneric>
codesimian.DefaultCS
codesimian.SimpleBayesNet
public class SimpleBayesNet
simpleBayes(input0 input1 input2 input3...) There are 2 phases... TRAINING-MODE and CALCULATE-MODE. During training, data is recorded, but nothing calculated. When training mode ends, an OUTPUT NODE is selected by DELETING any one of the params. You should use the last index because I'm going to remove the ability to put it anywhere else. An OUTPUT NODE is put in the last index. Now its in CALCULATE-MODE. Replace any of the params (with new chances, range 0 to 1), and SimpleBayesNet.DForProxy() will return the PREDICTED output value based on those new input chances. You can ignore the OUTPUT NODE. Quantity of input nodes can increase only during TRAINING-MODE. Training datas can have different sizes, but will be enlarged to the size of the biggest by filling the ends with 0.5. When CALCULATE-MODE starts, the last param is replaced by the one OUTPUT NODE. TRAINING-MODE ends when an output node is selected by deleting its index. That index is moved to the last index, and contains the OUTPUT NODE after every DForProxy(). From the OUTPUT NODE, you can find any node in this bayesian-network. If you execute the OUTPUT NODE, it should return the same as this SimpleBayesNet's D(). TODO: REFACTOR THIS: In either mode, D() always returns the value of the last param. If you replace the OUTPUT NODE, the new value is ignored, and D() will put the OUTPUT NODE back. END REFACTOR. In CALCULATE-MODE, you can try to optimize the network by adding or modifying bayes-nodes. You can find all the bayes-nodes by traversing the directed-acyclic-network starting at the last param (the 1 output node). To add new bayes-nodes, call setP(k, the new bayes-node), where k equals countP()-1 or countP(). This SimpleBayesNet judges its accuracy as a bayes-node. If it is a good OUTPUT NODE (judged by the CS returned by getNodeJudger()), then it BECOMES THE NEW OUTPUT NODE. It might also be put somewhere in the middle of the network if it looks useful for that, but this default implementation does not check for that (Do it in a subclass!). INPUT NODES are the only nodes with 0 childs. For any input node x, x.P(0).countP()==0 (0 childs) and x.P(1).countP()==2 (2 possible values of this node, this number doubles with every child added). SimpleBayesNet implements Comparator to compare bayes-nodes' values, and choose which nodes to use or modify, to evolve the data in bayes-nodes.
Nested Class Summary | |
---|---|
static class |
SimpleBayesNet.BayesNodeIndependentChildsDependentParent
param0 is a bayes-node. |
static class |
SimpleBayesNet.Test
Tests SimpleBayesNet to see if it works. |
Field Summary | |
---|---|
static int |
MINP
this is a "small" number, but not guaranteed to be any specific number |
protected int |
nameNumber
|
protected CS |
nodeJudger
|
protected java.util.List<CS> |
nodes
Nodes in this bayesian network. |
static java.util.Random |
rand
|
protected java.util.List |
trainingData
contains double[] arrays, probably with different sizes. |
protected boolean |
trainingMode
if false, calculateMode |
Fields inherited from class codesimian.CS |
---|
DESCRIPTION, END, EXECPROXY, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS |
Constructor Summary | |
---|---|
SimpleBayesNet()
|
Method Summary | |
---|---|
void |
addOneRandomlySelectedChildToEveryNonInputNode()
randomly selected child always has lower index than parent its put in. |
int |
compare(java.lang.Object bayesNodeA,
java.lang.Object bayesNodeB)
Comparator interface. |
double |
cost()
cost() should be changed to return a float, and should be renamed to costToExecute() cost of EXECUTING this CS, not including any CSs it executes recursively. |
java.util.List<CS> |
createNetwork(int networkSize)
Creates an untrained network with no experience. |
boolean |
deleteP(int index)
WARNING: if returns false, could have deleted but not moved other params down 1 index. WARNING: if duplicates not allowed, can not slide params down 1 index the standard way, returns false. |
static double |
dependence(double[] condProb,
int childIndexA,
int childIndexB,
boolean believeCondProbSumsTo1)
condProb[] is the param1 of some bayes-node. |
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()
Execute this CS and cast to double. |
static boolean |
exaggerate(double[] condProb,
double amount)
make big values bigger and small values smaller. |
static boolean |
exaggerateNode(CS bayesNode,
double amount)
|
CS |
getNodeJudger()
returns the CS that judges bayes-nodes. |
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()". |
int |
maxP()
unlimited, if enough memory |
int |
minP()
for hard-coded evolving reasons, need approximately at least 6 inputs + 1 output. |
CS |
newBayesNode(CS[] childs,
CS historyOfNewNode)
the type of bayes-node that this class prefers: BayesNode (and fills its param0 and param1). |
CS |
newRandomNode(CS replaceMe,
int childCountOfNewNode,
int maxChildIndexInNet)
Makes a new partially random bayes-node with the same HISTORY (every BayesNode's param2) values as replaceMe.param2's values. |
boolean |
offerBayesNodeToNetwork(CS newBayesNode)
This bayesian network looks for a place to use the bayes-node without changing its data. |
void |
randomizeNode(CS bayesNode)
randomize the history, then update the conditional-probabilities to match it |
void |
randomlyEnlargeNetwork(int newNetSize)
|
static java.util.List<CS> |
removeChildsThatDependMoreOnAnyOneSiblingThanParent(CS parentBayesNode)
Removes some childs and returns them in a List |
java.util.List<CS> |
removeNodesThatDoNotDescendFromOutputNode(java.util.List<CS> net)
Removes unused nodes, except input nodes (first) and the output node (last). |
boolean |
replaceOutputNodeWithBetterOutputNode(int tryThisManyNewNodes)
|
boolean |
shrinkAllNodesToHaveMaxChilds(int maxChildQuantity)
|
void |
testEnlargeNetwork()
|
boolean |
trainNetwork()
Done once between TRAINING-MODE and CALCULATE-MODE to set the conditional-probabilities of all the nodes and increase network size. |
boolean |
unknownCost()
|
boolean |
updateNetwork()
|
double |
valueOf(CS bayesNode)
the highest valued bayes node is the root |
Methods inherited from class codesimian.DefaultCS |
---|
B, C, countP, decrementMyFuel, 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, PType, S, setB, setC, setCountP, setD, 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 |
Methods inherited from interface java.util.Comparator |
---|
equals |
Field Detail |
---|
protected java.util.List<CS> nodes
protected int nameNumber
newBayesNode(CS[])
public static java.util.Random rand
protected java.util.List trainingData
protected boolean trainingMode
public static final int MINP
protected CS nodeJudger
Constructor Detail |
---|
public SimpleBayesNet()
Method Detail |
---|
public double DForProxy()
CS
DForProxy
in class DefaultCS
public boolean deleteP(int index)
DefaultCS
deleteP
in class DefaultCS
public double valueOf(CS bayesNode)
public int compare(java.lang.Object bayesNodeA, java.lang.Object bayesNodeB)
compare
in interface java.util.Comparator
public static java.util.List<CS> removeChildsThatDependMoreOnAnyOneSiblingThanParent(CS parentBayesNode)
dependence(double[],int,int,boolean)
public boolean shrinkAllNodesToHaveMaxChilds(int maxChildQuantity)
public void addOneRandomlySelectedChildToEveryNonInputNode()
public boolean updateNetwork()
public boolean replaceOutputNodeWithBetterOutputNode(int tryThisManyNewNodes)
public boolean trainNetwork()
public CS newRandomNode(CS replaceMe, int childCountOfNewNode, int maxChildIndexInNet)
public void randomizeNode(CS bayesNode)
public void randomlyEnlargeNetwork(int newNetSize)
public void testEnlargeNetwork()
public CS newBayesNode(CS[] childs, CS historyOfNewNode)
public int minP()
minP
in class DefaultCS
public int maxP()
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()
CS
cost
in class CS
public boolean unknownCost()
public java.util.List<CS> createNetwork(int networkSize)
public CS getNodeJudger()
public boolean offerBayesNodeToNetwork(CS newBayesNode)
public java.util.List<CS> removeNodesThatDoNotDescendFromOutputNode(java.util.List<CS> net)
public static double dependence(double[] condProb, int childIndexA, int childIndexB, boolean believeCondProbSumsTo1)
public static boolean exaggerate(double[] condProb, double amount)
public static boolean exaggerateNode(CS bayesNode, double amount)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |