Code Monkey home page Code Monkey logo

graph-embedding-mds-test's Introduction

Usage

Run python embed_graph.py path_to_graph mode.

Example: python embed_graph.py graphs/g1.

Graph should be represented by a text file. First line contains one integer (number of vertices). The rest of the lines have the following structure: first string (until the first whitespace) in a line is the ID of the node, after that there is an integer representing size, the rest is a list of node's neighbors (represented by their IDs). Examples are in the graphs folder. DO NOT put a new line at the end of the file, it will be interpreted as a vertex with no neighbors.

Script produces a text file with vertex embeddings and a plot, both are saved in path_to_graph directory. Dotted lines represent Voronoi borders. "Bad edges" is the number of edges in the graph that cross an area they don't belong to. It shows incorrect number for graphs with different node sizes at the moment, so ignore it for now.

I couldn't get rid of very large zones forming near the edges of a map. For now, I greyed out the points that are further than 0.5 from the nearest embedding point. This is probably not the best solution in the long run.

UPDATE: The program now rotates and scales the embeddings to make them fill map space better.

Transforming a graph

Let's say we have two connected vertices, v and u with sizes 3 and 8, respectively. I tried to just weight the edge u-v in a few different ways, but it didn't work very well. I ended up splitting each vertex x into size(x) vertices (v becomes v_1, v_2, v_3, for example). I chose to make those into a cycle (v_1-v_2, v_2-v_3, v_3-v_1). Clique gave bad results, the embeddins were too close to each other. Then I have to connect v and u in the transformed graph. I tried connecting each v_i with each u_j, it looked bad for big nodes. I found better way: connect one random v_i with one random u_j. The script uses this method.

Gravity pulling

Points are now pulled towards the map borders. More detailed description (hopefully) soon.

Results with _pregrav are saved before pulling, for comparison.

Sources

sammon.py comes from https://github.com/tompollard/sammon

min_bounding_rect.py and qhull_2d.py come from https://github.com/dbworth/minimum-area-bounding-rectangle

About graph embeddings:

[1] http://www.stat.yale.edu/~lc436/papers/JCGS-mds.pdf

[2] http://www.graphviz.org/Documentation/GKN04.pdf

[3] https://en.wikipedia.org/wiki/Sammon_mapping

[4] https://en.wikipedia.org/wiki/Multidimensional_scaling

[5] https://www.codeproject.com/Articles/43123/Sammon-Projection

graph-embedding-mds-test's People

Contributors

maciek16180 avatar

Stargazers

Ramsey avatar

Watchers

 avatar

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.