Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Temporal Pooling inspired by cortical layers 4 & 2/3
class layer4 {
constructor(){
this.distal = [
// X,A,B,C,D,Y
[0,0,0,0,0,0], // X
[0,0,0,0,0,0], // A
[1,1,0,0,0,0], // B
[0,0,1,0,0,0], // C
[0,0,0,1,0,0], // D
[0,0,0,1,0,0] // Y
]
this.apical = [
// N,K
[0,1], // X
[1,0], // A
[1,1], // B
[1,1], // C
[1,0], // D
[0,1] // Y
]
}
compute(l4,l3){
var apical = this.apical, distal = this.distal
// sum up all inputs by their weights
var sum = new Array(distal.length).fill(0)
for(var i = 0; i < l4.length; i++)
for(var j = 0; j < distal[i].length; j++)
for(var k = 0; k < l3.length; k++)
sum[i] += l4[j] * distal[i][j] * l3[k] * apical[i][k]
// binary output with only max equal to 1
var y = new Array(distal.length).fill(0)
y[sum.indexOf(Math.max(...sum))] = 1
return y
}
}
class layer3 {
constructor(){
this.proximal = [
// X,A,B,C,D,Y
[0,4,3,2,1,0], // N
[4,0,3,2,0,1] // K
]
}
compute(l4,l3){
var proximal = this.proximal
var y = new Array(proximal.length).fill(0)
for(var i = 0; i < proximal.length; i++)
for(var j = 0; j < proximal[i].length; j++)
y[i] += (l3[i] * (10 / proximal[i].length)) + (l4[j] * proximal[i][j])
return y.map(n => parseInt(n))
}
}
// Main
function run(fom,tp){
console.log('fom: ',JSON.stringify(fom))
for(var i = 0; i < 3; i++){
tp = l3.compute(fom,tp)
fom = l4.compute(fom,tp)
console.log('tp: ',JSON.stringify(tp))
console.log('fom: ',JSON.stringify(fom))
}
}
var l3 = new layer3()
var l4 = new layer4()
console.log('ABCD')
run([0,1,0,0,0,0],[0,0])
console.log('XBCY')
run([1,0,0,0,0,0],[0,0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment