lib/rumale/dataset.rb
# Generate a two-dimensional data set consisting of an inner circle and an outer circle.
#
# @param n_samples [Integer] The number of samples.
# @param shuffle [Boolean] The flag indicating whether to shuffle the dataset
# @param noise [Float] The standard deviaion of gaussian noise added to the data.
#   If nil is given, no noise is added.
# @param factor [Float] The scale factor between inner and outer circles. The interval of factor is (0, 1).
# @param random_seed [Integer] The seed value using to initialize the random generator.
Generate a two-dimensional data set consisting of an inner circle and an outer circle.
Generate a two - dimensional data set consisting of an inner circle and an outer circle .
def make_circles(n_samples, shuffle: true, noise: nil, factor: 0.8, random_seed: nil)
        Rumale::Validation.check_params_numeric(n_samples: n_samples, factor: factor)
        Rumale::Validation.check_params_boolean(shuffle: shuffle)
        Rumale::Validation.check_params_numeric_or_nil(noise: noise, random_seed: random_seed)
        raise ArgumentError, 'The number of samples must be more than 2.' if n_samples <= 1
        raise RangeError, 'The interval of factor is (0, 1).' if factor <= 0 || factor >= 1
        rs = random_seed
        rs ||= srand
        rng = Random.new(rs)
        n_samples_out = n_samples.fdiv(2).to_i
        n_samples_in = n_samples - n_samples_out
        linsp_out = Numo::DFloat.linspace(0, 2 * Math::PI, n_samples_out)
        linsp_in = Numo::DFloat.linspace(0, 2 * Math::PI, n_samples_in)
        circle_out = Numo::DFloat[Numo::NMath.cos(linsp_out), Numo::NMath.sin(linsp_out)].transpose
        circle_in = Numo::DFloat[Numo::NMath.cos(linsp_in), Numo::NMath.sin(linsp_in)].transpose
        x = Numo::DFloat.vstack([circle_out, factor * circle_in])
        y = Numo::Int32.hstack([Numo::Int32.zeros(n_samples_out), Numo::Int32.ones(n_samples_in)])
        if shuffle
          rand_ids = Array(0...n_samples).shuffle(random: rng.dup)
          x = x[rand_ids, true].dup
          y = y[rand_ids].dup
        end
        x += Rumale::Utils.rand_normal(x.shape, rng.dup, 0.0, noise) unless noise.nil?
        [x, y]
      end
def make_circles ( n_samples , shuffle : true , noise : nil , factor : 0.8 , random_seed : nil ) Rumale :: Validation . check_params_numeric ( n_samples : n_samples , factor : factor ) Rumale :: Validation . check_params_boolean ( shuffle : shuffle ) Rumale :: Validation . check_params_numeric_or_nil ( noise : noise , random_seed : random_seed ) raise ArgumentError , 'The number of samples must be more than 2.' if n_samples <= 1 raise RangeError , 'The interval of factor is (0, 1).' if factor <= 0 || factor >= 1 rs = random_seed rs ||= srand rng = Random . new ( rs ) n_samples_out = n_samples . fdiv ( 2 ) . to_i n_samples_in = n_samples - n_samples_out linsp_out = Numo :: DFloat . linspace ( 0 , 2 * Math :: PI , n_samples_out ) linsp_in = Numo :: DFloat . linspace ( 0 , 2 * Math :: PI , n_samples_in ) circle_out = Numo :: DFloat [ Numo :: NMath . cos ( linsp_out ) , Numo :: NMath . sin ( linsp_out ) ] . transpose circle_in = Numo :: DFloat [ Numo :: NMath . cos ( linsp_in ) , Numo :: NMath . sin ( linsp_in ) ] . transpose x = Numo :: DFloat . vstack ( [ circle_out , factor * circle_in ] ) y = Numo :: Int32 . hstack ( [ Numo :: Int32 . zeros ( n_samples_out ) , Numo :: Int32 . ones ( n_samples_in ) ] ) if shuffle rand_ids = Array ( 0 ... n_samples ) . shuffle ( random : rng . dup ) x = x [ rand_ids , true ] . dup y = y [ rand_ids ] . dup end x += Rumale :: Utils . rand_normal ( x . shape , rng . dup , 0.0 , noise ) unless noise . nil? [ x , y ] end
Generate a two-dimensional data set consisting of an inner circle and an outer circle.
Generate a two - dimensional data set consisting of an inner circle and an outer circle .
# initialize some variables. # make two circles. # shuffle data indices. # add gaussian noise.
n_samples
The number of samples.
The number of samples .
shuffle
The flag indicating whether to shuffle the dataset
The flag indicating whether to shuffle the dataset
noise
The standard deviaion of gaussian noise added to the data. If nil is given, no noise is added.
The standard deviaion of gaussian noise added to the data . If nil is given no noise is added .
factor
The scale factor between inner and outer circles. The interval of factor is (0, 1).
The scale factor between inner and outer circles . The interval of factor is ( 0 1 ) .
random_seed
The seed value using to initialize the random generator.
The seed value using to initialize the random generator .