This repository has been archived on 2020-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
tpmni/5/code.py

29 lines
606 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
import numpy as np
from copy import deepcopy as dp
"""
TP final MNI
auteurs: Cyril Colin
Dylan Voisin
date: 10/02/2020
"""
def gradient_conjugué(A: np.ndarray, b: np.ndarray, nb=50):
p = dp(b)
r = dp(b)
x = np.zeroes(b.shape)
for i in range(nb):
α = (r.transpose() @ r) / (p.transpose() @ A @ p)
x = x + α @ p
r = r - α @ A @ p
β = (r.transpose() @ r) / (r.transpose() @ r)
p = r + β @ p
return x
if __name__ == '__main__':
A = np.array(
[
[2, 3, 4]
]
)