Thrill  0.1
gen_data.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 ##########################################################################
3 # examples/stochastic_gradient_descent/gen_data.py
4 #
5 # Part of Project Thrill - http://project-thrill.org
6 #
7 # Copyright (C) 2017 Alina Saalfeld <[email protected]>
8 #
9 # All rights reserved. Published under the BSD-2 license in the LICENSE file.
10 ##########################################################################
11 
12 import random
13 
14 D = 1
15 N = 1000000
16 SEED = 666
17 
18 minx = -100
19 maxx = 100
20 
21 param_mu = 1
22 param_sig = 0.2
23 
24 noise_mu = 1
25 noise_sig = 0.1
26 
27 noise_add_sig = 10
28 
29 random.seed(SEED)
30 params = [random.gauss(param_mu, param_sig) for x in range(0, D)]
31 
32 comment = "# Params: "
33 comment += " ".join(map(str,params))
34 print(comment)
35 
36 print("# D = " + str(D) + ", N = " + str(N) + ", SEED = " + str(SEED))
37 
38 for i in range(0,N):
39  x = [random.uniform(minx, maxx) for x in range(0,D)]
40  string = " ".join(map(str,x)) + " "
41  value = 0
42  for d in range(0,D):
43  value += x[d] * params[d]
44  value *= random.gauss(noise_mu, noise_sig)
45  value += random.gauss(0, noise_add_sig)
46  print(string + str(value))
47 
48 ##########################################################################
std::string join(char glue, const std::vector< std::string > &parts)
Join a vector of strings by some glue character between each pair from the sequence.
Definition: join.cpp:16