Created
December 18, 2017 04:56
-
-
Save avgprog/7bfdf1340b37d83f84dcabb8afb91559 to your computer and use it in GitHub Desktop.
Tensorflow SOM implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# In[1]: | |
from tensorflow.examples.tutorials.mnist import input_data | |
# In[2]: | |
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) | |
# In[3]: | |
import tensorflow as tf | |
# In[9]: | |
x = tf.placeholder(tf.float32, [1,784]) | |
# In[10]: | |
weights = tf.Variable(tf.zeros([10,784])) | |
# In[16]: | |
closest_weight_index = tf.argmin(tf.reduce_mean(tf.squared_difference(x,weights),axis=1)) | |
# In[12]: | |
learning_rate = tf.constant(0.5) | |
# In[20]: | |
weights = tf.concat(axis=0, values=[weights[:closest_weight_index], weights[closest_weight_index] + learning_rate*(x-weights[closest_weight_index]), weights[closest_weight_index+1:]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Work in progress