-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.py
50 lines (40 loc) · 1.61 KB
/
generate.py
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
import math
import numpy as np
from numpy import linalg
from .spline_model import SplineModel, SplineModelConditional
def uniform_doseless(start, end, height=None):
scaled = False
if height is None:
height = 1 / (end - start)
scaled = True
conditional = SplineModelConditional()
conditional.add_segment(SplineModel.neginf, start, [SplineModel.neginf])
conditional.add_segment(start, end, [math.log(height)])
conditional.add_segment(end, SplineModel.posinf, [SplineModel.neginf])
return SplineModel(True, [''], [conditional], scaled)
# Generate constant uniform
def uniform_constant(xx, yy, min, max):
# header row
table = [['ddp1']]
table[0].extend(yy)
nn = float(sum(np.logical_and(yy >= min, yy < max)))
# data rows
for ii in range(len(xx)):
row = [xx[ii]]
row.extend(np.logical_and(yy >= min, yy < max) / nn)
table.append(row)
return table
def polynomial(lowbound, highbound, betas, covas, num=40):
betas = np.array(betas)
covas = np.mat(covas)
if covas.shape[0] != covas.shape[1] and len(betas) != covas.shape[0]:
return "Error: Please provide a complete covariance matrix."
if np.any(linalg.eig(covas)[0] < 0):
return "Error: Covariance matrix is not positive definite."
xx = np.linspace(lowbound, highbound, num=num)
xxs = {}
for x in xx:
xvec = np.mat([[1, x, x**2, x**3, x**4][0:len(betas)]])
serr = np.sqrt(xvec * covas * np.transpose(xvec))
xxs[x] = (betas.dot(np.squeeze(np.asarray(xvec))), serr[0,0]**2)
return SplineModel.create_gaussian(xxs, xx, False)