创建感知机 python
来源:互联网 发布:在手机上java编程软件 编辑:程序博客网 时间:2024/06/01 21:45
# ----------# # In this exercise, you will add in code that decides whether a perceptron will fire based# on the threshold. Your code will go in lines 32 and 34. ## ----------import numpy as npclass Perceptron: """ This class models an artificial neuron with step activation function. """ def __init__(self, weights = np.array([1]), threshold = 0): """ Initialize weights and threshold based on input arguments. Note that no type-checking is being performed here for simplicity. """ self.weights = weights self.threshold = threshold def activate(self,inputs): """ Takes in @param inputs, a list of numbers equal to length of weights. @return the output of a threshold perceptron with given inputs based on perceptron weights and threshold. """ # The strength with which the perceptron fires. strength = np.dot(self.weights, inputs) # TODO: return 0 or 1 based on the threshold if strength <= self.threshold : self.result = 0 else: self.result = 1 return self.resultdef test(): """ A few tests to make sure that the perceptron class performs as expected. Nothing should show up in the output if all the assertions pass. """ p1 = Perceptron(np.array([1, 2]), 0.) assert p1.activate(np.array([ 1,-1])) == 0 # < threshold --> 0 assert p1.activate(np.array([-1, 1])) == 1 # > threshold --> 1 assert p1.activate(np.array([ 2,-1])) == 0 # on threshold --> 0if __name__ == "__main__": test()
阅读全文
0 0
- 创建感知机 python
- Python感知机算法
- 感知机Python实现
- 感知机实现Python
- 感知机 Python代码
- 感知机 @ Python
- python感知机实现
- 感知机的 python 实现
- 感知机更新规则 python
- #感知机的Python实现
- 感知机算法python实现
- 使用感知机创建XOR网络
- 机器学习之感知机&&python实践
- 机器学习-感知机python实现
- 感知机相关概念及Python实现
- 感知机原理及python实现
- python实现感知机(perceptron)原型~
- [python]感知机学习算法实现
- 宠物商店编程问题
- oracle 创建表空间详细介绍
- fine-tuning的二三事
- GDBT
- 03Collection集合与Map集合的基础知识
- 创建感知机 python
- 欢迎使用CSDN-markdown编辑器
- Qt官方开发环境生成的exe发布方式--使用windeployqt
- Spring中最核心的两个类。
- case语句
- tree命令出现乱码
- CrackMe小程序编写
- xgboost
- 0522 js 条件语句