SOMPY icon indicating copy to clipboard operation
SOMPY copied to clipboard

visualisation not available

Open ldocao opened this issue 9 years ago • 5 comments

I installed the sompy package successfully and I was able to run the following code (http://nbviewer.jupyter.org/gist/sevamoo/ec0eb28229304f4575085397138ba5b1) until the training step included:

import matplotlib.pylab as plt
import pandas as pd
import numpy as np
from time import time
import sys
import sompy

### A toy example: two dimensional data, four clusters

dlen = 200
Data1 = pd.DataFrame(data= 1*np.random.rand(dlen,2))
Data1.values[:,1] = (Data1.values[:,0][:,np.newaxis] + .42*np.random.rand(dlen,1))[:,0]


Data2 = pd.DataFrame(data= 1*np.random.rand(dlen,2)+1)
Data2.values[:,1] = (-1*Data2.values[:,0][:,np.newaxis] + .62*np.random.rand(dlen,1))[:,0]

Data3 = pd.DataFrame(data= 1*np.random.rand(dlen,2)+2)
Data3.values[:,1] = (.5*Data3.values[:,0][:,np.newaxis] + 1*np.random.rand(dlen,1))[:,0]


Data4 = pd.DataFrame(data= 1*np.random.rand(dlen,2)+3.5)
Data4.values[:,1] = (-.1*Data4.values[:,0][:,np.newaxis] + .5*np.random.rand(dlen,1))[:,0]


Data1 = np.concatenate((Data1,Data2,Data3,Data4))

fig = plt.figure()
plt.plot(Data1[:,0],Data1[:,1],'ob',alpha=0.2, markersize=4)
fig.set_size_inches(7,7)

mapsize = [20,20]
som = sompy.SOMFactory.build(Data1, mapsize, mask=None, mapshape='planar', lattice='rect', normalization='var', initialization='pca', neighborhood='gaussian', training='batch', name='sompy')  # this will use the default parameters, but i can change the initialization and neighborhood methods
som.train(n_job=1, verbose='info')

However the next step doesn't work, the visualization tools are not accessible:

v = sompy.mapview.View2DPacked(50, 50, 'test',text_size=8)  
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-33-cf58d4047cc8> in <module>()
----> 1 v = sompy.mapview.View2DPacked(50, 50, 'test', text_size=8)

AttributeError: 'module' object has no attribute 'mapview'

I'm using

$ python --version
Python 3.4.4 :: Anaconda 2.3.0 (x86_64)

ldocao avatar Jul 04 '16 07:07 ldocao

Hi @EricSchles
Do you have any idea about this. I think this happened after the update to Python 3. Thanks Vahid

sevamoo avatar Jul 04 '16 08:07 sevamoo

@sebastiandev Any idea? What I see is that the dependencies between visualization and main folder has changed. I didn't figure it out unfortunately. But I think here is the main issue: https://github.com/sevamoo/SOMPY/pull/21/commits/f44ff75ff2fb93de7314b9e05997471ea5cc3fc6 Thanks a lot.

sevamoo avatar Jul 13 '16 21:07 sevamoo

Looks like it was changed on a previous pull request. Visualizations should live inside the sompy package and imported in init.py if you want to make all viz available directly by their module name.

@EricSchles also check that there are binary files uploaded that shouldn't be there, files like *.py~ and folders like pycache. You can add them to .gitignore so it wont happen again.

sebastiandev avatar Jul 13 '16 22:07 sebastiandev

Thanks a lot @sebastiandev I followed your points. Now it works, but not sure regarding the setup.py now. @ldocao could you please, check now with the new version?

sevamoo avatar Jul 14 '16 08:07 sevamoo

from sompy.visualization.hitmap import HitMapView This is how im importing my graphs and will use it as v = HitMapView(....) I believe you have to add .visualization

businessglitch avatar Nov 02 '18 00:11 businessglitch