모든 챌린지
쉬움 0명 해결 정답률 0%

Xavier and He Weight Initialization

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

배우게 될 내용

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

문제

번역본 보기

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.

제약 조건

1 ≤ fan_in, fan_out ≤ 100,000

예시

예시 1
입력:
fan_in = 3
method = "xavier_uniform"
fan_out = 3

예상 출력:
expected = 1.0
입력:
long long fan_in = 3;
std::string method = "xavier_uniform";
long long fan_out = 3;

예상 출력:
double expected = 1.0;
입력:
long fan_in = 3;
string method = "xavier_uniform";
long fan_out = 3;

예상 출력:
double expected = 1.0;

설명

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

예시 2
입력:
fan_in = 50
method = "he_normal"
fan_out = 10

예상 출력:
expected = 0.2
입력:
long long fan_in = 50;
std::string method = "he_normal";
long long fan_out = 10;

예상 출력:
double expected = 0.2;
입력:
long fan_in = 50;
string method = "he_normal";
long fan_out = 10;

예상 출력:
double expected = 0.2;

설명

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

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.