private static bool IsSame(LifeEventVectorArgs args1, LifeEventVectorArgs args2) { if (args1 == null && args2 == null) { return(true); } else if (args1 == null || args2 == null) { return(false); } if (args1.Type != args2.Type) { return(false); } else if (args1.Time != args2.Time) { return(false); } else if (args1.Strength != args2.Strength) { return(false); } else if (!IsSame(args1.Vector, args2.Vector)) // the vectors are small, so just compare all elements { return(false); } return(true); }
private void LifeEvents_EventOccurred(object sender, LifeEventVectorArgs e) { // Tell this list to suppress adds for a while _nonLifeEventSnapshots.EventOcurred(); var camera = _camera; if (camera == null) { return; } // Get a copy of the input that occurred before the event happened double[][] inputs = _shortTermMemory.GetSnapshots(e.Time, 3); if (inputs == null || inputs.Length == 0) { return; } // Get some rotations of it inputs = inputs. SelectMany(o => GetRotations(o, camera.PixelWidthHeight, camera.PixelWidthHeight, _isColor)). ToArray(); lock (_lock) { // Store these pairings foreach (double[] input in inputs) { _importantEvents.Add(Tuple.Create(e, input)); } _areLifeEventsDirty = true; if (_trainingTask != null) { // Training is currently running. Let it finish return; } // Kick off a training TrainerInput trainerInput = GetTrainingInput(); if (trainerInput == null) { return; } _areLifeEventsDirty = false; _trainingTask = new Task<TrainedRecognizer>(() => Train(trainerInput, _convolution, _isColor, _finalResolution)); _trainingTask.ContinueWith(r => FinishedTraining(r.Result)); _trainingTask.Start(); } }
private static bool IsSame(LifeEventVectorArgs args1, LifeEventVectorArgs args2) { if (args1 == null && args2 == null) { return true; } else if (args1 == null || args2 == null) { return false; } if (args1.Type != args2.Type) { return false; } else if (args1.Time != args2.Time) { return false; } else if (args1.Strength != args2.Strength) { return false; } else if (!IsSame(args1.Vector, args2.Vector)) // the vectors are small, so just compare all elements { return false; } return true; }