private static Convolution2D GetRandomFilter_Positive(bool isSquare) { Random rand = StaticRandom.GetRandomForThread(); var size = GetFilterSize(rand, isSquare); double[] values = Enumerable.Range(0, size.Item1 * size.Item2). Select(o => rand.NextDouble()). ToArray(); values = Convolutions.ToUnit(values); return(new Convolution2D(values, size.Item1, size.Item2, false)); }
private static Convolution2D GetRandomFilter_PosNeg(bool isSquare) { Random rand = StaticRandom.GetRandomForThread(); var size = GetFilterSize(rand, isSquare); double[] values = Enumerable.Range(0, size.Item1 * size.Item2). Select(o => rand.NextDouble(-1, 1)). ToArray(); if (values.All(o => o > 0) || values.All(o => o < 0)) { // They are all positive or all negative. Flip one of them values[rand.Next(values.Length)] *= -1d; } values = Convolutions.ToUnit(values); return(new Convolution2D(values, size.Item1, size.Item2, true)); }