public void DoFallDetection(ModelOutput modelOutput, int[] mRow) { if (ML.DetectMovingDown(mRow) && (modelOutput.Prediction == 4)) { fallRegistered = true; fallWarning(); } if (fallRegistered) { getUpCounter++; } if (getUpCounter > 1) { if (GetEvent(modelOutput.Score[1]) || GetEvent(modelOutput.Score[2]) || GetEvent(modelOutput.Score[3])) { fallNotDetected(); fallRegistered = false; getUpCounter = 0; } else if (getUpCounter == 10) { //Fall detected raise alarm fallDetected(); } } }
/// <summary> /// Called once in a second /// </summary> /// <param name="inputRow"></param> private void DoMachineLearning(int[] inputRow, string file, bool isPredicting) { try { if (previousInputRow == null) { previousInputRow = new int[32]; inputRow.CopyTo(previousInputRow, 0); return; } DateTime dtNow = DateTime.Now; movementRow = new int[32]; for (int i = 0; i < 32; i++) { movementRow[i] = inputRow[i] - previousInputRow[i]; } if (Properties.Settings.Default.MovementRow) { AddInfo(string.Join(",", movementRow)); } inputRow.CopyTo(previousInputRow, 0); if (isPredicting) { SetUpFallDetection(); ModelOutput modelOutput = ML.Predict(CalibratedInputRow(inputRow), movementRow); ShowMLPrediction(modelOutput); fallDetection.DoFallDetection(modelOutput, movementRow); } else if (trainingItem != MLTraining.FALLING || ML.DetectMovingDown(movementRow)) { if (trainingItem == MLTraining.FALLING) { AddInfo("Moving down detected"); } File.AppendAllText(file, (int)trainingItem + "\t" + string.Join("\t", CalibratedInputRow(inputRow)) + "\t" + string.Join("\t", movementRow) + Environment.NewLine); } } catch (Exception ex) { AddInfo("Error training: " + ex.Message); } }