当前位置: 首页>>代码示例>>C#>>正文


C# INode.Calculate方法代码示例

本文整理汇总了C#中INode.Calculate方法的典型用法代码示例。如果您正苦于以下问题:C# INode.Calculate方法的具体用法?C# INode.Calculate怎么用?C# INode.Calculate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在INode的用法示例。


在下文中一共展示了INode.Calculate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateFitness

        public double CalculateFitness(INode individual)
        {
            // Keep track the average error
            double totalError = 0;
            const int numberTests = 50;

            for (int i = 0; i < numberTests; ++i)
            {
                int input1 = RandomUtil.Random.Next(100);
                int input2 = RandomUtil.Random.Next(100);
                int input3 = RandomUtil.Random.Next(100);
                int input4 = RandomUtil.Random.Next(100);
                if (input4 == 0) input4 = 1;
                double expectedResult = (double)input1 + (double)input2*(double)input3/(double)input4;

                double error = expectedResult - individual.Calculate(new List<double>{input1, input2, input3, input4}, new List<List<double>>());
                error = Math.Abs(error);
                error = Math.Abs(Math.Sqrt(0.1*error));
                totalError += error;

                // Add some error if the error is too large taking account of the size
                //if (error > 0.3) totalError += individual.GetNodes().Count/100.0;
            }

            return totalError/numberTests;
        }
开发者ID:geoffsmith,项目名称:Genetic-Programming,代码行数:26,代码来源:AddThreeVariablesFitnessFunction.cs

示例2: SimplifyNode

        private static void SimplifyNode(ref INode result)
        {
            // Check for an InputVariableNode in result
            if (result.GetNodes().Any(n => n.GetType() == typeof(InputVariableNode) || n.GetType() == typeof(InputSizeNode)
                || n.GetType() == typeof(CollectionSizeNode) || n.GetType() == typeof(SumNode)))
                return;

            // We don't have an InputVariableNode, so we can simplify into a single constant
            double constant = result.Calculate(new List<double>(), new List<List<double>>());
            result = new ConstantNode(result.Context, constant);
        }
开发者ID:geoffsmith,项目名称:Genetic-Programming,代码行数:11,代码来源:NodeFactory.cs

示例3: CalculateFitness

        public double CalculateFitness(INode individual)
        {
            // Keep track the average error
            double totalError = 0;
            const int numberTests = 50;

            for (int i = 0; i < numberTests; ++i)
            {
                int input = RandomUtil.Random.Next(100);
                double expectedResult = input*20.0;

                double error = expectedResult - individual.Calculate(new List<double>{input}, new List<List<double>>());
                error = Math.Abs(error);
                totalError += Math.Abs(Math.Sqrt(0.1*error));
            }

            return totalError/numberTests;
        }
开发者ID:geoffsmith,项目名称:Genetic-Programming,代码行数:18,代码来源:TimesThreeFitnessFunction.cs

示例4: CalculateFitness

        public double CalculateFitness(INode individual)
        {
            // Don't allow nodes to get too big
            if (individual.GetNodes().Count > 30) return 1000;

            if (this.perfectNode == null) this.CreatePerfectNode();

            // Keep track the average error
            double totalError = 0;
            const int numberTests = 50;

            for (int i = 0; i < numberTests; ++i)
            {
                int top = RandomUtil.Random.Next(1000);
                int size = RandomUtil.Random.Next(10);
                if (size == 0) size = 1;
                double expectedTotal = 0.0;
                List<double> input = new List<double>();
                for (int j = 0; j < size; ++j)
                {
                    double expectedItem = RandomUtil.Random.Next(top);
                    input.Add(expectedItem);
                    expectedTotal += expectedItem;
                }
                double expectedResult = expectedTotal/(double) size;

                List<List<double>> inputs = new List<List<double>>();
                inputs.Add(input);

                double error = expectedResult - individual.Calculate(new List<double>(), inputs);
                error = Math.Abs(error);
                error = Math.Abs(Math.Sqrt(0.1*error));
                totalError += error;

                // Add some error if the error is too large taking account of the size
                //if (error > 0.3) totalError += individual.GetNodes().Count/100.0;

            }

            return totalError/(double)(numberTests);
        }
开发者ID:geoffsmith,项目名称:Genetic-Programming,代码行数:41,代码来源:AverageFitnessFunction.cs

示例5: CalculateFitness

        public double CalculateFitness(INode individual)
        {
            // Don't allow nodes to get too big
            if (individual.GetNodes().Count > 30) return 1000;

            // We don't allow an individual to take more than 1 second to test
            DateTime startTime = DateTime.Now;

            // Keep track the average error
            double totalError = 0;

            // Keep track of results to make sure that we have some non-zero
            bool haveNonZero = false;

            //INode ideal = MakeVarianceNode();

            foreach (TestCase testCase in this.testCases)
            {
                double calculate = individual.Calculate(new List<double>(), testCase.Inputs);

                if (calculate != 0) haveNonZero = true;

                double error = testCase.ExpectedResult - calculate;

                //error = Math.Abs(Math.Sqrt(0.1*error));
                if (testCase.ExpectedResult != 0) error = error/testCase.ExpectedResult;
                totalError += Math.Abs(error);

                // Add some error if the error is too large taking account of the size
                //if (error > 0.3) totalError += individual.GetNodes().Count/100.0;

                // If we've gone over a second, stop with a high error
                if ((DateTime.Now - startTime).TotalMilliseconds > StandardDeviationFitnessFunction.maximumRunLength)
                    return Double.MaxValue;
            }

            if (!haveNonZero) return Double.MaxValue;

            return totalError/(double)(this.testCases.Count);
        }
开发者ID:geoffsmith,项目名称:Genetic-Programming,代码行数:40,代码来源:StandardDeviationFitnessFunction.cs

示例6: Train

        public double Train(INode Node, int Epochs = 1000)
        {
            if (Epochs < 1)
                throw new ArgumentException("At least 1 epoch is required.");

            if (DataSets.Length < 1)
                throw new ArgumentException("No DataSets have been loaded.");

            if (InputCount != Node.Inputs)
                throw new ArgumentException("The given INode does not have the same number of Inputs as the DataSets.");

            if (OutputCount != 1)
                throw new ArgumentException("An INode only supports 1 output.");

            for (int i = 0; i < Epochs; i++)
            {
                foreach (var dataSet in DataSets)
                {
                    double delta = 0;
                    double result = Node.Calculate(dataSet.Inputs, dataSet.Outputs.First(), ref delta);

                    // weight delta = learning rate * error * weight
                    AdjustNode(Node, dataSet.Inputs, LearningRate * delta);

                }
            }

            double SSE = 0;
            foreach (var dataSet in DataSets)
            {
                double result = Node.Calculate(dataSet.Inputs);
                SSE += Math.Pow(dataSet.Outputs.First() - result, 2);
            }
            return SSE;
        }
开发者ID:RichTeaMan,项目名称:NeuralNet,代码行数:35,代码来源:BackPropagation.cs


注:本文中的INode.Calculate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。