-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomSimulationFunctions.py~
More file actions
executable file
·54 lines (40 loc) · 1.9 KB
/
Copy pathrandomSimulationFunctions.py~
File metadata and controls
executable file
·54 lines (40 loc) · 1.9 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#Take in two lists (x-data and y-data for some points) and return
# the same lists, with a random rearrangement of which x-y pairings.
import random
from cantrips import removeListElement
def simulateNormallyDistributedData(x_data, function, y_errs, n_draws = -1, replace = 0):
if n_draws < 0: n_draws = len(x_data)
new_x_data = []
new_y_data = []
new_y_errs = []
for i in range(n_draws):
x_index = random.randint(0, len(x_data) - 1)
#print 'x_index = ' + str(x_index)
#print 'y_index = ' + str(y_index)
new_x_data = new_x_data + [x_data[x_index]]
new_y_data = new_y_data + [function(x_data[x_index]) + random.gauss(0.0, y_errs[x_index])]
new_y_errs = new_y_errs + [y_errs[x_index]]
if not replace:
x_data = removeListElement(x_data[:], x_index)
y_errs =removeListElement(y_errs[:], x_index)
return new_x_data, new_y_data, new_y_errs
def randomSortData(x_data, y_data, n_draws = -1, y_errs = None, replace = 0):
if n_draws < 0: n_draws = len(x_data)
new_x_data = []
new_y_data = []
if not y_errs is None: new_y_errs = []
for i in range(n_draws):
#print 'i = ' + str(i)
x_index = random.randint(0, len(x_data) - 1)
y_index = random.randint(0, len(x_data) - 1)
#print 'x_index = ' + str(x_index)
#print 'y_index = ' + str(y_index)
new_x_data = new_x_data + [x_data[x_index]]
new_y_data = new_y_data + [y_data[y_index]]
if not y_errs is None: new_y_errs = new_y_errs + [y_errs[y_index]]
if not replace:
x_data = removeListElement(x_data[:], x_index)
y_data =removeListElement(y_data[:], y_index)
if not y_errs is None: y_errs =removeListElement(y_errs[:], y_index)
if not y_errs is None: return new_x_data, new_y_data, new_y_errs
else: return new_x_data, new_y_data