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


C# IRandomGenerator.Next方法代码示例

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


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

示例1: CreateIndividual

        public override Individual CreateIndividual(IRandomGenerator randomGenerator)
        {
            var ant = new ArtificialAnt(this, 0, StatesNumber, EventsNumber);

            for (int state = 0; state < StatesNumber; state++)
            {
                for (int @event = 0; @event < EventsNumber; @event++)
                {
                    ant.Transitions[state, @event] =
                        new FiniteAutomaton.StateTransition(randomGenerator.Next(StatesNumber), randomGenerator.Next(ant.OutputsNumber));
                }
            }

            return ant;
        }
开发者ID:shadercoder,项目名称:MathCore,代码行数:15,代码来源:ArtificialAntProblem.cs

示例2: Train

        public override void Train(IList<InputOutput> trainingSet,
            IList<InputOutput> validationSet,
            IRandomGenerator rand,
            INeuralNetwork nn)
        {
            var prevWeightGradients = nn.Weights.DeepClone();

            foreach (var gradSet in prevWeightGradients)
            {
                for (var j = 0; j < gradSet.Length; j++)
                    gradSet[j] = 0;
            }

            for (var s = 0; s < NumEpochs; s++)
            {
                var t = rand.Next(trainingSet.Count);
                var inputOutput = trainingSet[t];

                var batch = GetBatch(trainingSet, BatchSize, rand);

                var gradients = nn.Weights.DeepCloneToZeros();

                for (var j = 0; j < BatchSize; j++)
                {
                    gradients.AddInPlace(
                        nn.CalculateGradients(batch[j].Input.AddRelativeNoise(MaxRelativeNoise, rand), batch[j].Output));
                }

                gradients.MultiplyInPlace(1 / ((double)BatchSize));

                //var gradients = nn.CalculateGradients(inputOutput.Input, inputOutput.Output);
                AdjustWeights(nn, gradients, prevWeightGradients);
                gradients.DeepCopyTo(prevWeightGradients);
            }
        }
开发者ID:ikhramts,项目名称:NNX,代码行数:35,代码来源:SimpleGradientTrainer.cs

示例3: GenerateImage

        public static Bitmap GenerateImage(IRandomGenerator generator,int imageSize)
        {
            //Generates white gray black images
            Bitmap outImage = new Bitmap(imageSize,imageSize);

            for(int x=0;x<imageSize;x++)
            {
                for(int y=0;y<imageSize;y++ )
                {
                        int value = generator.Next();
                        outImage.SetPixel(x,y,Color.FromArgb(value,value,value));
                }
            }
            outImage.Save("test.bmp");
            return outImage;
        }
开发者ID:michal-franc,项目名称:ImageClassification,代码行数:16,代码来源:ImageGenerator.cs

示例4: Crossover

        public override IEnumerable<Individual> Crossover(Individual anotherIndividual, IRandomGenerator randomGenerator)
        {
            var another = anotherIndividual as FiniteAutomaton;
            if (another == null) throw new ArgumentException();

            var children = new FiniteAutomaton[2];
            for (int i = 0; i < 2; i++)
                children[i] = Create(0, StatesNumber, EventsNumber);

            if (randomGenerator.Next(2) == 1)
            {
                children[0].InitialState = another.InitialState;
                children[1].InitialState = InitialState;
            }
            else
            {
                children[0].InitialState = InitialState;
                children[1].InitialState = another.InitialState;
            }

            for (int state = 0; state < StatesNumber; state++)
            {
                int flag = randomGenerator.Next(4);
                switch (flag)
                {
                    case 0:
                        for (int @event = 0; @event < EventsNumber; @event++)
                        {
                            children[0].Transitions[state, @event] = another.Transitions[state, @event];
                            children[1].Transitions[state, @event] = Transitions[state, @event];
                        }
                        break;

                    case 1:
                        for (int @event = 0; @event < EventsNumber; @event++)
                        {
                            children[0].Transitions[state, @event] = Transitions[state, @event];
                            children[1].Transitions[state, @event] = another.Transitions[state, @event];
                        }
                        break;

                    case 2:
                        for (int @event = 0; @event < EventsNumber / 2; @event++)
                        {
                            int secondHalf = @event + EventsNumber / 2;
                            children[0].Transitions[state, @event] = another.Transitions[state, @event];
                            children[0].Transitions[state, secondHalf] = Transitions[state, secondHalf];
                            children[1].Transitions[state, @event] = another.Transitions[state, @event];
                            children[1].Transitions[state, secondHalf] = Transitions[state, secondHalf];
                        }
                        break;

                    case 3:
                        for (int @event = 0; @event < EventsNumber / 2; @event++)
                        {
                            int secondHalf = @event + EventsNumber / 2;
                            children[0].Transitions[state, @event] = Transitions[state, @event];
                            children[0].Transitions[state, secondHalf] = another.Transitions[state, secondHalf];
                            children[1].Transitions[state, @event] = Transitions[state, @event];
                            children[1].Transitions[state, secondHalf] = another.Transitions[state, secondHalf];
                        }
                        break;
                }
            }

            return children;
        }
开发者ID:shadercoder,项目名称:MathCore,代码行数:67,代码来源:FiniteAutomaton.cs

示例5: Mutate

        public override Individual Mutate(IRandomGenerator randomGenerator)
        {
            int newInitialState = InitialState;
            if (randomGenerator.Next(2) == 1)
            {
                newInitialState = randomGenerator.Next(StatesNumber);
            }

            var mutatedIndividual = Create(newInitialState, StatesNumber, EventsNumber);

            // copy all states
            for (int i = 0; i < mutatedIndividual.StatesNumber; i++)
            {
                for (int j = 0; j < mutatedIndividual.EventsNumber; j++)
                {
                    var t = Transitions[i, j];
                    mutatedIndividual.Transitions[i, j] = new StateTransition(t.EndState, t.Output);
                }
            }

            int randomState = randomGenerator.Next(StatesNumber);
            int randomEvent = randomGenerator.Next(EventsNumber);
            int randomEndState = randomGenerator.Next(mutatedIndividual.StatesNumber);
            mutatedIndividual.Transitions[randomState, randomEvent] = new StateTransition(randomEndState, randomGenerator.Next(OutputsNumber));

            return mutatedIndividual;
        }
开发者ID:shadercoder,项目名称:MathCore,代码行数:27,代码来源:FiniteAutomaton.cs

示例6: GetBatch

        public static IList<InputOutput> GetBatch(IList<InputOutput> set, int size, IRandomGenerator rand)
        {
            var batch = new InputOutput[size];

            for (var i = 0; i < size; i++)
                batch[i] = set[rand.Next(set.Count)];

            return batch;
        }
开发者ID:ikhramts,项目名称:NNX,代码行数:9,代码来源:BaseTrainer.cs

示例7: RotateFlipRandom

 public static void RotateFlipRandom(this Image image, IRandomGenerator random)
 {
     image.RotateFlip((RotateFlipType)random.Next(0, 7));
 }
开发者ID:piotrosz,项目名称:Collage,代码行数:4,代码来源:ImageExtensions.cs


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