-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGaussianTrashSource.py
50 lines (37 loc) · 1.45 KB
/
GaussianTrashSource.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
from numpy.random import multivariate_normal
class GaussianTrashSource:
def __init__(self, mean, max_y, max_x, cov=[[1,0],[0,1]], id=None):
"""
Creates a trashsource
Parameters
----------
cov: 2x2 matrix, covariance of the rnd var.
coords: (int,int), (y,x) trash hotspot, mean of the rnd var.
max_x : int, limits to the trash coordinates / grid of the environment
max_y : int, limits to the trash coordinates / grid of the environment
Returns
-------
"""
# mean of the gaussian
self.mean = mean
# covariance matrix of the multivariate gaussian
self.cov = cov
# strict limits to the gaussian
self.max_x = max_x
self.max_y = max_y
# Just an id of the trashsource
self.id = id
def draw_sample_in_limits(self):
"""
"""
y, x = multivariate_normal(self.mean, self.cov,1)[0]
y = int(min(self.max_y, round(y)))
x = int(min(self.max_x, round(x)))
return [y, x]
def get_trash(self, n=None):
"""
Returns a list of n coordinates drawn from the distribution
"""
if n:
return [self.draw_sample_in_limits() for i in range(n)]
return self.draw_sample_in_limits()