Repository navigation
Expand file tree
/
Copy pathsimulations.py
More file actions
79 lines (65 loc) · 2.35 KB
/
Copy pathsimulations.py
File metadata and controls
79 lines (65 loc) · 2.35 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import scipy
from scipy import ndimage
from scipy import misc
from sklearn import (manifold, datasets, decomposition, ensemble, discriminant_analysis, random_projection)
def make_cube(dx,dy,dz, sigma):
x_v = np.linspace(-4+dx,4+dx,9)
y_v = np.linspace(-4+dy,4+dy,9)
z_v = np.linspace(-4+dz,4+dz,9)
coord = []
for x in x_v:
for y in y_v:
for z in z_v:
if sigma > 0:
x += np.random.normal(0, sigma)
y += np.random.normal(0, sigma)
z += np.random.normal(0, sigma)
coord.append([x,y,z])
return coord
def cube_simulation(dt, frames, sigma = -1):
t = np.linspace(0,frames*dt - 1,frames)
x = t*np.cos(t)
y = t*np.sin(t)
z = np.cos(t)
video = []
for idt in range(0,frames):
video.append(make_cube(x[idt],y[idt],z[idt], sigma))
return np.array(video)
def make_moving_square(frames, sigma = -1):
square = np.ones((100,100))*255
empty = np.zeros((200,100))
square = np.concatenate((empty,square,empty), axis=0)
video = []
time = np.linspace(0,1,frames)
for idt in time:
left = np.zeros((500, int(np.ceil(idt*400))))
right = np.zeros((500, int(np.floor((1-idt)*400))))
img = np.concatenate((left, square, right), axis = 1)
if sigma > 0:
img += np.random.normal(0, sigma, (500, 500))
video.append(np.round(img))
return np.array(video)
def make_rotating_square(frames,percent,theta, sigma = -1):
square = np.ones((100,100))*255
empty = np.zeros((200,100))
square = np.concatenate((empty,square,empty), axis=0)
idt = percent
left = np.zeros((500, int(np.ceil(idt*400))))
right = np.zeros((500, int(np.floor((1-idt)*400))))
square = np.concatenate((left, square, right), axis = 1)
video = []
time = np.linspace(0,theta,frames)
for angle in time:
img = ndimage.interpolation.rotate(square, angle, reshape=False)
if sigma > 0:
img += np.random.normal(0, sigma, (500, 500))
img = np.absolute(img)
video.append(np.around(img))
return np.array(video)
def format_obervation_md_traj(t):
size = t.xyz.shape
X = [f.reshape((1, -1))[0] for f in t.xyz]
return X