/// <summary>
 ///   Draws a random sample from a group of observations, without repetitions.
 /// </summary>
 ///
 /// <typeparam name="T">The type of the observations.</typeparam>
 ///
 /// <param name="values">The observation vector.</param>
 /// <param name="size">The size of the sample to be drawn (how many samples to get).</param>
 ///
 /// <returns>A vector containing the samples drawn from <paramref name="values"/>.</returns>
 ///
 public static T[] Sample <T>(T[] values, int size)
 {
     int[] idx = Vector.Sample(size);
     return(values.Submatrix(idx));
 }
Пример #2
0
 /// <summary>
 ///   Draws a random sample from a group of observations, without repetitions.
 /// </summary>
 ///
 /// <typeparam name="T">The type of the observations.</typeparam>
 ///
 /// <param name="values">The observation vector.</param>
 /// <param name="size">The size of the sample to be drawn (how many samples to get).</param>
 ///
 /// <returns>A vector containing the samples drawn from <paramref name="values"/>.</returns>
 ///
 public static T[] Sample <T>(this T[] values, int size)
 {
     int[] idx = Vector.Sample(size, values.Length);
     System.Diagnostics.Debug.Assert(idx.Length == size);
     return(values.Get(idx));
 }
Пример #3
0
 /// <summary>
 ///   Draws a random sample from a group of observations, with or without repetitions.
 /// </summary>
 ///
 /// <typeparam name="T">The type of the observations.</typeparam>
 ///
 /// <param name="values">The observation vector.</param>
 /// <param name="size">The size of the sample to be drawn (how many samples to get).</param>
 /// <param name="replacement">Whether to sample with replacement (repeating values) or without replacement (non-repeating values).</param>
 ///
 /// <returns>A vector containing the samples drawn from <paramref name="values"/>.</returns>
 ///
 public static T[] Sample <T>(this T[] values, int size, bool replacement = false)
 {
     int[] idx = replacement ? Vector.Random(size, 0, values.Length) : Vector.Sample(size, values.Length);
     System.Diagnostics.Debug.Assert(idx.Length == size);
     return(values.Get(idx));
 }