This file contains 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
#!/usr/bin/env python | |
import numpy as np | |
def gradient(x, func, eps=1e-6): | |
""" | |
Central finite differences for computing gradient | |
INPUT: | |
x: vector of parameters with shape (n, 1) |
This file contains 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
def conjgrad(A, b, x): | |
""" | |
A function to solve [A]{x} = {b} linear equation system with the | |
conjugate gradient method. | |
More at: http://en.wikipedia.org/wiki/Conjugate_gradient_method | |
========== Parameters ========== | |
A : matrix | |
A real symmetric positive definite matrix. | |
b : vector | |
The right hand side (RHS) vector of the system. |