[2014 Stanford Machine Learning tutorial notes] Chapter 5 - calculated data

    In this section, we will learn how to perform arithmetic operations on the data. Next, we will use these arithmetic operations to achieve our learning algorithm.

    I quickly initialize some variables. A set such as a 3x2 matrix, B is a 3x2 matrix, c is a 2x2 matrix.

    I want to calculate the product of two matrices , such as computing AxC, simply enter A * C , which is a 3x2 matrix multiplied by 2x2 matrix, so get a 3x2 matrix.

           

    We can also operate on the elements. When the input A. * B time, will each of the elements B A multiplied by the corresponding element . Generally speaking, the number used generically to denote Octave midpoint computation element.

    Input A. ^ 2 , which in the matrix A will each element squared .

              

    Let v be a column vector [1; 2; 3], can enter 1./v , to obtain the reciprocal of each element , so that it will give 1/1 1/2 1/3 respectively. Such matrix may operate, 1. / A to give the reciprocal of each element in A.

           

    We can also enter log (v) , for v in all elements of the operands are evaluated . exp (v) is the base e, of elements in v raised to the power calculation .

                   

 

    Further, also with ABS (v), the absolute value of each element of v . V But all the elements are positive now. We input abs ([-1; 2; -3 ]), to the absolute value of all the elements of this matrix.

           

    If you enter -v v get all elements of opposite number . This is equivalent to -1 * v, -v but it is generally written.

    If I want to remove v, and for v each element will increase by one . One method is: first construct a 3 row vector of all of an element is 1, then the sum vector with the original vector .

    The rationale for this is: length (v) the value 3, ones (length (v), 1) is equivalent to the size of the ones made for the 3x1. Then let them together, i.e., each element in v plus 1.

    Another simpler approach is to: a direct v + 1 , v + v 1 is the same as the elements in each plus 1 .

    If you want to find the transpose of matrix A , we can input A ' (single quote left) so that we can get the transpose of A. If you want to ask the transpose of A transpose input (A ')' then we will get the original matrix A.

           

    There are some useful functions. We set a = [1 15 2 0.5] , which is a 4 1 matrix row, let us set = Val max (a) , which will return the elements in a maximum , which is 15. May also be provided [val, ind] = max ( a), which returns two values, val is a largest element, ind is the index of the element in a . I.e. a maximum elements in the second element, the value is 15. Special Note: If you use the command max (A), but a matrix, then do so is for each column seeking maximum . We discuss this later.

           

    If we enter A <. 3 , this is called a corresponding comparison element. This will be a one by one in each element 3 with the comparison operation , the element 1 is smaller than 3 returns 0 otherwise .

    If I enter the Find (a <3) , which will identify which elements are less than a 3 , then return to their index .

    If the input Magic = A (. 3), Magic called function returns a magic square matrix (magic squares), which has the following mathematical properties: they all rows and columns and diagonals add up to the same value . Although this function in machine learning is not very useful, but you can use this method to easily generate a 3x3 matrix. These magic square matrix each row, column, and each diagonal are equal to three of the same number of figures. This is the result through mathematical structure.

              

    If we enter the [r, c] = find (A> = 7), you will find the element A is greater than or equal to 7. r and c represent rows and columns, which represents the first column of a first row of elements is not less than 7, the second column of the third row of elements not less than 7, the third column of the second row of elements not less than 7.

           

    Summing function: When we enter SUM (a) , we will get a in all elements .

    If I want in a product of all the elements , we can enter Prod (a) . It returns the product of these four elements.

    floor (a) is rounded down. ceil (a) represents rounding up.

           

    If the input rand (3), which usually give a random matrix of 3 × 3. If the input  max (rand (3), rand (3)), which consists of random values of 3 × 3 matrix of two larger values of elements. All, you will find these elements in relative terms than the larger. Since each element of its corresponding elements of the result obtaining two random matrix maximum.

           

    Input max (A, [], . 1 ), this will give each column the maximum value. Therefore, the first column is the maximum value of 8, the second column is 9, the third column is the maximum value of 7, 1 indicates from where the first dimension to the value of the A matrix .

    In contrast, if type I max (A, [], 2 ), which will give each row maximum value, the maximum value of the first line is equal to 8, the second line maximum value is 7, the third line is 9 .

           

    You can use this method to obtain each row or column of the most value. Also, keep in mind, max (A) returns the default maximum value for each column, if you want to find the maximum value of the entire matrix A , you can enter max (max (A)) , or you can a conversion matrix to a vector, and then selecting the maximum value may be input max (a (:)), which is converted into a vector a, and returns the maximum value vector.

           

    Finally, let A design of a 9x9 magic square, magic square is characteristic of each row each column each diagonal sums are equal. This is a 9x9 magic square of.

    Input SUM (A,. 1) , is calculated for each column sum , which also verified in each column add up to the magic square are equal, are 369. Input SUM (A, 2) , calculate the sum of each row , which also verified the magic square of each line together we are the same, are 369.

    Then, we calculate the diagonal and ensure that they still add up to the same number. Now we have to a 9x9 matrix structure, the input eye (9), and we use it to A multiplied by the corresponding element. Input A. Eye * (. 9 ), the result of this is multiplied by the corresponding elements of two matrices, other elements except the diagonal elements are zero.

    Then enter SUM (SUM (A. Eye * (. 9)) , which is actually seeking diagonal elements of A and, indeed 369.

    You can also find other diagonal (diagonal from lower left to upper right corner) and. We can enter SUM (SUM (A. * flipup (Eye (. 9))) , which represents that the matrix flipup flipped vertically. In fact we find the other diagonal and are 369.

    Set A = magic (3). If you want inverse matrix A matrix input pinv (A), commonly referred to as pseudo-inverse matrix , you put it as the inverse matrix A, so this is the inverse matrix A matrix. Set temp = pinv (A), and then multiplied by the temp A, is obtained matrix, diagonal and other elements of 0.

           

    It is the above method for computing elements of the matrix. After running a learning algorithm, the most useful thing to observe the results, or let the visualization of results. In the next section, we'll learn how to quickly visualize data.

 

Guess you like

Origin www.cnblogs.com/shirleyya/p/12637444.html