/// <inheritdoc /> public double Transform(double[] data) { if (double.IsNaN(data[_fieldIdx])) { throw new InvalidOperationException($"Invalid data value at input field index {_fieldIdx} (NaN)."); } _lastValues.Enqueue(data[_fieldIdx], true); BasicStat stat = new BasicStat(); for (int i = 0; i < _lastValues.Count; i++) { stat.AddSample(_lastValues.GetElementAt(i, true)); } return(stat.Get(_cfg.OutputFigure)); }
/// <summary> /// Updates the predictors provider. /// </summary> /// <param name="activation">The current value of the activation.</param> /// <param name="normalizedActivation">The current value of the activation normalized between 0 and 1.</param> /// <param name="spike">Indicates whether the neuron is currently firing.</param> public void Update(double activation, double normalizedActivation, bool spike) { //Continuous statistics double activationDiff = activation - _lastActivation; _activationStat?.AddSample(activation); _activationDiffStat?.AddSample(activationDiff); //Data windows _activationMDW?.AddSample(activation); _firingMDW?.Enqueue(spike ? (byte)1 : (byte)0); //Predictors foreach (IPredictor predictor in _predictorCollection) { predictor.Update(activation, normalizedActivation, spike); } //Last activation _lastActivation = activation; _lastNormalizedActivation = normalizedActivation; _lastSpike = spike; return; }
/// <summary> /// Computes the rescaled range. /// </summary> public double Compute() { double rescaledRange = 0; if (_valueCollection.Count > 0) { BasicStat devStat = new BasicStat(); Interval cumulRange = new Interval(); double mean = _sum / _valueCollection.Count; double cumulDeviation = 0; for (int i = 0; i < _valueCollection.Count; i++) { devStat.AddSample(_valueCollection[i] - mean); cumulDeviation += _valueCollection[i] - mean; cumulRange.Adjust(cumulDeviation); } if (devStat.StdDev != 0) { rescaledRange = cumulRange.Span / devStat.StdDev; } } return(rescaledRange); }
/// <summary> /// Checks the predictors and sets the general enabling/disabling switches. /// </summary> /// <param name="predictorsCollection">The collection of predictors.</param> private void InitOutputFeaturesGeneralSwitches(List <double[]> predictorsCollection) { //Allocate general switches OutputFeatureGeneralSwitchCollection = new bool[PredictorDescriptorCollection.Count]; //Init general predictor switches to false OutputFeatureGeneralSwitchCollection.Populate(false); //Compute statistics on predictors Tuple <int, double>[] predictorValueSpanCollection = new Tuple <int, double> [PredictorDescriptorCollection.Count]; Parallel.For(0, PredictorDescriptorCollection.Count, i => { BasicStat stat = new BasicStat(); for (int row = 0; row < predictorsCollection.Count; row++) { stat.AddSample(predictorsCollection[row][i]); } //Use predictor's value span as a differentiator predictorValueSpanCollection[i] = new Tuple <int, double>(i, stat.Span); }); //Sort collected predictor differentiators Array.Sort(predictorValueSpanCollection, ComparePredictors); //Enable predictors int numOfPredictorsToBeRejected = (int)(Math.Round(PredictorDescriptorCollection.Count * _preprocessorCfg.PredictorsReductionRatio)); int firstIndexToBeRejected = predictorValueSpanCollection.Length - numOfPredictorsToBeRejected; NumOfActivePredictors = 0; for (int i = 0; i < predictorValueSpanCollection.Length; i++) { if (predictorValueSpanCollection[i].Item2 > _preprocessorCfg.PredictorValueMinSpan && i < firstIndexToBeRejected) { //Enable predictor OutputFeatureGeneralSwitchCollection[predictorValueSpanCollection[i].Item1] = true; ++NumOfActivePredictors; } } return; }