Description Usage Arguments Details Author(s) References See Also Examples
View source: R/plot_perceptron.R
Display perceptron results in two-dimensional space via two-dimensional targets. Decision boundaries, valid regions, and training data are included.
1 | plot_perceptron(ans, xlo, xhi, ylo, yhi, repper = 100)
|
ans |
A result originating from a call to package function
|
xlo |
The minimum value to display with respect to the x-axis. |
xhi |
The maximum value to display with respect to the x-axis. |
ylo |
The minimum value to display with respect to the y-axis. |
yhi |
The maximum value to display with respect to the y-axis. |
repper |
An integer giving the number of points to use to display linear
decision boundaries. Resulting piecewise segments numbers |
Function plot_perceptron assumes target vectors are
two-dimensional, i.e., \mathbf{t} \in \mathbb{R}^2, so as to induce
ease in depicting graphical results. Currently, the function assumes that
no more than 26 distinct classes are to be included.
Output from function perceptron includes a final weights matrix
\mathbf{W} and bias vector \mathbf{b}, each of which
contributes to plotting final linear decision boundaries. Note that the
i^{th} neuron corresponds to the i^{th} row of
\mathbf{W}, say \mathbf{w}_i^T and bias vector
\mathbf{b}, or b_i. From these, a linear decision boundary can
be found.
To see this, let \mathbf{w}_i^T = [A_i \,\, B_i] and b_i = c_i, so that the i^{th} decision boundary has equation \mathbf{w}_i^T \begin{bmatrix} 1 \\ 1 \end{bmatrix} + b_i = 0, or A_i x_i + B_i y_i + c_i = 0. Simple rearrangement into the traditional line form of y = mx + b leads to y_i = -\frac{A_i}{B_i}x - \frac{c_i}{B}. Thus, the decision boundary of the i^{th} neuron has slope -\frac{A_i}{B_i} and y-intercept - \frac{c_i}{B}.
Function perceptron_plot uses these derived values of the slope and
y-intercept to then draw linear decision boundaries. Colored regions
always correspond to areas greater than the given line. In the case of a
vertical line, the colored region subsumes +∞ if the weight row
vector \mathbf{w}_i^T points towards -∞ along the
y-axis, with the opposite true when \mathbf{w}_i^T points
positively along the y-axis.
Jason Mitchell
Martin T. Hagan, Howard B. Demuth, Mark H. Beale and Orlando De Jesús. 2014. Neural Network Design (2nd. ed.). Martin Hagan, Stillwater, OK, USA.
1 2 3 4 5 6 7 8 9 10 | ## Not run:
p <- list(c(1, 1), c(1, 2), c(2, -1), c(2, 0), c(-1, 2), c(-2, 1), c(-1, -1), c(-2 ,-2))
t <- list(c(0, 0), c(0, 0), c(0, 1), c(0, 1), c(1, 0), c(1, 0), c(1, 1), c(1, 1))
verbose <- TRUE
W_0 <- matrix(c(1, 0, 0, 1), ncol = 2)
b_0 <- c(1, 1)
ans <- perceptron(p, t, verbose, W_0, b_0)
plot_perceptron(ans, -5, 5, -5, 5)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.