예제 #1
0
파일: quadTree.py 프로젝트: harxish/Python
 def draw(self):
     for i in self.points:
         plot(i)
     if (self.divided):
         self.boundary.drawDivision()
         self.northEast.draw()
         self.northWest.draw()
         self.southEast.draw()
         self.southWest.draw()
예제 #2
0
def ppo_test():

    env = gym.make('Pendulum-v0')
    ppo = PPO(3, 1, 2)
    ppo.ep_max = 500

    for ep in range(ppo.ep_max):
        s = env.reset()
        buffer_s, buffer_a, buffer_r = [], [], []
        ep_r = 0
        for t in range(300):  # in one episode
            env.render()

            a = ppo.get_action(s)

            s_, r, done, _ = env.step(a)
            s_ = np.squeeze(s_)

            buffer_s.append(s)
            buffer_a.append(a)
            buffer_r.append((r + 2) / 2)  # normalize reward, find to be useful

            s = s_
            ep_r += r

            if (t + 1) % ppo.batch_size == 0 or t == 300 - 1:

                v_s_ = ppo.get_value(s_)

                discounted_r = []
                for r in buffer_r[::-1]:
                    v_s_ = r + 0.9 * v_s_
                    discounted_r.append(v_s_)
                discounted_r.reverse()

                bs, ba, br = np.vstack(buffer_s), np.vstack(
                    buffer_a), np.vstack(
                        discounted_r)  #np.array(discounted_r)[:,np.newaxis]

                buffer_s, buffer_a, buffer_r = [], [], []
                ppo.train(bs, ba, br, ep)

        ep_r_all.append(ep_r)
        print(ep, '  ', ep_r)

    plot(ppo.a_loss)
    plot(ppo.c_loss)
    plot(ep_r_all)
예제 #3
0
def drawMove(move, port):
    fileName = getfile(move)
    plot(fileName, port)
예제 #4
0
    X.append(data["X1"])
    X.append(data["X2"])

    # Now array X has two rows, first row contains all the numbers for X1 and the
    # second row contains all the numbers for X2 but I want an output in which
    # the number of rows is equal to the number of data and each row contains
    # one X1 and X2 so I got the transpose of array X
    Xt = np.transpose(X)

    return np.array(Xt), data["Label"].values


X, y = read_data('dataset.csv')

plot(X, y)

# I want to split the data to training and test data but before doing it I shuffle the data to get a different
# training and test data every time I run the code so the result I get may differ each time.
X_train, X_test, y_train, y_test = train_test_split(X,
                                                    y,
                                                    test_size=0.2,
                                                    shuffle=True)

# # Make a perceptron and train it
# p = perceptron.Perceptron()
# p.fit(X_train, y_train)
#
# border(X, p)
#
# # Now I want to test the trained perceptron
예제 #5
0
print("training...")
seller_train_data = []
buyer_train_data = []
for i in tqdm(range(NEG_TRAIN_DATA)):
    world = SCML2020World(
        **SCML2020World.generate(
            agent_types=[MyLearnNegotiationAgent, DecentralizingAgent,],
            n_steps=40,
            n_processes=2,
        ),
        construct_graphs=True
    )
    SCML2020World.cancelled_contracts = cancelled_contracts
    world.run()
    plot(world)

    seller_data, buyer_data = get_train_data(world)
    seller_train_data += seller_data
    buyer_train_data += buyer_data

seller_train_features, seller_train_tags = split_features_tags(seller_train_data)
seller_train_features = [
    torch.from_numpy(feature).float() for feature in seller_train_features
]
seller_train_tags = [torch.from_numpy(tag).float() for tag in seller_train_tags]

all_seller_data = list(zip(seller_train_features, seller_train_tags))
shuffle(all_seller_data)
train_seller_data = all_seller_data[: -int(len(all_seller_data) * NEG_VALIDATION_SPLIT)]
test_seller_data = all_seller_data[-int(len(all_seller_data) * NEG_VALIDATION_SPLIT) :]
예제 #6
0
from draw import plot
import argparse

parser = argparse.ArgumentParser(
    description='This is a basic gcode sender. http://crcibernetica.com')
parser.add_argument('-p', '--port', help='Input USB port', required=True)
parser.add_argument('-f', '--file', help='Gcode file name', required=True)
args = parser.parse_args()
port = args.port

#plot("1.g",port)
#plot("2.g",port)
#plot("3.g",port)
#plot("4.g",port)
#plot("5.g",port)
#plot("6.g",port)
#plot("7.g",port)
#plot("8.g",port)
plot(args.file, args.port)
예제 #7
0
파일: main.py 프로젝트: harxish/Quad-Trees
def clicked(x, y):
    qt.insertDraw([x, y])
    if qt.contains([x, y]): plot([x, y])
    print("You clicked : ", x, ", ", y)
예제 #8
0
파일: main.py 프로젝트: harxish/Quad-Trees
from quadTree import quadTree
from draw import Rect, win, head, plot
import random
import turtle


def clicked(x, y):
    qt.insertDraw([x, y])
    if qt.contains([x, y]): plot([x, y])
    print("You clicked : ", x, ", ", y)


boundary = Rect([0, 0], 250, 250)
boundary.draw()
qt = quadTree(boundary, 4)

for _ in [0] * 600:
    rand_x = random.uniform(-250, 251)
    rand_y = random.uniform(-250, 251)
    qt.insertDraw([rand_x, rand_y])
    plot([rand_x, rand_y])

win.onclick(clicked)

qt.draw()
win.mainloop()
import sys
import draw

if len(sys.argv) > 4:

    def f(x):
        return eval(sys.argv[1])

    draw.plot(f, float(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4]))
else:
    print('Bad arguments')