# #Paul Boersma and Zackary Gibson (2020) # form Sweep categories in a deep-belief network integer Number_of_data 0 (= input sweep) choice experiment: 3 button broad condition button narrow condition button narrow condition with congruent labels button narrow condition with single label button narrow condition with random label endform numberOfInputNodes = 42 numberOfMiddleNodes = 50 numberOfOutputNodes = 40 sigma = 1.0 peakWidth = 1.5 learningRate = 0.001 edge = 2 numberOfMeanFieldEchoes = 10 numberOfGibbsEchoes = 10 semf.offsetNode = 0 numberOfLegs = 2 legMean [1] = 2.5 legMean [2] = 8.5 numberOfTails = 2 tailMean [1] = 12.5 tailMean [2] = 18.5 numberOfNecks = 2 neckMean [1] = 22.5 neckMean [2] = 28.5 numberOfEars = 2 earMean [1] = 32.5 earMean [2] = 38.5 numberOfLabels = 2 meanLabel [1] = 41.0 meanLabel [2] = 42.0 x# = zero# (numberOfInputNodes) y# = zero# (numberOfMiddleNodes) z# = zero# (numberOfOutputNodes) a# = x# b# = y# c# = z# u## = zero## (numberOfInputNodes, numberOfMiddleNodes) v## = zero## (numberOfMiddleNodes, numberOfOutputNodes) # # Spread up # procedure setFourInputs: .formantLegs, .formantTails, .formantNecks, .formantEars x# ~ if col >=1 and col <=10 then 5 * exp (-0.5 * ((col - .formantLegs) / peakWidth) ^ 2) - 0.5 else self fi x# ~ if col >=11 and col <=20 then 5 * exp (-0.5 * ((col - .formantTails) / peakWidth) ^ 2) - 0.5 else self fi x# ~ if col >=21 and col <=30 then 5 * exp (-0.5 * ((col - .formantNecks) / peakWidth) ^ 2) - 0.5 else self fi x# ~ if col >=31 and col <=40 then 5 * exp (-0.5 * ((col - .formantEars) / peakWidth) ^ 2) - 0.5 else self fi endproc procedure setFiveInputs: .formantLegs, .formantTails, .formantNecks, .formantEars, .label x# ~ if col >=1 and col <=10 then 5 * exp (-0.5 * ((col - .formantLegs) / peakWidth) ^ 2) - 0.5 else self fi x# ~ if col >=11 and col <=20 then 5 * exp (-0.5 * ((col - .formantTails) / peakWidth) ^ 2) - 0.5 else self fi x# ~ if col >=21 and col <=30 then 5 * exp (-0.5 * ((col - .formantNecks) / peakWidth) ^ 2) - 0.5 else self fi x# ~ if col >=31 and col <=40 then 5 * exp (-0.5 * ((col - .formantEars) / peakWidth) ^ 2) - 0.5 else self fi x# [41] = 0 x# [42] = 0 x# [.label] = 5 endproc procedure spreadUp # GBC2016: 661 z# = zero# (numberOfOutputNodes) ; or to random values for iecho to numberOfMeanFieldEchoes y# = sigmoid# (mul# (x#, u##) + mul# (v##, z#) + b#) z# = sigmoid# (mul# (y#, v##) + c#) endfor endproc procedure resonate for iecho to numberOfGibbsEchoes x# = mul# (u##, y#) + a# z# = randomBernoulli# (sigmoid# (mul# (y#, v##) + c#)) y# = randomBernoulli# (sigmoid# (mul# (x#, u##) + mul# (v##, z#) + b#)) endfor endproc procedure hebbianLearning: .learningRate a# += .learningRate * x# b# += .learningRate * y# c# += .learningRate * z# u## += .learningRate * outer## (x#, y#) v## += .learningRate * outer## (y#, z#) endproc procedure antiHebbianLearning: .learningRate @hebbianLearning: - .learningRate endproc Erase all Font size: 10 oversampling = 10 numberOfTimes = (numberOfInputNodes - 5) * oversampling + 1 image = Create simple Matrix: "inputImage", numberOfInputNodes, numberOfTimes, "0" procedure drawImage Select outer viewport: 0, 3.7, 0, 2.5 selectObject: image Paint image: 0, 0, 0, 0, 0, 0 One mark left: 1, "yes", "yes", "no", "" Marks left every: 1, 5, "yes", "yes", "no" if number_of_data = 300 White endif Select outer viewport: 0.1, 3.3, 0.1, 2.4 Text bottom: "yes", "Time \->" Black Text left: "yes", "Input node \->" Select outer viewport: 0.1, 3.3, 0.3, 2.4 Remove endproc if number_of_data = 0 for itime to numberOfTimes formant = 1 + edge + (itime - 1) / oversampling @spreadUp: formant selectObject: image Formula: ~ if col = itime then x# [row] else self fi endfor @drawImage exitScript () endif # # Train the network. # if experiment = 1 for ipattern to number_of_data legs = randomInteger (1, 2) tails = randomInteger (1, 2) necks = if tails = 1 then 2 else 1 fi ears = if legs = 1 then 2 else 1 fi formantLegs = randomGauss (legMean [legs], sigma) formantTails = randomGauss (tailMean [tails], sigma) formantNecks = randomGauss (neckMean [necks], sigma) formantEars = randomGauss (earMean [ears], sigma) @setFourInputs: formantLegs, formantTails, formantNecks, formantEars @spreadUp @hebbianLearning: learningRate @resonate @antiHebbianLearning: learningRate endfor endif if experiment = 2 for ipattern to number_of_data legs = randomInteger (1, 2) tails = if legs = 1 then 1 else 2 fi necks = if legs = 1 then 1 else 2 fi ears = if legs = 1 then 1 else 2 fi formantLegs = randomGauss (legMean [legs], sigma) formantTails = randomGauss (tailMean [tails], sigma) formantNecks = randomGauss (neckMean [necks], sigma) formantEars = randomGauss (earMean [ears], sigma) @setFourInputs: formantLegs, formantTails, formantNecks, formantEars @spreadUp @hebbianLearning: learningRate @resonate @antiHebbianLearning: learningRate endfor endif if experiment = 3 for ipattern to number_of_data legs = randomInteger (1, 2) tails = if legs = 1 then 1 else 2 fi necks = if legs = 1 then 1 else 2 fi ears = if legs = 1 then 1 else 2 fi formantLegs = randomGauss (legMean [legs], sigma) formantTails = randomGauss (tailMean [tails], sigma) formantNecks = randomGauss (neckMean [necks], sigma) formantEars = randomGauss (earMean [ears], sigma) formantCongruentLabel = if legs = 1 then meanLabel [1] else meanLabel [2] fi @setFiveInputs: formantLegs, formantTails, formantNecks, formantEars, formantCongruentLabel @spreadUp @hebbianLearning: learningRate @resonate @antiHebbianLearning: learningRate endfor endif if experiment = 4 for ipattern to number_of_data legs = randomInteger (1, 2) tails = if legs = 1 then 1 else 2 fi necks = if legs = 1 then 1 else 2 fi ears = if legs = 1 then 1 else 2 fi formantLegs = randomGauss (legMean [legs], sigma) formantTails = randomGauss (tailMean [tails], sigma) formantNecks = randomGauss (neckMean [necks], sigma) formantEars = randomGauss (earMean [ears], sigma) formantSingleLabel = meanLabel [1] @setFiveInputs: formantLegs, formantTails, formantNecks, formantEars, formantSingleLabel @spreadUp @hebbianLearning: learningRate @resonate @antiHebbianLearning: learningRate endfor endif if experiment = 5 for ipattern to number_of_data legs = randomInteger (1, 2) tails = if legs = 1 then 1 else 2 fi necks = if legs = 1 then 1 else 2 fi ears = if legs = 1 then 1 else 2 fi formantLegs = randomGauss (legMean [legs], sigma) formantTails = randomGauss (tailMean [tails], sigma) formantNecks = randomGauss (neckMean [necks], sigma) formantEars = randomGauss (earMean [ears], sigma) formantRandomLabel = randomInteger (41.0, 42.0) @setFiveInputs: formantLegs, formantTails, formantNecks, formantEars, formantRandomLabel @spreadUp @hebbianLearning: learningRate @resonate @antiHebbianLearning: learningRate endfor endif # # Test the network. # for itime to numberOfTimes # #initializing x # formant = 1 + (itime - 1) / (numberOfTimes - 1) * (numberOfInputNodes - 1) x# ~ 5* exp (-0.5 * ((col - formant) / peakWidth) ^ 2) - 0.5 @spreadUp # # resonate deterministically (opposite of stochastically (random)) # each bump is a small input sample which activates all other relevant nodes (correlated inut nodes) and mid-level and output nodes # creates protoypical inputs and extrapolates from that # for iecho to numberOfGibbsEchoes x# = mul# (u##, y#) + a# z# = sigmoid# (mul# (y#, v##) + c#) y# = sigmoid# (mul# (x#, u##) + mul# (v##, z#) + b#) endfor selectObject: image Formula: ~ if col = itime then x# [row] else self fi endfor @drawImage