/// <inheritdoc/> public double Compute(BasicStat continuousActivationStat, BasicStat continuousActivationDiffStat, MovingDataWindow activationMDW, SimpleQueue <byte> firingMDW, double activation, double normalizedActivation, bool spike ) { PredictorFiringTraceSettings cfg = (PredictorFiringTraceSettings)Cfg; if (cfg.Window == PredictorFiringTraceSettings.NAWindowNum) { return(_continuousTrace); } else { if (firingMDW.Count >= cfg.Window) { double trace = 0d; for (int i = cfg.Window - 1; i >= 0; i--) { trace *= (1d - cfg.Fading); trace += firingMDW.GetElementAt(i, true); } return(trace); } else { return(0d); } } }
/// <inheritdoc/> public override byte[][] GetCode(double normalizedValue) { //Allocate and set all output to 0 byte[][] buffer = new byte[NumOfComponents][]; for (int i = 0; i < NumOfComponents; i++) { buffer[i] = new byte[BaseCodeLength]; buffer[i].Populate((byte)0); } double x = (normalizedValue + 1d) / 2d; //Code for (int i = 0; i < _coderCfg.NumOfReceptors; i++) { double histValue = _histValues.GetElementAt(i, true); if (x < histValue) { double diff = histValue - x; GetStrengthCode(diff, BaseCodeLength).CopyTo(buffer[i], 0); } } //Enqueue the last value _histValues.Enqueue(x, true); return(buffer); }
/// <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> /// Computes transformed value /// </summary> /// <param name="data">Collection of natural values of the already known input fields</param> public double Next(double[] data) { double transVal = 0d; if (double.IsNaN(data[_fieldIdx])) { throw new InvalidOperationException($"Invalid data value at input field index {_fieldIdx} (NaN)."); } if (_lastValues.Full) { //Moving data window is ready transVal = data[_fieldIdx] - _lastValues.GetElementAt(_settings.Interval - 1, true); } _lastValues.Enqueue(data[_fieldIdx], true); return(transVal); }
/// <summary> /// Computes transformed value /// </summary> /// <param name="data">Collection of natural values of the already known input fields</param> public double Next(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.AddSampleValue(_lastValues.GetElementAt(i, true)); } switch (_settings.Output) { case OutputValue.Sum: return(stat.Sum); case OutputValue.NegSum: return(stat.NegSum); case OutputValue.PosSum: return(stat.PosSum); case OutputValue.SumOfSquares: return(stat.SumOfSquares); case OutputValue.Min: return(stat.Min); case OutputValue.Max: return(stat.Max); case OutputValue.Mid: return(stat.Mid); case OutputValue.Span: return(stat.Span); case OutputValue.ArithAvg: return(stat.ArithAvg); case OutputValue.MeanSquare: return(stat.MeanSquare); case OutputValue.RootMeanSquare: return(stat.RootMeanSquare); case OutputValue.Variance: return(stat.Variance); case OutputValue.StdDev: return(stat.StdDev); case OutputValue.SpanDev: return(stat.SpanDev); default: return(0); } }
/// <summary> /// Returns number at the specified position within the moving data window /// </summary> /// <param name="index">Position</param> /// <param name="latestFirst">Specifies logical order (latest..oldest or oldest..latest)</param> public double GetAt(int index, bool latestFirst = false) { return(_dataWindow.GetElementAt(index, latestFirst)); }