Finish First Pass Python - Go/No-Go Perceptron Results




CS256

Chris Pollett

Sep 15, 2021

Outline

Introduction

Functions

Function Scoping, Functions as Variables

Objects and Classes

In-Class Exercise

Inheritance, static methods, abstract classes.

Exceptions

Modules

Documentation Strings and Help

What Single Perceptrons Cannot Do

Single Perceptrons Don't Do Equality - Proofyized Version

Two-Layer Networks

Example of Two Layer Network for Perceptron

How could we determine the perceptrons needed for a two layer perceptron network computing `PAR_3(x_1, x_2, x_3)`?

Answer. First, notice `PAR_3` is 1 for the boolean values `(1, 0, 0)`, `(0,1,0)`, `(0,0,1)`, and `(1,1,1)`. It is 0 for `(0,0,0)`, `(1, 1, 0)`, `(0,1,1)`, and `(1,0,1)`. We will build a perceptron circuit with four perceptron gates `G_1, ..., G_4`, which computes the function `G_4(G_1(x_1, x_2, x_3),G_2(x_1, x_2, x_3), G_3(x_1, x_2, x_3))`. `G_1` checks if `x+y+z ge 1/2`. The equation `x+y+z = 1/2` determines the plane that cuts the `x`, `y`, and `z` axis at a 1/2, so it is above the point `(0,0,0)`. So if `G_1` is `1` then we know the input isn't `(0,0,0)`, although it might be any of the other elements of the boolean cube. `G_2` checks if `x+y+z le 3/2`. The points `(1, 0, 0)`, `(0,1,0)`, `(0,0,1)` all satisfy this inequality, but `(1, 1, 0)`, `(0,1,1)`, and `(1,0,1)` do not. So `G_1` and `G_2` can both be 1 on the boolean cube only for the points `(1, 0, 0)`, `(0,1,0)`, `(0,0,1)`. We let `G_3` check if `x+y+z ge 2.5`. The only point on the boolean cube which satisfies this inequality is the point `(1,1,1)`. Notice if either `G_2` or `G_3` is 1, the other is 0. Finally, we let `G_4` check `Out_{G_1} + Out_{G_2} + 2Out_{G_3} ge 2`. Since `G_2` and `G_3` can't simultaneously be `1`, the only way for `G_4` to output `1` is if either `Out_{G_1}` and `Out_{G_2}` are both 1, or `Out_{G_1}` and `Out_{G_3}` are both 1. The first case corresponds only to `(1, 0, 0)`, `(0,1,0)`, `(0,0,1)` on the boolean cube, the latter to `(1,1,1)`.

Simplifying Symmetric Perceptrons

Given a boolean vector `vec{x}`, let `#(vec{x})` be the function which returns the number of 1 bits in `vec{x}`.

Lemma. Suppose a symmetric function `f(vec{x})` is computed as `|~ vec{w}\cdot vec{x} \geq theta ~|`, where `vec{w} in RR^n` and `theta in RR`. Then there exists a `gamma in RR` such that `f(vec{x}) = |~ gamma cdot #(vec{x}) \geq 1 ~|` for all `vec{x} in {0,1}^n`.

Proof. Since `f` is symmetric either all of the following `n` inequalities hold, or none of them do:
\begin{eqnarray*} w_1x_1 + w_2x_2 + w_3x_3 + \cdots + w_{n-1} x_{n-1} + w_n x_n &\geq& \theta\\ w_1x_2 + w_2x_3 + w_3x_4 + \cdots + w_{n-1} x_{n} + w_n x_1 &\geq& \theta\\ ...&&\\ w_1x_{n-1} + w_2x_n + w_3x_1 \cdots + w_{n-1} x_{n-3} + w_n x_{n-2} &\geq& \theta`\\ w_1x_{n} + w_2x_1 + w_3x_2 \cdots + w_{n-1} x_{n-2} + w_n x_{n-1} &\geq& \theta \end{eqnarray*} Adding these equations and grouping by the `x_i`'s implies `f(vec{x}) = 1` iff
`(sum_{i=1}^n w_i) x_1 + (sum_{i=1}^n w_i) x_2 + cdots + (sum_{i=1}^n w_i) x_n \geq n \cdot theta`.
Thus, `f(vec{x}) = 1` iff `(sum_{i=1}^n w_i)(sum_{i=1}^n x_i) \geq n\cdot theta` and as `#(\vec{x}) = (sum_{i=1}^n x_i)`, dividing both sides by `n \cdot theta` and defining `gamma = 1/(n\cdot theta) (sum_{i=1}^n w_i)` gives the result. Q.E.D.