Matrix
-
Matrix Multiplication Code | Advanced Learning AlgorithmMachine Learning/Stanford ML Specialization 2024. 2. 10. 20:59
Coursera Machine Learning Specialization > Supervised Machine Learning: Advanced Learning Algorithms > Neural Network Intuition 이제 전에 직접 계산했던것을 NumPy를 이용해서 계산해보자. 먼저 A matrix를 아래와 같이 생성할 수 있다. A = np.array([1, -1, 0.1], [2, -2, 0.2]]) 이제 이 matrix를 transpose 한 matrix를 생성해보자. AT = np.array([[1, 2], [-1, -2], [0.1, 0.2]]) 매번 이렇게 직접 쓰지 않아도, 원래의 matrix가 있다면, transpose를 이렇게 할 수 있다. AT = A.T 그리고 W matr..
-
Matrix Multiplication Rules | Advanced Learning AlgorithmMachine Learning/Stanford ML Specialization 2024. 2. 10. 18:40
Coursera Machine Learning Specialization > Supervised Machine Learning: Advanced Learning Algorithms > Neural Network Intuition 이번에는 Matrix를 곱할때 규칙들을 살펴보자. 아래와 같은 Matrix를 살펴보자. A를 Transpose 하게 되면 3x2 matrix가 된다. 이것을 2 x 4 matrix인 W와 곱하게 되면? A의 각 row들을 w을 컬럼들과 한번씩 곱하야하기 때문에 3 by 4 matrix가 생성된다. 그렇다면 계산은 어떻게 될까? 해당 column과 row를 sum product해서 돌바른 자리에 넣어주면 된다. 위의 계산 예시를 참고. 여기서, Multiplication을 하기위한..
-
Matrix Multiplication | Advanced Learning AlgorithmMachine Learning/Stanford ML Specialization 2024. 2. 10. 06:05
Coursera Machine Learning Specialization > Supervised Machine Learning: Advanced Learning Algorithms > Neural Network Intuition 지난시간, for loop을 이용하는것보다 vectorization을 통해서 2D Array, 즉 Matrix를 이용하면 훨씬 코드를 간단하게 만들 수 있었다. 그렇다면 이 Matrix를 곱한다는것은 어떤 의미일까? Linear Algibra 수업으로 되돌아가보자. 간단한 예시이다. 2개의 Vector를 dot product하게 되면, 간단하게 같은 층에 있는 값들끼리 곱해서 더하게 된다. 이런식의 행렬같은 경우, 같은 위치에 있는 값들을 모두 곱해서 더하는 방식인데, 이런것을 ..
-
How Neural Networks are Implemented Efficiently(Feat. mutmul) | Advanced Learning AlgorithmMachine Learning/Stanford ML Specialization 2024. 2. 10. 05:14
지난 10년동안 Neural Network 분야가 급속도로 성장할 수 있었던 이유중 하나는, 이 신경망을 Vector화 할 수 있었기 때문이다. Matrix(행렬) 곱셈을 사용하면 이 모델을 아주 효율적으로 구현할 수 있다. GPU를 포함한 병렬 컴퓨팅 하드웨어뿐만 아니라, 일부 CPU도 아주 큰 Matrix 곱셈을 수행할 때 아주 능숙하다는 것이 밝혀졌다. 이런 벡터화된 신경망 구현이 어떻게 작동하는지 알아보자. 먼저, loop들과 vectorization을 비교해보자. 먼저, 단일 레이어에서 Forward Propagation을 구현하는 방법을 살펴보자. x = np.array([200, 17]) W = np.array([[1, -3, 5], [-2, 4, -6]]) b = np.array([-1, ..