/// <summary> /// Performs the common tasks of TaskInitial and TaskIntermediate /// </summary> /// <param name="window"></param> private void Process(DataWindow window) { foreach (Feature feature in _featureObjects.Values) feature.frameBlockSize = window.frames.Count; foreach (Frame frame in window.frames) { foreach (Feature feature in _featureObjects.Values) feature.Process(frame); } foreach (string key in _featureObjects.Keys) { Feature feature; if (_featureObjects.TryGetValue(key, out feature)) { window.features.Add(key, feature.output); feature.Clear(); } } }
/// <summary> /// Used to remove elements from the feature vectors belonging to channels that are not active. /// Frames stored in each DataWindow are also discarded. /// </summary> /// <param name="inputDataSet"></param> /// <returns>A DataSet object containing no frames and only features for the active channels.</returns> private DataSet CreateLightDataSet(DataSet inputDataSet, TrainingPackage trainigPackage) { DataSet outputDataSet = new DataSet(inputDataSet.movementCode, inputDataSet.movementComposition); foreach (DataWindow window in inputDataSet.set) { DataWindow lightWindow = new DataWindow(); foreach (string featureName in window.features.Keys) { double[] channelVector; object placeholder; double[] cleanVector = new double[trainingPackage.recordingConfig.activeChannels]; window.features.TryGetValue(featureName,out placeholder); channelVector = (double[])placeholder; int pos = 0; for (int i = 0; i < channelVector.Length; i++) { if(trainingPackage.recordingConfig.channelMask[i]) { cleanVector[pos] = channelVector[i]; pos++; } } lightWindow.features.Add(featureName,cleanVector); } outputDataSet.set.Add(lightWindow); } return outputDataSet; }
/// <summary> /// Called when isOnline is set to false, which is NOT the default. /// </summary> /// <param name="outputItem"></param> protected override void TaskInitial(out object outputItem) { int frameLimit = _startFrame + config.windowLength; if (_startFrame < recording.data.Count()) { DataWindow dataWindow = new DataWindow(); for (int i = _startFrame; ((i < frameLimit) && (i < recording.data.Count())); i++) dataWindow.frames.Add((Frame)recording.data.ElementAt(i)); _startFrame += _stride; outputItem = dataWindow; } else //We have to stop the acquisition, but we cannot do it from the windowmaker thread { outputItem = null; _myPipeline.stopPending = true; if (!lockingCollection.IsAddingCompleted) lockingCollection.CompleteAdding(); } }
/// <summary> /// Called when isOnline is set to true, which is its default value. /// </summary> /// <param name="inputItem"></param> /// <param name="outputItem"></param> protected override void TaskIntermediate(object inputItem, out object outputItem) { outputItem=null; Frame inputFrame = (Frame)inputItem; _outputBuffer.Add(inputFrame); _offsetCounter = (_offsetCounter + 1) % _stride; if (_outputBuffer.Count == config.windowLength) { if (_offsetCounter == 0) { _dataWindow = new DataWindow(); foreach (Frame item in _outputBuffer) _dataWindow.frames.Add(item); outputItem = _dataWindow; } _outputBuffer.RemoveAt(0); } }
/// <summary> ///Prepare the training package with a training set based on the example solved in ///http://people.revoledu.com/kardi/tutorial/LDA/Numerical%20Example.html ///One set of vectors will be assigned to movement code 1, the other to movement code 2. /// </summary> /// <returns></returns> private TrainingPackage MakeTrainingPackage() { DataWindow tempWindow; TrainingPackage trainingPackage; List<DataWindow> windowList1 = new List<DataWindow>(); List<DataWindow> windowList2 = new List<DataWindow>(); //Filling the window lists with feature vectors //List 1 tempWindow = new DataWindow(); tempWindow.features.Add("curvature", 2.95); tempWindow.features.Add("diameter", 6.63); windowList1.Add(tempWindow); tempWindow = new DataWindow(); tempWindow.features.Add("curvature", 2.53); tempWindow.features.Add("diameter", 7.79); windowList1.Add(tempWindow); tempWindow = new DataWindow(); tempWindow.features.Add("curvature", 3.57); tempWindow.features.Add("diameter", 5.65); windowList1.Add(tempWindow); tempWindow = new DataWindow(); tempWindow.features.Add("curvature", 3.16); tempWindow.features.Add("diameter", 5.47); windowList1.Add(tempWindow); //List 2 tempWindow = new DataWindow(); tempWindow.features.Add("curvature", 2.58); tempWindow.features.Add("diameter", 4.46); windowList2.Add(tempWindow); tempWindow = new DataWindow(); tempWindow.features.Add("curvature", 2.16); tempWindow.features.Add("diameter", 6.22); windowList2.Add(tempWindow); tempWindow = new DataWindow(); tempWindow.features.Add("curvature", 3.27); tempWindow.features.Add("diameter", 3.52); windowList2.Add(tempWindow); trainingPackage = new TrainingPackage(); trainingPackage.trainingSets.Add(new DataSet(1, windowList1)); trainingPackage.trainingSets.Add(new DataSet(2, windowList2)); return trainingPackage; }