Example #1
0
 public static void Mutate(Network network, float chance, float magnitude, ref Rng r)
 {
     for (int l = 0; l < network.Layers.Count; l++)
     {
         for (int p = 0; p < network.Layers[l].ParamCount; p++)
         {
             if (r.NextDouble() < chance)
             {
                 network.Layers[l][p] = Mathf.Clamp(network.Layers[l][p] + Ramjet.Mathematics.Math.Gaussian(ref r, 0f, 1f) * magnitude, -PMax, PMax);
             }
         }
     }
 }
Example #2
0
        public static void Double()
        {
            Unity.Mathematics.Random rng = new Unity.Mathematics.Random(Helpers.GetRngSeed);

            Helpers.Test <double>(
                (array) =>
            {
                array.SIMD_MinMax(out double min, out double max);

                Assert.AreEqual(min, array.SIMD_Minimum());
                Assert.AreEqual(max, array.SIMD_Maximum());
            },
                () => rng.NextDouble(double.MinValue, double.MaxValue));
        }
Example #3
0
 public static void CrossOver(Network a, Network b, Network c, ref Rng r)
 {
     for (int l = 0; l < c.Layers.Count; l++)
     {
         int paramsLeft = c.Layers[l].ParamCount;
         while (paramsLeft > 0)
         {
             int     copySeqLength = Math.Min(r.NextInt(4, 16), paramsLeft);
             Network parent        = r.NextDouble() < 0.5f ? a : b;
             for (int p = 0; p < copySeqLength; p++)
             {
                 c.Layers[l][p] = parent.Layers[l][p];
             }
             paramsLeft -= copySeqLength;
         }
     }
 }
Example #4
0
 private static byte SelectOutcomeIndex(
     ref Unity.Mathematics.Random rand,
     NativeArray <RuleOutcome.Blittable> outcomes,
     JaggedIndexing allOutcomes)
 {
     if (allOutcomes.length > 1)
     {
         var    sample           = rand.NextDouble();
         double currentPartition = 0;
         for (byte i = 0; i < allOutcomes.length; i++)
         {
             var possibleOutcome = outcomes[i + allOutcomes.index];
             currentPartition += possibleOutcome.probability;
             if (sample <= currentPartition)
             {
                 return(i);
             }
         }
         throw new LSystemRuntimeException("possible outcome probabilities do not sum to 1");
     }
     return(0);
 }