-3

I'm writing some homework with python, but there is something wrong with the question, I haven't seen the function before,so i wonder if someone could help me,many thanks!

this is python function

def dF(x):
    return 2 * A.T @ (A @ x - np.eye(len(A), dtype=float))

def F(x):
    residual = A @ x - np.eye(len(A), dtype=float)
    return np.sum(residual ** 2)

def gradient_descent(F, dF, x, steps=100, lr=0.001):
    loss = []

    for _ in range(steps):
        dx = dF(x)
        x -= lr * dx
        loss.append(F(x))

    return x, loss

A = np.array([
    [2, 5, 1, 4, 6],
    [3, 5, 0, 0, 0],
    [1, 1, 0, 3, 8],
    [6, 6, 2, 2, 1],
    [8, 3, 5, 1, 4],
], dtype=float)


X, loss1 = gradient_descent(F, dF, A * 0, steps=300)
(A @ X).round(2), loss1[-1]

I don't know the meaning of * and @ , it's very hard for me.

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
  • Also see the documentation for [operators](https://docs.python.org/3/library/operator.html#mapping-operators-to-functions). – tfw Apr 13 '19 at 15:35

1 Answers1

0

The star * is the multiplication term by term and @ is the matrix multiplication :)

MarcM
  • 57
  • 5