当前位置:网站首页>Monadic linear function perceptron: Rosenblatt perceptron
Monadic linear function perceptron: Rosenblatt perceptron
2022-07-29 02:01:00 【Just for fun】
1. Data files
Write a first py file , Define a dataset :
import numpy as np
def get_beans(counts):
xs = np.random.rand(counts)
xs = np.sort(xs)
ys = [1.2*x+np.random.rand()/10 for x in xs]
return xs,ys
Function description :
# np.random.rand(counts) establish counts I'm obedient “0~1” Uniform distribution
# Random sample value of cloth . The range of random samples is [0,1), barring 1.
counts = 5
xs = np.random.rand(counts)
[0.70491788 0.42003216 0.65673763 0.76751605 0.47131048]
# np.sort(a,axis) The function sorts the elements of a given array
# a: Array to sort
# axis: Specify by what sort , Default axis = 1 Sort by row , axis = 0 Sort by column
xs = np.sort(xs)
[0.42003216 0.47131048 0.65673763 0.70491788 0.76751605]
# For generating a list ys, And xs The relationship is 1.2*xs+np.random.rand()/10
ys = [1.2*x+np.random.rand()/10 for x in xs]
[0.05303335450122437, 0.6920008171892412, 0.8394550531216658, 0.8587572065335468, 1.1020587170327967]
2. rosenblatt perceptron
Create a py file , Name it rosenblatt.py
import dataset
from matplotlib import pyplot as plt
xs, ys = dataset.get_beans(100)
plt.title("size-toxicity function", fontsize = 12)
plt.xlabel("bean size")
plt.ylabel("toxicity")
plt.scatter(xs,ys) # scatter Used to draw scatter plots
# The initial prediction model of this scatter diagram is y = 0.5*x
w = 0.5
for m in range(100):
for i in range(100):
x = xs[i]
y = ys[i]
y_pre = w * x
e = y - y_pre
alpha = 0.05
w = w + alpha * e * x
# here dataset The random number in is numpy Realized
# When a number is multiplied by an array ,
# Automatically broadcast this number to each element in the array , Multiply
# This is it. numpy Broadcasting mechanism in
y_pre = w * xs
print(y_pre)
plt.plot(xs, y_pre)
plt.show()
3. Predicted results
D:\lesson1>python rosenblatt.py
[0.03780218 0.04059785 0.0477705 0.0855943 0.12874181 0.13685395
0.14489358 0.15819581 0.15873595 0.17213861 0.18243123 0.18766552
0.19346648 0.19838957 0.20573188 0.20668577 0.24096686 0.24422348
0.24707373 0.25030397 0.26286694 0.26648086 0.31443808 0.35684708
0.3591003 0.39489619 0.39817362 0.40656083 0.41692886 0.41976208
0.42143049 0.43370606 0.44166334 0.44266134 0.44797852 0.50634899
0.54419973 0.54498475 0.56182277 0.5891967 0.59048749 0.61811849
0.63202426 0.63321798 0.63505258 0.64797476 0.64997838 0.65315589
0.67106602 0.67516753 0.67553516 0.7157855 0.73822292 0.75061685
0.75788042 0.76475806 0.79805265 0.80329171 0.81531963 0.81951605
0.83349578 0.84459298 0.84777837 0.84847466 0.84959395 0.85415659
0.8768467 0.87854525 0.87910801 0.8931603 0.89518502 0.90568107
0.92065886 0.93747641 0.94244445 0.96398146 0.97403517 1.01397134
1.02901236 1.03930353 1.05150133 1.06272852 1.06790564 1.07580509
1.07822583 1.08778958 1.11816681 1.12882552 1.13526779 1.14116164
1.14473274 1.16009282 1.16715462 1.17221958 1.1767737 1.18421983
1.19188772 1.19945019 1.21415735 1.24617466]
边栏推荐
- 基于 ICA 与 DL 的语音信号盲分离
- Super scientific and technological data leakage prevention system, control illegal Internet behaviors, and ensure enterprise information security
- 560 and K
- Leetcode 113: path sum II
- 规划数学期末考试模拟二
- [golang] network connection net.dial
- [the road of Exile - Chapter 6]
- golang run时报undefined错误【已解决】
- JVM learning minutes
- Js DOM2 和 DOM3
猜你喜欢
MySQL execution order
[网鼎杯 2020 朱雀组]Nmap
使用本地缓存+全局缓存实现小型系统用户权限管理
Dynamic memory and smart pointer
The basic concept of transaction and the implementation principle of MySQL transaction
What is the ISO assessment? How to do the waiting insurance scheme
What is the function of data parsing?
What are the common cyber threats faced by manufacturers and how do they protect themselves
StoneDB 邀请您参与开源社区月会!
Overview of Qualcomm 5g intelligent platform
随机推荐
How to crawl web pages with playwright?
分布式开发漫谈
Web crawler API Quick Start Guide
[observation] ranked first in SaaS of pure public cloud in three years, and yonsuite's "flywheel effect"
【流放之路-第二章】
【流放之路-第八章】
Random talk on distributed development
560 and K
What is a proxy server? [2022 guide]
Introduction to shared data center agent
The basic concept of transaction and the implementation principle of MySQL transaction
ciscn 2022 华中赛区 misc
[7.21-26] code source - [square count] [dictionary order minimum] [Z-type matrix]
[netding cup 2020 rosefinch group]nmap
科研环境对人的影响是很大的
[golang] use select {}
[7.21-26] code source - [sports festival] [Dan fishing war] [maximum weight division]
剑指offer专项突击版第13天
JVM learning minutes
Large scale web crawling of e-commerce websites (Ultimate Guide)