Try   HackMD

Linear Algebra for Machine Learning and Data Science(Week1: System of linear equations: 2 variables)

tags: coursera Linear Algebra math

week1

System of sentences

課程連結

System of sentences

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

systems of sentences能帶來的訊息是很重要的,以上面三個system為例:

  1. System1:完整,狗是黑的,貓是橘的
  2. System2:冗餘的,因為狗是黑的說了兩次,同樣的話說一次就夠了
  3. System3:矛盾,因為狗又是黑又是白,那到底是黑還是白

很明顯的,能帶來的訊息愈多就愈有用。如果系統是冗餘或是矛盾的話,那又稱為singular system,即為奇異系統。如果是完整的話,那就稱為non-singular system。

System of sentences

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

system of sentences並非只能帶兩句話,事實上它可以承載任何你想要的數量。上面給出的是三句話的範例。一樣的,system2、system3一樣是冗餘的,因為同樣的話說了多次;system4則為矛盾的,因為狗不能又黑又白。

後面的課程中就會提到如何去瞭解一個system of sentence有多麼的冗餘(利用rank)。

System of equations

課程連結

System of equations

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

上一堂課已經學到system of sentences,基本上這個概念跟system of equations是差不多的。

上面範例最左邊是我們上一堂課學習到的,也就是貓貓狗狗的顏色。接下來我們要瞭解的就是中間,以數值來陳述,蘋果跟香蕉總共要10元,這可以用最右邊的方程式來表述。

Solution: Systems of equations 1

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

這是課程中的一個範例,非常簡單:

  1. 第一天買蘋果跟香蕉花10元
  2. 第二天買蘋果跟兩根香蕉花12元

蘋果跟香蕉各多少錢?

啊第二天多一根香蕉多2元,當然就是香蕉2元,蘋果8元。

Solution: Systems of equations 2

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

這個問題是:

  1. 蘋果跟香蕉總共10元
  2. 2顆蘋果跟2根香蕉總共20元

仔細看一下會發現,這兩個句子是一樣的,冗餘的,所以根本沒有足夠的信息可以讓我們求解,帶入任何的價格都會成立,無窮解的概念。

Solution: Systems of equations 3

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

這個問題是:

  1. 蘋果跟香蕉總共10元
  2. 2顆蘋果跟2根香蕉總共24元

這很有問題,矛盾了,蘋果跟香蕉一起買又是10元又是12元的。有鬼。所以我們可以得到一個結論,這個方程式是沒有解的。

Systems of equations

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

總結剛剛的三個範例:

  1. 第一個範例有完整的信息,所以能得到一個唯一解,因此這個system是完整的,而且是非奇異(non-singular)
  2. 第二個範例給的訊息是冗餘(Redundant)的,無窮解,而且是奇異(singular)
  3. 第三個沒有解,因為互相矛盾(Contradictory),而且是奇異(singular)

What is a linear equation?

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

我們已經聽到多次的linear equation(線性方程式),它是什麼?它可以是任何你想要有多少變數(variables)都可以的描述,唯一的限制就是在描述中的a、b、c就只能是numbers或是scalar在它們的身邊。

相對的,non-linear就複雜多了。它可以是指數、正弦、餘弦、blablabla。

System of equations as lines

課程連結

Linear equation
line

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

事實上,lineaer equation是可以以『線』來表示,當然這是在兩個變數的情況下,但這是可以想像的。

a+b=10這個線性方程式為例,在紙上畫面一個網格(grid),假設橫軸是
a
(蘋果的價錢),蹤軸是
b
(香蕉的價錢)。有兩個座標點非常明顯,就是
a=10,b=0
a=0,b=10
。剩下的就只要是
a+b=10
成立就可以(如上左圖所述)。

很明顯的,這些點可以連成一條線,而這條線上所經過的全部座標點都是這個線性方程式的解。上圖右只是另一個範例,這邊就不多做說明。

這兩個範例還另外可以說明兩個觀念:

  1. 斜率(slope):也就是上升率,上圖左的斜率為-1,因為你每向右邊一個單位就會同時向下一個單位,向下就是負,所以就是-1。上圖右的斜率則為-0.5,因為每向右一個單位就會向下0.5個單位
  2. 截距項(y-intercept):上圖左的截距為10,上圖右則為6,就是直線過y軸至原點的距離

Linear equation
line(unique solution)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

每個方程式都跟一條直線相關,那如果是system of two equations的話會發生什麼事?從上圖可以看的到,把剛剛的左右兩個方程式合併變會得到一個交叉點,這個交叉點(8, 2)就是一個唯一解,也就是上一堂課範例中得到的答案。

Linear equation
line(infinitely solution)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

如果把

a+b=10
2a+2b=20
的直線重疊會發現,這兩條線完全密合,跟剛剛有一個交叉點是不一樣的情況。這代表每一個解都是一個解,也就是擁有無限多組解。

Linear equation
line(no solution)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

這是第三種情況,兩條線平行,完全不會相交。這種情況下是無解的。

System of equations as lines

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

總結來看剛剛的三種結果,我們可以說:

  1. 能求到唯一解的是Complete、Non-singular
  2. 無窮無解則是冗餘(Redundant)、Singualr
  3. 無解則是矛盾(Contradictory),Singular

A geometric notion of singularity

[課程連結]

System of equations as lines

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

這是上一節課程中最後的總結。三種結果,一個完成、一個冗餘、一個矛盾。不過,讓我們先把焦點放在singularity與non-sigularity。

System of equations as lines

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

這時候我們需要做點小調整才能把三種分類轉變成兩種,也就是單純就分成奇異與非奇異。我們把關注點放在聯立方程式(system of equations)的常數項,也就是等號的右邊。

當我們把三組聯立方程式的常數項都設置為0的時候就會有像上圖的轉變。因為

a+b=0,所以這三個聯立方程式都一定會有過原點的線。

system1、2都沒有變化。但system3的話就可以看的到,從不相交的兩條線性成重疊,從矛盾變冗餘,最重要的是,它仍然是Singular。

這意謂著,對於聯立方程式來說,是否為singular跟常數項是無關的。所以我們要判斷是不是singular就可以透過把常數項設置為0來觀察,而且那條線一定通過原點。

Singular vs nonsingular matrices

課程連結

Systems of equations as matrices

我們已經知道,聯立方程式的常數項對於是否為singular是沒有影響的。現在要帶入另一個觀念,也就是矩陣,matrix。矩陣可以用一種很自然的方式來表述聯立方程式的系數(coefficient)。

上圖範例可以看的到,我們將聯立方程式轉變為以矩陣來表述,取的聯立方程式的系數。而且矩陣就跟聯立方程式一樣可以是singular或是non-singular。如果還有印象的話就會記得,system1是non-singular matrix,因為它有唯一解。而system2則是singular,因為它有無限多組解。

Linear dependence and independence

課程連結

這邊就要來說明如何不利用求解整個聯立方程式來知道一個矩陣是singular或是non-singular。

Linear dependence between rows

首先來看上圖右那個singular的案例,基本上可以看的出來,第二個row是第一個row乘上2得到的結果,這意謂著第二個row是dependent on第一個row。反過來說第一個row是第二個row乘上1/2也是說的過的。不管如何,只要任一個row是depend on另一個row的情況下,那它們就是linear dependence,也就是線性相依

上圖左的non-singular是看不到的類似的情況,基本上我們無法拿任一個row乘上某一個值來得到另一個row的結果,這意謂著這些row是linear independence,也就是線性獨立

這種線性相依的概念在row、column都看的到,它們決定一個矩陣或是聯立方程式是否為奇異(singular)。

The determinant

課程連結

事實上能夠確定一個矩陣是否為奇異的方法不止一種,有很多種,這節課就來說說另一種,也就是determinant(行列式)。這種方法很簡單,反正回傳0就代表是singular,非0就是non-singular。

Linear dependence between rows

這邊單純的快速回憶一下上節課說過的線性相依與線性獨立的觀念。總之就是當一個row無法由另一個row乘上某一個值得到,那就是線性獨立。

Determinant

現在我們來仔細瞧瞧這個矩陣,它有四個元素

a,b,c,d,如果它是singular的話,那
a,b
這兩個元素去乘上
k
就會等於
c,d
,也就是說
ak=c,bk=d
,換句話說,
ca=db=k
,讓我們把這個乘數
k
先忘掉就可以得到
ad=bc
,移動一下就可以得到
adbc=0
,我們把這個
adbc
的值稱為determinat of matrix,也就是矩陣的行列式,就是
adbc

現在我們就知道了,當

adbc=0,那這個矩陣就是singular,反之則為non-singular。

Determinant

這邊給出兩個範例,總之就是以對角相乘減去反對角相乘的結果來判斷矩陣是否為singular。

Determinant and singularity

矩陣如果為singular,那它的Determinant就會是0。