void Start() { // Note: We're using the Bayes namespace up above ^^ // BayesDecider can handle 2 types of conditions // Discrete and Continuous // Discrete conditions are conditions with values that are 0-based and count up // ie True/False or an enumeration (like the outlook in the Golf example) // Discrete values are arbitrary (either 0 or 1 could be true), // just be consistent, start it at 0, and don't skip numbers (ie 0,1,2,3...) BayesDiscreteCondition outlook = new BayesDiscreteCondition( "Outlook", 3 ); BayesDiscreteCondition windy = new BayesDiscreteCondition( "Windy" ); // Continuous conditions are conditions with values that fall within a range // The values themselves don't really matter, but I don't think it can handle negative BayesContinuousCondition temp = new BayesContinuousCondition( "Temp" ); BayesContinuousCondition hum = new BayesContinuousCondition( "Humidity" ); // Here we assemble arrays of the discrete and continuous conditions to pass to the Decider // The order for discrete/coninuous conditions MUST be the same as the order in the data file! BayesDiscreteCondition[] discs = new BayesDiscreteCondition[ 2 ]; discs[ 0 ] = outlook; discs[ 1 ] = windy; BayesContinuousCondition[] conts = new BayesContinuousCondition[ 2 ]; conts[ 0 ] = temp; conts[ 1 ] = hum; // Here we create the decider, // and tell it what file to use and the name of the outcome (for debug printing) bd = new BayesDecider( "GolfTab.txt", "Play Golf" ); // Then we give it the conditions bd.SetConditions( conts, discs ); bd.Tab2Screen(); // Prints out the table for reference bd.BuildStats(); // Uses the data from the table to calculate values for conditions // Take a look at the Golf data file (Assets/Data/GolfTab.txt) to see some of its quirks // Discrete values are prefixed by "d" and continuous with a "c" // The outcome starts with an "o" // The first column in the data file is the outlook, with is an enum (0 = sunny, 1 = overcast, 2 = rainy) // The second column is windy, which is boolean (0 = true, 1 = false) // The third and fourth column are temperature and humidity which are continuous // The final column is the outcome (play or not) which is boolean as well // It's important to keep the order consistent and use the correct prefix or it will break! }
// Dump all the statistics to the Console for debugging purposes public void DumpStats() { string output = ""; output += "Overall Repair Outcomes:\n"; int[] outcomeCounts = outcomeAction.GetCounts(); double[] outcomeProps = outcomeAction.GetProportions(); output += string.Format("#True {0} Proportion {1:F3}", outcomeCounts[0], outcomeProps[0]); output += "\n"; output += string.Format("#False {0} Proportion {1:F3}", outcomeCounts[1], outcomeProps[1]); output += "\n\n"; for (int i = 0; i < continuousConditions.Length; i++) { BayesContinuousCondition cc = continuousConditions[i]; output += cc.Name + "\n"; output += DumpContAttr(cc.GetMean(0), cc.GetMean(1), cc.GetStdDev(0), cc.GetStdDev(1)); } output += "\n"; foreach (BayesDiscreteCondition dc in discreteConditions) { output += dc.Name + "\n"; int[,] counts = dc.GetCounts(); double[,] prps = dc.GetProportions(); for (int i = 0; i < counts.GetLength(0); i++) { output += "Value: " + i; output += " True: "; output += string.Format(" Count: {0:D}", counts[i, 0]); output += string.Format(" Prop: {0:F4} ", prps[i, 0]); output += " False: "; output += string.Format(" Count: {0:D}", counts[i, 1]); output += string.Format(" Prop: {0:F4} ", prps[i, 1]); output += "\n"; } } Debug.Log(output); }
public void SetConditions( BayesContinuousCondition[] contConds, BayesDiscreteCondition[] discConds ) { continuousConditions = contConds; discreteConditions = discConds; }
void Start() { currObservation.outcome = -1; BayesDiscreteCondition enemyInWay = new BayesDiscreteCondition( "No Enemy In Way" ); BayesDiscreteCondition enemiesAtGate = new BayesDiscreteCondition( "No Enemies At Gate" ); BayesContinuousCondition gateHealth = new BayesContinuousCondition( "Gate Health" ); BayesContinuousCondition distance = new BayesContinuousCondition( "Distance" ); BayesDiscreteCondition[] discs = new BayesDiscreteCondition[ 2 ]; discs[ 0 ] = enemyInWay; discs[ 1 ] = enemiesAtGate; BayesContinuousCondition[] conts = new BayesContinuousCondition[ 2 ]; conts[ 0 ] = gateHealth; conts[ 1 ] = distance; bd = new BayesDecider( "RepairTab.txt", "Repair Wall" ); bd.SetConditions( conts, discs ); bd.BuildStats(); }
void Start() { gate = GameObject.Find("Gate").GetComponent<Health>(); currObservation.outcome = -1; BayesDiscreteCondition enemyInWay = new BayesDiscreteCondition( "No Enemy In Way" ); BayesDiscreteCondition enemiesAtGate = new BayesDiscreteCondition( "No Enemies At Gate" ); BayesContinuousCondition gateHealth = new BayesContinuousCondition( "Gate Health" ); BayesContinuousCondition distance = new BayesContinuousCondition( "Distance" ); BayesDiscreteCondition[] discs = new BayesDiscreteCondition[ 2 ]; discs[ 0 ] = enemyInWay; discs[ 1 ] = enemiesAtGate; BayesContinuousCondition[] conts = new BayesContinuousCondition[ 2 ]; conts[ 0 ] = gateHealth; conts[ 1 ] = distance; bd = GameObject.Find("BayesDecider").GetComponent<BayesDeciderRef>().getBayesDecider(); bd.SetConditions( conts, discs ); bd.BuildStats(); }