first commit

This commit is contained in:
Sabic 2024-06-24 15:52:44 +02:00
commit 9c515aba8e
2 changed files with 58 additions and 0 deletions

29
generate_dataset.py Normal file
View File

@ -0,0 +1,29 @@
import numpy as np
import matplotlib.pyplot as plt
# Parameters
num_points = 1000 # Number of data points
radius = 5 # Radius to separate the classes
# Generate random (x, y) coordinates
x = np.random.uniform(-10, 10, num_points)
y = np.random.uniform(-10, 10, num_points)
# Calculate distance from the origin
distance = np.sqrt(x**2 + y**2)
# Class labels: 0 for inside the radius, 1 for outside the radius
labels = (distance > radius).astype(int)
# Plot the dataset
plt.figure(figsize=(8, 8))
plt.scatter(x[labels == 0], y[labels == 0], color='blue', label='Class 0 (Inside radius)')
plt.scatter(x[labels == 1], y[labels == 1], color='red', label='Class 1 (Outside radius)')
plt.axhline(0, color='black',linewidth=0.5)
plt.axvline(0, color='black',linewidth=0.5)
plt.grid(color = 'gray', linestyle = '--', linewidth = 0.5)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Generated Dataset for Classification Task')
plt.legend()
plt.show()

29
main.py Normal file
View File

@ -0,0 +1,29 @@
import numpy as np
from random import random
neurons_per_layer = 4
layers = 2
inputs = 2
outputs = 1
grid_min = -10
grid_max = 10
biases = [[] for _ in range(layers)]
for i in range(0, neurons_per_layer)
weights = [[] for _ in range(layers+2)]
# Input layer to first hidden layer weights
weights[0] = [random() for _ in range(inputs*neurons_per_layer)]
for i in range(1, layers+1):
# Weights between hidden layers
weights[i] = [random() for _ in range(neurons_per_layer ** 2)]
# Weights from last hidden layer to output layer
weights[-1] = [random() for _ in range(outputs*neurons_per_layer)]
def sigmoid(x):
return np.exp(-np.logaddexp(0, -x))