D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
MNoichl
Full window
Github gist
test-tsne
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <script src="tsne.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) var opt = {} opt.epsilon = 10; // epsilon is learning rate (10 = default) opt.perplexity = 30; // roughly how many neighbors each point influences (30 = default) opt.dim = 2; // dimensionality of the embedding (2 = default) var tsne = new tsnejs.tSNE(opt); // create a tSNE instance // initialize data. Here we have 3 points and some example pairwise dissimilarities d3.csv("data.csv", function(data) { dists = [[0,2,3],[0,4,6]] tsne.initDataRaw(dists); for(var k = 0; k < 500; k++) { tsne.step(); // every time you call this, solution gets better } var Y = tsne.getSolution(); // Y is an array of 2-D points that you can plot console.log("Y[0]") console.log("test: "+typeof(Y)) console.log(Y[0][0]) svg.selectAll("dot") .data(Y) .enter().append("circle") .attr("r", 3.5) .attr("cx", function(d,i) { return Y[i][0]+100; }) .attr("cy", function(d,i) { return Y[i][1]+100; }); //function(d,i) { return y(d.close); } } ) </script> </body>
https://d3js.org/d3.v4.min.js