Coder Social home page Coder Social logo

peterwittek / somoclu Goto Github PK

View Code? Open in Web Editor NEW
263.0 28.0 67.0 3.92 MB

Massively parallel self-organizing maps: accelerate training on multicore CPUs, GPUs, and clusters

Home Page: https://peterwittek.github.io/somoclu/

License: MIT License

Shell 0.25% C++ 27.06% MATLAB 4.38% Python 15.22% R 2.44% C 37.64% Cuda 5.27% Batchfile 0.05% Makefile 4.29% M4 3.00% SWIG 0.40%

somoclu's Introduction

Somoclu

Ubuntu2004 Ubuntu2004-R

Somoclu is a massively parallel implementation of self-organizing maps. It exploits multicore CPUs, it is able to rely on MPI for distributing the workload in a cluster, and it can be accelerated by CUDA. A sparse kernel is also included, which is useful for training maps on vector spaces generated in text mining processes.

Key features:

  • Fast execution by parallelization: OpenMP, MPI, and CUDA are supported.
  • Multi-platform: Linux, macOS, and Windows are supported.
  • Planar and toroid maps.
  • Rectangular and hexagonal grids.
  • Gaussian and bubble neighborhood functions.
  • Both dense and sparse input data are supported.
  • Large maps of several hundred thousand neurons are feasible.
  • Integration with Databionic ESOM Tools.
  • Python, R, Julia, and MATLAB interfaces for the dense CPU and GPU kernels.

For more information, refer to the manuscript about the library [1].

Usage

Basic Command Line Use

Somoclu takes a plain text input file -- either dense or sparse data. Example files are included.

$ [mpirun -np NPROC] somoclu [OPTIONs] INPUT_FILE OUTPUT_PREFIX

Arguments:

-c FILENAME              Specify an initial codebook for the map.
-d NUMBER                Coefficient in the Gaussian neighborhood function
                         exp(-||x-y||^2/(2*(coeff*radius)^2)) (default: 0.5)
-e NUMBER                Maximum number of epochs
-g TYPE                  Grid type: square or hexagonal (default: square)
-h, --help               This help text
-k NUMBER                Kernel type
                            0: Dense CPU
                            1: Dense GPU
                            2: Sparse CPU
-l NUMBER                Starting learning rate (default: 0.1)
-L NUMBER                Finishing learning rate (default: 0.01)
-m TYPE                  Map type: planar or toroid (default: planar)
-n FUNCTION              Neighborhood function (bubble or gaussian, default: gaussian)
-p NUMBER                Compact support for Gaussian neighborhood
                         (0: false, 1: true, default: 0)
-r NUMBER                Start radius (default: half of the map in direction min(x,y))
-R NUMBER                End radius (default: 1)
-s NUMBER                Save interim files (default: 0):
                            0: Do not save interim files
                            1: Save U-matrix only
                            2: Also save codebook and best matching
-t STRATEGY              Radius cooling strategy: linear or exponential (default: linear)
-T STRATEGY              Learning rate cooling strategy: linear or exponential (default: linear)
-v NUMBER                Verbosity level, 0-2 (default: 0)
-x, --columns NUMBER     Number of columns in map (size of SOM in direction x)
-y, --rows    NUMBER     Number of rows in map (size of SOM in direction y)

Examples:

$ somoclu data/rgbs.txt data/rgbs
$ mpirun -np 4 somoclu -k 0 --rows 20 --columns 20 data/rgbs.txt data/rgbs

With random initialization, the initial codebook will be filled with random numbers ranging from 0 to 1. Either supply your own initial codebook or normalize your data to fall in this range.

If the range of the values of the features includes negative numbers, the codebook will eventually adjust. It is, however, not advised to have negative values, especially if the codebook is initialized from 0 to 1. This comes from the batch training nature of the parallel implementation. The batch update rule will change the codebook values with weighted averages of the data points, and with negative values, the updates can cancel out.

The maps generated by the GPU and the CPU kernels are likely to be different. For computational efficiency, Somoclu uses single-precision floats. This occasionally results in identical distances between a data instance and the neurons. The CPU version will pick the best matching unit with the lowest coordinate values. Such sequentiality cannot be guaranteed in the reduction kernel of the GPU variant. This is not a bug, but it is better to be aware of it.

Efficient Parallel and Distributed Execution

The CPU kernels use OpenMP to load multicore processors. On a single node, this is more efficient than launching tasks with MPI to match the number of cores. The MPI tasks replicated the codebook, which is especially inefficient for large maps.

For instance, given a single node with eight cores, the following execution will use 1/8th of the memory, and will run 10-20% faster:

$ somoclu -x 200 -y 200 data/rgbs.txt data/rgbs

Or, equivalently:

$ OMP_NUM_THREADS=8 somoclu -x 200 -y 200 data/rgbs.txt data/rgbs

Avoid the following on a single node:

$ OMP_NUM_THREADS=1 mpirun -np 8 somoclu -x 200 -y 200 data/rgbs.txt data/rgbs

The same caveats apply for the sparse CPU kernel.

Visualisation

The primary purpose of generating a map is visualisation. Apart from the Python interface, Somoclu does not come with its own functions for visualisation, since there are numerous generic tools that are capable of plotting high-quality figures. The R version integrates with kohonen and the MATLAB version with somtoolbox.

The output formats U-matrix and the codebook of the command-line version are compatible with Databionic ESOM Tools for more advanced visualisation.

Input File Formats

One sparse and two dense data formats are supported. All of them are plain text files. The entries can be separated by any white-space character. One row represents one data instance across all formats. Comment lines starting with a hash mark are ignored.

The sparse format follows the libsvm guidelines. The first feature is zero-indexed. For instance, the vector [ 1.2 0 0 3.4] is represented as the following line in the file: 0:1.2 3:3.4. The file is parsed twice: once to get the number of instances and features, and the second time to read the data in the individual threads.

The basic dense format includes the coordinates of the data vectors, separated by a white-space. Just like the sparse format, this file is parsed twice to get the basic dimensions right.

The .lrn file of Databionic ESOM Tools is also accepted and it is parsed only once. The format is described as follows:

% n

% m

% s1 s2 .. sm

% var_name1 var_name2 .. var_namem

x11 x12 .. x1m

x21 x22 .. x2m

. . . .

. . . .

xn1 xn2 .. xnm

Here n is the number of rows in the file, that is, the number of data instances. Parameter m defines the number of columns in the file. The next row defines the column mask: the value 1 for a column means the column should be used in the training. Note that the first column in this format is always a unique key, so this should have the value 9 in the column mask. The row with the variable names is ignore by Somoclu. The elements of the matrix follow -- from here, the file is identical to the basic dense format, with the addition of the first column as the unique key.

If the input file is sparse, but a dense kernel is invoked, Somoclu will execute and results will be incorrect. Invoking a sparse kernel on a dense input file is likely to lead to a segmentation fault.

Interfaces

Python, Julia, R, and MATLAB interfaces are available for the dense CPU and GPU kernels. MPI and the sparse kernel are not support through the interfaces. For respective examples, see the folders in src.

The Python version is also available in PyPI. You can install it with

$ pip install somoclu

Alternatively, it is also available on conda-forge:

$ conda install somoclu

Some pre-built binaries in the wheel format or Windows installer are provided at PyPI Dowloads, they are tested with Anaconda distributions. If you encounter errors like ImportError: DLL load failed: The specified module could not be found when import somoclu, you may need to use Dependency Walker as shown here on _somoclu_wrap.pyd to find out missing DLLs and place them at the write place. Usually right version (32/64bit) of vcomp90.dll, msvcp90.dll, msvcr90.dll should be put to C:\Windows\System32 or C:\Windows\SysWOW64.

The wheel binaries for macOS are compiled with the system clang++, which means by default it is not parallelized. To use the parallel version on Mac, you can either use the version in conda-forge or compile it from source with your favourite OpenMP-friendly compiler. To get it working with the GPU kernel, you might have to follow the instructions at the Somoclu - Python Interface.

The R version is available on CRAN. You can install it with

install.packages("Rsomoclu")

To get it working with the GPU kernel, download the source zip file and specify your CUDA directory the following way:

R CMD INSTALL src/Rsomoclu_version.tar.gz --configure-args=/path/to/cuda

The Julia version is available on GitHub. The standard Pkg.add("Somoclu") should work.

For using the MATLAB toolbox, install SOM-Toolbox following the instructions at ilarinieminen/SOM-Toolbox and define the location of your MATLAB install to the configure script:

./configure --without-mpi --with-matlab=/usr/local/MATLAB/R2014a

For the GPU kernel, specify the location of your CUDA library for the configure script. More detailed instructions are in the MATLAB source folder.

Compilation & Installation

These are the instructions for compiling the core library and the command line interface. The only dependency is a C++ compiler chain -- GCC, ICC, clang, and VC were tested.

Multicore execution is supported through OpenMP -- the compiler must support this. Distributed systems are supported through MPI. The package was tested with OpenMPI. It should also work with other MPI flavours. CUDA support is optional.

Linux or macOS

If you have just cloned the git repository first run

$ ./autogen.sh

Then follow the standard POSIX procedure:

$ ./configure [options]
$ make
$ make install

Options for configure

--prefix=PATH           Set directory prefix for installation

By default Somoclu is installed into /usr/local. If you prefer a different location, use this option to select an installation directory.

--without-mpi           Disregard any MPI installation found.
--with-mpi=MPIROOT      Use MPI root directory.
--with-mpi-compilers=DIR or --with-mpi-compilers=yes
                          use MPI compiler (mpicxx) found in directory DIR, or
                          in your PATH if =yes
--with-mpi-libs="LIBS"  MPI libraries [default "-lmpi"]
--with-mpi-incdir=DIR   MPI include directory [default MPIROOT/include]
--with-mpi-libdir=DIR   MPI library directory [default MPIROOT/lib]

The above flags allow the identification of the correct MPI library the user wishes to use. The flags are especially useful if MPI is installed in a non-standard location, or when multiple MPI libraries are available.

--with-cuda=/path/to/cuda           Set path for CUDA

Somoclu looks for CUDA in /usr/local/cuda. If your installation is not there, then specify the path with this parameter. If you do not want CUDA enabled, set the parameter to --without-cuda.

Windows

Use the somoclu.sln under src/Windows/somoclu as an example Visual Studio 2015 solution. Modify the CUDA version or VC compiler version according to your needs.

The default solution enables all of OpenMP, MPI, and CUDA. The default MPI installation path is C:\Program Files (x86)\Microsoft SDKs\MPI\, modify the settings if yours is in a different path. The configuration default CUDA version is 9.1. Disable MPI by removing HAVE_MPI macro in the project properties (Properties -> Configuration Properties -> C/C++ -> Preprocessor). Disable CUDA by removing CUDA macro in the solution properties and uncheck CUDA in Project -> Custom Build Rules. If you open the solution without CUDA installed, please remove the following sections in somoclu.vcxproj:

  <ImportGroup Label="ExtensionSettings">
    <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 9.1.props" />
  </ImportGroup>

and

  <ImportGroup Label="ExtensionTargets">
    <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 9.1.targets" />
  </ImportGroup>

or change the version number according to which you installed.

The usage is identical to the Linux version through command line (see the relevant section).

Acknowledgment

This work was supported by the European Commission Seventh Framework Programme under Grant Agreement Number FP7-601138 PERICLES and by the AWS in Education Machine Learning Grant award.

Citation

  1. Peter Wittek, Shi Chao Gao, Ik Soo Lim, Li Zhao (2017). Somoclu: An Efficient Parallel Library for Self-Organizing Maps. Journal of Statistical Software, 78(9), pp.1--21. DOI:10.18637/jss.v078.i09. arXiv:1305.1422.

somoclu's People

Contributors

achapkowski avatar giacomolanciano avatar hellwue avatar jp-1992 avatar kurceliana avatar lucacalderaro avatar mattwenham avatar oliviaguest avatar peterwittek avatar sambitdash avatar standfest avatar tomcucinotta avatar xgdgsc avatar yao531441 avatar yoch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

somoclu's Issues

training function cannot be imported

Hello,
I am using 64 bit Python 2.7.10 in Windows 10.
I installed somoclu by typing pip install somoclu in cmd.
It installed without any error message.
I typed import somoclu
The prompt gave warning: Warning: training function cannot be imported. Only pre-trained maps can be analyzed.

I found a bug report but it talks only about IOS and Ubuntu, so not sure as to what I need to do in my case to resolve the issue.

Neighborhood Function Selection

Could you allow for user selection of neighborhood function beyond Gaussian? I would like the option of bubble but there are other functions that different users may prefer.

Thanks for the great work!

Batch training vs online training

Is there any way to update the SOM after a single pattern is a presented? I tried to send a pattern set with only a single member but I get the following error because presumably it needs more than a single pattern:

  File "/somoclu/train.py", line 224, in update_data
    self.n_vectors, self.n_dim = data.shape
ValueError: need more than 1 value to unpack

Is there an easy way around this I am missing? Shall I just edit the function to allow a single pattern or will that break other things?

MATLAB interface integration with som toolbox

Codebook integration is fine, but som_umat() in som toolbox return different size umatrix compared with somoclu/Databionic ESOM Tools, there seem to be conceptual differences that need to be sorted out and enhance the integration accordingly.

Weight updates on the GPU

chapleau/somoclu@9693de0dd008f02fa973faf2df6904614d42d229 implements the weight update on the GPU. This should be merged back.

makemex-GPU-sh not compiling/building

somoclu command line is working fine.(i tried the example:somoclu data/rgbs.txt data/rgbs. it worked fine.)

then i tried ./configure --without-mpi --with-cuda=/usr/local/cuda-6.5. then make, make install. it built fine. but when i try

  MEX_BIN="/usr/local/MATLAB/R2014a/bin/mex" ./makeMex-GPU.sh

I get error "Unknown file extension '.co'."
other details:
ubuntu 14.04, matlab2014a, gcc4.8.2, cuda-6.5, Nvidia-gt740

Reorganize Swig interface for Python

The Swig interface is currently a bit of a workaround. The following changes would make it more elegant:

  • Include code with %pythoncode "whatever.py" instead of the current double-wrapper structure.
  • Convert C++ exceptions to Python exceptions with %exception

Differing results between R and CLI

I had been using the CLI version of Somoclu and getting results consistent with other implementations of batch-trained SOMs (R-Kohonen and Matlab Neural network Toolbox). When you responded to my request for the inclusion of a bubble neighborhood function I decided to use the R package to test it rather than recompile for CLI (which was initially done for me by a colleague.) Following your instructions I compiled and tested the new version of the R package. I found that I was getting much higher quantitization errors than in CLI. In order to determine whether the difference was due to R or the requested changes I installed the current, unmodified, R package and compared the same input file using the same initial codebook. Using CLI I got a quantitization error of 5.73 but with R the quantitization error was 18.95.

Here is the CLI command:

somoclu -c T7_init_weights_nospace_CRend.wts -e 100 -k 1 -m planar -t linear -r 9 -R 1 -T linear -l 1 -L 0.01 -s 0 -x 18 -y 15 t7_norow_somoclu T_Opt_6

Here is the R script:
dataTemp <- data.frame(fread("t7_norow_somoclu"))
dataSource <- as.matrix(dataTemp)
initTemp <- data.frame(fread("T7_init_weights_nospace_CRend.wts"))
initSource <- as.matrix(initTemp)
nSomX <- 18
nSomY <- 15
nEpoch <- 100
radius0 <- 9
radiusN <- 1
radiusCooling <- "linear"
scale0 <- 1
scaleN <- 0.01
scaleCooling <- "linear"
kernelType <- 0
mapType <- "planar"
gridType <- "rectangular"
compactSupport <- FALSE
codebook <- initSource
res <- Rsomoclu.train(dataSource, nEpoch, nSomX, nSomY, radius0, radiusN, radiusCooling, scale0, scaleN, scaleCooling, kernelType, mapType, gridType, compactSupport, codebook)
head(res$globalBmus)

io.cpp should not be included in the interfaces

With commit 8d996de, io.cpp is included in all interfaces, and compiled in R, R+CUDA, Python+CUDA, and MATLAB+CUDA. The only reason for the inclusion is that the my_abort function is called from the CUDA kernel. This should not happen in the first place, so this kernel needs some restructuring.

some make problems in fedora20 - incl a way to get it to work, somehow

hi,
in order to make it was necessary to edit io.cpp and add "#include " because its dependency in iostream has been removed with gcc 4.3.
further more i comment the line with setDevice because of the error "undefined reference to `setDevice'", which allowed me to make it. BUT now i have problems with CUDA. if i try the gpu kernel, i get following error:
$somoclu -x 100 -y 200 file folder -e 20 -k 1
-->
nVectors: 417 nVectorsPerRank: 417 nDimensions: 0
Epoch: 0 Radius: 50
** On entry to SGEMM parameter number 8 had an illegal value
!!!! kernel execution error.
Aborted
terminate called after throwing an instance of 'thrust::system::system_error'
what(): unload of CUDA runtime failed
Aborted (core dumped)

would you have any suggestions?
thanks a lot!

wrap_train

Hello.

While using somoclu (windows7, python3.4) and calling the som.train() command (with and without args), I get the following error:
som.train(epochs=epochs, radius0=radius0, scale0=scale0)
File "C:\Python34\lib\site-packages\somoclu\train.py", line 158, in train
wrap_train(np.ravel(self._data), epochs, self._n_columns, self._n_rows,
NameError: name 'wrap_train' is not defined
Any ideas?

Thank you!

Python save codebook?

How do you save the codebook and umatrix for future use? The documentation has no API for this.

Python with CUDA support

I can't seem to get CUDA support enabled in Python.

I run the following series of commands:
export CUDAHOME=/usr/local/cuda-7.5/
./autogen.sh
./configure --with-cuda=/usr/local/cuda-7.5 -> Cuda support = yes here
make
sudo make install
make python
cd src/Python/
sudo python setup.py install

and then it outputs this as the first line:
Proceeding without CUDA

I run the example and only get CPU time,
n_rows, n_columns = 100, 160
som = somoclu.Somoclu(n_columns, n_rows, data=data, kerneltype=1)
%time som.train()
CPU times: user 34.9 s, sys: 104 ms, total: 35 s
Wall time: 19.5 s

any ideas on how to get CUDA working?

Thank you,

Amir

Alternative SOM computation methods.

Very impressive work, but I would like to know whether you have tried using Theano for this before writing your own kernels?
We all want the best possible performance and I'm somewhat skeptical that kernels coded by a single expert would beat the kernels created by a team of experts under tremendous pressure to optimize for performance (deep convolutional neural networks).

In case you are interested, there is an interesting example here:
https://github.com/erogol/RSOM

Or a more recent toy example in a newish framework (TensorFlow) here:
https://codesachin.wordpress.com/2015/11/28/self-organizing-maps-with-googles-tensorflow/

I have noticed that you were considering refactoring the kernels in pure cuda and not use Thrust. So perhaps you would find these two examples of interest.

make fail on CentoOS

Missing include cstring ?

make all
make -C src all
make[1]: Entering directory /cbio/cslab/home/pastore/bin/somoclu/src' mpic++ -DHAVE_CONFIG_H -fPIC -fopenmp -O3 -ffast-math -march=native -DMPICH_IGNORE_CXX_SEEK -DCLI -I/opt/mpich2/gcc/eth/include -I. -I.. -o somoclu.o -c ./somoclu.cpp ./somoclu.cpp: In function ‘int main(int, char**)’: ./somoclu.cpp:312:50: error: ‘strcpy’ was not declared in this scope strcpy(inFilenameCStr, inFilename.c_str()); ^ ./somoclu.cpp:319:44: error: ‘strcpy’ was not declared in this scope strcpy(mapTypeCStr, mapType.c_str()); ^ ./somoclu.cpp:326:46: error: ‘strcpy’ was not declared in this scope strcpy(gridTypeCStr, gridType.c_str()); ^ make[1]: *** [somoclu.o] Error 1 make[1]: Leaving directory/cbio/cslab/home/pastore/bin/somoclu/src'
make: *** [all] Error 2

./configure --prefix=/cbio/cslab/home/pastore/bin/
checking for g++... g++
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to support OpenMP... -fopenmp
checking for nvcc... yes
checking for mpic++... mpic++
checking for MPI directory... /opt/mpich2/gcc/eth
/usr /usr/lib/openmpi /cbio/cslab/home/pastore/nobackup/bcbio /opt/mpich2/gcc/eth /opt/gnu/gcc/4.8.1 /opt/gnu/gcc/4.8.1 /opt/gnu/gmp /opt/gnu/mpc /opt/gnu/mpfr
checking how to run the C++ preprocessor... g++ -E
checking whether we can preprocess mpi.h... yes
checking whether we can compile mpi.h... yes
checking whether special compile flag for MPICH is required... yes

Adding -DMPICH_IGNORE_CXX_SEEK to MPICH compilations

configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating config.h
config.status: config.h is unchanged

Somoclu Version 1.6.2

Prefix: /cbio/cslab/home/pastore/bin.
Compiler: mpic++ -fPIC -fopenmp -O3 -ffast-math -march=native -DMPICH_IGNORE_CXX_SEEK -I/opt/mpich2/gcc/eth/include -L/opt/mpich2/gcc/eth/lib -lmpi

Package features:
OpenMP enabled: yes
MPI enabled: yes
CUDA enabled: yes

Now type 'make []'
where the optional is:
all - build all binaries
install - install everything


std::bad_alloc: out of memory for dense gpu format

tried with a 4 dimensional dataset of txt format(~ to rgbs.txt).data size 1000000 lines.
somoclu -k 1 --rows 20 --columns 20 temp_data/temp2.txt temp_data/temp2

terminate called after throwing an instance of 'thrust::system::detail::bad_alloc'
what(): std::bad_alloc: out of memory
Aborted (core dumped).
is this out of gpu memory? but my gpu memory is 2Gb while my ram is 26Gb.
file size is found to be in 36Mb

ls -l temp2.txt
-rw-rw-r-- 1 shome shome 36773500 Sep 19 16:21 temp2.txt

error in denseGPU code : _Block_Type_Is_Valid (pHead->nBlockUse)

hello

i get the above error (_Block_Type_Is_Valid (pHead->nBlockUse) ) when i attempt to run the code with denseGPU enabled on the given rgbs.lrn file. The error happens in trainOneEpochDenseGPU, at the end of the function, trying to delete[] bmus.

I am running windows 7, visual studio 2013, i have cuda 7.5, Microsoft mpi, my video card is an NVidia 680m (kepler card, gk104). This is in a 64bit build, both debug and release - cuda dropped 32bit build support with cuda 7, afaik.

everything works fine with the denseCPU flag, just throwing that out there. :)

BMU Mapping

Hello,

I realized that in the .bm-output-files several input vectors can be associated with the same BMU. In this example one can see, that input vectors 2 and 3 are mapped to BMU (3,10) and 6 and 7 are mapped to BMU (2,49):

%50 50
%4616
0 49 17
1 47 12
2 3 10
3 3 10
4 49 2
5 0 11
6 2 49
7 2 49
8 0 11
9 4 0
10 11 4
...

Is there a way to have one and only one input vector mapped to one BMU? I. e. can the algorithm map to the next best matching unit if an input vector was already mapped to a BMU?

Update SOM after training in R (question)

Hi i have a matrix with 14M row and 50 variable. I'm training the SOM on a sample of the initial dataset and I would like to map and plot the test (-training) data in R. I have not figure out any way to do it, but I have seen that this is possible in your python interface.

Also I would like to exclude some variable from the training but project them and plot in the trained map. Is this possible?

I would really appreciate your help!

Thanks!

Rsomoclu with negative values

I scaled (subtract mean, divide by SD) my data before submitting to Rsomoclu -- consistent with using R's other som functions. This results(in Rsomoclu) in no codebook values below 0, which means nothing below the mean of the unscaled variables.

The documentation mentions "With random initialization, the initial codebook will be filled with random numbers ranging from 0 to 1. Either supply your own initial codebook or normalize your data to fall in this range." but it does not talk about how the initial codebook influences the final codebook values. Are negative values even possible? Can codebook values cross from positive to negative values? Is this an issue with R's native double-precision floats not mapping into Somoclu's single-precision floats?

Please either modify the algorithm or expand on the documentation to make clear the effects of the initial codebook values, etc.

Persistent object in C++ to improve efficiency of wrappers

Rather than passing all arguments from the wrappers to the C++ code, we could have a class in C++ to hold these values, and the interfaces would interact with this class. It would enable, for instance, an epoch by epoch training in the high-level languages.

Rcpp::not_compatible

I am getting Rcpp::not_compatible on both centOS and MacOSX.
Any suggestions?
Thanks !

set.seed(348)
nSomX <- 50
nSomY <- 50
nEpoch <- 10
radius0 <- 0
radiusN <- 0
radiusCooling <- "linear"
scale0 <- 0
scaleN <- 0.01
scaleCooling <- "linear"
kernelType <- 0
mapType <- "planar"
gridType <- "hexagonal"
snapshots <- 0
res <- Rsomoclu.train(SOM_data, nEpoch, nSomX, nSomY,

  •                      radius0, radiusN,
    
  •                      radiusCooling, scale0, scaleN,
    
  •                      scaleCooling, snapshots, gridType,
    
  •                      kernelType, mapType)
    
    terminate called after throwing an instance of 'Rcpp::not_compatible'
    what(): not compatible with requested type
    Aborted

sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS release 6.7 (Final)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.iso885915 LC_COLLATE=en_US.iso885915
[5] LC_MONETARY=en_US.iso885915 LC_MESSAGES=en_US.iso885915
[7] LC_PAPER=en_US.iso885915 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.iso885915 LC_IDENTIFICATION=C

attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets
[8] methods base

other attached packages:
[1] kohonen_2.0.19 MASS_7.3-45
[3] class_7.3-14 SummarizedExperiment_1.0.2
[5] Biobase_2.30.0 GenomicRanges_1.22.4
[7] GenomeInfoDb_1.6.3 IRanges_2.4.8
[9] S4Vectors_0.8.11 BiocGenerics_0.16.1
[11] Rsomoclu_1.6.2 Rcpp_0.12.6

loaded via a namespace (and not attached):
[1] zlibbioc_1.16.0 XVector_0.10.0

Sparse kernels in Python

In principle, it is straightforward to pass Python sparse matrices, for instance, scipy.sparse.lil_matrix, to C/C++. The problem is that Somoclu's internal sparse representation does not match any of them. First this representation has to be changed, and then we could implement the sparse kernels at least in the Python interface.

Inconsistent Results using Somoclu

I've been trying to get results with somoclu, more properly with the Python library. I can't get consistent data as I only get 20 to 50 clusters max, when with other (single-threaded) libraries I get 700+ clusters.

I don't know if I should ask this here as i think this may be some wrong parameter. The parameters i'm using are the following:

nSomX = 100
nSomY = 100
nVectors = self.npdata.shape[0]
nDimensions = self.npdata.shape[1]
data1D = np.ndarray.flatten(self.npdata)
nEpoch = 2000
radius0 = 50
radiusN = 1
radiusCooling = "linear"
scale0 = 0.35
scaleN = 0.15
scaleCooling = "linear"
kernelType = 0
mapType = "planar"

I can provide a sample of the dataset if needed.

Autogen hangs on Ubuntu 13.10

Hi,
After running ./autogen.sh, it hangs with the following errors:

configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)
automake: error: no 'Makefile.am' found for any configure output

Doing a little bit of research I found that AM_INIT_AUTOMAKE, is a flag that sets automake to output some warnings: http://www.gnu.org/software/automake/manual/automake.html#Hello-World
Setting it to:

AM_INIT_AUTOMAKE([-Wall -Werror foreign])

Solves the first error.

Now, the second error persists... I dont have lot skills on the c, c++ area... Any ideas how to solve this?
The automake version on the system is 1.13.3

BMU inconsistencies (Python)

[Using GPU, hexagonal lattice, toroid config]

I'm not sure what causes it but there appear to be some BMU inconsistencies when comparing the BMUs returned by training and the BMUs you compute yourself using the codebook and the data.

To reproduce:

import numpy as np
import somoclu
import matplotlib.pyplot as plt

SAMPLES = 50000
DIMS = 21

train_data = np.random.uniform(low=0.0, high=1.0, size=SAMPLES*DIMS).reshape((SAMPLES,DIMS)).astype(np.float32)

som = somoclu.Somoclu(
    32, 32,
    data=train_data,
    maptype="toroid",
    gridtype="hexagonal",
    kerneltype=0
)

som.train(epochs=32, radius0=min(som._n_rows, som._n_columns)/2, radiusN=1, scale0=0.1, scaleN=0.01)

W = som.codebook.reshape((som.codebook.shape[0] * som.codebook.shape[1], som.codebook.shape[2]))
X = train_data

D = -2*np.dot(W, X.T) + (W**2).sum(1)[:, None] + (X**2).sum(1)[:, None].T
BMU = (D==D.min(0)[None,:]).astype("float32").T
NBMU =  BMU.reshape((X.shape[0], som.codebook.shape[0], som.codebook.shape[1]))
new_bmus = np.vstack(NBMU.nonzero()[1:][::-1]).T

hitmap = BMU.sum(axis=0).reshape((som.codebook.shape[0], som.codebook.shape[1])).T
hitmap2 = np.zeros((som.umatrix.shape[0], som.umatrix.shape[1]))
for x in range(0, som.bmus.shape[0]):
    hitmap2[som.bmus[x][0], som.bmus[x][1]] += 1

print np.absolute(new_bmus - som.bmus).sum()

plt.imshow(hitmap - hitmap2)
plt.show()

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

Hello!

First of all, sorry if this is a stupid question, but I'm looking forward to working with somoclu and
unfortunately I'm facing this issue when I compile one of the examples shown on the main page.

  File "somoclu.py", line 1, in <module>
    import somoclu
  File "C:\Projects\nlp-django-api\somoclu\somoclu.py", line 18, in <module>
    som = somoclu.Somoclu(n_columns, n_rows, data=data, maptype="planar",
AttributeError: 'module' object has no attribute 'Somoclu'

somoclu seems to be in site-packages folder. I'm not sure what exactly I'm missing.

Thanks in advance.

[Python] sklearn warns with init=PCA

Warning (from warnings module):
File "C:\Users\yoch\AppData\Local\Programs\Python\Python35\lib\site-packages\sklearn\utils\deprecation.py", line 52
warnings.warn(msg, category=DeprecationWarning)
DeprecationWarning: Class RandomizedPCA is deprecated; RandomizedPCA was deprecated in 0.18 and will be removed in 0.20. Use PCA(svd_solver='randomized') instead. The new implementation DOES NOT store whiten components_. Apply transform to get them.

Why can't I run train() many times?

When I run som.train() in Python after having previously trained a SOM I get the following error:

TypeError: Array must have 1 dimensions.  Given array has 2 dimensions

What am I doing wrongly?

No rule to make target 'denseGpuKernels.cu.o', needed by 'denseGpuKernels.cu'. Stop.

After generating makefile with:

$ ./configure --without-mpi  --with-cuda=/opt/cuda --with-matlab=/home/gsc/data/MATLAB/R2014a/                                                                                                       
checking for g++... g++                                                                                             
checking whether the C++ compiler works... yes                                                                      
checking for C++ compiler default output file name... a.out                                                         
checking for suffix of executables...                                                                               
checking whether we are cross compiling... no                                                                       
checking for suffix of object files... o                                                                            
checking whether we are using the GNU C++ compiler... yes                                                           
checking whether g++ accepts -g... yes                                                                              
checking for a BSD-compatible install... /usr/bin/install -c                                                        
checking for gcc... gcc                                                                                             
checking whether we are using the GNU C compiler... yes                                                             
checking whether gcc accepts -g... yes                                                                              
checking for gcc option to accept ISO C89... none needed                                                            
checking for gcc option to support OpenMP... -fopenmp                                                               
checking for nvcc... yes                                                                                            
configure: creating ./config.status                                                                                 
config.status: creating Makefile                                                                                    
config.status: creating src/Makefile                                                                                
config.status: creating config.h                                                                                    
config.status: config.h is unchanged                                                                                
-------------------------------------------------                                                                   

 Somoclu Version 1.5                                                                                                

 Prefix: /usr/local.                                                                                                
 Compiler: g++ -fPIC -fopenmp -Ofast -march=native                                                                  

 Package features:                                                                                                  
   OpenMP enabled: yes                                                                                              
   MPI enabled: no                                                                                                  
   CUDA enabled: yes                                                                                                

 Now type 'make [<target>]'                                                                                         
   where the optional <target> is:                                                                                  
     all                - build all binaries                                                                        
     install            - install everything                                                                        

-------------------------------------------------- 

I get error:

$ make
make -C src all
make[1]: Entering directory '/home/gsc/tmp/somoclu-master/src'
g++ -DHAVE_CONFIG_H -fPIC -fopenmp -Ofast -march=native -DCLI  -I. -I.. -o sparseCpuKernels.o -c ./sparseCpuKernels.cpp
g++ -DHAVE_CONFIG_H -fPIC -fopenmp -Ofast -march=native -DCLI  -I. -I.. -o denseCpuKernels.o -c ./denseCpuKernels.cpp
g++ -DHAVE_CONFIG_H -fPIC -fopenmp -Ofast -march=native -DCLI  -I. -I.. -o mapDistanceFunctions.o -c ./mapDistanceFunctions.cpp
g++ -DHAVE_CONFIG_H -fPIC -fopenmp -Ofast -march=native -DCLI  -I. -I.. -o training.o -c ./training.cpp
g++ -DHAVE_CONFIG_H -fPIC -fopenmp -Ofast -march=native -DCLI  -I. -I.. -o uMatrix.o -c ./uMatrix.cpp
make[1]: *** No rule to make target 'denseGpuKernels.cu.o', needed by 'denseGpuKernels.cu'.  Stop.

The 1.5 tag version worked fine. I looked at the changes since then and haven' t found the cause of this make error. Can you make properly?

R interface visual capabilities

The current R interface does not do anything but returns the structure it got from C++. Some simple visualization routines like the ones for the Python interface would make a big difference.

Request for cosine distance

Hi,

I have been using somoclu for a week now and really enjoying it. I would appreciate it if cosine distance is also implemented, as it is useful for many document matching application.

Thanks,
Mos

Integer overflow

Hi, I try to train the SOM on a larger dataset (1.4M row or larger with 50 or more variable) Rsomoclu.kohone return this error message:

Error in matrix(0, nd * ncodes, nmaps) : invalid 'nrow' value (too large or NA) In addition: Warning message: In nd * ncodes : NAs produced by integer overflow

Julia interface

Julia lacks a SOM implementation. Once v0.4 of Julia is released and Cxx.jl matures, it will be worthwhile to make a module.

R interface with CUDA support on Windows

R interface with CUDA support on Windows cannot be properly built. The CUDA code that requires VC to compile, whereas Rcpp requires GCC to compile, and linking cannot be done without error. Though the linking completes, a function call results in wrong/inaccessible values and crashes the R session.

All training examples are assigned to the same neuron after gpu-training

Hi,

I had a hard time installing the python interface of somoclu with Cuda on Ubuntu 16.4 today. First I ran into a "‘memcpy’ was not declared in this scope" error. After reading BVLC/caffe#4046, I added -D_FORCE_INLINES to CXXFLAGS and CUDA_CFLAGS in src/Makefile. Whyever, this helped with the error.
Than I got 2 similar errors where one looked like: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line. The other was for libm library. So I added -lstdc++ -lm to LIBS in the same Makefile. This worked and make ended without errors. After this I did make python and python setup.py install. Both seemed to work fine.
But when I tried the example from the README in the python folder on gpu, all examples where assigned to the same neuron [49, 29]. When I tried a 50x50 map, all examples where assigned to neuron [49,49]. I ran the example on cpu and everything looked fine, the examples where assigned to different neurons. I don't know why this is like that. Did I do something wrong in the installation process?

Activation on the surface of the map

I would like to obtain the activation of every SOM unit for a given input, i.e., not just the MAU/BMU.

I see from the comment here #39 (comment) by @ghost that obtaining the BMUs is relatively simple. This makes me assume/infer that the activation across the whole map is calculated by the codebook times the input - is this correct?

For example:

def get_surface_state(som, X):
    D = np.dot(som.codebook.reshape((som.codebook.shape[0] * som.codebook.shape[1], som.codebook.shape[2])), X.T).T
    return D

If yes, can D be used as the input to another SOM? Or would that be meaningless, in your opinion?

R CUDA support in new build structure

With commit 73abe64, the scripts that were floating around for the R interface were merged to a Makefile target. To build the source distribution for R, just issue make r.

The R directory contains a configure script by default. If we build the module without CUDA, the script just exits and the usual R compilation procedure starts. To build with CUDA, you have to supply a parameter to the R install system:

R CMD INSTALL Rsomoclu_1.5.tar.gz --configure-args=/path/to/cuda

The .so file is built correctly and the module is installed, but the test fails. Please look into this.

Visual Studio 2015 - project load failed

Project load fails when trying to open src\Windows\somoclu\somoclu.sln (1.6.1) in Visual Studio Community 2015 Update 3 on Windows 10. The error message in Solution Explorer is,: "The project requires user input. Reload the project for more information." What am I missing?

Query in compilation with cuda and matlab

Hello,

I am trying to compile the program with CUDA and MATLAB. After I do the ./configure and make all. I go inside the source folder to make MATLAB. And am getting the following error-

make: *** No rule to make target denseGpuKernels.cu.o', needed bymatlab'. Stop.

Do I need to change the Makefile.
I will appreciate any help I can get. Thank you.
Following is the Makefile that was generated-

src/Makefile. Generated from Makefile.in by configure.

Package-related substitution variables

package = Somoclu
version = 1.5
tarname = somoclu
distdir = $(tarname)-$(version)

Prefix-related substitution variables

prefix = /Users/abhshah/Project_data/new_project/somoclu
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
libdir = ${exec_prefix}/lib

Tool-related substitution variables

CXX = g++
CXXFLAGS = -fPIC -fopenmp -Ofast -march=native
LIBS =
DEFS = -DHAVE_CONFIG_H
INSTALL = /usr/bin/install -c
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM= ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
CUDA_CFLAGS = -I/usr/local/cuda-6.5//include -use_fast_math -Xcompiler "-fPIC -fopenmp -Ofast -march=native"
CUDA_LIBS = -lcudart -lcublas
CUDA_LDFLAGS = -L/usr/local/cuda-6.5//lib64
NVCC = /usr/local/cuda-6.5//bin/nvcc
MPI_INC =
MPI_LIBDIR =
MPI_LIBS =
MATLAB_ROOT = /opt/matlab/R2015a/
MEX_BIN = /opt/matlab/R2015a//bin/mex

VPATH-related substitution variables

srcdir = .

LIBOBJS=sparseCpuKernels.o denseCpuKernels.o mapDistanceFunctions.o training.o uMatrix.o

MEX_FLAGS=-I./
MEX_LIBS=-lgomp
MEX_OBJS=sparseCpuKernels.o denseCpuKernels.o mapDistanceFunctions.o training.o uMatrix.o

ifdef CUDA_LIBS
LIBOBJS+=denseGpuKernels.cu.co
MEX_FLAGS+=-I"$(MATLAB_ROOT)/toolbox/distcomp/gpu/extern/include/" -DCUDA
MEX_LIBS+=$(CUDA_LDFLAGS) $(CUDA_LIBS) -lnvblas -lmwgpu
MEX_OBJS+=denseGpuKernels.cu.o
endif

OBJS=$(LIBOBJS) io.o somoclu.o

all: somoclu

lib: $(LIBOBJS)
$(CXX) -g $(DEFS) $(CXXFLAGS) $(CUDA_LDFLAGS) ${MPI_LIBDIR} -shared -o libsomoclu.so $^ $(LIBS) $(CUDA_LIBS) ${MPI_LIBS}

somoclu: CXXFLAGS+= -DCLI
somoclu: $(OBJS)
$(CXX) $(DEFS) $(CXXFLAGS) $(CUDA_LDFLAGS) ${MPI_LIBDIR} -o $@ $^ $(LIBS) $(CUDA_LIBS) ${MPI_LIBS}

%.o: %.cpp
$(CXX) $(DEFS) $(CXXFLAGS) ${MPI_INC} -I$(srcdir) -I.. -o $@ -c $(srcdir)/$<

%.cu.co: %.cu
$(NVCC) $(DEFS) $(CUDA_CFLAGS) ${MPI_INC} -I$(srcdir) -I.. -o $@ -c $(srcdir)/$<

matlab: $(MEX_OBJS)

if [ -e denseGpuKernels.cu.co ]; then cp denseGpuKernels.cu.co denseGpuKernels.cu.o; fi

$(MEX_BIN) $(MEX_FLAGS) MATLAB/MexSomoclu.cpp $(MEX_OBJS) $(MEX_LIBS)

matlab_clean: clean
-rm -f MexSomoclu* denseGpuKernels.cu.o

python:
mkdir -p ./Python/somoclu/src

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.