आसान 0 हल किए गए 0% स्वीकृति

Derivatives of Activation Functions

Compute the derivative of sigmoid, ReLU, Leaky ReLU or tanh at each value, the slopes backpropagation needs.

आप क्या सीखेंगे

  • Compute slopes of common activations
  • Reuse the sigmoid output for its derivative
  • Prepare the pieces backpropagation needs

समस्या

अनुवाद दिखाएँ

Backpropagation multiplies gradients by the derivative of each activation function. Implement activation_derivative(name, values) and return the derivative at every value:

namederivative
"sigmoid"s × (1 - s), where s = 1 / (1 + e^(-x))
"relu"1 if x > 0, otherwise 0
"leaky_relu"1 if x > 0, otherwise 0.01
"tanh"1 - tanh(x)²

Input

name: One of "sigmoid", "relu", "leaky_relu" or "tanh".

values: The inputs x of the activation.

Output

Return the derivative at each value, in the same order.

सीमाएँ

1 ≤ length ≤ 1,000

-50 ≤ each value ≤ 50

उदाहरण

उदाहरण 1
इनपुट:
name = "sigmoid"
values = [0.0, 2.0]

अपेक्षित आउटपुट:
expected = [0.25, 0.104994]
इनपुट:
std::string name = "sigmoid";
std::vector<double> values = {0.0, 2.0};

अपेक्षित आउटपुट:
std::vector<double> expected = {0.25, 0.104994};
इनपुट:
string name = "sigmoid";
double[] values = new double[] {0.0, 2.0};

अपेक्षित आउटपुट:
double[] expected = new double[] {0.25, 0.104994};

व्याख्या

At 0, s = 0.5 and the slope is 0.5 × 0.5 = 0.25, the steepest point of the sigmoid. At 2, s ≈ 0.880797 and the slope is about 0.104994.

उदाहरण 2
इनपुट:
name = "relu"
values = [-3.0, 0.0, 4.5]

अपेक्षित आउटपुट:
expected = [0.0, 0.0, 1.0]
इनपुट:
std::string name = "relu";
std::vector<double> values = {-3.0, 0.0, 4.5};

अपेक्षित आउटपुट:
std::vector<double> expected = {0.0, 0.0, 1.0};
इनपुट:
string name = "relu";
double[] values = new double[] {-3.0, 0.0, 4.5};

अपेक्षित आउटपुट:
double[] expected = new double[] {0.0, 0.0, 1.0};

व्याख्या

ReLU is flat for x ≤ 0 (slope 0) and has slope 1 for x > 0, so the result is [0, 0, 1].

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।