Tous les défis
Facile 1 résolu 100.0 % de réussite

Single Artificial Neuron

Compute the output of one neuron: weighted sum of the inputs plus a bias, passed through sigmoid.

Ce que vous allez apprendre

  • Combine inputs, weights and a bias
  • Pass the sum through an activation
  • See how a neuron makes a prediction

Problème

Afficher la traduction

An artificial neuron multiplies each input by a weight, adds a bias, and passes the result through an activation function:

z = x₁×w₁ + x₂×w₂ + … + xₙ×wₙ + bias

output = sigmoid(z) = 1 / (1 + e^(-z))

Implement neuron_output(inputs, weights, bias).

Input

inputs: The input values.

weights: One weight per input (same length as inputs).

bias: The neuron's bias.

Output

Return the neuron's output, a decimal number between 0 and 1.

Contraintes

1 ≤ length of inputs = length of weights ≤ 100

-10 ≤ each input, weight and bias ≤ 10

Exemples

Exemple 1
Entrée :
inputs = [1.0, 2.0, 3.0]
weights = [0.2, 0.4, 0.6]
bias = 0.5

Sortie attendue :
expected = 0.964429
Entrée :
std::vector<double> inputs = {1.0, 2.0, 3.0};
std::vector<double> weights = {0.2, 0.4, 0.6};
double bias = 0.5;

Sortie attendue :
double expected = 0.964429;
Entrée :
double[] inputs = new double[] {1.0, 2.0, 3.0};
double[] weights = new double[] {0.2, 0.4, 0.6};
double bias = 0.5;

Sortie attendue :
double expected = 0.964429;

Explication

z = 1×0.2 + 2×0.4 + 3×0.6 + 0.5 = 3.3, and sigmoid(3.3) ≈ 0.964429.

Exemple 2
Entrée :
inputs = [0.5, -1.0]
weights = [2.0, 1.0]
bias = 0.0

Sortie attendue :
expected = 0.5
Entrée :
std::vector<double> inputs = {0.5, -1.0};
std::vector<double> weights = {2.0, 1.0};
double bias = 0.0;

Sortie attendue :
double expected = 0.5;
Entrée :
double[] inputs = new double[] {0.5, -1.0};
double[] weights = new double[] {2.0, 1.0};
double bias = 0.0;

Sortie attendue :
double expected = 0.5;

Explication

z = 0.5×2 + (-1)×1 + 0 = 0, and sigmoid(0) = 0.5: the neuron is exactly undecided.

Comment l'aborder

Essayez d'abord seul, puis ouvrez les indices un par un.

Indice 1

This is just a weighted sum of the inputs plus a bias, followed by one sigmoid.

Indice 2

Pair each input with its corresponding weight and accumulate the products before adding the bias.

Indice 3

Watch that the final output is passed through sigmoid, not returned as the raw sum.

Complexité attendue

O(n) time, O(1) extra space

Références

Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.

La meilleure solution validée de chaque codeur. Les plus rapides, les plus légères et les mieux notées passent devant.

# Codeur Langage Temps Mémoire Note de l'IA Solution
1 FSFilippo Sanguineti C++ 3,185 ms - 4/5 Voir le code

Apprenez des autres

Solutions de la communauté

Attention spoiler : 1 solution complète ci-dessous Essayez d'abord de le résoudre vous-même. Vous pouvez toujours jeter un œil au code des autres développeurs et aux avis IA. Connectez-vous et résolvez le défi pour rejoindre la discussion.