public override void DoDropout(Volume <double> result, bool isTraining, double dropProbability) { if (isTraining) { if (((NcwhVolumeStorage <double>) this.Storage).Dropped == null || ((NcwhVolumeStorage <double>) this.Storage).Dropped.Length != this.Shape.TotalLength) { ((NcwhVolumeStorage <double>) this.Storage).Dropped = new bool[this.Shape.TotalLength]; } } if (isTraining) { // do dropout this.Storage.Map((x, i) => { var nextDouble = RandomUtilities.NextDouble(); if (nextDouble < dropProbability) { ((NcwhVolumeStorage <double>) this.Storage).Dropped[i] = true; return(0); } else { ((NcwhVolumeStorage <double>) this.Storage).Dropped[i] = false; return(x / (1 - dropProbability)); // a bit different than ConvNetJS here to match cudnn behaviour } }, result.Storage); } else { // scale the activations during prediction this.Storage.Map(x => x, result.Storage); } }
public override void Dropout(float dropProbability, Volume <float> result) { if (((NcwhVolumeStorage <float>) this.Storage).Dropped == null || ((NcwhVolumeStorage <float>) this.Storage).Dropped.Length != this.Shape.TotalLength) { ((NcwhVolumeStorage <float>) this.Storage).Dropped = new bool[this.Shape.TotalLength]; } if (dropProbability > 0.0f) { // do dropout this.Storage.Map((x, i) => { var nextDouble = RandomUtilities.NextDouble(); if (nextDouble < dropProbability) { ((NcwhVolumeStorage <float>) this.Storage).Dropped[i] = true; return(0); } ((NcwhVolumeStorage <float>) this.Storage).Dropped[i] = false; return(x / (1 - dropProbability)); // Scale up so that magnitude remains constant accross training and testing }, result.Storage); } else { this.Storage.Map(x => x, result.Storage); } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText optionText, PlainText minValueText, PlainText maxValueText, ComplexMessage elements) { string option = optionText.Content.ToLower(); if (option == "number") { if (double.TryParse(minValueText, out double minValue) && double.TryParse(maxValueText, out double maxValue)) { e.Reply(RandomUtilities.NextDouble(minValue, maxValue).ToString()); Handled = true; } } else if (option == "numberint") { if (long.TryParse(minValueText, out long minValue) && long.TryParse(maxValueText, out long maxValue)) { e.Reply(RandomUtilities.Next(minValue, maxValue).ToString()); Handled = true; } } }
public override void DoDropout(Volume <float> result, bool isTraining, float dropProbability) { if (isTraining) { if (((NcwhVolumeStorage <float>) this.Storage).Dropped == null || ((NcwhVolumeStorage <float>) this.Storage).Dropped.Length != this.Shape.TotalLength) { ((NcwhVolumeStorage <float>) this.Storage).Dropped = new bool[this.Shape.TotalLength]; } } var batchSize = this.Shape.DimensionCount > 1 ? this.Shape.GetDimension(-1) : 1; for (var n = 0; n < batchSize; n++) { if (isTraining) { // do dropout this.Storage.Map((x, i) => { var nextDouble = RandomUtilities.NextDouble(); if (nextDouble < dropProbability) { ((NcwhVolumeStorage <float>) this.Storage).Dropped[i] = true; return(0); } ((NcwhVolumeStorage <float>) this.Storage).Dropped[i] = false; return(x / (1 - dropProbability)); // a bit different than ConvNetJS here to match cudnn behaviour }, result.Storage); } else { // scale the activations during prediction this.Storage.Map(x => x, result.Storage); } } }