Пример #1
0
        public void Run()
        {
            foreach (Tasks t in Enum.GetValues(typeof(Tasks)))
            {
                int max_i = ((t == Tasks.PERSON) ? 2 * numTestTrials : numTestTrials);
                foreach (Groups g in Enum.GetValues(typeof(Groups)))
                {
                    Console.WriteLine("Running Group " + g + " through task " + t);
                    for (int r = 0; r < numRepeats; r++)
                    {
                        Console.Write("Participant #" + r + " is performing the task          ");
                        double currentW = rand.Next(12);
                        double lastP    = rand.Next(12);
                        Initialize(g);

                        ActivationCollection irlSI = ImplicitComponentInitializer.NewDataSet();
                        var irlVars = (from a in As
                                       select from b in Bs
                                       select from c in Cs
                                       select
                                       new
                        {
                            A = World.GetDimensionValuePair("A", a),
                            B = World.GetDimensionValuePair("B", b),
                            C = World.GetDimensionValuePair("C", c)
                        }).SelectMany(k => k).SelectMany(k => k);
                        foreach (var k in irlVars)
                        {
                            irlSI.Add(k.A, 1);
                            irlSI.Add(k.B, 1);
                            irlSI.Add(k.C, 1);
                        }

                        DimensionValuePair targetDV = World.GetDimensionValuePair("Target P", target);

                        GenerateIRLRuleSet(IRL_Rule_Sets.ONE);
                        SensoryInformation si = null;
                        SensoryInformation prevSI;

                        for (int i = 0; i < max_i; i++)
                        {
                            int shift = 10 - (int)Math.Round(10 * ((double)i / (double)max_i));
                            Console.CursorLeft -= shift;
                            Console.Write(".");
                            for (int s = 0; s < shift - 1; s++)
                            {
                                Console.Write(" ");
                            }
                            if ((from a in John.GetInternals(Agent.InternalContainers.ACTION_RULES) where a is IRLRule select a).Count() == 0)
                            {
                                GenerateIRLRuleSet(IRL_Rule_Sets.TWO);
                            }

                            prevSI = si;

                            si = World.NewSensoryInformation(John);

                            foreach (var s in irlSI)
                            {
                                si.Add(s);
                            }

                            si.Add(targetDV, 1);
                            si.Add(World.GetActionChunk(currentW), 1);
                            lastP = FactoryOutput(lastP, currentW);
                            si.Add(World.GetDimensionValuePair("Current P", lastP), 1);

                            if (Math.Abs(lastP - target) < double.Epsilon)
                            {
                                if ((t != Tasks.PERSON || (t == Tasks.PERSON && i >= numTestTrials)))
                                {
                                    results[(int)t, (int)g, r]++;
                                }

                                if (prevSI != null)
                                {
                                    John.ReceiveFeedback(prevSI, 1);
                                }
                            }
                            else
                            {
                                if (prevSI != null)
                                {
                                    John.ReceiveFeedback(prevSI, 0);
                                }
                            }

                            John.Perceive(si);

                            currentW = (double)John.GetChosenExternalAction(si).LabelAsIComparable;
                        }
                        Console.WriteLine();
                        Console.WriteLine("Participant #" + r + " is finished performing the task and hit the target " +
                                          results[(int)t, (int)g, r] + " times out of " + max_i);

                        Console.WriteLine("At the end of the task, the participant had the following rules: ");
                        foreach (var ar in John.GetInternals(Agent.InternalContainers.ACTION_RULES))
                        {
                            Console.WriteLine(ar);
                        }
                        John.Die();
                        World.Remove(John);
                    }
                }
                Console.WriteLine("Tabular results for the " + t + " task:");
                Console.WriteLine("Group\tParticipant\tHits");
                foreach (Groups g in Enum.GetValues(typeof(Groups)))
                {
                    for (int i = 0; i < numRepeats; i++)
                    {
                        Console.WriteLine(g + "\t" + i + "\t" + results[(int)t, (int)g, i]);
                    }
                }
            }
        }