Code Monkey home page Code Monkey logo

sammon's Introduction

Sammon mapping in Python

Date: 18 April 2014

sammontest.py

Run sammontest.py() with no arguments to test sammon.py on Fisher's iris dataset. You should get an output image as the one shown below:

alt tag

sammon.py

Simple python implementation of Sammon's non-linear mapping algorithm [1]. Perform Sammon mapping on dataset x

y = sammon(x) applies the Sammon nonlinear mapping procedure on multivariate data x, where each row represents a pattern and each column represents a feature. On completion, y contains the corresponding co-ordinates of each point on the map. By default, a two-dimensional map is created. Note if x contains any duplicated rows, SAMMON will fail (ungracefully).

[y,E] = sammon(x) also returns the value of the cost function in E (i.e. the stress of the mapping).

An N-dimensional output map is generated by y = sammon(x,n) .

A set of optimisation options can be specified using optional arguments, y = sammon(x,n,[OPTS]):

  • maxiter - maximum number of iterations
  • tolfun - relative tolerance on objective function
  • maxhalves - maximum number of step halvings
  • input - {'raw','distance'} if set to 'distance', X is interpreted as a matrix of pairwise distances.
  • display - 0 to 2. 0 least verbose, 2 max verbose.
  • init - {'pca', 'random'}

The default options are retrieved by calling sammon(x) with no parameters.

Authors

Tom J. Pollard (https://twitter.com/tompollard)

Ported from MATLAB implementation by Gavin C. Cawley and Nicola L. C. Talbot

References

[1] Sammon, John W. Jr., "A Nonlinear Mapping for Data Structure Analysis", IEEE Transactions on Computers, vol. C-18, no. 5, pp 401-409, May 1969.

Copyright

Copyright : (c) Dr Gavin C. Cawley, November 2007.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

sammon's People

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

Watchers

 avatar  avatar  avatar

sammon's Issues

error doesn't decrease

To me it seems there is something wrong with the sammon mapping. The error does not decrease and it seems to do not deliver good results if pca is not used.

Reshaping s array with / division operator results in float which raises an error

In here:
# Use step-halving procedure to ensure progress is made

for j in range(maxhalves):
        s_reshape = s.reshape(2,len(s)/2).T`

When I tried to use your function with a matrix of shape (2400, 20) and setting init='random' I got the error

'float' object cannot be interpreted as an integer

To fix this I changed the code to
s_reshape = s.reshape(2,len(s)//2).T

I was getting a different error when I left the default setting of init='pca', something like 2 (dim 1) != 1 (dim 0) and I couldn't figure that one out so I went with init='random'.

all output are nan?!

hey, thanks for you code. but I run the sammontest.py, both raw and distance output are nan, because E-E_new array is all nan.

at first glance i am not sure where to fix it, since there Dinv but you catch the inf error and replace it with 0.

Test is not working

Hi Tom,

Thanks for your code. I had similar problems as in the Issue #1 (#1) and applying the suggestions to the code, it is working and providing the following image, which might be nice to add to the main page of the project. :-)
iris

What I can do now is making a pull request.

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.