Exemplo n.º 1
0
    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!
    }
Exemplo n.º 2
0
    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();
    }
Exemplo n.º 3
0
    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();
    }