Answers for "python with gradient"

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

Python Answers by Framework

Browse Popular Code Answers by Language