Langbahn Team – Weltmeisterschaft

File:Perceptron convergence theorem.svg

Original file (SVG file, nominally 900 × 900 pixels, file size: 31 KB)

Summary

Description
English: Desc

Matplotlib code

import numpy as np
import matplotlib.pyplot as plt

# Initialize variables
ws = []
gamma = 0.01
R = 1

# Generate random points within the circle of radius R
points = []
while len(points) < 100:
    x, y = np.random.uniform(-R, R, 2)
    if x**2 + y**2 <= R**2:
        points.append((x, y))

# Remove points with x < gamma
points = [point for point in points if point[0] >= gamma]

# Initialize w
ws = []
w = np.array([-0.1, 0.0])
ws.append(w.copy())

# Perceptron learning algorithm
convergence_flag = False
while not convergence_flag:
    np.random.shuffle(points)
    convergence_flag = True
    for v in points:
        if np.dot(w, v) <= 0:
            w += v
            ws.append(w.copy())
            convergence_flag = False
# Plot the items
fig, ax = plt.subplots(figsize=(10,10))

# Vertical dotted line at x=gamma
ax.axvline(x=gamma, linestyle='--', color='r', label='x=gamma')

# Circle with radius R centered at (0, 0)
circle = plt.Circle((0, 0), R, fill=False, color='b', linestyle='-', label='Circle')
ax.add_artist(circle)

# Jagged line connecting entries in ws
points = np.array(points)
ax.scatter(points[:,0], points[:,1])
ws = np.array(ws)
for i in range(1, ws.shape[0]):
    ax.arrow(ws[i-1, 0], ws[i-1, 1], ws[i, 0] - ws[i-1, 0], ws[i, 1] - ws[i-1, 1], color='g', linewidth=0.5,
             head_width=0.03, head_length=0.04, length_includes_head=True)

# Set axis limits
# ax.set_xlim(-R, R)
# ax.set_ylim(-R, R)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.legend()

plt.gca().set_aspect('equal')
plt.savefig("perceptron convergence.svg")

Date
Source Own work
Author Cosmia Nebula

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

creator

some value

author name string: Cosmia Nebula
Wikimedia username: Cosmia Nebula

copyright status

copyrighted

copyright license

Creative Commons Attribution-ShareAlike 4.0 International

source of file

original creation by uploader

inception

3 November 2023

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current23:49, 3 November 2023Thumbnail for version as of 23:49, 3 November 2023900 × 900 (31 KB)Cosmia NebulaUploaded while editing "Perceptron" on en.wikipedia.org

The following page uses this file:

Metadata