当前位置:网站首页>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]

边栏推荐
- Come on, handwritten RPC S2 serialization exploration
- [understanding of opportunity-54]: plain book-1-the origin of things [original chapter 1]: the road is simple.
- The information security and Standardization Commission issued the draft for comments on the management guide for app personal information processing activities
- MPEG音频编码三十年
- [golang] network connection net.dial
- The basic concept of transaction and the implementation principle of MySQL transaction
- What is the ISO assessment? How to do the waiting insurance scheme
- [7.21-26] code source - [good sequence] [social circle] [namonamo]
- 【7.21-26】代码源 - 【好序列】【社交圈】【namonamo】
- 数学建模——带相变材料的低温防护服御寒仿真模拟
猜你喜欢

LeetCode 113:路径总和 II

StoneDB 邀请您参与开源社区月会!

Data platform data access practice

【7.21-26】代码源 - 【体育节】【丹钓战】【最大权值划分】
![[the road of Exile - Chapter 5]](/img/ef/7ecc1cb4a95c613f7be91f7acc761c.png)
[the road of Exile - Chapter 5]

Top network security prediction: nearly one-third of countries will regulate blackmail software response within three years

九天后我们一起,聚焦音视频、探秘技术新发展

5g commercial third year: driverless "going up the mountain" and "going to the sea"

How to crawl web pages with playwright?
![[web technology] 1395 esbuild bundler HMR](/img/74/be75c8f745f18b374ed15c8e1b4466.png)
[web technology] 1395 esbuild bundler HMR
随机推荐
Six noteworthy cloud security trends in 2022
[golang] use select {}
Anaconda environment installation problem
规划数学期末考试模拟二
【7.21-26】代码源 - 【好序列】【社交圈】【namonamo】
Planning mathematics final exam simulation II
动态内存与智能指针
Analyzing the function of human-computer interface module of runtime manager based on autoware
使用POI,实现excel文件导出,图片url导出文件,图片和excel文件导出压缩包
分布式开发漫谈
基于 ICA 与 DL 的语音信号盲分离
What are the common cyber threats faced by manufacturers and how do they protect themselves
JVM learning minutes
Where will Jinan win in hosting the first computing power conference?
[the road of Exile - Chapter 2]
Comprehensive analysis of news capture doorway
Stonedb invites you to participate in the open source community monthly meeting!
【流放之路-第五章】
Process -- user address space and kernel address space
What is a proxy server? [2022 guide]