예제 #1
0
        private void LoadParameterInstructions()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(ParameterInstructions);
            List <ParameterSetting> parameters = new List <ParameterSetting>();
            var children = doc["Root"]?.ChildNodes;

            if (children != null)
            {
                foreach (XmlNode child in children)
                {
                    if (child.Name == "Parameter")
                    {
                        var attributes = child.Attributes;
                        if (attributes != null)
                        {
                            ParameterSetting current = new ParameterSetting
                            {
                                ParameterName = attributes["Name"].InnerText,
                                MsNumber      = int.Parse(attributes["MS"].InnerText),
                                Start         = float.Parse(attributes["Start"].InnerText),
                                Stop          = float.Parse(attributes["Stop"].InnerText)
                            };
                            current.Current = current.Start;
                            parameters.Add(current);
                        }
                    }
                }
            }
            Parameters = parameters.ToArray();
        }
예제 #2
0
        public void Explore(ParameterSetting[] parameters, Action UpdateProgress, Func <ParameterSetting[], float> evaluationfunction)
        {
            this.Progress = 0;
            Random rand = new Random((++this.NumberOfExplorations) * (this.RandomSeed));
            var    numberOfParameters = parameters.Length;

            this.Kernel = parameters.Clone() as ParameterSetting[];
            this.GenerateRandomSeed(rand);
            float[,] explorationErrors    = new float[numberOfParameters, 2];
            float[,] explorationGradients = new float[numberOfParameters, 2];
            ParameterSetting[, ][] explorationPoints = new ParameterSetting[numberOfParameters, 2][];

            for (int i = 0; i < numberOfParameters; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    explorationPoints[i, j] = parameters.Clone() as ParameterSetting[];
                }
            }

            // Explore it for all of the pre-defined iterations
            for (int iteration = 0; iteration < this.TotalIterations; iteration++)
            {
                this.CurrentIteration = iteration;
                this.Progress         = (float)iteration / this.TotalIterations;
                UpdateProgress();
                // figure out how good our point is
                if (this.Exit)
                {
                    break;
                }
                var kernelError = evaluationfunction(this.Kernel);
                // Calculate all of the errors
                GenerateExplorationPoints(numberOfParameters, this.Kernel, explorationPoints, explorationErrors, evaluationfunction, UpdateProgress);
                // Calculate the gradients from the errors
                ComputeGradients(numberOfParameters, explorationErrors, explorationGradients, kernelError);
                MoveKernel(explorationGradients, rand);
            }
            this.Progress = 1;
        }
예제 #3
0
        private void LoadParameterInstructions()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(this.ParameterInstructions);
            List <ParameterSetting> parameters = new List <ParameterSetting>();

            foreach (XmlNode child in doc["Root"].ChildNodes)
            {
                if (child.Name == "Parameter")
                {
                    ParameterSetting current = new ParameterSetting();
                    current.ParameterName = child.Attributes["Name"].InnerText;
                    current.MSNumber      = int.Parse(child.Attributes["MS"].InnerText);
                    current.Start         = float.Parse(child.Attributes["Start"].InnerText);
                    current.Stop          = float.Parse(child.Attributes["Stop"].InnerText);
                    current.Current       = current.Start;
                    parameters.Add(current);
                }
            }
            this.Parameters = parameters.ToArray();
        }
예제 #4
0
파일: NetworkAI.cs 프로젝트: lunaxi7/XTMF
        public void Explore(ParameterSetting[] parameters, Action updateProgress, Func <ParameterSetting[], float> evaluationfunction)
        {
            Progress = 0;
            Random rand = new Random((++NumberOfExplorations) * (RandomSeed));
            var    numberOfParameters = parameters.Length;

            Kernel = parameters.Clone() as ParameterSetting[];
            ParameterVolatility = new float[numberOfParameters];
            Momentum            = new float[numberOfParameters];
            MoveChoice          = new float[numberOfParameters];
            PreviousMoveChoice  = new float[numberOfParameters];
            GenerateRandomSeed(rand);
            float[,] explorationErrors    = new float[numberOfParameters, 4];
            float[,] explorationGradients = new float[numberOfParameters, 4];
            ParameterSetting[, ][] explorationPoints = new ParameterSetting[numberOfParameters, 4][];
            float bestSoFar = float.MaxValue;
            int   numberOfIterationSinceBest = 0;

            for (int i = 0; i < numberOfParameters; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    explorationPoints[i, j] = parameters.Clone() as ParameterSetting[];
                }
            }

            // Explore it for all of the pre-defined iterations
            for (int iteration = 0; iteration < TotalIterations; iteration++)
            {
                CurrentIteration = iteration;
                Progress         = (float)iteration / TotalIterations;
                updateProgress();
                // figure out how good our point is
                if (Exit)
                {
                    break;
                }
                var kernelError = evaluationfunction(Kernel);
                if (kernelError < bestSoFar)
                {
                    bestSoFar = kernelError;
                    numberOfIterationSinceBest = 0;
                }
                else if ((++numberOfIterationSinceBest) > IterationsFromBest)
                {
                    break;
                }
                // Calculate all of the errors
                GenerateExplorationPoints(numberOfParameters, Kernel, explorationPoints, explorationErrors, evaluationfunction, updateProgress);
                // Calculate the gradients from the errors
                ComputeGradients(numberOfParameters, explorationErrors, explorationGradients, kernelError);
                ComputeVolatility(explorationGradients);
                if (EarlyTermination())
                {
                    break;
                }
                MoveKernel(explorationGradients, rand);
                var moveChoiceTemp = PreviousMoveChoice;
                PreviousMoveChoice = MoveChoice;
                MoveChoice         = moveChoiceTemp;
            }
            Progress = 1;
        }