Problema
Un neurone artificiale moltiplica ogni input per un peso, aggiunge un bias e passa il risultato attraverso una funzione di attivazione:
z = x₁×w₁ + x₂×w₂ + … + xₙ×wₙ + bias
output = sigmoid(z) = 1 / (1 + e^(-z))
Implementa neuron_output(inputs, weights, bias).
Input
inputs: I valori di input.
weights: Un peso per ogni input (stessa lunghezza di inputs).
bias: Il bias del neurone.
Output
Restituisci l'output del neurone, un numero decimale tra 0 e 1.
Vincoli
1 ≤ lunghezza di inputs = lunghezza di weights ≤ 100
-10 ≤ ogni input, peso e bias ≤ 10
Esempi
Input:
bias = 0.5
inputs = [1.0, 2.0, 3.0]
weights = [0.2, 0.4, 0.6]
Output atteso:
expected = 0.964429
Input:
double bias = 0.5;
std::vector<double> inputs = {1.0, 2.0, 3.0};
std::vector<double> weights = {0.2, 0.4, 0.6};
Output atteso:
double expected = 0.964429;
Input:
double bias = 0.5;
double[] inputs = new double[] {1.0, 2.0, 3.0};
double[] weights = new double[] {0.2, 0.4, 0.6};
Output atteso:
double expected = 0.964429;
Spiegazione
z = 1×0.2 + 2×0.4 + 3×0.6 + 0.5 = 3.3, e sigmoid(3.3) ≈ 0.964429.
Input:
bias = 0.0
inputs = [0.5, -1.0]
weights = [2.0, 1.0]
Output atteso:
expected = 0.5
Input:
double bias = 0.0;
std::vector<double> inputs = {0.5, -1.0};
std::vector<double> weights = {2.0, 1.0};
Output atteso:
double expected = 0.5;
Input:
double bias = 0.0;
double[] inputs = new double[] {0.5, -1.0};
double[] weights = new double[] {2.0, 1.0};
Output atteso:
double expected = 0.5;
Spiegazione
z = 0.5×2 + (-1)×1 + 0 = 0, e sigmoid(0) = 0.5: il neurone è esattamente indeciso.
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.