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

# get number of rows and number of clusters
NUM_ROWS = (ARGV.shift || 1000).to_i
NUM_CLUSTERS = (ARGV.shift || 4).to_i

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

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

def noise(y, x, scale)
  Q[y % NUM_CLUSTERS][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(' ')
}