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

Single Artificial Neuron

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

배우게 될 내용

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

문제

번역본 보기

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.

제약 조건

1 ≤ length of inputs = length of weights ≤ 100

-10 ≤ each input, weight and bias ≤ 10

예시

예시 1
입력:
inputs = [1.0, 2.0, 3.0]
weights = [0.2, 0.4, 0.6]
bias = 0.5

예상 출력:
expected = 0.964429
입력:
std::vector<double> inputs = {1.0, 2.0, 3.0};
std::vector<double> weights = {0.2, 0.4, 0.6};
double bias = 0.5;

예상 출력:
double expected = 0.964429;
입력:
double[] inputs = new double[] {1.0, 2.0, 3.0};
double[] weights = new double[] {0.2, 0.4, 0.6};
double bias = 0.5;

예상 출력:
double expected = 0.964429;

설명

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

예시 2
입력:
inputs = [0.5, -1.0]
weights = [2.0, 1.0]
bias = 0.0

예상 출력:
expected = 0.5
입력:
std::vector<double> inputs = {0.5, -1.0};
std::vector<double> weights = {2.0, 1.0};
double bias = 0.0;

예상 출력:
double expected = 0.5;
입력:
double[] inputs = new double[] {0.5, -1.0};
double[] weights = new double[] {2.0, 1.0};
double bias = 0.0;

예상 출력:
double expected = 0.5;

설명

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

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

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

힌트 2

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

힌트 3

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

예상 복잡도

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

참고 자료

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

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

# 코더 언어 시간 메모리 AI 평가 풀이
1 FSFilippo Sanguineti C++ 3,185 ms - 4/5 코드 보기

다른 사람의 풀이 보기

커뮤니티 솔루션

스포일러: 아래에 1개 전체 솔루션 있음 먼저 직접 풀어보세요. 다른 개발자의 코드와 AI 리뷰도 참고할 수 있습니다. 로그인하고 문제를 풀면 토론에 참여할 수 있습니다.