Example #1
0
        protected Operator(IEnumerable <IOperand> operands, IField field = null, uint?boost = null)
        {
            if (operands == null)
            {
                throw new ArgumentNullException("operands");
            }

            _operands = operands.ToList(); // Make a copy of operands

            if (_operands.Count == 0)
            {
                throw new ArgumentOutOfRangeException("operands", "An Operator must have at least one operand.");
            }

            _options = new List <Option>();
            _field   = field;
            _boost   = boost;

            if (Field != null)
            {
                AddOption("field", Field.Name);
            }
            if (Boost.HasValue)
            {
                AddOption("boost", Boost.ToString());
            }
        }
 protected override void communicate_main()
 {
     serialWrite((char)0x01 + "1" + Boost.ToString("X3")
                 + (char)0x02 + "1" + Tacho.ToString("X3")
                 + (char)0x03 + "1" + Oil_Pres.ToString("X3")
                 + (char)0x04 + "1" + Fuel_Pres.ToString("X3")
                 + (char)0x05 + "1" + Ext_Temp.ToString("X3")
                 + (char)0x07 + "1" + Oil_Temp.ToString("X3")
                 + (char)0x0f + "1" + Water_Temp.ToString("X3"));
     Thread.Sleep(14);
 }
 protected override void communicate_main()
 {
     serialWriteLine("T" + Tacho.ToString());
     serialWriteLine("S" + Speed.ToString());
     serialWriteLine("A" + Boost.ToString());
     serialWriteLine("B" + Water_Temp.ToString());
     serialWriteLine("C" + Oil_Temp.ToString());
     serialWriteLine("D" + Oil_Temp2.ToString());
     serialWriteLine("E" + Oil_Pres.ToString());
     serialWriteLine("F" + Fuel_Pres.ToString());
     Thread.Sleep(14);
 }
Example #4
0
        /// <summary>
        /// Converts the Persona to its multilined string equivalent.
        /// </summary>
        public override String ToString()
        {
            string sPersonaData = "Persona Information: {" + Environment.NewLine +
                                  "   Id: " + Id.ToString() + Environment.NewLine +
                                  "   Avatar Index: " + IconIndex.ToString() + Environment.NewLine +
                                  "   Name: " + Name + Environment.NewLine +
                                  "   Motto: " + Motto + Environment.NewLine +
                                  "   Level: " + Level.ToString() + Environment.NewLine +
                                  "   Cash: " + Cash.ToString() + Environment.NewLine +
                                  "   Boost: " + Boost.ToString() + Environment.NewLine +
                                  "}";

            return(sPersonaData);
        }
Example #5
0
        static void Main(string[] args)
        {
            var data = HealthInfo.DeserialiseData(HEART_DATASET);

            var testData = new List <HealthInfo>();

            while (testData.Count < 25)
            {
                int index = _randEngine.Next(data.Count - 1);

                testData.Add(data[index]);

                data.RemoveAt(index);
            }

            var agent = new Boost <HealthInfo>();

            agent.Add(new Agent <HealthInfo>(100));

            int Nbsucces = 0;

            int bestNbSuccess = 0;

            int run = 0;

            int nbRunSinceLastSuccess = 0;

            int nbAgent = 1;

            while ((double)Nbsucces / data.Count < 0.85)
            {
                Nbsucces = 0;

                for (int i = 0; i < 1; i++)
                {
                    agent.Fit(data);
                }

                foreach (var item in data)
                {
                    if ((agent.MakePrediction(item) > 0) == (item.Target > 0))
                    {
                        Nbsucces++;
                    }
                }

                if (Nbsucces > bestNbSuccess)
                {
                    Console.WriteLine($"Last best result at : {DateTime.Now.ToString()}");
                    Console.WriteLine($"The agent made {Nbsucces} prediction succefully on a total of {data.Count} at run {run}.");
                    Console.WriteLine($"This is accurate at {(double)Nbsucces / data.Count}");

                    Console.WriteLine($"The Agent spec");
                    Console.WriteLine(agent.ToString());

                    Console.WriteLine("Result");
                    Console.WriteLine($"{data[0].Header()} Prediction");
                    int lineToBePrintedCount = 303;
                    for (int i = 0; i < data.Count; i++)
                    {
                        if (lineToBePrintedCount > 0 && (_randEngine.Next() % 303 == 0 || data.Count - i < lineToBePrintedCount))
                        {
                            Console.WriteLine($"{data[i].ToString()} {agent.MakePrediction(data[i])}");
                            lineToBePrintedCount--;
                        }
                    }

                    Console.WriteLine($"This is accurate at {(double)Nbsucces / data.Count}");

                    bestNbSuccess = Nbsucces;

                    nbRunSinceLastSuccess = -1;
                }
                nbRunSinceLastSuccess++;

                if (nbRunSinceLastSuccess >= 500)
                {
                    if (_randEngine.Next() % 2 == 0)
                    {
                        agent = new Boost <HealthInfo>();
                        agent.Add(new Agent <HealthInfo>(100));
                        Console.WriteLine($"New Agent at run {run}");
                    }

                    nbRunSinceLastSuccess = 0;
                    nbAgent++;
                }

                run++;
            }

            Console.WriteLine($"The tranning is complete after {run} run and {nbAgent} agents");
            int dataEvaluation = 0;

            foreach (var d in testData)
            {
                if ((agent.MakePrediction(d) > 0) == (d.Target > 0))
                {
                    dataEvaluation++;
                }
            }
            Console.WriteLine($"Final score is {(double)dataEvaluation/testData.Count} or {dataEvaluation} / {testData.Count}");
            Console.ReadLine();
        }