static void ApplyLSF(string predVal) { datapoints.Enqueue(new Tuple <int, double>(dataN, double.Parse(predVal))); if (datapoints.Count > 20) { datapoints.Dequeue(); } if (datapoints.Count >= 2) { var func = Fitters.GeneratePolynomialFit( datapoints.Select(dp => (double)dp.Item1).ToArray(), datapoints.Select(dp => dp.Item2).ToArray(), 1 ); var pred = func(dataN++); var needGoUp = pred < -0; // Should the drone go upwards? var goingUp = double.Parse(predVal) > 0; // Is the drone going upwards? if (needGoUp && goingUp) { bci_client.PutEvent(new BufferEvent("shrdcontrol.prediction", 2, -1)); } else if (!needGoUp && !goingUp) { bci_client.PutEvent(new BufferEvent("shrdcontrol.prediction", -2, -1)); } else if (needGoUp && !goingUp) { // What to do when need to go up, but going down? bci_client.PutEvent(new BufferEvent("shrdcontrol.prediction", 0, -1)); } else if (!needGoUp && goingUp) { // What if need to go down, but going up? bci_client.PutEvent(new BufferEvent("shrdcontrol.prediction", 0, -1)); } } }