[Linear Algebra] Lecture 16

Author

SEOYEON CHOI

Published

April 10, 2024

Import

import numpy as np import matplotlib.pyplot as plt

Lecture

학습 목표

  • Projections
  • Least Squares and best straight line

P=A(ATA)1AT

  • If b in column space Pb=b
    • 민약 b가 컬럼 스페이스에 존재한다면 프로젝션 매트릭스에 곱해도 그대로 b가 나옴
    • P=A(ATA)1ATb=A(ATA)1ATAx=b
    • b는 컬럼 스페이스 위에 존재하는 벡터이므로 위와 같이 계산된다.
  • If b column space Pb=0
    • 만약 b가 컬럼 스페이스랑 수직을 이루면 프로젝션 매트릭스에 곱하면 0이 나옴
    • P=Pb=A(ATA)1ATb=0
    • b가 컬럼 스페이스가 아닌 다른 공간인 left null space에 존재하면 0이 된다.
  • p = projection, e = error, b = a vector
    • p는 columns space 에 있고
    • e는 left null space 에 있다.
  • P = symmetric (IP) = symmetric
  • P = projection (IP) = projection

- Least Square Method

# 주어진 데이터 포인트
data = [(1, 1), (2, 2), (3, 2)]
x_data = [d[0] for d in data]
y_data = [d[1] for d in data]

# 다항 회귀를 위해 데이터를 변형합니다.
x = np.array(x_data)
y = np.array(y_data)

# 다항 회귀를 위한 최소자승법을 사용하여 회귀선을 구합니다.
coefficients = np.polyfit(x, y, 1)  # 1차 다항식을 사용합니다.

# 다항식 생성
p = np.poly1d(coefficients)

# 회귀선 그리기
plt.scatter(x, y, label='Data Points')
plt.plot(x, p(x), color='red', label='Regression Line')
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Linear Regression')
plt.legend()
plt.grid(True)
plt.show()

Ax=b [111213][CD][122]

  • y=C+Dt 식을 찾아본다고 할 때,
    • C+D=1
    • C+2D=2
    • C+3D=2
      • Don’t have a solution.
  • best solution 찾기
    • ATAx^=ATb
  • ||Axb||2=||e||2
    • e12+e22+e32
    • x 점에서 projection 한 값들
  • I want to minimized the sum of error.

Find x^=[c^p^],P

  • b normal wquations(=eqnas)

    • 3C+6D=5
    • 6C+14D=15
    • 2D=1 D=12,C=23
  • best line 12t+23

    • e1=16,ex2=26,e3=16
  • (C+D1)2 + (C+2D2)2+(3D22)

  • $A^T A = A^T b $

  • P=Ax^

  • If A has independant columns then ATA is invertible.

    • Suppose ATAx=0
    • X must be 0
  • Idea

    • $X^T A^T A x = 0 = (A_x)^T Ax Ax=0,X+0
  • columns definitely independent if they are perp unit vectors or thomominal vectores