Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ttlg committed Jul 8, 2016
1 parent 4ad0626 commit 42d9698
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
17 changes: 16 additions & 1 deletion README.md
@@ -1,10 +1,25 @@
# sompy
numpy based SOM (Self Organizing Map) Library
a numpy based SOM (Self Organizing Map) Library


## Description

### Demo
from sompy import SOM
import numpy as np
import matplotlib.pyplot as plt


input_data = np.random.rand(10000, 3)
output_shape = (40, 40)
som = SOM(output_shape, input_data)
som.set_parameter(neighbor=0.1, learning_rate=0.2)

output_map = som.train(10000)

plt.imshow(output_map,
interpolation='none')
plt.show()
![alt tag](https://github.com/ttlg/sompy/blob/master/examples/sample_color.png)

## Requirement
Expand Down
15 changes: 6 additions & 9 deletions examples/sample_color.py
@@ -1,18 +1,15 @@
import numpy as np
from sompy import SOM
import numpy as np
import matplotlib.pyplot as plt


N = 40

input_layer = np.random.rand(10000, 3)
output_shape = (N, N)

som = SOM(output_shape, input_layer)
input_data = np.random.rand(10000, 3)
output_shape = (40, 40)
som = SOM(output_shape, input_data)
som.set_parameter(neighbor=0.1, learning_rate=0.2)

output_layer = som.train(10000)
output_map = som.train(10000)

plt.imshow(output_layer,
plt.imshow(output_map,
interpolation='none')
plt.show()
6 changes: 4 additions & 2 deletions sompy/sompy.py
Expand Up @@ -66,8 +66,10 @@ def _neighbourhood(self, t):
initial = max(self.shape) * self._param_neighbor
return initial*np.exp(-t/self._life)

def train(self, n):
for i in range(n):
def train(self, iterate=None):
if not iterate:
iterate = self.input_num
for i in range(iterate):
r = rand.randint(0, self.input_num)
data = self.input_layer[r]
win_idx = self._get_winner_node(data)
Expand Down

0 comments on commit 42d9698

Please sign in to comment.