本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例7: RotateFlipRandom
public static void RotateFlipRandom(this Image image, IRandomGenerator random)
{
image.RotateFlip((RotateFlipType)random.Next(0, 7));
}