Пример #1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="BootstrapResult"/> class.
        /// </summary>
        /// 
        /// <param name="owner">The <see cref="Bootstrap"/> that is creating this result.</param>
        /// <param name="models">The models created during the cross-validation runs.</param>
        /// 
        public BootstrapResult(Bootstrap owner, BootstrapValues[] models)
        {
            double[] trainingValues = new double[models.Length];
            double[] trainingVariances = new double[models.Length];
            int[] trainingCount = new int[models.Length];

            double[] validationValues = new double[models.Length];
            double[] validationVariances = new double[models.Length];
            int[] validationCount = new int[models.Length];

            for (int i = 0; i < models.Length; i++)
            {
                trainingValues[i] = models[i].TrainingValue;
                trainingVariances[i] = models[i].TrainingVariance;

                validationValues[i] = models[i].ValidationValue;
                validationVariances[i] = models[i].ValidationVariance;

                owner.GetPartitionSize(i, out trainingCount[i], out validationCount[i]);
            }

            this.Settings = owner;
            this.Training = new CrossValidationStatistics(trainingCount, trainingValues, trainingVariances);
            this.Validation = new CrossValidationStatistics(validationCount, validationValues, validationVariances);

            this.Estimate = 0.632 * Validation.Mean + 0.368 * Training.Mean;
        }
Пример #2
0
        /// <summary>
        ///   Computes the cross validation algorithm.
        /// </summary>
        ///
        public BootstrapResult Compute()
        {
            if (Fitting == null)
            {
                throw new InvalidOperationException("Fitting function must have been previously defined.");
            }

            var models = new BootstrapValues[Subsamples.Length];

            if (RunInParallel)
            {
                Parallel.For(0, Subsamples.Length, i =>
                {
                    int[] trainingSet, validationSet;

                    // Create training and validation sets
                    CreatePartitions(i, out trainingSet, out validationSet);

                    // Fit and evaluate the model
                    models[i] = fitting(trainingSet, validationSet);
                });
            }
            else
            {
                for (int i = 0; i < Subsamples.Length; i++)
                {
                    int[] trainingSet, validationSet;

                    // Create training and validation sets
                    CreatePartitions(i, out trainingSet, out validationSet);

                    // Fit and evaluate the model
                    models[i] = fitting(trainingSet, validationSet);
                }
            }

            // Return cross-validation statistics
            return(new BootstrapResult(this, models));
        }
Пример #3
0
        /// <summary>
        ///   Computes the cross validation algorithm.
        /// </summary>
        /// 
        public BootstrapResult Compute()
        {
            if (Fitting == null)
                throw new InvalidOperationException("Fitting function must have been previously defined.");

            var models = new BootstrapValues[Subsamples.Length];

            if (RunInParallel)
            {
                Parallel.For(0, Subsamples.Length, i =>
                {
                    int[] trainingSet, validationSet;

                    // Create training and validation sets
                    CreatePartitions(i, out trainingSet, out validationSet);

                    // Fit and evaluate the model
                    models[i] = fitting(trainingSet, validationSet);
                });
            }
            else
            {
                for (int i = 0; i < Subsamples.Length; i++)
                {
                    int[] trainingSet, validationSet;

                    // Create training and validation sets
                    CreatePartitions(i, out trainingSet, out validationSet);

                    // Fit and evaluate the model
                    models[i] = fitting(trainingSet, validationSet);
                }
            }

            // Return cross-validation statistics
            return new BootstrapResult(this, models);
        }