1 / 58

Biologically Inspired Intelligent Systems

Biologically Inspired Intelligent Systems. Lecture 04 Dr. Roger S. Gaborski. Single Neuron Model. Artificial Neurons. v k = b k *1 + x 1 *w 1 + x 2 *w 2 + …x n *w n Redefine v k as net and b k as simply b net = b + ∑ x i * w i

yael
Download Presentation

Biologically Inspired Intelligent Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Biologically Inspired Intelligent Systems Lecture 04 Dr. Roger S. Gaborski Roger S. Gaborski

  2. Single Neuron Model

  3. Artificial Neurons vk = bk*1 + x1*w1 + x2*w2 + …xn*wn Redefine vk as net and bk as simply b net = b + ∑ xi * wi The activation function, f, can take several forms, including The identity function, binary step function, bipolar step function, sigmoid function or a bipolar sigmoid function

  4. Artificial Neural Networks/Neural Network Basicshttp://en.wikibooks.org/wiki/Artificial_Neural_Networks/Neural_Network_Basics

  5. 2 Input Neuron Decision Boundary Requirement for positive output: b + x1w1+ x2w2 > 0 During training the values for w1 , w2 and b are determined so that the neuron will have a positive output (correct response) during training

  6. 2 Input Neuron Decision Boundary f(net) = 1 if net ≥ 0 = -1 if net < 0 Where net = b + ∑ xi * wi where i = 1 or 2 Decision Boundary: The line separating the positive and negative output values of the net as a function of the weights w1 and w2 b + x1w1+ x2w2 = 0 Assuming w2 ≠ 0, x2 = - (w1/w2)x1- (b/w2)

  7. Response for given weights (AND) x2 x2 = -x1 +1 Decision Boundary x1 x2 0 +1 -1 +2 +1 0 Responses + 2 1 x1 1 2 -1 -1 -

  8. Bipolar AND Training Input Target Weight Changes New Weights (x1 x2 1 ) ∆w1 ∆w2 ∆b w1 w2 b 0 0 0 ( 1 1 1 ) 1 1 1 1 1 1 1 ( 1 -1 1 ) -1 -1 1 -1 0 2 0 ( -1 1 1 ) -1 1 -1 -1 1 1 -1 ( -1 -1 1 ) -1 1 1 -1 2 2 -2 x2 = - (w1/w2)x1- (b/w2) x2 = -(2/2)x1 – (-2/2) = -x1 +1

  9. Hebb Learning %OR data (x1 x2 1 ) Target inp = [ 1 1 1; 1 -1 1; -1 1 1; -1 -1 1]; tar = [ 1; 1; 1; -1]; W = [ 0, 0, 0]; %w1, w2, b %Initialize weights to 0 %Pass through the data only once, updating the weights %for each data point for i=1: size(inp,1) for k=1:size(inp,2) W(k) = W(k)+ inp(i,k)*tar(i); end W end NOTE: THIS CODE CONTAINS LOOPS, DO NOT USE THIS CODE TO ANSWER HW2 – use matrix operations

  10. Test Results %Check if response is correct %W contains final weight matrix %inp is the input data %tar is the target data for cnt=1:size(inp,1) YY(cnt) = W(3)+W(1)*inp(cnt,1)+W(2)*inp(cnt,2); end result = sign(YY) (%bipolar threshold)

  11. A Few Ideas on Matrix Representation • Weight Calculation: W(new) = w(initial) + targets*inputs • Testing: net = b + ∑ xi * wi • Response = fcn(net) • Let fcn be the bipolar threshold (sign) +1 Input value 0 -1

  12. Feed Forward Operation For OR: w0 = 1, w1 = 1, w2 = 1 net = w0 + ∑ xi * wi (redefine b = w0) Response = fcn(net) net = w0 + x1*w1 + x2*w2 redefine b = w0 net = [ w0 w1 w2 ] * 1 x1 x2 Response = f(net) = f[ w0 w1 w2 ] * 1 x1 x2

  13. Feed Forward Operation net = w0 + x1*w1 + x2*w2 net = [ 1 1 1 ] * +1 -1 -1 Response = sign(net) = sign [ 1 1 1 ] * 1 -1 -1 Response = sign(1) = -1

  14. Matrix of Data Inputs weights = -1 1 1 >> data = [1 -1 1; 1 -1 -1; 1 1 1; 1 1 -1]' data = 1 1 1 1bias -1 -1 1 1x1 value 1 -1 1 -1x2 value Responses = sign(weights*data) = -1 -1 1 -1

  15. Single Neuron • a = x0w0+ x1w1 + x2w2 + … + xnwn • x0 is bias term = 1 • Output = tanh(a) Roger S. Gaborski

  16. 4 Fully Connected Neurons N1 N2 Notation: wto, from W1,2 To neuron 1 From neuron 2 w23 N3 N4 w34 w44 Roger S. Gaborski

  17. 4x4 Weight Matrix w11 w12 w13 w14 w21 w22 w23 w24 w31 w32 w33 w34 w41 w42 w43 w44 w11 is weight between neuron n1 and itself w12 is the weight connection from N2 to N1 Roger S. Gaborski

  18. Outputs of Neurons • x1 is output of neuron 1 • x2 is output of neuron 2 • x3 is output of neuron 3 • x4 is output of neuron 4 Roger S. Gaborski

  19. 4 Fully Connected Neurons with BIAS w10 w20 N1 N2 Notation: wto, from W1,2 To neuron 1 From neuron 2 w23 N3 N4 w34 w44 w30 w40 Roger S. Gaborski

  20. Append Bias Term Column:Column 0 w10 w11 w12 w13 w14 w20 w21 w22 w23 w24 w30 w31 w32 w33 w34 w40 w41 w42 w43 w44 Roger S. Gaborski

  21. Multiply by Neuron Output Column Vector w10 w11 w12 w13 w14 1 w20 w21 w22 w23 w24 * x1 w30 w31 w32 w33 w34 x2 w40 w41 w42 w43 w44 x3 x4 WEIGHT MATRIX STATE VECTOR Roger S. Gaborski

  22. Recall: Single Neuron • a = x0w0+ x1w1 + x2w2 + … + xnwn • x0 is bias term = 1 a1 = w10 w11 w12 w13 w14 * 1 x1 x2 x3 x4 Roger S. Gaborski

  23. Include Input Data to Neuron 1 w1in w10 w11 w12 w13 w14 Iin 0 w20 w21 w22 w23 w24 * 1 0 w30 w31 w32 w33 w34 x1 0 w40 w41 w42 w43 w44 x2 x3 x4 Roger S. Gaborski

  24. Apply Non-linear Function w1in w10 w11 w12 w13 w14 Iin 0 w20 w21 w22 w23 w24 * 1 0 w30 w31 w32 w33 w34 x1 =x1 0 w40 w41 w42 w43 w44 x2 x2 x3 x3 x4 x4 tanh Where x1, x2, x3 and x4 are update state values of network Roger S. Gaborski

  25. 2 Neuron XOR Network • Two inputs applied to both neurons • Both neurons have bias terms Roger S. Gaborski

  26. 2 Neuron XOR Network with BIAS w10 w20 w22 w11 w12 N1 N2 x2 Notation: wto, from W1,2 To neuron 1 From neuron 2 w21 x1 w1in1 w1in2 w2in2 w2in1 Iin1 Iin2 Roger S. Gaborski

  27. Weight Matrix w1in1 w1in2 w10 w11 w12 Iin1 input1 w2in1 w2in2w20 w21 w22 * Iin2 input2 1 bias x1 output N1 x2 output N2 Roger S. Gaborski

  28. No self connections (w11 , w22 )No recurrent feedback connections (w12) w10 w20 N1 N2 x2 Notation: wto, from W2,1 To neuron 2 From neuron 1 w21 x1 w1in1 w1in2 w2in2 w2in1 Iin1 Iin2 Roger S. Gaborski

  29. Weight Matrix – no self connections (w11 , w22 )no recurrent feedback connections (w12) w1in1 w1in2 w100 0 Iin1 input1 w2in1 w2in2w20 w210 * Iin2 input2 1 bias x1 output N1 x2 output N2 Roger S. Gaborski

  30. Weight Matrix Valuesno self connections (w11 , w22 )no recurrent feedback connections (w12) -2.19 -2.20 .139 0 0 Iin1 -2.81 -2.703.90 -31.8 0 * Iin2 1 x1 x2 ASSUME WE KNOW WEIGHT VALUES Roger S. Gaborski

  31. Non-linear Fuction, State Update -2.19 -2.20 .139 0 0 Iin1 -2.81 -2.703.90 -31.8 0 * Iin2 1 = x1 x1 x2 x2 tanh Roger S. Gaborski

  32. Example of first Neuron . [-2.19 -2.20 0.139 0 0] * In1 In2 1 x1 x2 Net1 = -2.19*In1 + -2.2*In2 + .139*1 + 0*x1 + 0*x2 Roger S. Gaborski

  33. Two Time Cycles Required • 1. Apply inputs, calculates update X vector. x1 is correct at this time, but x2 was calculated with x1=0. • 2. Update x1 and x2 • Apply same inputs second time, this time x2 is correct. • Output x2 Roger S. Gaborski

  34. Results for XOR For four pairs of inputs: Network Inputs– Targets 1 1 0 1 0 1 0 1 1 0 0 0 err1 = 0.0071066 Iin1 = 1 Iin2 = 1 x2out = 0.000319 err1 = 0.0071066 Iin1 = 1 Iin2 = 0 x2out = 0.995698 err1 = 0.0071066 Iin1 = 0 Iin2 = 1 x2out = 0.997514 err1 = 0.0071066 Iin1 = 0 Iin2 = 0 x2out = 2.54158e-038 Roger S. Gaborski

  35. What if I simply guessed the weights?? These weights work correctly: W = -2.1900 -2.2000 0.1390 0 0 -2.8100 -2.7000 3.9000 -31.8000 0 Need to keep zeros in proper positions so that we have valid net equation If we let W = abs(W) err1 = 2 Iin1 = 1 Iin2 = 1 x2out = 1 err1 = 2 Iin1 = 1 Iin2 = 0 x2out = 1 err1 = 2 Iin1 = 0 Iin2 = 1 x2out = 1 err1 = 2 Iin1 = 0 Iin2 = 0 x2out = 1 Roger S. Gaborski

  36. Randomly Create W Correct W = -2.1900 -2.2000 0.1390 0 0 -2.8100 -2.7000 3.9000 -31.8000 0 W = 3.9013 1.2085 0.4823 0 0 1.9487 2.0196 0.6599 4.7807 0 err1 = 2 Iin1 = 1 Iin2 = 1 x2out = 1 err1 = 2 Iin1 = 1 Iin2 = 0 x2out = 1 err1 = 2 Iin1 = 0 Iin2 = 1 x2out = 1 err1 = 2 Iin1 = 0 Iin2 = 0 x2out = 1 We Need a Smart Way to Find the Weight Values Roger S. Gaborski

  37. Stochastic Optimization • Algorithms that use some degree of randomness to find optimal, or nearly optimal solutions to difficult problems • Don’t know optimal solution • Don’t know how to find it • Random search is impossible (in a practical sense) because the search space is too large • You know the solution when you find it, so you can test candidate solutions Roger S. Gaborski

  38. Text Creation • A room full of monkeys with typewriters given enough time can write (create) …… (fill in the blank; the bible, a textbook, etc.) • How practical is this approach? • Assume text you want to create is as follows: • TODAY IS TUESDAY • Assume all uppercase characters, ignore spaces: • TODAYISTUESDAY • What is the probability a randomly created string of characters matches the phrase? • The are 14 characters in the phrase Roger S. Gaborski

  39. The first character typed can be any letter in the alphabet. • There is a 1 in 26 chance the first letter typed is a T • There is a 1 in 26 chance the second letter typed is an O • etc. • Probability the correct phase is typed is: p = 1/(26^14) = 1/6.451e19 Roger S. Gaborski

  40. What about the name ‘ROGER’ • Probability = 1/ 26.^5 = 1/11,881,376 • Consider two randomly generated words: • EDGTY • RPHER • The second string is closer than the first • The second string is correct 3 out of 5 characters, in the first string every character is incorrect Roger S. Gaborski

  41. One approach • Create a population of random vectors each containing 5 characters (Length of the phrase) • Compare each vector to the correct phrase (in this case ROGER) • Score each vector • Select the best scoring vector • Create a new population of vectors • For each entry in the new population mutate the previously chosen best scoring vector • Retain the best scoring vector in the population • Select the new best scoring vector and repeat Roger S. Gaborski

  42. Mutation • mutationRate: probability a particular character is mutated • mRadius: The amount an individual character can be incremented or decremented - if mRadius is 2, the character can be increased or decreased by ‘two characters’, for example: • If original character is D and mRadius is 2, the resulting character is either B or F, depending if you increment or decrement the character. The increment/decrement is a random decision Roger S. Gaborski

  43. MATLAB conversions character string to uint8 name = uint8('ROGER') name =82 79 71 69 82 name is of type uint8 name(2) = 79 convert to type double: Q1 = double(name) Q1 =82 79 71 69 82 Convert back to type character: W1 = char(Q1) W1 =ROGER whos Q1 W1 Name Size Bytes Class Attributes Q1 1x5 40 double W1 1x5 10 char Roger S. Gaborski

  44. Q2 = double('ROGER') Q2 =82 79 71 69 82 Q3 = double('DDGER') Q3 =68 68 71 69 82 differ = abs(Q2-Q3) differ =14 11 0 0 0 differ_sum = sum(abs(Q2-Q3)) differ_sum =25 Roger S. Gaborski

  45. Create Random Character Data data1 = floor(rand(1,5)*26)+65 data1 =80 79 68 87 81 Convert to char string cdata =char(data1) cdata =PODWQ display characters: disp(char(data1)) PODWQ Roger S. Gaborski

  46. Best Parent Retained in New Population mutationRate = .25; %Probability an individual character in the phrase will be mutatedmRadius = 3; %Individual character in phrase can increment or decrement by m_radius Objective Phrase (op) is ROGER The original bestParent = VLGDO, with a score of 7 Count = 1 The bestParent = TOGDO, with a score of 2.8 Count = 2 The bestParent = TOGDP, with a score of 1.8 Count = 3 The bestParent = ROGDP, with a score of 1 Count = 4 The bestParent = ROGDQ, with a score of 0.4 Count = 5 The bestParent = ROGDR, with a score of 0.2 Count = 6 The bestParent = ROGDR, with a score of 0.2 Count = 7 The bestParent = ROGER, with a score of 0 Roger S. Gaborski

  47. Keep an original copy of the ‘best parent’ in the mutated list so that the performance is monotonic (error will not go up). Roger S. Gaborski

  48. ‘ROGER’ Roger S. Gaborski

  49. op =PROFESSORROGERGABORSKI Roger S. Gaborski

  50. ‘PROFESSORROGERGABORSKI’ The original bestParent = HQJOAQRPOYKCBVUCGSQEGV, with a score of 42.3182 Count = 1 The bestParent = HQKOAQTMOVKCBVRAGRREGV, with a score of 36.5909 Count = 2 The bestParent = HQIOAQTMPVKCBVQBDRRGGV, with a score of 33.0455 Count = 3 The bestParent = HQILAQTPPVICBVQBDRRGGS, with a score of 28.6364 Count = 4 The bestParent = HSILAQTPSVIDBVOBERRIGP, with a score of 22.4545 Count = 5 The bestParent = KTILFPTPSVLDBVOBERRIGP, with a score of 19.1364 Count = 6 The bestParent = JTILDPTPSVLEBVLCERRLGP, with a score of 15.4545 Count = 7 The bestParent = JTLIDPTPSVLFBVLCEQRLGP, with a score of 12.6364 Count = 8 The bestParent = JTLIDPTPPTLFDVLCCQRLIP, with a score of 10.9545 Count = 9 The bestParent = JTMFDPTPPTLFDVJCCQRLIM, with a score of 8.09091 Count = 10 The bestParent = JQMFDPTPPTOFDVJCCPRMIM, with a score of 6.81818 Count = 11 The bestParent = JPMDDPTPPTOFDVJCCPRPIM, with a score of 5.90909 Count = 12 The bestParent = JPMDDPTPPTOFFTJDCPRPHJ, with a score of 5.13636 Count = 13 The bestParent = MPMDDPTPRTOFFSJDCMRPHJ, with a score of 3.72727 Count = 14 The bestParent = MPMDDPTNRTOFFSJACMRSHJ, with a score of 2.90909 Count = 15 The bestParent = MPMDDPTNTUOFFSGACMRSJJ, with a score of 2.54545 Roger S. Gaborski

More Related