コード例 #1
0
    def __init__(self, stock_code, chart_data, training_data=None,
                 min_trading_unit=1, max_trading_unit=2,
                 delayed_reward_threshold=0.05, l_rate=0.01):
        self.stock_code = stock_code 
        self.chart_data = chart_data

        # 환경 객체
        self.environment = Environment(chart_data)
        
        # 에이전트 객체
        self.agent = Agent(self.environment,
                           min_trading_unit=min_trading_unit,
                           max_trading_unit=max_trading_unit,
                           delayed_reward_threshold=delayed_reward_threshold)

        # 학습 데이터
        self.training_data = training_data 
        self.sample = None      # 여기서 sample도 training_data와 같이 17차원
        self.training_data_idx = -1

        # 정책 신경망의 Input layer에 들어오는 입력의 크기 또는 특징의 수(17) = 학습 데이터의 크기(15) + 에이전트 상태의 크기(2)
        # TODO self.training_data.shape의 [1]이 왜 학습 데이터의 크기인지 확인
        # TODO <해결> shape가 2차원이면 (n,15)일 것이고, 여기서 행은 전체 갯수이고, 열의 갯수가 학습 데이터의 크기로 들어갈 특징의 갯수일 것이다.
        #            shape가 2차원인 이유는 policy_network.py에서 설명했다.
        #              --> "Sequential 클래스의 predict() 함수는 여러 샘플을 한번에 받아서 신경망의 출력을 반환한다. 
        #                   하나의 샘플에 대한 결과만을 받고 싶어도 입력값을 샘플의 배열로 구성해야하기 때문에 2차원 배열로 재구성한다."
        self.num_features = self.training_data.shape[1] + self.agent.STATE_DIM
        # 정책 신경망 객체
        self.policy_network = PolicyNetwork(
            input_dim=self.num_features, output_dim=self.agent.NUM_ACTIONS, l_rate=l_rate)
        
        # 가시화기 객체 (에포크마다 투자 결과 가시화)
        self.visualizer = Visualizer()  
コード例 #2
0
def main():
    print('Opening webcam...')
    with videocapture_context(0) as cap:
        visualizer = Visualizer()

        while True:
            _, frame = cap.read()

            if frame is not None:
                estimator.process_frame(frame, options)
                humans2d = estimator.humans_2d()
                if humans2d:
                    human = humans2d[0]
                    visualizer.draw_image(frame)
                    joints = human.joints()
                    with open('data.csv', 'w', newline='') as f:
                        writer = csv.writer(f)
                        writer.writerow(joints[20:32].tolist())
                    visualizer.draw_points(joints[20:32])
                    visualizer.draw_lines(joints, bone_pairs)

                    visualizer.show()

            key = cv2.waitKey(1)

            if key & 255 == 27:
                break
コード例 #3
0
    def __init__(self,
                 config: Dict[str, Any]) -> None:
        """Initialize a new simulation using the given configuration.

        Precondition:
            arrival_generator is RandomArrivals(num_floors, people_per_round) or
                FileArrivals(num_floors, 'csv_file_name')
            moving_algorithm is RandomAlgorithm() or PushyPassenger() or
                ShortSighted()
            num_floors >= 2
            waiting keys are floor numbers
            people_per_round >= 0
        """
        # Initialize the visualizer.
        # Note that this should be called *after* the other attributes
        # have been initialized.
        self.arrival_generator = config['arrival_generator']
        self.elevators = []
        for i in range(config['num_elevators']):
            self.elevators.append(Elevator(config['elevator_capacity']))
        self.moving_algorithm = config['moving_algorithm']
        self.num_floors = config['num_floors']
        self.waiting = {}
        for i in range(1, self.num_floors + 1):
            self.waiting[i] = []
        self.people_per_round = config['num_people_per_round']
        self.results = {
            'num_iterations': 0,
            'total_people': 0,
            'people_completed': 0,
            'max_time': 0,
            'min_time': 0,
            'avg_time': 0.0}
        self.visualizer = Visualizer(self.elevators, self.num_floors,
                                     config['visualize'])
コード例 #4
0
def main():
    input_video_name = 'MVI_40855.mp4'
    input_video_folder = './unbox_test/input/'
    output_folder = './unbox_test/output/'

    loader = Loader(input_video_name, input_video_folder)
    tracker = Tracker(input_video_name, fps=loader.video.fps)
    loader_iter = loader.read_iter(batch_size=1)

    frames_count = int(loader.video.fps * loader.video.duration)

    detector = Detector(gpu_id=0)

    v1 = Visualizer()

    for i in range(frames_count):
        images, image_ids = next(loader_iter)
        frame = detector.detect(images, image_ids)[0]
        frame = tracker.track(frame)

        img_bgr = v1.draw_scene(frame)
        result_image_name = output_folder + str(i) + '.png'

        img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
        cv2.imwrite(result_image_name, img_rgb)

        print('[{0}/{1}] - {2}'.format(i, frames_count, result_image_name))
        pass
    print('done.')
コード例 #5
0
    def __init__(self, config: Dict[str, Any]) -> None:
        """Initialize a new simulation using the given configuration."""
        """
        config = {
        'num_people_per_round': 2,
    }
        """
        self.arrival_generator = config['arrival_generator']

        self.elevators = []
        for i in range(config['num_elevators']):
            new_elevator = Elevator(config['elevator_capacity'])
            self.elevators.append(new_elevator)

        self.moving_algorithm = config['moving_algorithm']

        self.num_floors = config['num_floors']

        self.waiting = {}
        for i in range(1, config['num_floors'] + 1):
            self.waiting[i] = []

        # Initialize the visualizer.
        # Note that this should be called *after* the other attributes
        # have been initialized.
        self.visualizer = Visualizer(self.elevators, self.num_floors,
                                     config['visualize'])
        self.num_round = 0
        self.total_people = 0
        self.people_completed = []
コード例 #6
0
    def __init__(self,
                 stock_code,
                 chart_data,
                 training_data=None,
                 min_trading_unit=1,
                 max_trading_unit=2,
                 delayed_reward_threshold=0.05,
                 l_rate=0.01):

        self.stock_code = stock_code
        self.chart_data = chart_data

        self.environment = Environment(chart_data)

        self.agent = Agent(self.environment,
                           min_trading_unit=min_trading_unit,
                           max_trading_unit=max_trading_unit,
                           delayed_reward_threshold=delayed_reward_threshold)

        self.training_data = training_data
        self.sample = None
        self.training_data_idx = -1

        self.num_features = self.training_data.shape[1] + self.agent.STATE_DIM

        self.policy_network = PolicyNetwork(input_dim=self.num_features,
                                            output_dim=self.agent.NUM_ACTIONS,
                                            l_rate=l_rate)

        self.visualizer = Visualizer()
コード例 #7
0
 def toggle_cam(self, video_source, json_path=None, options=None, processed=False):
     if self.cam_window.winfo_viewable():
         self.cam_window.withdraw()
         self.visualizer.close_cam()
         campage_elements = [self.btn_snapshot,
                             self.render_frame, self.render_legend]
         for element in campage_elements:
             element.grid_remove()
         if self._playback_job is not None:
             self.window.after_cancel(self._playback_job)
             self._playback_job = None
     else:
         self.visualizer = Visualizer(video_source, json_path, processed)
         self.visualizer.open_cam()
         # 10 miliseconds spent during calculations
         self.delay = int(1000/self.visualizer.vid.get(cv2.CAP_PROP_FPS))-10
         if self.delay < 1:
             print(
                 "Note: Cannot reliably replay videos above 90 FPS. Playback will be at 60 FPS")
             self.delay = 15
         if video_source == self.video_source:
             self.cam_window.title("Webcam")
             self.btn_snapshot.grid()
         elif json_path is not None:
             self.cam_window.title("JSON Render")
             self.render_legend.grid()
             self._toggle_render(options)
         else:
             self.cam_window.title("Annotated Playback")
         if self._playback_job is None:
             self.update()
         self.cam_window.deiconify()
コード例 #8
0
def vis_offline(results,
                poses,
                map_poses,
                mapsize,
                numParticles=1000,
                grid_res=0.2,
                start_idx=0):
    """ Visualize localization results offline.
    Args:
      results: localization results including particles in every timestamp.
      poses: ground truth poses.
      map_poses: poses used to generate the map.
      mapsize: size of the map.
      numParticles: number of particles.
      grid_res: the resolution of the grids.
      start_idx: the start index.
  """
    plt.ion()
    visualizer = Visualizer(mapsize,
                            poses,
                            map_poses,
                            numParticles=numParticles,
                            grid_res=grid_res,
                            strat_idx=start_idx)
    for frame_idx in range(start_idx, len(poses)):
        particles = results[frame_idx]
        visualizer.update(frame_idx, particles)
        visualizer.fig.canvas.draw()
        visualizer.fig.canvas.flush_events()
コード例 #9
0
 def __init__(self, station_file: str, ride_file: str) -> None:
     """Initialize this simulation with the given configuration settings.
     """
     self.visualizer = Visualizer()
     self.all_stations = create_stations(station_file)
     self.all_rides = create_rides(ride_file, self.all_stations)
     self.active_rides = []
コード例 #10
0
ファイル: simulation.py プロジェクト: alicewuuu/Csc148
    def __init__(self, config: Dict[str, Any]) -> None:
        """Initialize a new simulation using the given configuration.

        Precondition:
            config['num_floors'] >= 2
            config['num_elevators'] >= 1
            config['elevator_capacity'] >= 1
            config['num_people_per_round'] >= 0
        """

        # Initialize the visualizer.
        # Note that this should be called *after* the other attributes
        # have been initialized.
        self.arrival_generator = config['arrival_generator']
        elevator = []
        while len(elevator) != config['num_elevators']:
            elevator.append(Elevator(config['elevator_capacity']))
        self.elevators = elevator
        self.moving_algorithm = config['moving_algorithm']
        self.num_floors = config['num_floors']
        self.waiting = {}
        self.iterations = 0
        self.total_people = 0
        self.completed_people = 0
        self.waiting_time = []
        self.visualizer = Visualizer(self.elevators, self.num_floors,
                                     config['visualize'])
コード例 #11
0
def main():
	#flag for debugging
	flag_subset = False
	boosting_type = 'Real' #'Real' or 'Ada'
	training_epochs = 100 if not flag_subset else 20
	act_cache_dir = 'wc_activations.npy' if not flag_subset else 'wc_activations_subset.npy'
	chosen_wc_cache_dir = 'chosen_wcs.pkl' if not flag_subset else 'chosen_wcs_subset.pkl'

	#data configurations
	pos_data_dir = 'newface16'
	neg_data_dir = 'nonface16'
	image_w = 16
	image_h = 16
	data, labels = load_data(pos_data_dir, neg_data_dir, image_w, image_h, flag_subset)
	data = integrate_images(normalize(data))

	#number of bins for boosting
	num_bins = 25

	#number of cpus for parallel computing
	num_cores = 6 if not flag_subset else 1 #always use 1 when debugging
	
	#create Haar filters
	filters = generate_Haar_filters(4, 4, 16, 16, image_w, image_h, flag_subset)

	#create visualizer to draw histograms, roc curves and best weak classifier accuracies
	drawer = Visualizer([10, 20, 50, 100], [1, 10, 20, 50, 100])
	
	#create boost classifier with a pool of weak classifier
	boost = Boosting_Classifier(filters, data, labels, training_epochs, num_bins, drawer, num_cores, boosting_type)
コード例 #12
0
ファイル: main.py プロジェクト: unexpectedCoder/Blaba_2
def modeling():
    """Основная функция программы. Запускает алгоритм моделирования."""
    print("\nМоделирование...")

    wall = init_wall()
    striker = init_striker()
    space = init_space()
    vis = Visualizer(space, win_size=(900, 900))

    # Основная часть моделирования
    # Начальное состояние
    solver = Solver(wall, striker, space,
                    sigma=0.003, epsilon=1e-10)
    solver.gen_mesh()
    vis.show_in_static(solver)
    # Релаксация
    # ...ударника
    striker = solver.relax_striker(5e-4, (0, 1e-2))
    vis.show_in_static(solver)
    solver.clear_mesh()
    # ...стенки
    wall = solver.relax_wall(1e-3, (0, 2.5e-2))
    vis.show_in_static(solver)
    solver.clear_mesh()
    # Основная симуляция
    a = striker.rotate
    v0 = np.array([800. * np.cos(a), 800. * np.sin(a)])
    solver.solve(wall.copy(), striker.copy(), 1e-6, (0, 0.2/800), v0)
    vis.show_in_static(solver)
コード例 #13
0
 def __init__(self,
              stock_code,
              chart_data,
              training_data=None,
              min_trading_unit=1,
              max_trading_unit=2,
              delayed_reward_threshold=.05,
              lr=0.01,
              tax=False):
     self.stock_code = stock_code  # Stock code
     self.chart_data = chart_data
     self.environment = Environment(chart_data)  # Environment object
     self.tax = tax
     # Agent object
     self.agent = Agent(self.environment,
                        min_trading_unit=min_trading_unit,
                        max_trading_unit=max_trading_unit,
                        delayed_reward_threshold=delayed_reward_threshold,
                        tax=tax)
     self.training_data = training_data  # Training data
     self.sample = None
     self.training_data_idx = -1
     # Policy neural network; Input size = size of training data + agent state size
     self.num_features = self.training_data.shape[1] + self.agent.STATE_DIM
     self.policy_network = PolicyNetwork(input_dim=self.num_features,
                                         output_dim=self.agent.NUM_ACTIONS,
                                         lr=lr)
     self.visualizer = Visualizer()  # Visualization module
コード例 #14
0
    def __init__(self, agents, env, dma_indiv, spin_rate,
                 viz_trees=False, headless=False):
        """ Plan object runs multiagent experiments with DMA-RRT.

            Args:
                agents: a list containing Agent objects
                env: an Environment object
                dma_indiv: a method representing the individual component
                    of the DMA-RRT algorithm.
                spin_rate: the rate (in Hz) at which the planner should run
                viz_trees: if True, visualizer will show RRT trees for all
                    agents in orange.
                headless: if True, nothing will be visualized during spin.
        """
        self.agents = agents

        # randomly assign one agent to hold the token for replanning
        random.choice(self.agents).token_holder = True

        # make all the agents aware of the antenna IDs of their peers
        for agent in self.agents:
            agent.broadcast_id()

        self.env = env
        self.spin_rate = spin_rate
        self.curr_time = 0
        self.viz_trees = viz_trees
        self.headless = headless

        Plan.dma_individual_normal = dma_indiv

        self.visualizer = Visualizer(self.env)
コード例 #15
0
ファイル: main.py プロジェクト: minh0206/fake-tradingview
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Init
        self.db = Database(0, "5T")
        self.visualizer = Visualizer(self)
        self.ui.verticalLayout.addWidget(self.visualizer.dockArea)
        self.volumeProfile = VolumeProfile(self)
        self.console = pyqtgraph.console.ConsoleWidget(
            namespace={"vs": self.visualizer})

        # Auto update
        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.visualizer.candlestick.refresh)
        self.timer.start(2000)

        # Tool menu
        self.ui.actionVolumeProfile.triggered.connect(self.actionVolumeProfile)
        self.ui.actionConsole.triggered.connect(self.console.show)

        # Indicator menu
        self.ui.actionVolume.toggled.connect(
            lambda checked: self.visualizer.toggleVolume(checked))

        # Toolbar
        self.previousIndex = 7
        self.ui.cbInterval.setCurrentIndex(7)
        self.ui.cbInterval.activated.connect(self.cbIntervalSelect)
        self.ui.cbSymbol.currentIndexChanged.connect(self.cbSymbolSelect)
コード例 #16
0
    def __init__(self, config: Dict[str, Any]) -> None:
        """Initialize a new simulation using the given configuration.
        """
        self.data_record = {
            "total_people_arrived": 0,
            "total_people_completed": 0,
            "total_round": 0,
            "time_record": []
        }
        self.num_floors = config["num_floors"]
        self.arrival_generator = config["arrival_generator"]
        self.moving_algorithm = config["moving_algorithm"]

        self.elevators = []
        for i in range(0, config["num_elevators"]):
            self.elevators.append(Elevator(config["elevator_capacity"]))

        self.waiting = {}
        for i in range(1, self.num_floors + 1):
            self.waiting[i] = []

        # Initialize the visualizer.
        # Note that this should be called *after* the other attributes
        # have been initialized.
        self.visualizer = Visualizer(self.elevators, self.num_floors,
                                     config['visualize'])
コード例 #17
0
 def __init__(self, torrent):
     self.torrent = torrent
     self.tracker = Tracker(self.torrent.announce, self.torrent.get_params())
     self.peers = self.create_peers()
     self.message_handler = MessageHandler(self.torrent, self)
     self.io_loop = get_event_loop()
     self.visualizer = Visualizer()
コード例 #18
0
    def __init__(self, config: Dict[str, Any]) -> None:
        """Initialize a new simulation using the given configuration."""

        self.moving_algorithm = config['moving_algorithm']
        self.arrival_generator = config['arrival_generator']
        self._num_elevators = config['num_elevators']
        # Initialize elevators
        self.elevators = []
        count = self._num_elevators
        while count > 0:
            self.elevators.append(Elevator(config["elevator_capacity"]))
            count -= 1
        self.num_floors = config['num_floors']
        self.waiting = {}
        for floor in range(1, self.num_floors + 1):
            self.waiting[floor] = []
        self._num_people_per_round = config['num_people_per_round']
        self._people_completed = []
        self._num_rounds = 0
        self._total_people = 0

        # Initialize the visualizer.
        # Note that this should be called *after* the other attributes
        # have been initialized.
        self.visualizer = Visualizer(
            self.elevators,  # should be self.elevators
            self.num_floors,
            # should be self.num_floors
            config['visualize'])
コード例 #19
0
    def initVisualizer(self):
        if self.config['showModelVisualization'] and self.mpi_rank == 0:
            from visualizer import Visualizer
            self.visualizer = Visualizer(self.config)
            self.visualizer.loadMeshes(self.model.urdf_file, self.model.linkNames, self.idf.urdfHelpers)

            # set draw method for visualizer. This taps into local variables here, a bit unclean...
            def draw_model():
                if self.trajectory:
                    # get data of trajectory
                    self.visualizer.trajectory.setTime(self.visualizer.display_index/self.visualizer.fps)
                    q0 = [self.visualizer.trajectory.getAngle(d) for d in range(self.num_dofs)]
                else:
                    p_id = self.visualizer.display_index
                    q0 = self.visualizer.angles[p_id*self.num_dofs:(p_id+1)*self.num_dofs]

                q = iDynTree.VectorDynSize.fromList(q0)
                dq = iDynTree.VectorDynSize.fromList([0.0]*self.num_dofs)
                self.model.dynComp.setRobotState(q, dq, dq, self.world_gravity)
                self.visualizer.addIDynTreeModel(self.model.dynComp, self.link_cuboid_hulls,
                        self.model.linkNames, self.config['ignoreLinksForCollision'])
                if self.world:
                    self.visualizer.addWorld(self.world_boxes)
                self.visualizer.updateLabels()
            self.visualizer.event_callback = draw_model
コード例 #20
0
    def __init__(self, config: Dict[str, Any]) -> None:
        """Initialize a new simulation using the given configuration."""

        # Running Attributes
        self.arrival_generator = config['arrival_generator']
        self.elevators = []
        self.moving_algorithm = config['moving_algorithm']
        self.num_floors = config['num_floors']
        self.waiting = {}

        # Stat Attributes
        self._num_iterations = 0  # updated in self.run
        self._total_people = 0  # changed in self._generate_arrivals()
        self._people_completed = 0  # changed in self._handle_leaving()
        self._max_time = 0  # This and below update in self.handle_leaving()
        self._min_time = 16  # 1 + num_rounds so first occurrence is always min
        self._wait_times = list()  # updates in self._handle_leaving()

        # Populates waiting with empty lists for every floor_num
        # i + 1 b/c first floor is 1
        for i in range(self.num_floors):
            self.waiting[i + 1] = []

        # Populates self.elevators with number if elevators needed
        i = 0
        while i < config['num_elevators']:
            self.elevators.append(Elevator(config['elevator_capacity']))
            i += 1

        # Initialize the visualizer.
        # Note that this should be called *after* the other attributes
        # have been initialized.
        self.visualizer = Visualizer(self.elevators, self.num_floors,
                                     config['visualize'])
コード例 #21
0
ファイル: base_solver.py プロジェクト: michaeldinata/FMPN-FER
    def initialize(self, opt):
        self.opt = opt
        self.visual = Visualizer()
        self.visual.initialize(self.opt)

        self.CK_FACIAL_EXPRESSION = ['anger', 'contempt', 'disgust', 'fear', 'happy', 'sadness', 'surprise']
        self.OC_FACIAL_EXPRESSION = ['Anger', 'Disgust', 'Fear', 'Happiness', 'Sadness', 'Surprise']
コード例 #22
0
 def __init__(self,
              stock_code,
              chart_data,
              training_data=None,
              min_trading_unit=1,
              max_trading_unit=2,
              delayed_reward_threshold=.05,
              lr=0.01):
     self.stock_code = stock_code  # 종목코드
     # 차트 데이터
     self.chart_data = chart_data
     # 환경
     self.environment = Environment(stock_code, chart_data)  # 환경 객체
     # 에이전트 객체
     self.agent = Agent(self.environment,
                        min_trading_unit=min_trading_unit,
                        max_trading_unit=max_trading_unit,
                        delayed_reward_threshold=delayed_reward_threshold)
     # 학습 데이터 매칭
     self.training_data = training_data  # 학습 데이터
     # 샘플 초기 상태
     self.sample = None
     # 현재 학습 데이터 인덱스
     self.training_data_idx = -1
     # 입력은 환경에서 발생하는 모든 요소를 반영한다.
     # 정책 신경망; 입력 크기 = 학습 데이터의 크기 + 에이전트 상태 크기
     self.num_features = self.training_data.shape[1] + self.agent.STATE_DIM
     # 정첵 신경멍 객체 생성 및 매칭, 입력 계층 갯수, 출력 갯수, 학습률을 넣어 준다.
     self.policy_network = PolicyNetwork(input_dim=self.num_features,
                                         output_dim=self.agent.NUM_ACTIONS,
                                         lr=lr)
     self.visualizer = Visualizer()  # 가시화 모듈
コード例 #23
0
ファイル: test_bed.py プロジェクト: al13mi/traffic
def main(m=2, r=2, window_size=20, batch_size=2):
    gen = SimpleGenerator(num=m)
    bed = TestBed(m=m, r=r, window_size=window_size, batch_size=batch_size)
    vis = Visualizer()

    for i in xrange(10):
        bed.supply(gen.next())

    for i, y in enumerate(gen):
        if i % window_size == 0:
            # pretrain
            avg_cost = bed.pretrain(10, pretraining_lr=0.1)
            print("   pretrain cost: {}".format(avg_cost))

        # predict
        y_pred = bed.predict()
        print("{}: y={}, y_pred={}".format(i, y, y_pred))
        vis.append(y, y_pred)

        # finetune
        bed.supply(y)
        avg_cost = bed.finetune(10, finetunning_lr=0.1)
        # bed.finetune(100, finetunning_lr=0.01)
        # bed.finetune(100, finetunning_lr=0.001)
        print("   train cost: {}".format(avg_cost))
        time.sleep(.1)
コード例 #24
0
 def __init__(self,
              stock_code,
              chart_data,
              training_data=None,
              min_trading_unit=1,
              max_trading_unit=2,
              delayed_reward_threshold=.05,
              lr=0.01):
     self.stock_code = stock_code  # 종목코드
     self.chart_data = chart_data
     self.environment = Environment(chart_data)  # 환경 객체
     # Environment 클래스는 차트 데이터를 순서대로 읽으면서 주가, 거래량 등의 환경을 제공한다.
     # 에이전트 객체
     self.agent = Agent(self.environment,
                        min_trading_unit=min_trading_unit,
                        max_trading_unit=max_trading_unit,
                        delayed_reward_threshold=delayed_reward_threshold)
     self.training_data = training_data  # 학습 데이터. 학습에 사용할 특징(feature)들을 포함한다.
     self.sample = None
     self.training_data_idx = -1
     # 정책 신경망; 입력 크기(17개) = 학습 데이터의 크기(15개) + 에이전트 상태 크기(2개)
     self.num_features = self.training_data.shape[1] + self.agent.STATE_DIM
     self.policy_network = PolicyNetwork(input_dim=self.num_features,
                                         output_dim=self.agent.NUM_ACTIONS,
                                         lr=lr)
     self.visualizer = Visualizer()  # 가시화 모듈
コード例 #25
0
 def __init__(self,
              stock_code,
              chart_data,
              training_data=None,
              min_trading_unit=1,
              max_trading_unit=2,
              delayed_reward_threshold=.05,
              lr=0.01):
     self.stock_code = stock_code  # 종목코드
     self.chart_data = chart_data
     self.environment = Environment(chart_data)  # 환경 객체
     # 에이전트 객체
     self.agent = Agent(self.environment,
                        min_trading_unit=min_trading_unit,
                        max_trading_unit=max_trading_unit,
                        delayed_reward_threshold=delayed_reward_threshold)
     self.training_data = training_data  # 학습 데이터
     self.samples = None
     self.training_data_idx = -1
     # 정책 신경망; 입력 크기 = 학습 데이터의 크기 + 에이전트 상태 크기
     self.num_features = self.training_data.shape[1] + self.agent.STATE_DIM
     self.policy_network = PolicyNetwork(input_dim=self.num_features,
                                         output_dim=self.agent.NUM_ACTIONS,
                                         lr=lr)
     self.visualizer = Visualizer()  # 가시화 모듈
コード例 #26
0
    def __init__(self):
        self.val_best_acc = 0

        args = ParserArgs().args

        model = resnet101(num_classes=3, channels=1)
        model = nn.DataParallel(model).cuda()
        # optimizer = torch.optim.SGD(model.parameters(), lr=args.lr,
        #                             momentum=args.momentum,
        #                             weight_decay=args.weight_decay)
        optimizer = torch.optim.Adam(model.parameters(),
                                     lr=args.lr,
                                     weight_decay=args.weight_decay)
        # optimizer = torch.optim.Adadelta(model.parameters(), args.lr,
        #                                  weight_decay=args.weight_decay)

        # Optionally resume from a checkpoint
        if args.resume:
            ckpt_root = os.path.join('checkpoints', args.version)
            ckpt_path = os.path.join(ckpt_root, args.resume)
            if os.path.isfile(ckpt_path):
                print("=> loading checkpoint '{}'".format(args.resume))
                checkpoint = torch.load(ckpt_path)
                args.start_epoch = checkpoint['epoch']
                model.load_state_dict(checkpoint['state_dict'])
                optimizer.load_state_dict(checkpoint['optimizer'])
                print("=> loaded checkpoint '{}' (epoch {})".format(
                    args.resume, checkpoint['epoch']))
            else:
                print("=> no checkpoint found at '{}'".format(args.resume))

        cudnn.benchmark = True

        self.vis = Visualizer(server='http://10.10.10.100',
                              env='{}'.format(args.version),
                              port=args.port)

        self.dataset_name = args.dataset
        self.train_loader = get_dataloader(self.dataset_name,
                                           args.data_path,
                                           batch_size=args.batch_size,
                                           mode='train',
                                           transform=transform_)
        self.val_loader = get_dataloader(self.dataset_name,
                                         args.data_path,
                                         batch_size=args.batch_size,
                                         mode='val',
                                         transform=transform_)
        self.test_loader = get_dataloader(self.dataset_name,
                                          args.data_path,
                                          batch_size=args.batch_size,
                                          mode='test',
                                          transform=transform_)
        print_args(args)
        self.args = args
        self.model = model
        self.optimizer = optimizer
        self.criterion = nn.CrossEntropyLoss()

        self.cls_list = {}
コード例 #27
0
    def __init__(self,
                 coin_code,
                 coin_chart,
                 training_data=None,
                 min_trading_unit=1,
                 max_trading_unit=2,
                 delayed_reward_threshold=.05,
                 lr=0.01):

        self.coin_code = coin_code
        self.coin_chart = coin_chart

        self.environment = Environment(coin_chart)
        self.agent = Agent(self.environment,
                           min_trading_unit=min_trading_unit,
                           max_trading_unit=max_trading_unit,
                           delayed_reward_threshold=delayed_reward_threshold)

        self.training_data = training_data
        self.sample = None
        self.training_data_idx = -1

        self.num_features = self.training_data.shape[
            1] + self.agent.STATE_DIM  # -1 # input_dim = 15 + 2 = 17
        self.policy_network = PolicyNetwork(input_dim=self.num_features,
                                            output_dim=self.agent.NUM_ACTIONS,
                                            lr=lr)

        self.visualizer = Visualizer()
コード例 #28
0
 def __init__(self, rl_method='rl', stock_code=None, 
             chart_data=None, training_data=None,
             min_trading_unit=1, max_trading_unit=2, 
             delayed_reward_threshold=.05,
             net='dnn', num_steps=1, lr=0.001,
             value_network=None, policy_network=None,
             output_path='', reuse_models=True):
     # 인자 확인
     assert min_trading_unit > 0
     assert max_trading_unit > 0
     assert max_trading_unit >= min_trading_unit
     assert num_steps > 0
     assert lr > 0
     # 강화학습 기법 설정
     self.rl_method = rl_method
     # 환경 설정
     self.stock_code = stock_code
     self.chart_data = chart_data
     self.environment = Environment(chart_data)
     # 에이전트 설정
     self.agent = Agent(self.environment,
                 min_trading_unit=min_trading_unit,
                 max_trading_unit=max_trading_unit,
                 delayed_reward_threshold=delayed_reward_threshold)
     # 학습 데이터
     self.training_data = training_data
     self.sample = None
     self.training_data_idx = -1
     # 벡터 크기 = 학습 데이터 벡터 크기 + 에이전트 상태 크기
     self.num_features = self.agent.STATE_DIM
     if self.training_data is not None:
         self.num_features += self.training_data.shape[1]
     # 신경망 설정
     self.net = net
     self.num_steps = num_steps
     self.lr = lr
     self.value_network = value_network
     self.policy_network = policy_network
     self.reuse_models = reuse_models
     # 가시화 모듈
     self.visualizer = Visualizer()
     # 메모리
     self.memory_sample = []
     self.memory_action = []
     self.memory_reward = []
     self.memory_value = []
     self.memory_policy = []
     self.memory_pv = []
     self.memory_num_stocks = []
     self.memory_exp_idx = []
     self.memory_learning_idx = []
     # 에포크 관련 정보
     self.loss = 0.
     self.itr_cnt = 0
     self.exploration_cnt = 0
     self.batch_size = 0
     self.learning_cnt = 0
     # 로그 등 출력 경로
     self.output_path = output_path
コード例 #29
0
def visualize_dataset_raw(dataset, start_date, end_date):
    ''' Visualsiert den Stromverbrauch aus Rohdaten

        :start_date: Anfangsdatum, von welchem ausgehend die Visualsierungen durchgeführt werden
        :end_date: Enddatum, bis zu welchem die Visualsierungen durchgeführt werden
    '''
    visualizer = Visualizer(dataset)
    visualizer.visualize_dataset_raw(start_date, end_date)
コード例 #30
0
 def __init__(self, args):
     super(Demo, self).__init__(args)
     if args.data == 'box':
         self.data = BoxDataBidirect(args)
     elif args.data == 'mnist':
         self.data = MnistDataBidirect(args)
     self.model, self.model_gt = self.init_model(self.data.m_kernel)
     self.visualizer = Visualizer(args, self.data.reverse_m_dict)
     self.num_inputs = (self.num_frame - 1) / 2