从头实现linux操作系统_从头开始实现您的第一个人工神经元

从头实现linux操作系统

介绍 (Introduction)

Warren McCulloch and Walter Pitts first proposed artificial neuron in the year 1943, and it is a highly simplified computational model which resembles its behavior with neuron possessed by the human brain. Before we dig deeper into the concepts of artificial neuron let us take a look at the biological neuron.

沃伦·麦卡洛克(Warren McCulloch)和沃尔特·皮茨(Walter Pitts)于1943年首次提出了人工神经元,它是一个高度简化的计算模型,类似于人脑拥有的神经元的行为。 在深入研究人工神经元的概念之前,让我们看一下生物神经元。

Image for post
image source: Wikipedia
图片来源:维基百科

生物神经元 (Biological Neuron)

The biological neuron receives input signals through dendrites and sends it to soma or cell body which is the processing unit of a neuron, the processed signal is then carried through the axon to other neurons. The junction where two neurons meet is called a synapse, the degree of synapse tells the strength of signal carried to other neurons.

生物神经元通过树突接收输入信号,并将其发送到作为神经元处理单元的体细胞或细胞体,然后经过处理的信号通过轴突传递到其他神经元。 两个神经元相遇的连接点称为突触,突触的程度表明了传递给其他神经元的信号强度。

人工神经元-McCulloch Pitts神经元(MP Neuron) (Artificial Neuron — McCulloch Pitts Neuron (MP Neuron))

McCulloch Pitts Neuron model is also called as a Threshold Logic Unit (TLU), or Linear Threshold Unit, it is named so because the output value of the neuron depends on a threshold value. The working of a biological neuron inspires this artificial neuron, it is structured and meant to behave similarly to biological neuron.

McCulloch Pitts神经元模型也称为阈值逻辑单元(TLU)线性阈值单元 ,之所以这样命名是因为神经元的输出值取决于阈值 。 生物神经元的工作激发了这种人工神经元,它的结构和作用与生物神经元类似。

Image for post
image by the Author
图片由作者

Input Vector [x₁ x₂ x₃…xₙ] — In an Artificial neuron, the input vector act as inputs to the neuron, it behaves similar to dendrites in Biological Neuron.

输入向量[x₁x2x₃…xₙ] -在人工神经元中,输入向量充当神经元的输入,其行为类似于生物神经元中的树突。

Function f(x) — In an Artificial neuron, the function f(x) is a summation function, which behaves similar to soma in Biological Neuron.

函数f(x) -在人工神经元中,函数f(x)是求和函数,其行为类似于生物神经元中的躯体。

A. MP神经元模型 (A. Model of MP Neuron)

We can define the Model as an approximation function, of the true relationship between the dependent and independent variables.

我们可以将模型定义为因变量和自变量之间真实关系的近似函数。

Image for post
Image for post

[x₁ x₂ x₃ … xₙ] — inputs or attributes of the MP Neuron Model.

[x x 2 x x…xx]-MP Neuron模型的输入或属性。

b — Threshold Values which is the only parameter in the MP Neuron Model.

b —阈值,这是MP Neuron模型中的唯一参数。

The function g(x) performs a summation of all the inputs and the function f(x) applies a threshold value to the output returned by the function g(x). The value returned by the function f(x) is a boolean value, that is, if the summation of inputs is greater than the fixed threshold(b) then the neuron gets activated else the neuron is fired.

函数g(x)对所有输入进行求和,函数f(x)将阈值应用于函数g(x)返回的输出。 函数f(x)返回的值是布尔值,即,如果输入的总和大于固定阈值(b),则神经元被激活,否则神经元被触发。

您需要了解MP Neuron的事情 (Things you need to know about MP Neuron)

  1. It takes only binary data, which is input vector X ϵ {0,1}.

    它仅采用二进制数据,即输入向量X ϵ {0,1}。

  2. Task performed by the neuron is binary classification ie Y ϵ {0,1}.

    神经元执行的任务是二进制分类,即Y ϵ {0,1}。

MP神经元的几何解释 (Geometrical Interpretation of MP Neuron)

For simplicity let us consider there are only two features in the dataset, so the input vector looks like, x = [x₁ x₂], and the functions look like…

为简单起见,让我们考虑数据集中只有两个特征 ,因此输入向量看起来像x = [x₁x²],而函数看起来像…

Image for post
Image for post

converting it into the form of linear equation ie, y = m*x + c

将其转换为线性方程式,即y = m * x + c

Image for post

compare equations(1) and (2), we find that…

比较方程式(1)和(2),我们发现……

The slope of the line m = -1 (it is fixed for any dataset).

线的斜率m = -1 (对于任何数据集都是固定的)。

The y-intercept of the line c= b (the only thing we can change to tune the model).

线c = b的y截距(唯一可以更改以调整模型的东西)。

Note: all the points that lie on top of the line are classified as positive(1) and all the points that lie below the line are classified as negative(0).

注意:位于该线上方的所有点都被分类为正(1),位于该线下方的所有点都被分类为负(0)。

when we plot the line x2 = -x1 + 1

当我们画线x2 = -x1 + 1

Image for post
image by the author
作者形象

总结: (Summary :)

  1. All the points above the line (green points) are classified as positive.

    线上方的所有点(绿色点)都归为正。
  2. All the points below the line (red points) are classified as negative.

    线下的所有点(红色点)都归为负。
  3. MP Neuron model works only when the points are linearly separable.

    MP Neuron模型仅在点可线性分离时有效。

  4. The slope of the line in the MP Neuron model is fixed that is -1.

    MP Neuron模型中直线的斜率固定为-1。
  5. We have got the power to change the value of y-intercept(b).

    我们有能力更改y-intercept(b)的值。

损失函数 (B. Loss function)

Loss is the error or mistake that the model has incurred during its training phase, it can be calculated using mean squared error loss function.

损失是模型在训练阶段发生的错误或失误,可以使用均方误差损失函数来计算。

Image for post

C.优化算法 (C. Optimization Algorithm)

since the only parameter in the model is b, we need to choose the best value of b such that the loss is reduced.

由于模型中的唯一参数是b,因此我们需要选择b的最佳值,以减少损耗。

We can choose the b value using a brute force approach since the range of b is from [0,n], where n is the number of features in data.

我们可以使用蛮力方法选择b值,因为b的范围是[0,n] ,其中n是数据中特征的数量。

  1. b takes a minimum value when x₁ + x₂ + x₃ … xₙ =0, ie when feature vector looks like [x₁ x₂ x₃ … xₙ]= [0 0 0 …0]

    x₁+x²+x₃…xₙ= 0时, b取最小值即当特征向量看起来像 [x₁x²x₃…xₙ] = [0 0 0…0]

  2. b takes a maximum value when x₁ + x₂ + x₃ … xₙ =n, ie when feature vector looks like [x₁ x₂ x₃ … xₙ] = [1 1 1 … 1]

    x₁+x²+x₃…xₙ= n时 ,b取最大值,即当特征向量看起来像[x₁x2x₃...xₙ] = [1 1 1…1]时

since the value of b lies between [0,n], we can compute loss the model incurred for each value of b and pick the best one among them.

由于b的值介于[0,n]之间,因此我们可以计算b的每个值引起的模型损失,并从中选择最佳的一个。

D.评估 (D. Evaluation)

we can evaluate the performance of the model using this simple formula

我们可以使用这个简单的公式来评估模型的性能

Image for post

E. MP神经元模型的局限性 (E. Limitation of MP Neuron Model)

  • The Model accepts data only in the form of {0,1}, we can not feed it with real values.

    该模型仅接受{0,1}形式的数据,我们无法将其提供给实际值。
  • It is only used for Binary classification.

    它仅用于二进制分类。
  • It performs well only when data is linearly separable

    仅当数据可线性分离时,它才能发挥出色的性能
  • The line equation has a fixed slope, so there is no flexibility in changing the slope of the line.

    线方程具有固定的斜率,因此更改线的斜率没有灵活性。
  • We can not judge which feature is more important and we can not give priority to any feature.

    我们无法判断哪个功能更重要,也无法优先考虑任何功能。
  • The learning algorithm is not so impressive, we are using a brute force approach to find the threshold value.

    学习算法并不是那么令人印象深刻,我们正在使用蛮力方法来找到阈值。

让我们编码… (Let’s Code…)

资料需求 (Data Requirements)

we use the breast cancer dataset present in sklearn datasets package, and our task is to predict if the person has cancer or not based on the data provided

我们使用sklearn数据包包含的乳腺癌数据集,而我们的任务是根据提供的数据来预测该人是否患有癌症

A.导入基本库 (A. Importing essential libraries)

B.加载数据 (B. Loading Data)

C.可视化数据 (C. Visualizing Data)

Image for post
image by the author (output of above code snippet)
作者提供的图片(上述代码段的输出)

From the above plot, we infer that data is not in binary form but for the MP neuron model requires we require data to be in binary form that is {0,1}. So let’s convert this data into binary form. before that, we need to split the data into train data and test data

从上图可以看出,数据不是二进制形式,但对于MP神经元模型,我们要求数据必须为{0,1}的二进制形式。 因此,让我们将这些数据转换为二进制形式。 在此之前,我们需要将数据分为训练数据和测试数据

D.将数据分为训练和测试数据 (D. Splitting Data into train and test data)

E.分箱数据 (E. Binning data)

Here we convert the data into zeros and ones, to make it compatible with the MP Neuron model, we do this using cut method in pandas library.

在这里,我们将数据转换为零和一,以使其与MP Neuron模型兼容,我们在pandas库中使用cut方法进行此操作。

Image for post
image by the author (data after binning)
作者提供的图片(合并后的数据)

F.定义MP神经元 (F. Defining the MP Neuron)

G.评估 (G. Evaluation)

Image for post
image by the author (output of above code snippet)
作者提供的图片(上述代码段的输出)

on the training data the performance of the model is pretty good, ie 84.6%, let visualize the performance of the model for different values of b.

根据训练数据,模型的性能相当好,即84.6%,让我们直观地看到不同b值时模型的性能。

Image for post
image by the author
作者形象

测试数据性能 (performance on test data)

Image for post
image by the author
作者形象

结论 (Conclusion)

We build a very simplified computational model of a biological neuron, and we got 78% accuracy on test data that is not bad for such a simple model. I hope you learned something new in this article.

我们建立了一个非常简化的生物神经元计算模型,并且在测试数据上获得了78%的准确度,这对于这种简单的模型而言还不错。 希望您在本文中学到了新东西。

翻译自: https://towardsdatascience.com/implement-your-first-artificial-neuron-from-scratch-dc01b9505c18

从头实现linux操作系统

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值