Nội dung text [Practice] Single-Input Neural Networks (with Activation Function)
THỰC HÀNH MẠNG NEURON PHI TUYẾN —------------------------------------------------------------------------------------------------------------------------ MẠNG NEURON: - Số input: 01 - Số layer: 01. - Số neuron / layer: 01 - Hàm kích hoạt: sigmoid —------------------------------------------------------------------------------------------------------------------------ import numpy as np # Hàm kích hoạt Sigmoid def sigmoid(x): return 1 / (1 + np.exp(-x)) # Hàm tính đạo hàm của Sigmoid def sigmoid_derivative(x): return x * (1 - x) # Lớp Neuron sử dụng hàm kích hoạt Sigmoid class SimpleNeuronSigmoid: def __init__(self): # Khởi tạo trọng số và bias ngẫu nhiên self.weight = np.random.rand() self.bias = np.random.rand() def forward(self, input_data): # Tính đầu ra của neuron self.input = input_data self.linear_output = self.weight * self.input + self.bias self.output = sigmoid(self.linear_output) return self.output def backward(self, error, learning_rate): # Tính gradient cho trọng số và bias d_output = error * sigmoid_derivative(self.output) # Cập nhật trọng số và bias