Example #1
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    inputs = array([[0, 0], [0, 1], [1, 0], [1, 1]])
    targets = array([[0], [1], [1], [1]])

    p = pcn_logic_eg.pcn(inputs, targets)
    p.pcntrain(inputs, targets, 0.25, 6)

    inputs_bias = concatenate((-ones((shape(inputs)[0], 1)), inputs), axis=1)
    print p.pcnfwd(inputs_bias)
Example #2
0
def main():
	or_inputs = np.array( [[0,0], [0,1], [1,0], [1,1]])
	or_targets = np.array([[0],[1],[1],[0]])

	p = pcn.pcn(or_inputs, or_targets)
	p.pcntrain(or_inputs, or_targets, 0.25, 10)
	print "confusion matrix"
	p.confmat(or_inputs, or_targets)

	print "doing"
	print "  for "
	print or_inputs
	inputs_bias = np.concatenate((or_inputs,-np.ones((np.shape(or_inputs)[0],1))), axis=1)
	print "  results"
	print p.pcnfwd(inputs_bias)
Example #3
0
# You are free to use, change, or redistribute the code in any way you wish for
# non-commercial purposes, but please maintain the name of the original author.
# This code comes with no warranty of any kind.

# Stephen Marsland, 2008, 2014

# Demonstration of the Perceptron and Linear Regressor on the basic logic functions

import numpy as np
inputs = np.array([[0,0],[0,1],[1,0],[1,1]])
# AND data
ANDtargets = np.array([[0],[0],[0],[1]])
# OR data
ORtargets = np.array([[0],[1],[1],[1]])
# XOR data
XORtargets = np.array([[0],[1],[1],[0]])
import pcn_logic_eg

print "AND logic function"
pAND = pcn_logic_eg.pcn(inputs,ANDtargets)
pAND.pcntrain(inputs,ANDtargets,0.25,6)

print "OR logic function"
pOR = pcn_logic_eg.pcn(inputs,ORtargets)
pOR.pcntrain(inputs,ORtargets,0.25,6)

print "XOR logic function"
pXOR = pcn_logic_eg.pcn(inputs,XORtargets)
pXOR.pcntrain(inputs,XORtargets,0.25,6)
Example #4
0
from numpy import *
import pcn_logic_eg

inputs = array([[0, 0], [0, 1], [1, 0], [1, 1]])
print('inputs=\n', inputs)

targets = array([[0], [1], [1], [1]])
print('targets=\n', targets)

p = pcn_logic_eg.pcn(inputs, targets)
p.pcntrain(inputs, targets, 0.25, 6)
Example #5
0
import matplotlib.pyplot as pl
import numpy as np
import pcn_logic_eg
from pcn import *

gaussian = lambda x: 1/(np.sqrt(2*np.pi)*1.5)*np.exp(-(x-0)**2/(2*(1.5**2)))
x = np.arange(-5,5,0.01)
y = gaussian(x)

pl.plot(x,y,'k',linewidth=3)
pl.xlabel('x')
pl.ylabel('y(x)')
pl.axis([-5,5,0,0.3])
pl.title('Gaussian Function (mean 0, standard deviation 1.5)')
#pl.show()

inputs = np.array([[0,0,1],[0,1,0],[1,0,0],[1,1,0]])
targets = np.array([[0],[1],[1],[0]])


p = pcn_logic_eg.pcn(inputs,targets)
p.pcntrain(inputs,targets, 0.25, 15)


Example #6
0
from numpy import *
inputs = array([[0, 0], [0, 1], [1, 0], [1, 1]])
# AND data
ANDtargets = array([[0], [0], [0], [1]])
# OR data
ORtargets = array([[0], [1], [1], [1]])
# XOR data
XORtargets = array([[0], [1], [1], [0]])
import pcn_logic_eg

print("AND logic function")
p = pcn_logic_eg.pcn(inputs, ANDtargets)
p.pcntrain(inputs, ANDtargets, 0.25, 6)

print("OR logic function")
p = pcn_logic_eg.pcn(inputs, ORtargets)
p.pcntrain(inputs, ORtargets, 0.25, 6)

print("XOR logic function")
p = pcn_logic_eg.pcn(inputs, XORtargets)
p.pcntrain(inputs, XORtargets, 0.25, 6)
Example #7
0
# You are free to use, change, or redistribute the code in any way you wish for
# non-commercial purposes, but please maintain the name of the original author.
# This code comes with no warranty of any kind.

# Stephen Marsland, 2008, 2014

# Demonstration of the Perceptron and Linear Regressor on the basic logic functions

import numpy as np
inputs = np.array([[0,0],[0,1],[1,0],[1,1]])
# AND data
ANDtargets = np.array([[0],[0],[0],[1]])
# OR data
ORtargets = np.array([[0],[1],[1],[1]])
# XOR data
XORtargets = np.array([[0],[1],[1],[0]])
import pcn_logic_eg

print "AND logic function"
pAND = pcn_logic_eg.pcn(inputs,ANDtargets)
pAND.pcntrain(inputs,ANDtargets,0.25,6)

print "OR logic function"
pOR = pcn_logic_eg.pcn(inputs,ORtargets)
pOR.pcntrain(inputs,ORtargets,0.25,6)

print "XOR logic function"
pXOR = pcn_logic_eg.pcn(inputs,XORtargets)
pXOR.pcntrain(inputs,XORtargets,0.25,6)

pOR.confmat(inputs, ORtargets)
Example #8
0
# This code comes with no warranty of any kind.

# Stephen Marsland, 2008

# Demonstration of the Perceptron and Linear Regressor on the basic logic functions

from numpy import *

import pcn_logic_eg


inputs = array([[0,0],[0,1],[1,0],[1,1]])
# AND data
ANDtargets = array([[0],[0],[0],[1]])
# OR data
ORtargets = array([[0],[1],[1],[1]])
# XOR data
XORtargets = array([[0],[1],[1],[0]])

print "AND logic function"
p = pcn_logic_eg.pcn(inputs,ANDtargets)
p.pcntrain(inputs,ANDtargets,0.25,6)

print "OR logic function"
p = pcn_logic_eg.pcn(inputs,ORtargets)
p.pcntrain(inputs,ORtargets,0.25,6)

print "XOR logic function"
p = pcn_logic_eg.pcn(inputs,XORtargets)
p.pcntrain(inputs,XORtargets,0.25,6)
import pcn_logic_eg
import numpy as np

Xorinput = np.array([[0,0,0],[0,0,1],[0,1,0],[1,0,0],[1,0,1],[1,1,0],[0,1,1],[1,1,1]])
Xorexpected = np.array([[0], [1], [1], [0], [1], [0], [0], [1]])
NAndinput = np.array([[0,0],[0,1],[1,0],[1,1]])
NAndexpected = np.array([[1],[1],[1],[0]]) 
NotAinput = np.array([[0],[1]])
NotAexpected = np.array([[1],[0]])


p=pcn_logic_eg.pcn(Xorinput, Xorexpected)
p.pcntrain(Xorinput, Xorexpected, .25,25)
print('///////////////////END of XOR////////////////')

p=pcn_logic_eg.pcn(NAndinput, NAndexpected)
p.pcntrain(NAndinput, NAndexpected, .25,8)
print('///////////////////END of NAND////////////////')

p=pcn_logic_eg.pcn(NotAinput, NotAexpected)
p.pcntrain(NotAinput, NotAexpected, .25,5)
print('///////////////////END of NOTA////////////////')
Example #10
0
#training target
tTarget = trainSet[:,4]
tTarget = np.asmatrix(tTarget)

#test target
testTarget = testSet[:,4]

#concatenate
#training = concatenate((training, -ones((shape(training)[0],1))), axis=1)
beta = linreg2.linreg2(training, tTarget)
testing = concatenate((testing, -ones((shape(testing)[0],1))), axis=1)
testout = dot(testing, beta)

error = 0
error = [(testout[i,0]-testTarget[i])**2 for i in range(30)]
print sum(error)

"""print testing.shape
print testout.shape
print tTarget.shape
print testTarget.shape
print testout[0]
print testTarget[0]"""

p = pcn_logic_eg.pcn(training, tTarget)
#weights = p.pcntrain(training, tTarget, 0.25, 6)
weights = 0.01
testoutput = p.pcnfwd(testing)
testoutput=dot(testing, weights)
print sum(testoutput)