분류 전체보기 68

Basic RL

목차 강화학습의 적용분야는 상당히 넓다. Optimal decision making하는 분야라면 다 적용가능하다! RL과 다른 머신러닝의 차이점은 agent가 action(환경과의 상호작용)을 통해 얻는 reward signal(delay 될 수 있음)이다. Reward agent 가 받는 피드백으로, 현재 timestep t에서 얼마나 잘했는가를 알 수 있다. agent는 cumulative reward를 최대화해야한다. RL reward hypothesis : 모든 goal은 expected cumulative reward의 최대화로 표현 가능하다. (동의하는가?!) History 현재 timestep t까지의 일련의 observation, action, reward를 의미한다. H_t = O_1, ..

LSTM으로 주식 가격 예측하기

목차 1. 주식 데이터 Load 2. 학습 데이터 생성 3. LSTM LSTM으로 주식 예측하기 이번 포스팅에서는 특정 종목의 가격(상승 or 하락)을 예측하는 LSTM 모델을 생성합니다. 모델의 input으로 Transfer entropy를 도입하여 특정 종목에 대한 KOSPI의 영향력을 반영합니다. 1. 주식 데이터 Load 1.1 모듈 import %pip install yfinance %pip install pandas-datareader from pandas_datareader import data as pdr import yfinance as yf import numpy as np import pandas as pd import matplotlib.pyplot as plt import math..

기타 2022.12.05

Torch 기본

Tensor - 3D Tensor : t3.ndim = 3 시계열 데이터 (feature / timestep/ sample) - 4D Tensor : t4.ndim = 4 컬러 이미지 (height, width, channel, sample) Tensor 연산 torch.abs(a) torch.ceil(a) torch.floor(a) torch.clamp(a, -0.5,0.5) torch.std(a) torch.prod(a) torch.unique(a) a.max(dim = 0) #dim 지정시, argmax 와 같이 작동 a.min(dim = 1) # dim 지정시, argmin처럼 index함께 반환 in-place방식 : 텐서의 값을 변경하는 연산 뒤에 underbar '_' 붙음 y.add_(x)..

기타 2022.12.02

Pytorch| RuntimeError: Trying to backward through the graph a second time

목차 1. Error 2. Problem Case 3. Solution & MFA 1. Error RuntimeError: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved..

삽질Log 2022.11.10

6. Latent Variable Models PCA & FA & MFA

목차 1. Latent Variable Model 2. PCA 3. FA & MFA Latent Variable Model 이번 포스팅에서는 Expectation maximization, EM알고리즘을 자세히 알아보도록 합시다. 1. Latent Variable Model ff 2. Principal Component Analysis (PCA) PCA는 데이터의 dimension을 줄이기 위한 대표적인 방법입니다. 원래의 데이터셋의 특징은 잘 살리면서도, 차원을 줄이기 위해선 어떻게 해야할까요? 원래의 데이터를 새로운, 더 작은 차원의 projected space에 투영 시켰을 때, 데이터셋의 분산을 가장 크게 하는 orthogonal projection을 찾는 것이 핵심 아이디어입니다. '분산을 크게 ..

5. Expectation Maximization(EM)

목차 1. Mathematical preliminaries 2. EM Algorithm EM Algorithm 이번 포스팅에서는 Expectation maximization, EM알고리즘을 자세히 알아보도록 합시다. 이전 포스팅에서 latent variable이 있는 MoG를 EM알고리즘으로 풀었고, 2개의 의문을 남겼습니다. (1) 왜 complete data log likelihood를 사용하는지. (2) E-step에서 왜 posterior distribution을 사용하는지. 이번 포스팅에서 샅샅이 밝혀보도록 하겠습니다!! 1. Mathematical preliminaries 우선, EM 알고리즘을 이해하기 위해 필요한 선수 지식을 소개합니다. (1) Jensen's Inequality, (2) ..

4. Clustering

목차 1. k-Means 2. Mixture of Gaussians 3. k-Means & MoG Clustering Clustering이란 라벨이 없는 데이터들을 미리 지정해둔 k개 그룹에 분리하는 작업입니다. 각 그룹으로 묶인 데이터는 유사한 성질을 가져야 합니다. 이때, 유사함을 측정하는 지표로 사용되는 distance measure에 따라 clustering 결과가 달라질 수 있습니다. 이번 포스팅에서는 k-Means와 Mixture of Gaussians Clustering(MoG) Clustering에 다룹니다. 각각의 방법을 이해한 뒤, k-Means가 MoG를 간략히 한 버전임을 이해해봅시다!! 1. k-Means Clustering의 가장 기본적인 알고리즘은 k-Means입니다. 말 그대..

3. Density Estimation

목차 1. MLE 2. MAP 3. Bayesian Inference Density Estimation이란,, $\;\;$Density Estimation 이란, observation 데이터셋 $x_1, \cdots, x_N$가 주어졌을 때, random variable $x$의 probability distribution $p(x)$를 찾는 것(modeling) 입니다. 이때, 각각의 데이터는 I.I.D(independent and identically distributed)를 가정하고 있습니다. Parametric estimation vs Nonparametric estimation $\;\;$Density Estimation에는 크게 2가지 접근이 가능합니다. $\rightarrow$ Paramet..