Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Esercizi Avanzati (opzionali)

a guest Apr 10th, 2020 153 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def ulr_gd_step_2(x, y, alpha, beta):
  2.     if ulr_gd_step_2.exit is False:
  3.         # calcolo il vettore degli errori nei dati
  4.         error = alpha * x + beta - y
  5.         # calcolo le derivate parziali del MSE
  6.         d_alpha = 2 * (error * x).mean()
  7.         d_beta = 2 * error.mean()
  8.         # calcolo alpha e beta aggiornati
  9.         new_alpha = alpha - ulr_gd_step_2.step_size * d_alpha
  10.         new_beta = beta - ulr_gd_step_2.step_size * d_beta
  11.         #calcolo il nuovo passo per l'iterazione successiva
  12.         ulr_gd_step_2.step_size /= 1.5
  13.         #controllo che sia almeno la seconda iterazione
  14.         if ulr_gd_step_2.last_error is not None:
  15.             #Calcolo il nuovo errore
  16.             new_error = ulr_mse(x, y, new_alpha, new_beta)
  17.             if (ulr_gd_step_2.last_error - new_error >= 0) and (ulr_gd_step_2.last_error - new_error) <= 0.001:
  18.                 ulr_gd_step_2.exit = True
  19.                 return new_alpha, new_beta
  20.         ulr_gd_step_2.last_error = ulr_mse(x, y, new_alpha, new_beta)
  21.         return new_alpha, new_beta
  22. ulr_gd_step_2.last_error = None
  23. ulr_gd_step_2.step_size = 0.001
  24. ulr_gd_step_2.exit = False
  25.  
  26. alpha = 0
  27. beta = 0
  28.  
  29. for i in range(20):
  30.     alpha, beta = ulr_gd_step_2(temp, demand, alpha, beta)
  31.     if(ulr_gd_step_2.exit == True):
  32.         break
  33. ulr_mse(temp, demand, alpha, beta)
  34.  
  35. plot_model_on_data(temp, demand, make_model(alpha, beta))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top