Answers for "gradient function in python"

8

exemple python gradient

import numpy as np
Posted by: Guest on April-01-2020
0

exemple python gradient

import numpy as np

class Model():
    def __call__(self, x):
        return 2 * (2 * x ** 2 - 10) * 4 * x
alpha = 0.005
x = 5.0
norme_epsilon= 100
seuil_epsilon = 0.001
ma_fonction = Model()
while norme_epsilon > seuil_epsilon:
    dfx_dx = ma_fonction(x)
    norme_epsilon = np.abs(dfx_dx)
    x = x - alpha * dfx_dx
    print(x)
Posted by: Guest on January-21-2021

Browse Popular Code Answers by Language