Accord.MachineLearning.Bootstrap.Samplings C# (CSharp) Method

Samplings() public static method

Draws the bootstrap samples from the population.
public static Samplings ( int size, int resamplings, int subsampleSize ) : int[][]
size int The size of the samples to be drawn.
resamplings int The number of samples to drawn.
subsampleSize int The size of the samples to be drawn.
return int[][]
        public static int[][] Samplings(int size, int resamplings, int subsampleSize)
        {
            // Create samples with replacement
            int[][] idx = new int[resamplings][];

            // For each fold to be created
            for (int i = 0; i < idx.Length; i++)
            {
                idx[i] = new int[subsampleSize];

                // Generate a random sample (with replacement)
                for (int j = 0; j < idx[i].Length; j++)
                    idx[i][j] = Accord.Math.Random.Generator.Random.Next(0, size);
            }

            return idx;
        }
    }

Usage Example

Example #1
0
        /// <summary>
        ///   Creates a new Bootstrap estimation algorithm.
        /// </summary>
        ///
        /// <param name="size">The size of the complete dataset.</param>
        /// <param name="subsamples">The number B of bootstrap resamplings to perform.</param>
        /// <param name="subsampleSize">The number of samples in each subsample. Default
        ///   is to use the total number of samples in the population dataset.</param>.
        ///
        public Bootstrap(int size, int subsamples, int subsampleSize)
        {
            this.samples          = size;
            this.subsampleIndices = new int[subsamples][];

            this.subsampleIndices = Bootstrap.Samplings(size, subsamples, subsampleSize);
        }