示例#1
0
 def __init__(self):
     init()
     self.n = 0
     self.balls = []
     self.player = PLAYER()
     self.target = TARGET()
     self.target.new()
     display.set_caption('Ball Game')
     self.clock = time.Clock()
     self.Font = font.SysFont("arial", 40)
def error_over_speed(tau, ws):
    speeds = np.arange(0.1, 0.9, 0.1)
    y = []
    for s in speeds:
        tg_var = TARGET(speed=s,
                        max_speed=0.8,
                        size=20,
                        peak_cell_num=peak_cell_num)
        can = CAN(target=tg_var,
                  size=20,
                  tau=tau,
                  dt=tau / 10,
                  kappa=0.1,
                  beta=-8,
                  ws_param=ws,
                  h=0)
        can.init_network_activity(peak_cell_num=peak_cell_num, init_time=1)
        can.run(sim_time=20)
        y.append(can.slope_accuracy(s, 20, peak_cell_num))
    fig, ax = plt.subplots()
    ax.xaxis.set_ticks_position('bottom')
    ax.set_title("Error in relation to speed [Tau=" + str(tau) + "][WS=" +
                 str(ws) + "]")
    ax.set_xlabel("Speed [m/s]")
    ax.set_ylabel("Error")
    plt.plot(speeds, y, 'r-')
    plt.ylim(-20, 20)
示例#3
0
文件: main.py 项目: codelurker/Pygame
 def __init__(self):
     init()
     self.n = 0
     self.balls = []
     self.player = PLAYER()
     self.target = TARGET()
     self.target.new()
     display.set_caption('Ball Game')
     self.clock = time.Clock()
     self.Font = font.SysFont("arial", 40);
示例#4
0
文件: test.py 项目: Aganonce/TARGET
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler

from target import TARGET


def plot_pca(X):
    pca = PCA(n_components=2)
    X_r1 = pca.fit_transform(X)

    fig, ax = plt.subplots()
    for i in range(len(X_r1)):
        plt.scatter(X_r1[i][0], X_r1[i][1], c='r')

    plt.xlabel('x1')
    plt.ylabel('x2')
    plt.title('PCA on TARGET')
    plt.show()


if __name__ == '__main__':
    infile = 'data/small_sample.csv'

    start = time.time()
    target = TARGET(verbose=True, workers=2,
                    nodes_per_thread=2).train_csv(infile)
    print('Runtime:', time.time() - start)

    for c in target.resf_:
        X = StandardScaler().fit_transform(target.resf_[c])
        plot_pca(X)
示例#5
0
class Game:
    def __init__(self):
        init()
        self.n = 0
        self.balls = []
        self.player = PLAYER()
        self.target = TARGET()
        self.target.new()
        display.set_caption('Ball Game')
        self.clock = time.Clock()
        self.Font = font.SysFont("arial", 40)

    def put_message(self):
        message = "Balls : %d" % (self.n)
        text = self.Font.render(message, True, (0, 0, 255))
        screen.blit(text, (100, int(.9 * screen.get_height())))
        display.update(
            [[0, int(screen.get_height() * .9)],
             [int(screen.get_width() / 2),
              int(screen.get_height() * .1)]])

    def check(self):
        if (abs(self.target.x - self.player.x) <
                self.target.width / 2 + self.player.width / 2) and (
                    abs(self.target.y - self.player.y) <
                    self.target.width / 2 + self.player.height / 2):
            self.balls.append(BALL())
            self.n += 1
            self.target.play_sound()
            self.target.new()
            self.put_message()
            self.draw()
        for ball in self.balls:
            if (self.player.x - self.player.width / 2 < ball.x <
                    self.player.x + self.player.width / 2) and (
                        self.player.y - self.player.height / 2 < ball.y <
                        self.player.y + self.player.height / 2):
                self.player.play_sound()
                self.stop = True

    def update(self):
        self.player.move()
        for ball in self.balls:
            ball.bounce()
            ball.move()

    def draw(self):
        screen.fill(color_black)
        draw.rect(
            screen, color_white,
            [[0, 0], [int(screen.get_width()),
                      int(screen.get_height() * .9)]])
        self.target.draw()
        self.player.draw()
        for ball in self.balls:
            ball.draw()
        display.update(
            [[0, 0], [int(screen.get_width()),
                      int(screen.get_height() * .9)]])

    def reset(self):
        self.n = 0
        self.balls = []
        self.player = PLAYER()

    def handle_events(self):
        keys = key.get_pressed()
        if keys[K_q] or keys[K_ESCAPE]:
            self.quit = True
        if keys[K_SPACE] and self.stop:
            self.reset()
            self.stop = False
        for evt in event.get():
            if evt.type == QUIT:
                self.quit = True
            if evt.type == MOUSEBUTTONDOWN:
                for ball in self.balls:
                    ball.reverse()

    def run(self):
        self.quit = False
        self.stop = False
        self.put_message()
        while not self.quit:

            self.handle_events()

            if not self.stop:
                self.update()
                self.draw()
                self.check()
            self.clock.tick(100)
示例#6
0
文件: main.py 项目: codelurker/Pygame
class Game:
    def __init__(self):
        init()
        self.n = 0
        self.balls = []
        self.player = PLAYER()
        self.target = TARGET()
        self.target.new()
        display.set_caption('Ball Game')
        self.clock = time.Clock()
        self.Font = font.SysFont("arial", 40);
    
    def put_message(self):
        message = "Balls : %d"%(self.n)
        text = self.Font.render(message, True, (0, 0, 255))    
        screen.blit(text, (100,int(.9*screen.get_height())))
        display.update([[0,int(screen.get_height()*.9)],[int(screen.get_width()/2),int(screen.get_height()*.1)]])
        
    def check(self):
        if (abs(self.target.x-self.player.x) < self.target.width/2+self.player.width/2) and (abs(self.target.y-self.player.y) < self.target.width/2+self.player.height/2):
            self.balls.append(BALL())
            self.n+=1
            self.target.play_sound()
            self.target.new()
            self.put_message()
            self.draw()
        for ball in self.balls:
            if (self.player.x-self.player.width/2 < ball.x < self.player.x+self.player.width/2) and (self.player.y-self.player.height/2 < ball.y < self.player.y+self.player.height/2):
                self.player.play_sound()
                self.stop = True      
                
    def update(self):
        self.player.move()
        for ball in self.balls:
            ball.bounce()
            ball.move() 
            
    def draw(self):
        screen.fill(color_black)
        draw.rect(screen, color_white, [[0,0],[int(screen.get_width()),int(screen.get_height()*.9)]])
        self.target.draw()
        self.player.draw()
        for ball in self.balls:
            ball.draw()
        display.update([[0,0],[int(screen.get_width()),int(screen.get_height()*.9)]])
        
    
    def reset(self):
        self.n = 0
        self.balls = []
        self.player = PLAYER()
    
    def handle_events(self):
        keys = key.get_pressed()
        if keys[K_q] or keys[K_ESCAPE]:
            self.quit = True
        if keys[K_SPACE] and self.stop:
            self.reset()
            self.stop = False
        for evt in event.get():
            if evt.type == QUIT:
                self.quit = True
            if evt.type == MOUSEBUTTONDOWN:
                for ball in self.balls:
                    ball.reverse()
        
    def run(self):
        self.quit = False
        self.stop = False
        self.put_message()
        while not self.quit:
            
            self.handle_events()
            
            if not self.stop:
                self.update()
                self.draw()
                self.check()
            self.clock.tick(100)
from can import CAN
from target import TARGET
import numpy as np
import matplotlib.pyplot as plt
import os.path
import math

peak_cell_num = 15
speed = 0.2

tg = TARGET(speed=speed, max_speed=0.8, size=20, peak_cell_num=peak_cell_num)


def single_run():
    #tau 0.05, ws 0.08
    can = CAN(target=tg,
              size=20,
              tau=0.05,
              dt=0.005,
              kappa=0.1,
              beta=-8,
              ws_param=0.08,
              h=0)
    can.init_network_activity(peak_cell_num=peak_cell_num, init_time=1)
    can.run(sim_time=15)
    can.plot_activities(u_out=True)
    #print(can.slope_accuracy(speed,20,peak_cell_num))
    #can.plot_single_cell(speed,20,0)
    #plt.show()