본문 바로가기

전체 글

(94)
[3.4.6] Dive into Deep Learning : exercise answers 3.4. Linear Regression Implementation from Scratch — Dive into Deep Learning 1.0.3 documentation d2l.ai [1] The algorithm will still work even if the weight is initially zero. Since the algorithm we are using is gradient descent, typically it doesn't matter where you start. The gradient will mostly always guide the weight to the spot where the loss function is minimum. We can confirm this by run..
[3.3.5] Dive into Deep Learning : exercise answers 3.3. Synthetic Regression Data — Dive into Deep Learning 1.0.3 documentation d2l.ai [1] The question is asking me if the batch_size is 8 and I have a data size of 50. Since 50 is not dividable by 8, what should I do to the remaining 2?. Actually the attributes in torch.tensor and even in the list already fixes our concerns. The below is the example of dealing with the unmatched size. import torc..
[3.2.6]Dive into Deep Learning : exercise answers 3.2. Object-Oriented Design for Implementation — Dive into Deep Learning 1.0.3 documentation d2l.ai [1] So there are a bunch of classes and methods in the torch.py file and I will go through only the classes that are shown in 3.2. Before we get into the library, I found something interesting which is the way torch let users to implement their own functions for additional perposes. For example, w..
[머신러닝] 지도 학습(Supervised Learning) INDEX 1. 지도 학습 개요 2. 데이터 3. 피쳐 벡터(x) 4. 손실 함수 5. 데이터 분리 1. 지도 학습 개요 지도 학습은 사람이 먼저 어떤 데이터(x)에 대한 답(y)을 알려주고 이후에 새로운 데이터(x')를 입력받았을 때 x'에 대한 답(y')를 추측하는 학습 방법이다. 어찌 보면 우리 인간이 학습하는 방법과 매우 유사하다. 우리는 어떤 개념을 학습하기 위해 예시들을 접하고 그 예시들(데이터)에서 규칙을 찾으려고 노력하고 이 학습 과정은 뇌에서 일어난다. 이후 보지 못한 상황(데이터)에 우리의 학습된 뇌를 토대로 결과를 도출한다. 컴퓨터의 관점에서 재해석하자면 뇌는 학습하는 모델이다. 즉 모델은 답을 내놓는 몸체인 것이고 이를 학습시키는 것이 데이터인 것이다. 인간의 경우 자신이 얼마나 잘..
[3.1.6]Dive into Deep Learning : exercise answers 3.1. Linear Regression — Dive into Deep Learning 1.0.3 documentation d2l.ai This post is just my personal solutions to the exercise problems from the linear regression part of the book. Although I tried my best to come up with the most logical solution, there must be flawes in the solutions(I am currently just a masters student(I am just a hot potato)). [1-1] If we view the equation as a loss fu..
[백준]_1016번 : 제곱 ㄴㄴ 수(파이썬) 1016번: 제곱 ㄴㄴ 수 어떤 정수 X가 1보다 큰 제곱수로 나누어 떨어지지 않을 때, 그 수를 제곱ㄴㄴ수라고 한다. 제곱수는 정수의 제곱이다. min과 max가 주어지면, min보다 크거나 같고, max보다 작거나 같은 제곱ㄴㄴ수 www.acmicpc.net 문제의 전체 맥락을 보아하니 특정 자연수 구간에서 제곱 수로 나누어 떨어지는 수들을 제외시켜야 하는 작업이 필요하다. 제곱수들의 배수에 해당하는 숫자들을 지우면 되기 때문에 에라토스테네스의 체 알고리즘과 비슷한 맥락임을 알 수 있다. 즉 아래와 같은 코드로 시작하면 좋지 않을까 생각이 든다. s, f = map(int, input().split()) # (int)(f ** 0.5)보다 큰 자연수의 제곱은 f보다 크기 때문에 관찰할 필요가 없다. ..
[백준]_1202번 : 보석 도둑(파이썬) 1202번: 보석 도둑 첫째 줄에 N과 K가 주어진다. (1 ≤ N, K ≤ 300,000) 다음 N개 줄에는 각 보석의 정보 Mi와 Vi가 주어진다. (0 ≤ Mi, Vi ≤ 1,000,000) 다음 K개 줄에는 가방에 담을 수 있는 최대 무게 Ci가 주어진다. (1 ≤ Ci www.acmicpc.net 먼저 무게와 가격 중에서 무엇을 더 중시할 것인지 알아야 한다. 우리가 최종적으로 원하는 것은 훔칠 수 있는 최대 값어치의 보석이지만 가방의 무게 한계를 고려하지 않으면 무용지물이다. 즉 가격은 무게 다음으로 중요한 요소이다. 무게(w)와 가격(v)을 튜플로 묶어서 힙큐(tag)에 push 해준다. 이후에 tag에서 무게가 적은 순서로 보석이 나올 것이다. 이제 보석을 담아야 하는데 가능하다면 무게 한..
[백준]_1655번 : 가운데를 말해요(파이썬) 1655번: 가운데를 말해요 첫째 줄에는 백준이가 외치는 정수의 개수 N이 주어진다. N은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수이다. 그 다음 N줄에 걸쳐서 백준이가 외치는 정수가 차례대로 주어진다. 정수는 -1 www.acmicpc.net 문제를 보면 정렬되지 않은 데이터가 입력되고 입력이 일어날 때마다 정렬을 한 후에 가운데 요소를 출력해야 한다. 하지만 입력이 있을 때마다 데이터들을 정렬하는 것은 시간 복잡도가 $O(N^2log{N})$이므로 바람직하지 않다. 특히나 이문제는 시간제한이 0.1초이므로 매우 빠듯한 편에 속한다. 데이터 입력이 일어날 때마다 정렬을 해주는 우선순위 큐(heapq)를 이용해주자. 힙큐는 원소의 추가(heappush)가 $O(logN)$, 원소 추출(..