Hop distribution
Distribution of hop probability within a Prime graph depending on node distance. https://github.com/danstocker/prime
by Dan Stocker
HTML
<script src="http://dl.dropboxusercontent.com/u/9258903/JavaScript/phil-0.2.2.js"></script>
<script src="http://dl.dropboxusercontent.com/u/9258903/JavaScript/dessert-0.3.2.js"></script>
<script src="http://dl.dropboxusercontent.com/u/9258903/JavaScript/troop-0.5.1.js"></script>
<script src="http://dl.dropboxusercontent.com/u/9258903/JavaScript/sntls-0.13.0.js"></script>
<script src="https://dl.dropboxusercontent.com/u/9258903/jsPerf/prime-0.3.2.js"></script>
<span>Random word associations along learned paths. Starting from the word "fruit" with 50% chance for consecutive jumps.</span>
JavaScript
var colors = ['paleTurquoise', 'moccasin', 'darkSeaGreen', 'lightBlue', 'pink', 'yellowGreen', 'paleVioletRed', 'orange'];
var graph = prime.Graph.create();
var statistics = (function () {
var _ = graph.getConnector(),
node = graph.getFetcher(),
result = {},
i, load;
// establishing connections
_('food',
_('fruit',
_('apple'),
_('pear')),
_('turkey'));
_('animal',
_('bird',
_('turkey')),
_('feline',
_('cat'),
_('lion')));
// traversing connections, gathering statistics
for (i = 0; i < 1000; i++) {
load = node('fruit').hop().load;
result[load] = (result[load] || 0) + 1;
}
return result;
}());
/*global $, dictionary */
$('body')
.height(400)
.width(500)
.css('position', 'relative');
var words = graph.getKeys().sort(),
i, word;
// adding bars
for (i = 0; i < words.length; i++) {
word = words[i];
$('<div></div>')
.text(word)
.css({
position: 'absolute',
left: 30 * i,
bottom: 0,
height: statistics[word],
width: 20,
background: colors[i % 8]
})
.appendTo($('body'));
}