A simple neural network with one hidden layer can be used to demonstrate forward propagation.
import numpy as np
# Input data
X = np.array([0.5, 0.2, 0.1])
# Weights
W1 = np.array([[0.4, 0.3], [0.2, 0.7], [0.6, 0.5]])
W2 = np.array([0.8, 0.6])
# Forward pass
Z1 = np.dot(X, W1)
A1 = np.tanh(Z1)
Z2 = np.dot(A1, W2)
output = 1 / (1 + np.exp(-Z2))
print("Output:", output)
Backward propagation uses gradient descent to update weights and minimize error.
import numpy as np
# Derivative of sigmoid function
def sigmoid_derivative(x):
return x * (1 - x)
# Error calculation
error = output - target
d_output = error * sigmoid_derivative(output)
# Backpropagation
d_hidden_layer = d_output.dot(W2.T) * sigmoid_derivative(A1)
W2 -= A1.T.dot(d_output) * learning_rate
W1 -= X.T.dot(d_hidden_layer) * learning_rate
import numpy as np
# Activation functions
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def relu(x):
return np.maximum(0, x)
def tanh(x):
return np.tanh(x)
# Example usage
x = np.array([-1.0, 0.0, 1.0])
print("Sigmoid:", sigmoid(x))
print("ReLU:", relu(x))
print("Tanh:", tanh(x))
import numpy as np
# Random weight initialization
def initialize_weights(shape):
return np.random.randn(*shape) * 0.01
# Xavier initialization
def xavier_initialization(shape):
return np.random.randn(*shape) * np.sqrt(1. / shape[0])
# He initialization
def he_initialization(shape):
return np.random.randn(*shape) * np.sqrt(2. / shape[0])
# Example usage
W1 = initialize_weights((3, 2))
W2 = xavier_initialization((2, 1))
W3 = he_initialization((2, 1))
print("Random:", W1)
print("Xavier:", W2)
print("He:", W3)
import numpy as np
# Mean Squared Error
def mse(y_true, y_pred):
return np.mean(np.power(y_true - y_pred, 2))
# Cross-Entropy Loss
def cross_entropy(y_true, y_pred):
return -np.sum(y_true * np.log(y_pred))
# Example usage
y_true = np.array([1, 0, 0])
y_pred = np.array([0.7, 0.2, 0.1])
print("MSE:", mse(y_true, y_pred))
print("Cross-Entropy:", cross_entropy(y_true, y_pred))
import numpy as np
# Gradient Descent
def gradient_descent(w, grad, lr):
return w - lr * grad
# Example usage
w = np.array([0.5, 0.3])
grad = np.array([0.1, 0.2])
lr = 0.01
w_updated = gradient_descent(w, grad, lr)
print("Updated Weights:", w_updated)
import numpy as np
# Batch normalization
def batch_norm(X, gamma, beta, epsilon=1e-5):
mu = np.mean(X, axis=0)
var = np.var(X, axis=0)
X_norm = (X - mu) / np.sqrt(var + epsilon)
return gamma * X_norm + beta
# Example usage
X = np.array([[1, 2], [3, 4], [5, 6]])
gamma = np.array([1.0, 1.0])
beta = np.array([0.0, 0.0])
X_bn = batch_norm(X, gamma, beta)
print("Batch Normalized:", X_bn)
Newsletter
Subscribe to our newsletter for weekly updates and promotions.
Wiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterCompany
About usCareersPressCompany
About usCareersPressCompany
About usCareersPressLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesCompany
About usCareersPressCompany
About usCareersPressCompany
About usCareersPressLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesAds Policies