Ejemplo n.º 1
0
	def __init__(self, window_size, item_dict):

		self.window_size = window_size
		self.img = cv2.imread('p_map3.jpg')
		self.img = cv2.resize(self.img, (64,64))
		self.img = cv2.erode(self.img, np.ones((2,2)), iterations=1) 
		self.img = np.asarray(self.img[:,:,1] < 200 ).astype(np.uint)
		#self.dot_path = []
		self.current_loc = []
		self.my_loc = [(120//2,64//2), 0, (-1,-1), (-1,-1)]
		self.check_out_1 = Data('Check_out_1',(115//2,40//2),0,(100 // 2,25 // 2),(100 // 2,52 // 2), None)
		self.check_out_2 = Data('Check_out_2',(115//2,96//2),0,(100 // 2,73 // 2),(100,100 // 2), None)
		self.item_dict = item_dict
		self.idx = []
		self.idx_name = []
Ejemplo n.º 2
0
    def DataDelete(self, query):
        logging.error(query)

        if query.tag:
            datakey = Data.query(Data.tag == query.tag).get()
        if query.name:
            datakey = Data.query(Data.name == query.name).get()
        logging.error(datakey)
        if query.tag or query.name:

            if datakey:

                logging.error(datakey)
                datakey.key.delete()
                return (datakey)
Ejemplo n.º 3
0
	def DataDelete(self,query):
		logging.error(query)
		
		
		if query.tag:
			datakey=Data.query(Data.tag==query.tag).get()
		if query.name:
			datakey=Data.query(Data.name==query.name).get()
		logging.error(datakey)
		if query.tag or query.name:
			
			if datakey:
			
				logging.error(datakey)
				datakey.key.delete()
				return(datakey)
Ejemplo n.º 4
0

n_days = 334
coefs = np.ones(n_days)
znam = np.arange(n_days + 1, 1, -1)
#print(znam.shape, coefs.shape)
coefs /= znam
coefs = np.array([coefs]).T
coefs *= coefs


def rescale_features(X):
    X[:n_days, :] *= coefs
    X[n_days:2 * n_days, :] *= coefs
    X[2 * n_days:3 * n_days, :] *= coefs
    return X


if __name__ == "__main__":
    create_ds = Data('learning_set/')
    ts = create_ds.create_train_set(isFull=False)
    scl = StandardScaler()
    X = scl.fit_transform(ts[0])
    X = rescale_features(X)
    cl = KMeans(n_clusters=12).fit(X)
    labels = cl.predict(X)
    centr = get_centriod(cl, ts[0])

    book_data = acum_all_gr(create_ds, 1, ts[2])
    interv = conf_intervals(book_data, labels, 0.05)
Ejemplo n.º 5
0
def data_fixture():
    data_handler = Data()
    return data_handler
Ejemplo n.º 6
0
	def test_photo_size(self):
		data = Data()
		dataset = data.body["SN1987A"]["photometry"]
		types, _ = photometry.part(dataset)
		length = len(types)
		self.assertEqual(length, 5)
Ejemplo n.º 7
0
	def test_xray_size(self):
		data = Data()
		dataset = data.body["SN1987A"]["xray"]
		_, flux = xray.part(dataset)
		length = len(flux)
		self.assertEqual(length, 105)
Ejemplo n.º 8
0
	def test_spect_size(self):
		data = Data()
		dataset = data.body["SN1987A"]["spectra"]
		values = spectra.part(dataset)
		length = len(values)
		self.assertEqual(length, 36)
Ejemplo n.º 9
0
# Logistic regression using scikit learn
from sklearn.linear_model import LogisticRegression
from main import Data

# initialize data
data = Data()
data.init_data()
data.standard_split()

lr = LogisticRegression(C=100.0, random_state=1)
lr.fit(data.X_train_std, data.y_train)
plt = data.plot_decision_regions(data.X_train_std, data.y_train, lr)
plt.xlabel('petal length [standardized]')
plt.ylabel('petal length [standardized]')
plt.legend(loc='upper left')
plt.show()
Ejemplo n.º 10
0
import xgboost as xgb
from main import Data
import numpy as np
import pandas as pd


def predict_qlty(dt):
    (X_train, Y_train, uid_train) = dt.create_train_set()
    (X_test, uid_test) = dt.create_test_set()
    regr = xgb.XGBRegressor(colsample_bytree=1,
                            subsample=0.9,
                            min_child_weight=5,
                            max_depth=6,
                            colsample_bylevel=0.8,
                            learning_rate=0.1,
                            n_estimators=200)
    regr.fit(X_train[Y_train >= 0], Y_train[Y_train >= 0])
    #print(X_test)
    preds = regr.predict(X_test)
    #print(preds)
    preds_int = np.round(preds)
    #print(preds_int)
    df = pd.DataFrame({'UID': uid_test, 'score': preds_int})
    #print(df)
    df.to_csv('marked_data_test.csv', sep=';')


create_ds = Data('learning_set/')
predict_qlty(create_ds)
    def draw_stats():
        w, h = GlobalSetup.WINDOW_RESOLUTION

        # draw background
        Graphics.draw_rect(Graphics.shifted((0, 0)), Graphics.shifted((w, h)),
                           Colors.BG_COLOR)
        Graphics.draw_rect(Graphics.shifted((w // 3, h // 2)),
                           Graphics.shifted((w * 2 // 3, h * 9 // 10)),
                           Colors.WHITE)
        Graphics.draw_rect(Graphics.shifted((w // 3, h * 2 // 5)),
                           Graphics.shifted((w * 2 // 3, 0)), Colors.WHITE)

        x_axis_len = w // 3 - h // 10 - 1
        y_axis_len = h * 3 // 10
        jump = len(Data.data) / x_axis_len
        # value_jump = y_axis_len / GlobalSetup.no_balls
        Graphics.plot_area(jump, y_axis_len, w, h)

        # draw axes
        Graphics.draw_line(Graphics.shifted((w // 3 + h // 20, h * 11 // 20)),
                           Graphics.shifted((w // 3 + h // 20, h * 17 // 20)))
        Graphics.draw_line(
            Graphics.shifted((w // 3 + h // 20, h * 11 // 20)),
            Graphics.shifted((w * 2 // 3 - h // 20, h * 11 // 20)))

        # draw upper arrow
        Graphics.draw_line(
            Graphics.shifted((w // 3 + h // 20, h * 17 // 20)),
            Graphics.shifted(
                (w // 3 + h // 20 - h // 200, h * 17 // 20 - h // 200)))
        Graphics.draw_line(
            Graphics.shifted((w // 3 + h // 20, h * 17 // 20)),
            Graphics.shifted(
                (w // 3 + h // 20 + h // 200, h * 17 // 20 - h // 200)))

        # draw right arrow
        Graphics.draw_line(
            Graphics.shifted((w * 2 // 3 - h // 20, h * 11 // 20)),
            Graphics.shifted(
                (w * 2 // 3 - h // 20 - h // 200, h * 11 // 20 + h // 200)))
        Graphics.draw_line(
            Graphics.shifted((w * 2 // 3 - h // 20, h * 11 // 20)),
            Graphics.shifted(
                (w * 2 // 3 - h // 20 - h // 200, h * 11 // 20 - h // 200)))

        shift = 25
        # Labels
        Graphics.write(
            "Population size:",
            Graphics.shifted((w // 3 + w // 30, h * 2 // 5 - 2 * shift)))
        Graphics.write(
            "Speed:",
            Graphics.shifted((w // 3 + w // 30, h * 2 // 5 - 3 * shift)))
        Graphics.write(
            "Recovery:",
            Graphics.shifted((w // 3 + w // 30, h * 2 // 5 - 4 * shift)))
        Graphics.write(
            "Social distancing:",
            Graphics.shifted((w // 3 + w // 30, h * 2 // 5 - 5 * shift)))
        Graphics.write(
            "Ball radius:",
            Graphics.shifted((w // 3 + w // 30, h * 2 // 5 - 6 * shift)))

        Graphics.write(
            "Infected:",
            Graphics.shifted((w // 3 + w // 30, h * 2 // 5 - 8 * shift)))
        Graphics.write(
            "Duration:",
            Graphics.shifted((w // 3 + w // 30, h * 2 // 5 - 9 * shift)))
        Graphics.write(
            "\u03B2 (SIR model):",
            Graphics.shifted((w // 3 + w // 30, h * 2 // 5 - 10 * shift)))
        Graphics.write(
            "\u03B3 (SIR model):",
            Graphics.shifted((w // 3 + w // 30, h * 2 // 5 - 11 * shift)))
        Graphics.write(
            "R0:", Graphics.shifted(
                (w // 3 + w // 30, h * 2 // 5 - 12 * shift)))

        # Values
        Graphics.write(f"{GlobalSetup.NO_BALLS}",
                       Graphics.shifted((w // 2, h * 2 // 5 - 2 * shift)))
        Graphics.write(f"No speed",
                       Graphics.shifted((w // 2, h * 2 // 5 - 3 * shift)))
        Graphics.write(f"{GlobalSetup.RECOVERY_PROB} chance/iteration",
                       Graphics.shifted((w // 2, h * 2 // 5 - 4 * shift)))
        Graphics.write(f"No social distancing",
                       Graphics.shifted((w // 2, h * 2 // 5 - 5 * shift)))
        Graphics.write(f"{GlobalSetup.BALL_RADIUS}",
                       Graphics.shifted((w // 2, h * 2 // 5 - 6 * shift)))

        Graphics.write(
            f"{Data.data[-1][States.RECOVERED] / GlobalSetup.NO_BALLS * 100: .2f}% ({Data.data[-1][States.RECOVERED]})",
            Graphics.shifted((w // 2, h * 2 // 5 - 8 * shift)))
        Graphics.write(f"{len(Data.data)} iterations",
                       Graphics.shifted((w // 2, h * 2 // 5 - 9 * shift)))
        beta, gamma, r0 = Data.SIR_analyse()
        beta2, gamma2, r02 = Data.SIR_analyse_improved()
        Graphics.write(f"{beta: .2f} ({beta2: .2f})",
                       Graphics.shifted((w // 2, h * 2 // 5 - 10 * shift)))
        Graphics.write(f"{gamma: .2f} ({gamma2: .2f})",
                       Graphics.shifted((w // 2, h * 2 // 5 - 11 * shift)))
        Graphics.write(f"{r0: .2f} ({r02: .2f})",
                       Graphics.shifted((w // 2, h * 2 // 5 - 12 * shift)))

        tt.update()
        tt.exitonclick()
def main(_):

  data = Data()

  # Create the model
  x = tf.placeholder(tf.float32, [None, 300, 300, 1])

  # Define loss and optimizer
  y_ = tf.placeholder(tf.int32, [None, 116, 116])

  # Build the graph for the deep net
  y_conv = unet(x)


  with tf.name_scope('loss'):
    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y_, logits=y_conv)
  loss = tf.reduce_mean(loss)
  tf.summary.scalar('loss', loss)

  with tf.name_scope('AdamOptimizer'):
    train_step = tf.train.AdamOptimizer(0.0001, 0.95, 0.99).minimize(loss)

  with tf.name_scope('Accuracy'):
    # Training accuracy
    prediction = tf.argmax(y_conv, 3) # argmax the 3rd dimension, the label
    correct_pix_pred = np.sum(prediction == y_)
    incorrect_pix_pred = np.sum(prediction != y_)
    n_pix = 116 * 116
    train_acc = correct_pix_pred / (incorrect_pix_pred + n_pix)
    # Validation accuracy
    val_acc = 0
    val_images = data.get_test_image_list_and_label_list()
    for i in range(len(val_images[0])):
      x_val = val_images[0][i]
      y_val = val_images[1][i]
      y_conv_acc = unet(x_val)
      prediction = tf.argmax(y_conv_acc, 3)
      correct_pix_pred = np.sum(prediction == y_val)
      incorrect_pix_pred = np.sum(prediction != y_val)
      n_pix = 116 * 116
      val_acc += correct_pix_pred / (incorrect_pix_pred + n_pix)

  train_acc = tf.summary.scalar('Training accuracy', train_acc)
  val_acc = tf.summary.scalar('Validation accuracy', val_acc)

  graph_location = tempfile.mkdtemp()
  print('Saving graph to: %s' % graph_location)
  writer = tf.summary.FileWriter(graph_location)
  writer.add_graph(tf.get_default_graph())


  with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    writer = tf.summary.FileWriter(FLAGS.log_dir + '/assignment04', sess.graph)
    for i in range(400):
      batch = data.get_train_image_list_and_label_list()
      if i % 100 == 0:
        train_acc, val_acc = sess.run([train_acc, val_acc], 
                                      feed_dict={x: batch[0], y_: batch[1]})  
        writer.add_summary(train_acc, i)
        writer.add_summary(val_acc, i)
        print('step %d'% (i))
      train_step.run(feed_dict={x: batch[0], y_: batch[1]})
    writer.close()