File:Perceptron convergence theorem.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
Source: Wikipedia, the free encyclopedia.

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

Summary

Description
English: ```python

import numpy as np import matplotlib.pyplot as plt

  1. Initialize variables

ws = [] gamma = 0.01 R = 1

  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))
  1. Remove points with x < gamma

points = [point for point in points if point[0] >= gamma]

  1. Initialize w

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

  1. 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
  1. Plot the items

fig, ax = plt.subplots(figsize=(10,10))

  1. Vertical dotted line at x=gamma

ax.axvline(x=gamma, linestyle='--', color='r', label='x=gamma')

  1. 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)

  1. 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)
  1. Set axis limits
  2. ax.set_xlim(-R, R)
  3. 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

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 pages on the English Wikipedia use this file (pages on other projects are not listed):

Metadata