def test_train(self): """ Test forward computation """ layer = SpatialPooler(4, learning_rate=0.1, pool_density=1, boost_strength=0) x = tf.placeholder(tf.float32, [None, 4], name='Input') layer.build([1, 4]) train = layer.train(x, tf.constant([[0., 1, 0, 1]])) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) # Override permenance with a custom value sess.run( tf.assign(layer.permanence, [[0.6, 0, 0.6, 0.6], [0, 0.6, 0, 0], [0.6, 0.6, 0.6, 0], [0, 0, 0.6, 0.6]])) # Compute result = sess.run(train, {x: [[1, 1, 0, 1]]}) # Check the new permenance test.assert_allclose(result[0], [[0.6, 0, 0.6, 0.7], [0, 0.7, 0, 0], [0.6, 0.5, 0.6, 0], [0, 0, 0.6, 0.7]])
def __init__(self): pooler = SpatialPooler(htm_units, lr=1e-2) # Model input self.x = tf.placeholder(tf.float32, [None, input_units]) self.y = pooler(self.x) self.train_ops = pooler.train_ops cluster = RecruitmentLayer(htm_units, num_clusters=6) self.x1 = tf.placeholder(tf.float32, [1, htm_units]) self.y1 = cluster(self.x1) self.recruitment_train_ops = cluster.train_ops
def __init__(self): pooler = SpatialPooler(htm_units, lr=1e-2) # Model input self.x = tf.placeholder(tf.float32, [None, input_units]) self.y = pooler(self.x) self.train_ops = pooler.train_ops # Build classifier classifier_in = Input((htm_units, )) classifier_out = Dense(num_classes, activation='softmax')(classifier_in) self.classifier = Model(classifier_in, classifier_out) self.classifier.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])
def __init__(self, input_units, sp_units, clusters): self.input_units = input_units self.sp_units = sp_units self.clusters = clusters self.pooler = SpatialPooler(sp_units, lr=1e-2) # Model input self.x = tf.placeholder(tf.float32, [None, input_units]) self.y = self.pooler(self.x) self.train_ops = self.pooler.train_ops cluster = RecruitmentLayer(sp_units, num_clusters=clusters) self.x1 = tf.placeholder(tf.float32, [1, sp_units]) self.y1 = cluster(self.x1) self.recruitment_train_ops = cluster.train_ops
def test_call(self): """ Test forward computation """ layer = SpatialPooler(4, pool_density=1, boost_strength=0) x = tf.placeholder(tf.float32, [None, 4], name='Input') y = layer(x) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) # Override permenance with a custom value sess.run( tf.assign( layer.permanence, [[1, 0, 1, 1], [0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 1, 1]])) # Compute result = sess.run(y, {x: [[1, 1, 0, 1], [1, 1, 0, 0]]}) test.assert_array_equal(result[0], [0, 0, 1, 0])
def __init__(self): pooler = SpatialPooler(htm_units, lr=1e-2) # Model input self.x = tf.placeholder(tf.float32, [None, input_units]) self.y = pooler(self.x) self.train_ops = pooler.train_ops