多层感知器-找到“分离的"感知器曲线 [英] multi layer perceptron - finding the "separating" curve

查看:127
本文介绍了多层感知器-找到“分离的"感知器曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用单层感知器,很容易找到分隔线"的方程式(我不知道专业术语),即根据感知器的权重将两种类型的点分开的线训练有素.如何以类似的方式在多层感知器中找到在两种类型的点之间分开的曲线方程(不是直线)?

with single-layer perceptron it's easy to find the equation of the "separating line" (I don't know the professional term), the line that separate between 2 types of points, based on the perceptron's weights, after it was trained. How can I find in a similar way the equation of the curve (not straight line) that separate between 2 types of points, in a multi-layer perceptron?

谢谢.

推荐答案

这仅是尝试获得分离边界或曲线的近似值.

This is only an attempt to get an approximation to the separating boundary or curve.

下面,我绘制了示例数据集的两种类型之间的分离曲线.数据集是从Coursera借来的-Andrew Ng的机器学习课程.另外,下面的代码段借鉴了安德鲁ML课程的Ex6的思想.

Below I plotted the separating curve between the two types of the example dataset. The dataset is borrowed from coursera - Andrew Ng's machine learning course. Also the code snippet below borrows the ideas from Ex6 of Andrew's ML course.

要绘制分离曲线,

  • 您首先要根据训练数据训练神经网络;
  • 使用所需的粒度生成二维数据网格,在Matlab中,这类似于:
  • You first train your neural network against your training data;
  • Generate a 2d grid of data using the granularity you want, in Matlab, this is something like:

    x1plot = linspace(min(X(:,1)), max(X(:,1)), 100)';
    x2plot = linspace(min(X(:,2)), max(X(:,2)), 100)';
    [X1, X2] = meshgrid(x1plot, x2plot);

  • 对于网格中的每个数据点,使用神经网络计算预测标签;
  • 绘制网格的结果标签的coutour图
  • 
        vals = zeros(size(X1));
        for i = 1:size(X1, 2)
           this_X = [X1(:, i), X2(:, i)];
           % mlpPredict() is the function to use your trained neural network model
           %    to get a predicted label. 
           vals(:, i) = mlpPredict(model, this_X);
        end
    
        % Plot the boundary
        hold on
        [C, Lev] = contour(X1, X2, vals, [0 0], 'Color', 'b');
        hold off;

    如果您的目标只是获得边界曲线的精确数学表示,则此方法将不起作用.此方法只能使曲线近似到您在网格中设置的粒度.

    If your goal is only to get the exact mathematical representation of the boundary curve, this method won't work. This method can only give you an approximation of the curve up to the granularity you set up in your grid.

    如果您确实希望精确描述边界,则SVM可能是一个不错的选择,因为整个支持向量集都可以用作边界描述.

    If you do want a precise description of the boundary, SVM might be a good alternative since the whole set of support vectors could serve as the boundary descriptive.

    我看了octave关于contour的文档.基本上,contour使用由contourc从相同参数计算出的轮廓矩阵C.这是contourc的签名:

    I took a look at octave's documentation about contour. Basically, contour uses the contour matrix C computed by contourc from the same arguments. Here is the signature of contourc:

    [C, LEV] = contourc (X, Y, Z, VN)
    

    此函数计算矩阵Z的轮廓线.参数XYVN是可选的.

    This function computes contour lines of the matrix Z. Parameters X, Y and VN are optional.

     The return value LEV is a vector of the contour levels.  The
     return value C is a 2 by N matrix containing the contour lines in
     the following format
    
          C = [lev1, x1, x2, ..., levn, x1, x2, ...
               len1, y1, y2, ..., lenn, y1, y2, ...]
    
     in which contour line N has a level (height) of LEVN and length of
     LENN.
    

    因此,如果您确实想获得曲线的解析描述,矩阵C应该包含有关该曲线的足够信息.在我的示例图中,解析C之后,我得到了30个级别.下面列出了第一级中前6个点的坐标:

    So if you do want to get an analytical description of the curve, matrix C should contain enough information about it. In my sample plot, after parsing of C, I get 30 levels. The coordinates of the first 6 points in the first level are listed below:

    x: 2.3677e-01   2.3764e-01   2.4640e-01   2.4640e-01   2.4640e-01   2.4640e-01 ...
    y: 4.0263e-01   4.0855e-01   4.0909e-01   4.1447e-01   4.2039e-01   4.2631e-01 ...
    

    请注意,它们恰好是轮廓上从(0.23677,0.40263)开始的点.使用这些轮廓点,可以直接使用多个线段来近似曲线(因为每个线段可以由两个端点确定).

    Please notice that they are exactly the points on the contour starting from (0.23677, 0.40263). Using these contour points, it's straightforward to approximate the curve using multiple line segments (because each line segment can be determined by two end points).

    希望它会有所帮助.

    这篇关于多层感知器-找到“分离的"感知器曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆