Skip to content

Instantly share code, notes, and snippets.

@avgprog
Created December 18, 2017 04:56
Show Gist options
  • Save avgprog/7bfdf1340b37d83f84dcabb8afb91559 to your computer and use it in GitHub Desktop.
Save avgprog/7bfdf1340b37d83f84dcabb8afb91559 to your computer and use it in GitHub Desktop.
Tensorflow SOM implementation
# 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:]])
@avgprog
Copy link
Author

avgprog commented Dec 18, 2017

Work in progress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment