/// <summary> /// Returns a particular testing example from the examples in the dataset. /// </summary> public int[] getTestingExample(int exampleNum) { if (exampleNum < 0 || exampleNum >= TestingSet.Count) { throw new Exception("Example number " + exampleNum + " does not exist."); } return((int[])TestingSet.ElementAt(exampleNum)); }
/// <summary> /// Moves an example from the training set to /// the testing set. If the supplied example number /// is out of range no example is moved. /// </summary> /// <param name="exampleNum">The example to transfer to the training set.</param> public void moveToTrainingSet(int exampleNum) { if (exampleNum < 0 || exampleNum > (TestingSet.Count - 1)) { return; } TrainingSet.Add((int[])TestingSet.ElementAt(exampleNum)); TestingSet.RemoveAt(exampleNum); }
public void StartRecording(TestingSet TestingSet) { int record = TestingSet.RecordDuration; int rest = TestingSet.RestDuration; EmotivCommandType[] prompts = TestingSet.Prompts; if (OverideDurations) { record = RecordDuration; rest = RestDuration; } if (OveridePrompts) { prompts = Prompts; } LastTestingSessions = prompts; try { Title.text = ""; States = new List <IEmotivState> [prompts.Length]; for (int i = 0; i < States.Length; i++) { States[i] = new List <IEmotivState>(); } IsBreak = true; SessionIndex = 0; DeviceManager.ReaderPlugin.OnRead -= ListenToState; DeviceManager.ReaderPlugin.OnRead += ListenToState; StartCoroutine(StartReading(prompts, record, rest)); } catch (Exception e) { Debug.Log(e); Crashlytics.RecordCustomException("Profile Exception", "thrown exception", e.StackTrace); } }
/// <summary> /// Creates a random testing dataset. Calling this /// method will destroy any previously built testing set. /// </summary> /// <param name="percentage">Percentage of the entire dataset to use for testing.</param> /// <param name="balanced">to create a balanced /// testing set, where the testing set and the /// remaining training set have the same proportion /// of each class.</param> public void createRndTestSet(int percentage, bool balanced) { if (percentage < 0 || percentage > 100) { throw new Exception("Percentage value out of range."); } // Move any examples that are part of the current testing // set back to the training set. for (int i = 0; i < TestingSet.Count; i++) { TrainingSet.Add((int[])TestingSet[i]); } TestingSet.Clear(); // Calculate the number of examples that should be // in the testing set. int totalNumExamples = TrainingSet.Count; int numTestingExamples = (int)Math.Round(totalNumExamples * ((float)percentage) / 100.0f); Random rand = new Random(); // If the set doesn't have to be balanced, then just // pick examples at random. if (!balanced) { for (int i = 0; i < numTestingExamples; i++) { int temp = rand.Next(TrainingSet.Count); TestingSet.Add((int[])TrainingSet[temp]); TrainingSet.RemoveAt(temp); } } else { // We have the target value distribution for the dataset, // so reference it. for (int i = 0; i < TargetSums.Length; i++) { int numExamplesToMove = (int)Math.Round(TargetSums[i] / ((float)totalNumExamples) * numTestingExamples); for (int j = 0; j < numExamplesToMove; j++) { // Attempt to randomly pick examples from the // dataset that have the required target classification. int[] example = null; while (true) { example = (int[])TrainingSet[rand.Next(TrainingSet.Count)]; if (example[0] == i) { break; } } int temp = TrainingSet.IndexOf(example); TestingSet.Add((int[])TrainingSet[temp]); TrainingSet.RemoveAt(temp); } } } }
/// <summary> /// Returns an iterator over the testing examples in the current dataset. /// </summary> public IEnumerator <int[]> getTestingExamples() { return(TestingSet.GetEnumerator()); }
/// <summary> /// Constructor that creates object with given training set and testing set /// </summary> /// <param name="trainingSet">Training set loaded from a file</param> /// <param name="testingSet">Testing set loaded from a file</param> public SureClassifiers(TrainingSet trainingSet, TestingSet testingSet) { this.trainingSet = trainingSet; this.testingSet = testingSet; }