Esempio n. 1
0
        public static double Score(WeightSet weights, Dictionary <string, double> features)
        {
            //double score = weights["intercept"];
            double score = 0.0;

            foreach (string feature in weights.FeatureList)
            {
                score += weights.Weights[feature] * features[feature];
            }
            return(score);
        }
Esempio n. 2
0
        public static Point AimCannons(MapGenerator myMap, WeightSet weights, bool printB = false)
        {
            // Look for open space with highest probability
            Point            shootAt = new Point();
            bool             firstOpenSpaceFoundB = false;
            double           highestProb          = 0.0f;
            List <DataPoint> possiblePoints       = new List <DataPoint>();

            foreach (MapSpace m in myMap.CurrentMap.Cells)
            {
                if (m.State == SpaceState.Open)
                {
                    if (firstOpenSpaceFoundB == false)
                    {
                        firstOpenSpaceFoundB = true;
                        shootAt = m.Coords;
                    }
                    double prob = 0.0f;

                    DataPoint d = new DataPoint(myMap.CurrentMap, m.Coords);
                    prob = MLHelper.Probability(weights, d.Features);
                    prob = Math.Round(prob, 10);
                    //Log(String.Format("{0}",prob));
                    if (prob > highestProb)
                    {
                        highestProb    = prob;
                        possiblePoints = new List <DataPoint>();
                    }

                    if (prob == highestProb)
                    {
                        possiblePoints.Add(d);
                    }
                }
            }

            Random rnd = new Random();

            if (possiblePoints.Count > 0)
            {
                shootAt = possiblePoints[rnd.Next(0, possiblePoints.Count)].Coords;
            }

            if (printB == true)
            {
                Console.WriteLine("HIGHEST PROB: " + highestProb);
                Console.WriteLine("POINTS: " + possiblePoints.Count);
            }

            return(shootAt);
        }
Esempio n. 3
0
        public static double Probability(WeightSet weights, Dictionary <string, double> features)
        {
            double score = MLHelper.Score(weights, features);

            return(1.0f / (1.0f + Math.Pow(Math.E, (-1.0f * score))));
        }
Esempio n. 4
0
 public static Point AimCannons(dynamic state, WeightSet weights)
 {
     return(AimCannons(new MapGenerator(state), weights));
 }