brunch

You can make anything
by writing

C.S.Lewis

by 라인하트 Oct 04. 2020

앤드류 응의 머신러닝 (3-1) : 행렬과 벡터

  온라인 강의 플랫폼 코세라의 창립자인 앤드류 응 (Andrew Ng) 교수는 인공지능 업계의 거장입니다. 그가 스탠퍼드 대학에서 머신 러닝 입문자에게 한 강의를 그대로 코세라 온라인 강의 (Coursera.org)에서 무료로 배울 수 있습니다. 이 강의는 머신러닝 입문자들의 필수코스입니다. 인공지능과 머신러닝을 혼자 공부하면서 자연스럽게 만나게 되는 강의입니다. 


Linear Algebra Review 

선형 대수 리뷰 


Matrixs and Vectors (행렬과 벡터)


   Let's get started with our linear algebra review. In this video, I want to tell you what are matrices and what are vectors.


   지금부터 선형대수 리뷰를 시작합니다. 이번 강의에서 행렬과 벡터를 공부합니다.  

      

   A matrix is a rectangular array of numbers written between square brackets. So, for example, here is a matrix on the right, a left square bracket. And then, write in a bunch of numbers.  These could be features from a learning problem or it could be data from somewhere else, but the specific values don't matter, and then I'm going to close it with another right bracket on the right. And so that's one matrix. And, here's another example of the matrix, let's write 3, 4, 5,6. So matrix is just another way for saying, is a 2D or a two dimensional array.

  

   행렬이란 각 괄호들 안에 사각형 모양으로 나열된 숫자들의 배열입니다. 예를 들면, 여기에 행렬이 있습니다. 먼저 왼쪽에서 각 괄호를 열고 몇 개의 숫자들을 그 안에 적습니다. 이것은 머신 러닝 문제일 수도 데이터일 수도 있습니다. 숫자들은 중요하지 않습니다. 그리고, 오른쪽에 각 괄호로 행렬을 닫습니다. 이것이 행렬입니다. 오른쪽에 또 다른 예가 있습니다. 2D 또는 2차원 배열입니다. 



   And the other piece of knowledge that we need is that the dimension of the matrix is going to be written as the number of row times the number of columns in the matrix. So, concretely, this example on the left, this has 1, 2, 3, 4 rows and has 2 columns, and so this example on the left is a 4 by 2 matrix - number of rows by number of columns. So, four rows, two columns. This one on the right, this matrix has two rows. That's the first row, that's the second row, and it has three columns.  That's the first column, that's the second column, that's the third column So, this second matrix we say it is a 2 by 3 matrix. So we say that the dimension of this matrix is 2 by 3.Sometimes you also see this written out, in the case of left, you will see this written out as R4 by 2 or concretely what people will sometimes say this matrix is an element of the set R 4 by 2. So, this thing here, this just means the set of all matrices that of dimension 4 by 2 and this thing on the right, sometimes this is written out as a matrix that is an R 2 by 3. So if you ever see, 2 by 3. So if you ever see something like this are 4 by 2 or are 2 by 3, people are just referring to matrices of a specific dimension.


   행렬의 차원은 행렬의 행(Row)의 개수와 열(Column)의 개수의 곱으로 표현합니다. 예를 들면, 왼쪽의 행렬은 1, 2, 3, 4개의 행(row)과 2개의 열(Column)이 있습니다. 따라서, 왼쪽의 행렬은 4 X 2 행렬입니다. 4 X 2 행렬은 4개의 행들과 2개의 열을 구성된 행렬이라는 의미입니다. 오른쪽 행렬은 2개의 행(Row)과 세 개의 열(Column)이 있습니다. 오른쪽 행렬은 2 X 3 행렬이고, 2 X 3차원 행렬입니다. 

 행렬을 다른 방식으로 표현할 수 있습니다. 왼쪽의 행렬은 R^(4 X 2)라고 표현하고, 왼쪽 행렬은  R^(4 X 2) 행렬 집합의 성분입니다. R^(4 X 2)는 모든 4 X 2차원 행렬의 집합을 의미합니다. 왼쪽의 4X2 행렬은 R^(4 X 2) 집합에 속하고, 오른쪽 행렬은 R^(2 X 3) 집합에 속합니다. 따라서, 2 X 3 또는 4 X 2와 같은 표기는 특정 차원을 가지는 행렬을 의미합니다. 


   Next, let's talk about how to refer to specific elements of the matrix. And by matrix elements, other than the matrix I just mean the entries, so the numbers inside the matrix.  So, in the standard notation, if A is this matrix here, then A sub-strip ij is going to refer to the i, j entry, meaning the entry in the matrix in the ith row and jth column.


   다음으로, 매트릭스 내의 특정 성분을 지칭하는 방법을 알아봅시다. 행렬의 성분은 행렬의 구성 요소를 나타냅니다. 행렬 자체가 아니라 행렬 안에 있는 숫자입니다. 일반적으로 행렬은 대문자로 표기하고, 행렬의 성분은 대문자에 아래 첨자 ij로 표기합니다. 예를 들면, Aij는 i 번째 행과 j 번째 열에 위치한 성분을 가리킵니다. 


   So for example, A11 is going to refer to the entry in the 1st row and the 1st column, so that's the first row and the first column and so A11 is going to be equal to 1402. Another example, A12 is going to refer to the entry in the first row and the second column and so A12 is going to be equal to one nine one. This come from a quick examples. Let's see, A, oh let's say A32, is going to refer to the entry in the 3rd row, and second column, right, because that's 32 so that's equal to 1437. And finally, A41 is going to refer to this one right, fourth row, first column is equal to 147 and if, hopefully you won't, but if you were to write and say well this A43, well, that refers to the fourth row, and the third column that, you know, this matrix has no third column so this is undefined, you know, or you can think of this as an error. There's no such element as A43, so, you know, you shouldn't be referring to A43. So, the matrix gets you a way of letting you quickly organize, index and access lots of data. 



   예를 들어, A11은 행렬 A의 첫 번째 줄과 첫 번째 열의 성분을 나타냅니다. A11은 1402입니다. 또, A12는 행렬 A의 첫 번째 줄과 두 번째 열에 있는 성분을 나타냅니다. A12는 191입니다. 또 다른 예를 봅시다. A32는 행렬 A의 세 번째 행과 두 번째 열에 있는 성분을 나타냅니다. A32는 1437입니다. 마지막으로 A41은 행렬 A의 네 번째 행과 첫 번째 열에 있는 성분을 나타냅니다. A41은 147입니다. 그리고, A43은 행렬 A의  네 번째 행과 세 번째 열에 있는 성분을 나타냅니다. 행렬 A는 세 번째 열이 없기 때문에 정의되지 않았습니다. 즉, 에러입니다. A43 행렬 성분이 없기 때문에 요청해서는 안됩니다. 행렬은 많은 데이터를 빠르게 정리하고 색인하는 도구입니다.   

   

   In case I seem to be tossing up a lot of concepts, a lot of new notations very rapidly, you don't need to memorize all of this, but on the course website where we have posted the lecture notes, we also have all of these definitions written down. So you can always refer back, you know, either to these slides, possible coursework, so audible lecture notes if you forget well, A41 was that? Which row, which column was that? Don't worry about memorizing everything now. You can always refer back to the written materials on the course website, and use that as a reference. So that's what a matrix is. 


   행렬의 개념을 너무 빨리 설명했습니다. 하지만, 모든 것을 기억할 필요가 없습니다. 필요할 때 다시 찾아보고 참고할 수 있습니다. A41이 몇 번째 줄이고 몇 번째 칼럼인지 당장 기억할 필요는 없습니다. 지금까지 행렬을 설명했습니다.   



   Next, let's talk about what is a vector. A vector turns out to be a special case of a matrix. A vector is a matrix that has only 1 column so you have an N x 1 matrix, then that's a remember, right? n is the number of rows, and 1 here is the number of columns, so, so matrix with just one column is what we call a vector. So here's an example of a vector, with I guess I have N equals four elements here. so we also call this thing, another term for this is a four dmensional vector, just means that this is a vector with four elements, with four numbers in it. And, just as earlier for matrices you saw this notation R3 by 2 to refer to 3by 2 matrices, for this vector we are going to refer to this as a vector in the set R4. So this R4 means a set of four-dimensional vectors. Next let's talk about how to refer to the elements of the vector. We are going to use the notation yi to refer to the ith element of the vector y. So if y is this vector, y subscript i is the ith element. So y1 is the first element, four sixty, y2 is equal to the second element, two thirty two -there's the first. There's the second. Y3 is equal to 315 and so on, and only y1 through y4 are defined consistency 4-dimensional vector.


   다음으로, 벡터를 설명합니다. 벡터는 행렬의 특수한 형태입니다. 벡터는 하나의 열만 있는 행렬입니다. 즉, n X 1 행렬입니다. n은 행(row)의 개수이고 1은 열(Column))의 개수입니다.  즉, 한 개의 열만을 가진 행렬을 벡터라고 합니다. 예를 들면, n=4인 벡터, 네 개의 성분으로 이루어져 있습니다. 이 벡터는 4차원 벡터입니다.  4차원 벡터는 4개의 성분으로 이루어진 벡터를 의미합니다. 앞에서 보았듯이 R^(3 X 2) 집합은 모든 3 X 2 행렬을 포함합니다. 4차원 벡터는 R^(4) 집합에 속합니다. R^(4)는 4차원 벡터의 집합입니다.  



   다음은 벡터의 성분을 지칭하는 방법입니다.  벡터는 주로 소문자로 표기하고, 'yi'는 벡터 y의 i번째 행의 성분을 가리킵니다. 예를 들어, y1은 첫 번째 성분인 460입니다. y2는 두 번째 성분인 232입니다. y3는 315입니다.  y1에서 y4까지만 정의한 4차원 벡터입니다. 



      

   Also it turns out that there are actually 2 conventions for how to index into a vector and here they are. Sometimes, people will use one index and sometimes zero index factors. So this example on the left is a one in that specter where the element we write is y1, y2, y3, y4. And this example in the right is an example of a zero index factor where we start the indexing of the elements from zero. So the elements go from a zero up to y three. And this is a bit like the arrays of some primary languages where the arrays can either be indexed starting from one. The first element of an array is sometimes a y1, this is sequence notation I guess, and sometimes it's zero index depending on what programming language you use. So it turns out that in most of math, the one index version is more common. For a lot of machine learning applications, zero index vectors gives us a more convenient notation.So what you should usually do is, unless otherwised specified, you should assume we are using one index vectors. In fact, throughout the rest of these videos on linear algebra review, I will be using one index vectors. But just be aware that when we are talking about machine learning applications, sometimes I will explicitly say when we need to switch to, when we need to use the zero index vectors as well.


   벡터의 성분을 표시하는 방법은 두 가지입니다. 하나는 1부터 시작하는 1-인덱스드 벡터 (1-indexed vector)이고 다른 하나는 0부터 시작하는 0-인덱스드 벡터(0-indexed vector)입니다. 


   

   왼쪽 예제는 1-인덱스드 벡터이고, 벡터의 성분은 1부터 시작하는  y1, y2, y3, y4로 표시합니다. 그리고 오른쪽 예제는  0-인덱스드 벡터이고, 벡터의 성분은 0부터 시작하는 y0, y1, y2, y3입니다. 프로그래밍 언어에 따라 1부터 시작하거나 0부터 시작합니다. 수학 분야는 1-인덱스드 벡터를 선호하고 머신 러닝 분야는 0-인덱스드 벡터를 선호합니다. 특별히 표시하지 않으면 1-인덱스드 벡터를 사용하는 것으로 간주합니다. 선형 대수 리뷰 강의에서 1-인덱스드 벡터를 사용합니다. 하지만, 머신러닝 분야를 설명할 때 직접적으로 다른 표기법을 사용한다고 언급합니다. 그때는 0-인덱스드 벡터를 사용합니다. 


    Finally, by convention, usually when writing matrices and vectors, most people will use upper case to refer to matrices. So we're going to use capital letters like A, B, C, you know, X, to refer to matrices, and usually we'll use lowercase, like a, b, x, y, to refer to either numbers, or just raw numbers or scalars or to vectors. This isn't always true but this is the more common notation where we use lower case "Y" for referring to vector and we usually  use upper case to refer to a matrix.


   마지막으로, 행렬은 보통 대문자로 표시합니다. 앞으로 A, B, C, X와 같은 대문자는 행렬을 뜻합니다. 그리고 a, b, x, y와 같은 소문자는 일반적인 숫자, 데이터 값, 스칼라 값, 혹은 벡터를 지칭합니다. 언제나 그런 것은 아니지만, 소문자는 벡터를 지칭하고, 대문자는 행렬을 의미합니다. 

      

   So, you now know what are matrices and vectors. Next, we'll talk about some of the things you can do with them


   행렬과 벡터를 공부했습니다. 다음 강의에서는 행렬을 가지고 응용을 할 것입니다.  





정리하며


   행렬이란 각 괄호들 안에 사각형 모양으로 나열된 숫자들의 배열입니다. 행렬의 차원은 행렬의 행(row)의 숫자와 열(Column)의 숫자의 곱으로 표현합니다. 예를 들어, 행렬은 4행과 2열로 구성되었다면, 4 X 2 행렬 또는 4X 2차원의 행렬이라고 합니다. 또한, 4 X 2 행렬은 집합 R^(4x2)의 구성요소입니다. 


   행렬은 일반적으로 대문자로 표기하고, 행렬의 성분의 위치는 소문자로 표기합니다. 행렬 성분의 위치는 A에 아래 첨자 ij로 표기합니다.  Aij는 i 번째 행과 j 번째 열에 위치한 성분을 가리킵니다. 예를 들어, A41은 네 번째 행과 첫 번째 열에 위치한 성분을 의미합니다. 즉, 행렬은 많은 데이터를 빠르게 정리하고 색인해 주는 도구입니다.  


      벡터는 하나의 열(Column)만 있는 N X 1 행렬입니다. 벡터의 첫 번째 성분을 1로 지칭하면 1-인덱스드 벡터, 0으로 지칭하면 0-인덱스드 벡터입니다. 수학 분야는 1-인덱스드 벡터를 선호하고, 머신 러닝 분야는  0 인덱스드 벡터를 선호합니다. 


   벡터는 주로 소문자 y로 표기하고, 'yi'는 벡터 y의 i번째 행의 성분을 가리킵니다. 


문제풀이


    다음 중에 맞는 것은 무엇일까요?  


   정답은 1번, 3번, 4번입니다. 2번은 2 X 4 행렬입니다. 



매거진의 이전글 앤드류 응의 머신러닝 정리 1:비용함수와 경사하강법까지
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari