public void CustomResetSpeedTest() { int iter = 10000; float initialValueWeights = 1.0f; mlp.Reset(initialValueWeights, true); mlpMN.Reset(true); SystemRandomSource rndGenerator = new SystemRandomSource(seed); List <Matrix <float> > weightsMN = new List <Matrix <float> >(); List <float[, ]> weights = new List <float[, ]>(); for (int i = 0; i < shapes.Count - 1; i++) { weightsMN.Add(Matrix <float> .Build.Random(mlpMN.layers[i + 1].RowCount, mlpMN.layers[i].RowCount, new ContinuousUniform(-initialValueWeights, initialValueWeights, rndGenerator))); } for (int i = 0; i < shapes.Count - 1; i++) { weights.Add(new float[mlp.layers[i].GetLength(1), mlp.layers[i + 1].GetLength(1)]); } for (int i = 0; i < shapes.Count - 1; i++) { for (int j = 0; j < weights[i].GetLength(0); j++) { for (int k = 0; k < weights[i].GetLength(1); k++) { weights[i][j, k] = (float)ContinuousUniform.Sample(rndGenerator, -initialValueWeights, initialValueWeights); } } } var watch = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < iter; i++) { mlpMN.Reset(false, weightsMN); } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Debug.Log("Reset Time MathNet: " + elapsedMs); watch = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < iter; i++) { mlp.Reset(initialValueWeights, false, weights); } watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; Debug.Log("Reset Time Array: " + elapsedMs); Assert.AreEqual(mlp.weights, weights); Assert.AreEqual(mlpMN.weights, weightsMN); }
public void ResetSpeedTest() { int iter = 1000; mlpMN = new MultiLayerMathsNet(seed, null, shapes, 1, initialValueWeights); mlp = new MultiLayer(shapes, seed, 1, null); var watch = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < iter; i++) { mlpMN.Reset(true); } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Debug.Log("Reset Time MathNet: " + elapsedMs); watch = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < iter; i++) { mlp.Reset(1.0f, true); } watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; Debug.Log("Reset Time Array: " + elapsedMs); }