diff --git a/js/tsne_vis.js b/js/tsne_vis.js
index 132f462..0c29925 100755
--- a/js/tsne_vis.js
+++ b/js/tsne_vis.js
@@ -3,7 +3,7 @@
var k; var points = []; var all_fields; var pointsbeta = []; var KNNEnabled = true;
// These are the dimensions for the square shape of the main panel\
var dimensions = document.getElementById('modtSNEcanvas').offsetWidth;
-var prevRightClick;
+var prevRightClick; var ColorsCategorical; var Category;
// These are the dimensions for the overview panel
var dim = document.getElementById('tSNEcanvas').offsetWidth;
@@ -133,6 +133,18 @@ function setLayerSche(){
d3.select("#modtSNEcanvas_svg_Schema").style("z-index", 2);
d3.select("#modtSNEcanvas").style("z-index", 1);
d3.select("#modtSNEcanvas_svg").style("z-index", 1);
+ let c = 0;
+ for (var i=0; i < points.length; i++){
+ points[i].selected = true;
+ if (points[i].starplot == true){
+ c = c + 1;
+ if (c == 1){
+ alert("The starplot visualization will be lost!");
+ }
+ points[i].starplot = false;
+ }
+ }
+ redraw(points);
click();
}
@@ -250,9 +262,58 @@ function setAnnotator(){
);
animate();
+ var Arrayx = [];
+ var Arrayy = [];
+ var XYDistId = [];
+ var Arrayxy = [];
+ var DistanceDrawing1D = [];
+ var allTransformPoints = [];
+ var p;
+ var pFinal = [];
+ var paths;
+ var path;
+ var ArrayLimit = [];
+ var minimum;
+ var correlationResults = [];
+ var ArrayContainsDataFeaturesLimit = [];
// function that executes after data is successfully loaded
function init(data, results_all, fields) {
+
+ d3.selectAll("#correlation > *").remove();
+ d3.selectAll("#modtSNEcanvas_svg > *").remove();
+ d3.selectAll("#modtSNEcanvas_svg_Schema > *").remove();
+ d3.selectAll("#SvgAnnotator > *").remove();
+ d3.selectAll("#sheparheat > *").remove();
+
+ var oldcanvOver = document.getElementById('tSNEcanvas');
+ var contxOver = oldcanvOver.getContext('experimental-webgl');
+ contxOver.clear(contxOver.COLOR_BUFFER_BIT);
+
+ scene = new THREE.Scene();
+ scene.background = new THREE.Color(0xffffff);
+
+ d3.selectAll("#legend1 > *").remove();
+ d3.selectAll("#legend3 > *").remove();
+ d3.selectAll("#legend4 > *").remove();
+
+ lassoEnable();
+
+ Arrayx = [];
+ Arrayy = [];
+ XYDistId = [];
+ Arrayxy = [];
+ DistanceDrawing1D = [];
+ allTransformPoints = [];
+ p;
+ pFinal = [];
+ paths;
+ path;
+ ArrayLimit = [];
+ minimum;
+ correlationResults = [];
+ ArrayContainsDataFeaturesLimit = [];
+
prevRightClick = false;
step_counter = 0;
max_counter = document.getElementById("param-maxiter-value").value;
@@ -277,14 +338,35 @@ function init(data, results_all, fields) {
});
ArrayContainsDataFeaturesCleared.push(object);
}
+
+ all_labels = [];
+ dataFeatures.filter(function(obj) {
+
+ var temp = [];
+ temp.push(Object.keys(obj));
+ for (var object in temp[0]){
+ if(temp[0][object].indexOf("*") != -1){
+ Category = temp[0][object];
+ return Category;
+ }
+ }
+
+ });
- $("#datasetDetails").html("Number of Dimensions: " + (ArrayContainsDataFeatures[0].length - 1) + ", Number of Samples: " + final_dataset.length);
+ var valCategExists = 0;
+ for (var i=0; i *").remove();
- d3.selectAll("#modtSNEcanvas_svg > *").remove();
- lassoEnable();
- d3.selectAll("#modtSNEcanvas_svg_Schema > *").remove();
- d3.selectAll("#SvgAnnotator > *").remove();
- Arrayx = [];
- Arrayy = [];
- XYDistId = [];
- Arrayxy = [];
- DistanceDrawing1D = [];
- allTransformPoints = [];
- p;
- pFinal = [];
- paths;
- path;
- ArrayLimit = [];
- minimum;
- correlationResults = [];
- ArrayContainsDataFeaturesLimit = [];
+
var canvas = document.getElementById('tSNEcanvas');
gl = canvas.getContext('experimental-webgl');
@@ -700,11 +749,14 @@ function OverviewtSNE(points){
alert('Unable to initialize WebGL. Your browser or machine may not support it.');
return;
}
+
+ ColorsCategorical = ['#a6cee3','#fb9a99','#b2df8a','#33a02c','#1f78b4','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a'];
+
if (all_labels[0] == undefined){
- var colorScale = d3.scaleOrdinal(d3.schemeCategory10).domain(["No Category"]).range(["#0000ff"]);
+ var colorScale = d3.scaleOrdinal().domain(["No Category"]).range(["#C0C0C0"]);
}
else{
- var colorScale = d3.scaleOrdinal(d3.schemeCategory10).domain(all_labels);
+ var colorScale = d3.scaleOrdinal().domain(all_labels).range(ColorsCategorical);
}
d3.select("#legend3").select("svg").remove();
var svg = d3.select("#legend3").append("svg");
@@ -755,7 +807,7 @@ function OverviewtSNE(points){
singleCol = colval.b/255;
colors.push(singleCol);
}else{
- let colval = d3.rgb(colorScale(points[i].name));
+ let colval = d3.rgb(colorScale(points[i][Category]));
singleCol = colval.r/255;
colors.push(singleCol);
singleCol = colval.g/255;
@@ -1172,6 +1224,7 @@ function CalculateCorrel(){
var SignStore = [];
correlationResults = [];
+
const arrayColumn = (arr, n) => arr.map(x => x[n]);
for (var temp = 0; temp < ArrayContainsDataFeaturesLimit[0].length - 2; temp++) {
var tempData = new Array(
@@ -1181,7 +1234,7 @@ function CalculateCorrel(){
if (isNaN(pearsonCorrelation(tempData, 0, 1))) {
} else{
SignStore.push([temp, pearsonCorrelation(tempData, 0, 1)]);
- correlationResults.push(["Dimension "+temp, Math.abs(pearsonCorrelation(tempData, 0, 1))]);
+ correlationResults.push([Object.keys(dataFeatures[0])[temp] + " (" + temp + ")", Math.abs(pearsonCorrelation(tempData, 0, 1))]);
}
}
correlationResults = correlationResults.sort(
@@ -1265,6 +1318,8 @@ function drawBarChart(){
.tickSize(0)
.outerTickSize(0);
+
+
//Add group for the y axis
mainGroup.append("g")
.attr("class", "y axis")
@@ -1658,7 +1713,6 @@ function mapOrder(array, order, key) {
.on('mousemove', function() {
x = d3.event.pageX;
y = d3.event.pageY;
- console.log( d3.event.pageX, d3.event.pageY ) // log the mouse x,y position
});
@@ -1736,7 +1790,7 @@ height = Math.min(width, window.innerHeight - margin.top - margin.bottom);
RadarChart("#starPlot", wrapData, colors, IDS, radarChartOptions);
function BetatSNE(points){
-
+
selectedPoints = [];
var findNearestTable = [];
for (let m=0; m 0){
var FeatureWise = [];
@@ -1925,32 +1982,60 @@ function BetatSNE(points){
}
}
}
-
- var sum = new Array(Object.values(dataFeatures[0]).length).fill(0);
-
+
+ var max = [];
+ var min = [];
+ var vectors = [];
+ var FeatureWiseSlicedArray = [];
for (var j=0; j FeatureWiseSliced[i]){
+ min[j] = FeatureWiseSliced[i];
+ }
}
}
-
+
+ var vectors = PCA.getEigenVectors(ArrayContainsDataFeaturesCleared);
+ var PCAResults = PCA.computeAdjustedData(ArrayContainsDataFeaturesCleared,vectors[0]);
+ var PCASelVec = [];
+ PCASelVec = PCAResults.selectedVectors[0];
+
+ var len = PCASelVec.length;
+ var indices = new Array(len);
+ for (var i = 0; i < len; ++i) indices[i] = i;
+ indices = indices.sort(function (a, b) { return PCASelVec[a] < PCASelVec[b] ? -1 : PCASelVec[a] > PCASelVec[b] ? 1 : 0; });
+ //const list = dataFeatures.sort((a,b) => a.index - b.index).map((dataFeatures, index, array) => dataFeatures[Category])
+
var wrapData = [];
var IDS = [];
for (var i=0; i b)
+ return a * Math.sqrt(1.0 + (b * b / a / a))
+ else if (b == 0.0)
+ return a
+ return b * Math.sqrt(1.0 + (a * a / b / b))
+ }
+
+ //rep function
+ function rep(s, v, k) {
+ if (typeof k === "undefined") {
+ k = 0;
+ }
+ var n = s[k],
+ ret = Array(n),
+ i;
+ if (k === s.length - 1) {
+ for (i = n - 2; i >= 0; i -= 2) {
+ ret[i + 1] = v;
+ ret[i] = v;
+ }
+ if (i === -1) {
+ ret[0] = v;
+ }
+ return ret;
+ }
+ for (i = n - 1; i >= 0; i--) {
+ ret[i] = rep(s, v, k + 1);
+ }
+ return ret;
+ }
+
+ //Householder's reduction to bidiagonal form
+
+ var f = 0.0;
+ var g = 0.0;
+ var h = 0.0;
+ var x = 0.0;
+ var y = 0.0;
+ var z = 0.0;
+ var s = 0.0;
+
+ for (i = 0; i < n; i++) {
+ e[i] = g; //vector
+ s = 0.0; //sum
+ l = i + 1; //stays i+1
+ for (j = i; j < m; j++)
+ s += (u[j][i] * u[j][i]);
+ if (s <= tolerance)
+ g = 0.0;
+ else {
+ f = u[i][i];
+ g = Math.sqrt(s);
+ if (f >= 0.0) g = -g;
+ h = f * g - s
+ u[i][i] = f - g;
+ for (j = l; j < n; j++) {
+ s = 0.0
+ for (k = i; k < m; k++)
+ s += u[k][i] * u[k][j]
+ f = s / h
+ for (k = i; k < m; k++)
+ u[k][j] += f * u[k][i]
+ }
+ }
+ q[i] = g
+ s = 0.0
+ for (j = l; j < n; j++)
+ s = s + u[i][j] * u[i][j]
+ if (s <= tolerance)
+ g = 0.0
+ else {
+ f = u[i][i + 1]
+ g = Math.sqrt(s)
+ if (f >= 0.0) g = -g
+ h = f * g - s
+ u[i][i + 1] = f - g;
+ for (j = l; j < n; j++) e[j] = u[i][j] / h
+ for (j = l; j < m; j++) {
+ s = 0.0
+ for (k = l; k < n; k++)
+ s += (u[j][k] * u[i][k])
+ for (k = l; k < n; k++)
+ u[j][k] += s * e[k]
+ }
+ }
+ y = Math.abs(q[i]) + Math.abs(e[i])
+ if (y > x)
+ x = y
+ }
+
+ // accumulation of right hand transformations
+ for (i = n - 1; i != -1; i += -1) {
+ if (g != 0.0) {
+ h = g * u[i][i + 1]
+ for (j = l; j < n; j++)
+ v[j][i] = u[i][j] / h //u is array, v is square of columns
+ for (j = l; j < n; j++) {
+ s = 0.0
+ for (k = l; k < n; k++)
+ s += u[i][k] * v[k][j]
+ for (k = l; k < n; k++)
+ v[k][j] += (s * v[k][i])
+ }
+ }
+ for (j = l; j < n; j++) {
+ v[i][j] = 0;
+ v[j][i] = 0;
+ }
+ v[i][i] = 1;
+ g = e[i]
+ l = i
+ }
+
+ // accumulation of left hand transformations
+ for (i = n - 1; i != -1; i += -1) {
+ l = i + 1
+ g = q[i]
+ for (j = l; j < n; j++)
+ u[i][j] = 0;
+ if (g != 0.0) {
+ h = u[i][i] * g
+ for (j = l; j < n; j++) {
+ s = 0.0
+ for (k = l; k < m; k++) s += u[k][i] * u[k][j];
+ f = s / h
+ for (k = i; k < m; k++) u[k][j] += f * u[k][i];
+ }
+ for (j = i; j < m; j++) u[j][i] = u[j][i] / g;
+ } else
+ for (j = i; j < m; j++) u[j][i] = 0;
+ u[i][i] += 1;
+ }
+
+ // diagonalization of the bidiagonal form
+ prec = prec * x
+ for (k = n - 1; k != -1; k += -1) {
+ for (var iteration = 0; iteration < itmax; iteration++) { // test f splitting
+ var test_convergence = false
+ for (l = k; l != -1; l += -1) {
+ if (Math.abs(e[l]) <= prec) {
+ test_convergence = true
+ break
+ }
+ if (Math.abs(q[l - 1]) <= prec)
+ break
+ }
+ if (!test_convergence) { // cancellation of e[l] if l>0
+ c = 0.0
+ s = 1.0
+ var l1 = l - 1
+ for (i = l; i < k + 1; i++) {
+ f = s * e[i]
+ e[i] = c * e[i]
+ if (Math.abs(f) <= prec)
+ break
+ g = q[i]
+ h = pythag(f, g)
+ q[i] = h
+ c = g / h
+ s = -f / h
+ for (j = 0; j < m; j++) {
+ y = u[j][l1]
+ z = u[j][i]
+ u[j][l1] = y * c + (z * s)
+ u[j][i] = -y * s + (z * c)
+ }
+ }
+ }
+ // test f convergence
+ z = q[k]
+ if (l == k) { //convergence
+ if (z < 0.0) { //q[k] is made non-negative
+ q[k] = -z
+ for (j = 0; j < n; j++)
+ v[j][k] = -v[j][k]
+ }
+ break //break out of iteration loop and move on to next k value
+ }
+ if (iteration >= itmax - 1)
+ throw 'Error: no convergence.'
+ // shift from bottom 2x2 minor
+ x = q[l]
+ y = q[k - 1]
+ g = e[k - 1]
+ h = e[k]
+ f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y)
+ g = pythag(f, 1.0)
+ if (f < 0.0)
+ f = ((x - z) * (x + z) + h * (y / (f - g) - h)) / x
+ else
+ f = ((x - z) * (x + z) + h * (y / (f + g) - h)) / x
+ // next QR transformation
+ c = 1.0
+ s = 1.0
+ for (i = l + 1; i < k + 1; i++) {
+ g = e[i]
+ y = q[i]
+ h = s * g
+ g = c * g
+ z = pythag(f, h)
+ e[i - 1] = z
+ c = f / z
+ s = h / z
+ f = x * c + g * s
+ g = -x * s + g * c
+ h = y * s
+ y = y * c
+ for (j = 0; j < n; j++) {
+ x = v[j][i - 1]
+ z = v[j][i]
+ v[j][i - 1] = x * c + z * s
+ v[j][i] = -x * s + z * c
+ }
+ z = pythag(f, h)
+ q[i - 1] = z
+ c = f / z
+ s = h / z
+ f = c * g + s * y
+ x = -s * g + c * y
+ for (j = 0; j < m; j++) {
+ y = u[j][i - 1]
+ z = u[j][i]
+ u[j][i - 1] = y * c + z * s
+ u[j][i] = -y * s + z * c
+ }
+ }
+ e[l] = 0.0
+ e[k] = f
+ q[k] = x
+ }
+ }
+
+ for (i = 0; i < q.length; i++)
+ if (q[i] < prec) q[i] = 0
+
+ //sort eigenvalues
+ for (i = 0; i < n; i++) {
+ for (j = i - 1; j >= 0; j--) {
+ if (q[j] < q[i]) {
+ c = q[j]
+ q[j] = q[i]
+ q[i] = c
+ for (k = 0; k < u.length; k++) {
+ temp = u[k][i];
+ u[k][i] = u[k][j];
+ u[k][j] = temp;
+ }
+ for (k = 0; k < v.length; k++) {
+ temp = v[k][i];
+ v[k][i] = v[k][j];
+ v[k][j] = temp;
+ }
+ i = j
+ }
+ }
+ }
+
+ return {
+ U: u,
+ S: q,
+ V: v
+ }
+ }
+
+ return {
+ computeDeviationScores: computeDeviationScores,
+ computeDeviationMatrix: computeDeviationMatrix,
+ computeSVD: computeSVD,
+ computePercentageExplained: computePercentageExplained,
+ computeOriginalData: computeOriginalData,
+ computeVarianceCovariance: computeVarianceCovariance,
+ computeAdjustedData: computeAdjustedData,
+ getEigenVectors: getEigenVectors,
+ analyseTopResult: analyseTopResult,
+ transpose: transpose,
+ multiply: multiply,
+ clone: clone,
+ scale: scale
+ }
+})();
+
+if(typeof module !== 'undefined')
+module.exports = PCA;
\ No newline at end of file
diff --git a/modules/savage.toggle-switch.js b/modules/savage.toggle-switch.js
deleted file mode 100755
index 469a926..0000000
--- a/modules/savage.toggle-switch.js
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2015 Jose F. Maldonado
- * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
- * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-// Verify if the namespace is not already defined.
-if(typeof SaVaGe !== 'object') SaVaGe = {};
-
-/**
- * Creates a SVG element representing a toggle switch.
- *
- * The parameter must be an object with the following attributes:
- * 'container' (a selector of the element where the element must be appended),
- * 'value' (a boolean indicating the initial value of the switch, by default 'false'),
- * 'height' (a number indicating the height, in pixels, of the element, by default 50),
- * 'width' (a number indicating the width, in pixels, of the element, by default 80),
- * 'radius' (a number indicating the radius of the lever),
- * 'border' (a number indicating the width, in pixels, the distance between the element background and the switch's button, by default 5),
- * 'duration' (a number indicating the number of milliseconds that the toggle animation must last, by default 250),
- * 'colors' (an object with the attributes 'backLeft', 'foreLeft', 'backRight' and 'foreRight' indicating the colors of the element in each state) and
- * 'onChange' (a callback function which is invoked every time that the element is clicked).
- *
- * The object returned by this function contains the methods:
- * 'svg', and instance of the SVG object created with D3.js,
- * 'getValue()', for get the current state of the switch,
- * 'serValue(newVal)', for change the state of the switch and
- * 'remove()', for remove the element from the document.
- *
- * @param {object} params An collection of values for customize the element.
- * @returns {object} An object with methods for manipulate the element.
- */
-SaVaGe.ToggleSwitch = function(params) {
- // Verify parameters.
- if(typeof params !== 'object') params = {};
- if(typeof params.container !== 'string') params.container = "body";
- if(typeof params.value !== 'boolean') params.value = false;
- if(typeof params.height !== 'number') params.height = 50;
- if(typeof params.width !== 'number' || params.width < params.height) params.width = parseInt(params.height*1.6, 10);
- if(typeof params.radius !== 'number') params.radius = params.height/2 - 4;
- if(typeof params.duration !== 'number') params.duration = 250;
- if(typeof params.colors !== 'object') params.colors = {};
- if(params.colors.backLeft === undefined) params.colors.backLeft = "lightgray";
- if(params.colors.foreLeft === undefined) params.colors.foreLeft = "white";
- if(params.colors.backRight === undefined) params.colors.backRight = "#88f";
- if(params.colors.foreRight === undefined) params.colors.foreRight = "white";
-
- // Define internal variables.
- var atRight = params.value;
-
- // Calculate SVG dimensions and position offset.
- var svgHeight = params.height;
- var svgWidth = params.width;
- var offsetX = 0;
- var offsetY = 0;
- if(params.radius*2 > params.height) {
- svgHeight = params.radius*2;
- svgWidth = parseInt(params.width + (params.radius*2 - params.height), 10);
- offsetX = parseInt((svgWidth - params.width)/2, 10);
- offsetY = parseInt((svgWidth - params.width)/2, 10);
- }
-
- // Create widget.
- var svg = d3.select(params.container).append("svg")
- .attr("width", svgWidth)
- .attr("height", svgHeight)
- .style("cursor", "pointer");
- var rect = svg.append("rect")
- .attr("x", offsetX)
- .attr("y", offsetY)
- .attr("rx", params.height/2)
- .attr("ry", params.height/2)
- .style("fill", atRight? params.colors.backRight : params.colors.backLeft)
- .attr("width", params.width)
- .attr("height", params.height);
- var circle = svg.append("circle")
- .attr("cx", (atRight? (params.width-params.height/2) : (params.height/2)) + offsetX)
- .attr("cy", params.height/2 + offsetY)
- .attr("r", params.radius)
- .style("fill", atRight? params.colors.foreRight : params.colors.foreLeft);
-
- // Define internal functions.
- var setAtRight = function(newValue) {
- atRight = newValue;
- circle.transition().duration(params.duration)
- .attr("cx", (atRight? (params.width-params.height/2) : (params.height/2)) + offsetX)
- .style("fill", atRight? params.colors.foreRight : params.colors.foreLeft);
- rect.transition().duration(params.duration).style("fill", atRight? params.colors.backRight : params.colors.backLeft);
-
- };
-
- // Define result's object.
- var res = {
- 'svg' : svg,
- 'getValue': function() { return atRight; },
- 'setValue': setAtRight,
- 'remove': function() { svg.remove(); }
- };
-
- // Define click listener.
- svg.on('click', function(data, index){
- setAtRight(!atRight);
- if(typeof params.onChange === 'function') params.onChange(res);
- });
-
- return res;
-};