1 Star 0 Fork 0

JJustRight/ACM-ICPC-Algorithms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

A perceptron is an algorithm that acts as a simple model of our brain to recognise and discriminate against data to obtain a single identifying function for a set of data.

In other words, it is a function that takes in a set of sample data with valid output values (eg: various features of houses and the price the house sold for) and then outputs a function that returns an accurate prediction for other data (eg: estimate a houses cost based on its features.)

Here is an example of what values can be inputted for the perceptron to return a valid function

max_epochs = Maximum number of iterations before the function gives up trying to create a perceptron

weights = [2, -4] # The initial weight assigned to each data point

bias = 0 # The bias for each weight (a positive value means to favour one value whilst negative means to oppose it)

learning_rate = 0.5 # The rate at which the perceptron learns and adapts is model. Too low value can cause the perceptron to constantly undervalue the data and not adapt within the max_epochs. However, too high a value can cause the perceptron to overvalue the data and never adapt to an accurate model.

examples = []  # The data specified as a list of tuples. The first item in each tuple is the data which itself is another tuple of values and the second item in the tuple is the output value of this data. In this case, the value is either 0 or 1.
examples.append((0,0),0)
examples.append((0,1),0)
examples.append((1,0),0)
examples.append((1,1),1)

max_epochs = 50 # The maximum number of attempts before the function gives up

Here is an example of the code performing against the following data

classifier = learn_perceptron(weights, bias, examples, learning_rate, 50)
if not classifier:
  print("No model could be learnt.")
else:
  print(classifier((0,0)))
  print(classifier((0,1)))
  print(classifier((1,0)))
  print(classifier((1,1)))
  print(classifier((2,2)))
  print(classifier((-3,-3)))
  print(classifier((3,-1)))

This code is already contained in the python file so just run it to see how it performs

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/jjustright/ACM-ICPC-Algorithms.git
git@gitee.com:jjustright/ACM-ICPC-Algorithms.git
jjustright
ACM-ICPC-Algorithms
ACM-ICPC-Algorithms
master

搜索帮助