From 48452bdf222df8d78124c5fdc054618503dda044 Mon Sep 17 00:00:00 2001 From: Artem Oppermann Date: Wed, 16 May 2018 16:50:41 +0200 Subject: [PATCH] final version --- model v2/__pycache__/data_gen.cpython-36.pyc | Bin 2008 -> 1983 bytes model v2/data_gen.py | 59 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/model v2/__pycache__/data_gen.cpython-36.pyc b/model v2/__pycache__/data_gen.cpython-36.pyc index e69bb2c8ae8676c419b4ec97a47500569461c71b..f85757bf60605263e745f0701f7421591434909e 100644 GIT binary patch delta 227 zcmcb?zn`Den3tDJ*Y!`7-bT(yOOkT-m wC(dz;GcUe4F}ENmwfGiSQEGBYVqSVq>SQ+dU|t!ZVg@E2Mi3O5oW-680LYXwfB*mh delta 243 zcmdnbe}kXXn3tF9vha^6$Bmq;Sj8BifD=e_0I@R=7cZN9lGUP~A)TR?5r~<9n7JaZ zgfWFNg}s@{g&{VemZgRzg+q*?mbHW_i@AoOhE?5UbEHoS}v}m_d`_Al*E$6TWmRrNvS!LKe7c2DgbpcF!3;gpb#Sq KBg^DK_B;R?dN|Yo diff --git a/model v2/data_gen.py b/model v2/data_gen.py index e69de29..abd82ec 100644 --- a/model v2/data_gen.py +++ b/model v2/data_gen.py @@ -0,0 +1,59 @@ +import numpy as np +import random + +csv_path='./data.txt' + +class Rectangle: + + def __init__(self, x, y, width, height): + + self.x=x + self.y=y + self.width=width + self.height=height + self.matrix_size=10 + self.matrix=self._init_zeros_matrix() + self.fill() + + def _init_zeros_matrix(self): + return np.zeros(shape=(self.matrix_size, self.matrix_size), dtype=np.float32) + + def add_noise(self): + + new_matrix=np.zeros(shape=(self.matrix_size, self.matrix_size), dtype=np.float32) + + for i in range(10): + for j in range(10): + new_matrix[i][j]+=self.matrix[i][j]+np.random.poisson(lam=2.0) + return new_matrix + + def fill(self): + + for i in range(self.width): + for j in range(self.height): + self.matrix[self.x+i][self.y+j]=10.0 + + def get_matrix(self): + return self.matrix + +def gen_data(n_samples): + + rectangles={0:Rectangle(0,0,2,2), + 1:Rectangle(3,3,2,2), + 2:Rectangle(5,5,2,2), + 3:Rectangle(7,7,2,2),} + data=[] + + for i in range(0,n_samples): + label=i%4 + rect=np.array(rectangles[label].add_noise()) + rect_reshaped=np.reshape(rect,[1,100]) + + data_sample=[] + data_sample.append(rect_reshaped) + data_sample.append(label) + data.append(data_sample) + + return data + + -- 2.22.0