Todos los desafíos
Fácil 1 resuelto 100.0% de aceptación

Single Artificial Neuron

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

Lo que aprenderás

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

Problema

Ver traducción

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.

Restricciones

1 ≤ length of inputs = length of weights ≤ 100

-10 ≤ each input, weight and bias ≤ 10

Ejemplos

Ejemplo 1
Entrada:
inputs = [1.0, 2.0, 3.0]
weights = [0.2, 0.4, 0.6]
bias = 0.5

Salida esperada:
expected = 0.964429
Entrada:
std::vector<double> inputs = {1.0, 2.0, 3.0};
std::vector<double> weights = {0.2, 0.4, 0.6};
double bias = 0.5;

Salida esperada:
double expected = 0.964429;
Entrada:
double[] inputs = new double[] {1.0, 2.0, 3.0};
double[] weights = new double[] {0.2, 0.4, 0.6};
double bias = 0.5;

Salida esperada:
double expected = 0.964429;

Explicación

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

Ejemplo 2
Entrada:
inputs = [0.5, -1.0]
weights = [2.0, 1.0]
bias = 0.0

Salida esperada:
expected = 0.5
Entrada:
std::vector<double> inputs = {0.5, -1.0};
std::vector<double> weights = {2.0, 1.0};
double bias = 0.0;

Salida esperada:
double expected = 0.5;
Entrada:
double[] inputs = new double[] {0.5, -1.0};
double[] weights = new double[] {2.0, 1.0};
double bias = 0.0;

Salida esperada:
double expected = 0.5;

Explicación

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

Cómo abordarlo

Inténtalo primero por tu cuenta y luego abre las pistas una a una.

Pista 1

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

Pista 2

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

Pista 3

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

Complejidad esperada

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

Referencias

Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.

Clasificación

Clasificación completa

La mejor solución aprobada de cada programador. Las más rápidas, ligeras y mejor valoradas van primero.

# Programador Lenguaje Tiempo Memoria Revisión de IA Solución
1 FSFilippo Sanguineti C++ 3,185 ms - 4/5 Ver código

Aprende de otros

Soluciones de la comunidad

Alerta de spoiler: 1 solución completa abajo Intenta resolverlo tú mismo primero. Igual puedes ver el código de otros desarrolladores y las reseñas de IA. Inicia sesión y resuelve el reto para unirte a la discusión.