Last active
November 7, 2017 18:05
-
-
Save jasonmhite/9581b991b34e80576b6c70e07f08ed47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.optimize import minimize | |
def least_squares(A, b, x0): # Least-squares solution for Ax=b, initial guess of x0 | |
return minimize( | |
lambda x: np.linalg.norm(A.dot(x) - b), | |
x0, | |
) | |
def least_squares_tikhonov(A, b, alpha, x0): # Least squares for Ax=b with simple Tikhonov regularization | |
return minimize( | |
lambda x: np.linalg.norm(A.dot(x) - b) + alpha * np.linalg.norm(x), | |
x0, | |
) | |
def least_squares_generalized_tikhonov(A, b, Gamma, x0): # Least squares with generalized Tikhonov regularization | |
return minimize( | |
lambda x: np.linalg.norm(A.dot(x) - b) + np.linalg.norm(Gamma.dot(x)), | |
x0, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment