Alle Herausforderungen
Einfach 0 gelöst 0% Erfolgsquote

Xavier and He Weight Initialization

Compute the range or standard deviation used to initialize the weights of a layer.

Das lernst du

  • Compute initialization ranges for a layer
  • Choose between Xavier and He
  • Understand why initialization matters

Problem

Übersetzung anzeigen

Weights that start too big or too small make deep networks hard to train. Two standard schemes pick the scale from the layer size, where fan_in is the number of inputs and fan_out the number of outputs:

methodreturns
"xavier_uniform"limit √(6 / (fan_in + fan_out)), weights drawn from [-limit, limit]
"xavier_normal"standard deviation √(2 / (fan_in + fan_out))
"he_uniform"limit √(6 / fan_in)
"he_normal"standard deviation √(2 / fan_in)

Xavier (Glorot) suits sigmoid and tanh layers; He suits ReLU layers.

Implement init_bound(method, fan_in, fan_out).

Input

method: One of "xavier_uniform", "xavier_normal", "he_uniform" or "he_normal".

fan_in, fan_out: The layer's number of inputs and outputs.

Output

Return the limit or standard deviation as a decimal number.

Einschränkungen

1 ≤ fan_in, fan_out ≤ 100,000

Beispiele

Beispiel 1
Eingabe:
fan_in = 3
method = "xavier_uniform"
fan_out = 3

Erwartete Ausgabe:
expected = 1.0
Eingabe:
long long fan_in = 3;
std::string method = "xavier_uniform";
long long fan_out = 3;

Erwartete Ausgabe:
double expected = 1.0;
Eingabe:
long fan_in = 3;
string method = "xavier_uniform";
long fan_out = 3;

Erwartete Ausgabe:
double expected = 1.0;

Erläuterung

√(6 / (3 + 3)) = √1 = 1, so weights are drawn from [-1, 1].

Beispiel 2
Eingabe:
fan_in = 50
method = "he_normal"
fan_out = 10

Erwartete Ausgabe:
expected = 0.2
Eingabe:
long long fan_in = 50;
std::string method = "he_normal";
long long fan_out = 10;

Erwartete Ausgabe:
double expected = 0.2;
Eingabe:
long fan_in = 50;
string method = "he_normal";
long fan_out = 10;

Erwartete Ausgabe:
double expected = 0.2;

Erläuterung

He only uses fan_in: √(2 / 50) = √0.04 = 0.2.

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.