aboutsummaryrefslogtreecommitdiff
path: root/gen-data.rb
blob: e010ed1bbce89bd0abb445b75dab41f5a9997447 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env ruby

# get number of rows 
NUM_ROWS = (ARGV.shift || 100).to_i

# data shape (num_floats, num_ints)
SHAPE = [2, 0]

# cluster centers
Q = [[-1, -1], [-1, +1], [+1, -1], [+1, +1]].map { |c|
  c.map { |v| 0.5 + 0.25 * v }
}

def noise(y, x, scale)
  Q[y % Q.size][x] + scale * rand * Math.cos(Math::PI * rand)
end

# print output
puts [SHAPE.join(' ')] + NUM_ROWS.times.map { |y|
  SHAPE.first.times.map { |x|
    '%1.5f' % [noise(y, x, 0.1)]
  }.join(' ')
}