Пример #1
0
        /// <summary>
        /// Returns a collation of all unassigned, training, validation, and test data points.
        /// </summary>
        /// <returns></returns>
        public DataPoint[] GetWholeSet()
        {
            DataPoint[] set = new DataPoint[unassigned.Count + TrainingSet.Length +
                                            ValidationSet.Length + TestSet.Length];

            TrainingSet.CopyTo(set, 0);
            ValidationSet.CopyTo(set, TrainingSet.Length);
            TestSet.CopyTo(set, TrainingSet.Length + ValidationSet.Length);
            unassigned.CopyTo(set, set.Length - unassigned.Count);

            return(set);
        }
Пример #2
0
        public void CopyTo()
        {
            // Setup
            var sequence = InitializeSequence();
            var set      = new TestSet <SimpleType>(sequence);
            var array    = new SimpleType[4];

            // Execute
            set.CopyTo(array, 0);

            // Assert
            Assert.IsTrue(array.All(i => i != null));
            Assert.AreSame(sequence[0], array[0]);
            Assert.AreSame(sequence[1], array[1]);
            Assert.AreSame(sequence[2], array[2]);
            Assert.AreSame(sequence[3], array[3]);
        }
Пример #3
0
        /// <summary>
        /// Randomly assign any unassigned points to the training, validation, and test sets with
        /// the given ratio of probabilities.
        /// </summary>
        /// <param name="trainingRatio"></param>
        /// <param name="validationRatio"></param>
        /// <param name="testRatio"></param>
        public void AssignDataPoints(double trainingRatio, double validationRatio,
                                     double testRatio)
        {
            // Calculate probability cutoffs for assignment
            double cutoff1 = trainingRatio / (trainingRatio + validationRatio + testRatio);
            double cutoff2 = (trainingRatio + validationRatio) /
                             (trainingRatio + validationRatio + testRatio);

            List <DataPoint> training   = new List <DataPoint>();
            List <DataPoint> validation = new List <DataPoint>();
            List <DataPoint> test       = new List <DataPoint>();

            while (unassigned.Count > 0)
            {
                double randomDouble = random.NextDouble();
                if (randomDouble < cutoff1)
                {
                    training.Add(unassigned.Dequeue());
                }
                else if (randomDouble < cutoff2)
                {
                    validation.Add(unassigned.Dequeue());
                }
                else
                {
                    test.Add(unassigned.Dequeue());
                }
            }

            // Construct new arrays
            DataPoint[] trainingBuffer = new DataPoint[TrainingSet.Length + training.Count];
            TrainingSet.CopyTo(trainingBuffer, training.Count);
            training.CopyTo(trainingBuffer, 0);
            TrainingSet = trainingBuffer;

            DataPoint[] validationBuffer = new DataPoint[ValidationSet.Length + validation.Count];
            ValidationSet.CopyTo(validationBuffer, validation.Count);
            validation.CopyTo(validationBuffer, 0);
            ValidationSet = validationBuffer;

            DataPoint[] testBuffer = new DataPoint[TestSet.Length + test.Count];
            TestSet.CopyTo(testBuffer, test.Count);
            test.CopyTo(testBuffer, 0);
            TestSet = testBuffer;
        }
Пример #4
0
        public void CopyToAtNonZeroArrayIndex()
        {
            // Setup
            var sequence = InitializeSequence();
            var set      = new TestSet <SimpleType>(sequence);
            var array    = new SimpleType[5];

            // Execute
            set.CopyTo(array, 1);

            // Assert
            Assert.IsNull(array[0]);
            Assert.IsTrue(array.Skip(1).All(i => i != null));
            Assert.AreSame(sequence[0], array[1]);
            Assert.AreSame(sequence[1], array[2]);
            Assert.AreSame(sequence[2], array[3]);
            Assert.AreSame(sequence[3], array[4]);
        }
Пример #5
0
        public void CopyToAtNonZeroArrayIndex()
        {
            // Setup
            var sequence = InitializeSequence();
            var set = new TestSet<SimpleType>(sequence);
            var array = new SimpleType[5];

            // Execute
            set.CopyTo(array, 1);

            // Assert
            Assert.IsNull(array[0]);
            Assert.IsTrue(array.Skip(1).All(i => i != null));
            Assert.AreSame(sequence[0], array[1]);
            Assert.AreSame(sequence[1], array[2]);
            Assert.AreSame(sequence[2], array[3]);
            Assert.AreSame(sequence[3], array[4]);
        }
Пример #6
0
        public void CopyTo()
        {
            // Setup
            var sequence = InitializeSequence();
            var set = new TestSet<SimpleType>(sequence);
            var array = new SimpleType[4];

            // Execute
            set.CopyTo(array, 0);

            // Assert
            Assert.IsTrue(array.All(i => i != null));
            Assert.AreSame(sequence[0], array[0]);
            Assert.AreSame(sequence[1], array[1]);
            Assert.AreSame(sequence[2], array[2]);
            Assert.AreSame(sequence[3], array[3]);
        }