From d0fffd5c73f5b63c6fc4d0039f14e8d349cf1d4d Mon Sep 17 00:00:00 2001 From: Angelos Chatzimparmpas Date: Wed, 29 Jul 2020 15:40:40 +0200 Subject: [PATCH] new --- __pycache__/run.cpython-37.pyc | Bin 12946 -> 13044 bytes frontend/src/components/FeatureSpace2.vue | 296 +++++++++++++++++----- run.py | 16 +- 3 files changed, 249 insertions(+), 63 deletions(-) diff --git a/__pycache__/run.cpython-37.pyc b/__pycache__/run.cpython-37.pyc index 3d2484dfbbd3476cfe3703e0b419ef46cb3d06ce..3e9e870320dcf21712efe21b91d4e847dd0c17cc 100644 GIT binary patch delta 1498 zcmY+^J8u(N6ae74cWfzmX8g{0#)%y}!NDOR&I36l5FoZAu`6xGHmjA$f(9ZvS_(7U ztj@@VSpfylONo?8O9hHVfyATY2T)L;6i5`?K!dj2V$VIfcx_8F=W#VN=kq)sUH#{3 zykS`}4SzpumA4*Vd>%Io{Kt{~@xlt*iig&o7R12_O^gXhP@Mpi>LetoPJ%^s3Q|<3 zAl8n1Bi@m_EQo>8&kZp9xd~P~E*=#(x`{9e={*+MzRWV1 zV+P|G#w^BhjH4I}ej4l^^AbCe2fXvm&v;2Mh1V~F9cI;9dXEP-6vI)l@r*^^4s%fK zVmjg5Z3kj7vCX}-m$}P>5|oHkhBA>bwhd47w7)o>EZ<`W<=42Y1!dobSeW0_dhCvd zXBxYuU1MI>Gj5Lf|qBn}?pHw5+J6$>N7k>gTZ})gG1yf-O|LddI zBinMHl~ZC}#yEy?Qg-p+oU-bjgTA!_IkL(%Y0W_etvLi%$XdZ{ny3a$f2WEIC9_M$ zDpUuIV?)L&8VzM+WMpW}DI*&)GG&}mW7>F2^v(w)8aOr&j>B;x&JuAJi5CxzRb`w( z<18NRC}X7au5X+Jhm3Mf8XcHJql2>RpkP#bWK54mdSGL?&yi=)d? zE`%BuI}Oesw>wDx>jjQ`ChG2CZD>~l*xN@hBB#Hmj-;+*SLxU)Zo+x0ThOAq1shav!Y0+5IFf_Mmhtaq z+YCo*P^UT2X;P;(&}mUe1XKBFv3)cw?LV1vIkUuz%1ss*;k3sRv`>oYv3qPRrxR<8iOhUm{61gpZ?EPT xvHSP@d-g)Stlf5Z@k9NFYuXL^Wa|+<#z$D3b$0iEU3ksduE;O_q5qOU@*fk)tVjR= delta 1461 zcmY+^y>Ht_6aaAEQEFs<*s?5%q`qv$u`Jn&i%J-0FqSdqF;*}ZFjm89C=QrE z^*Hq{4?c!DKkHB9^=nX!XVhG7$fF|E;ye^_#adX1@u-jKY*^?yV8HA#_jCTtJ08u! z98u~}@0q^lYp*yiQW`Lm@<-g$qI&3p5qm>zz}{-OLg}^ki1~Tne3=Q$Z?s;;&v`g^ zh<`k)`UPC~qH3i`ZGH%A&^NGe9?ipiJd5}8(n;!Aj(OP~9@jCJFkX~ZJlRo3Jvd8@ z3*eAZ&Pk&K3utr@wm`-O%o;>Ap^*?5VNnwMQ4^XY#`2i4iAGZy85tQG9c5%=My8A{ z)uuG+!B1#3v27kL!4eUdiMXtY_qC|0j4d=SrvWH#eTai^<%u~K}@FMZ8gGW9&Cw(5Qqt8RtI{DTyyFztkkJnKxCN(wq*SqtV8;d2|h~k#URma4R8hDB>m( zx5B=Bv*bIrO})z}@j7L4ziv<_Wjo|CU_0^Lq>2gGlgchtEVz+WZc)XCousk{H|Z|y z!!E^xJ8+AVL)fEu8!zd=eq6^}%Z?dddY>u>Bb5WH9F9~DWkvisUrtwhm*Uy;zvn&9 zCd6lrm&_3VG<;^#Xo)Wt-?O^-Yw@JR9igqi@j>JyuEAd0?n{@g~@b$@g zcj-T!-4UJ6ws_L%ieaZA|5Fuau}PL?296n)5oet;)?KmMb;N`2AM8w2R^E80_znJ* gYuZ!#8tWO@0TY22bTbtG5`Po diff --git a/frontend/src/components/FeatureSpace2.vue b/frontend/src/components/FeatureSpace2.vue index 727f355..77f6b9d 100644 --- a/frontend/src/components/FeatureSpace2.vue +++ b/frontend/src/components/FeatureSpace2.vue @@ -22,8 +22,9 @@ export default { }, methods: { initializeNetwork () { - var dataLoc = JSON.parse(this.dataFS2[3]) + var listofNodes = this.dataFS2[0] + var dataLoc = JSON.parse(this.dataFS2[3]) var nodes = [] listofNodes.forEach(element => nodes.push({"name": element})) @@ -50,11 +51,79 @@ export default { }, graphVizualization () { + var uniqueTarget = JSON.parse(this.dataFS2[15]) + var corrTarget = JSON.parse(this.dataFS2[7]) + var corrGlob = JSON.parse(this.dataFS2[11]) + var VIFVar = JSON.parse(this.dataFS2[19]) + var MIVar = JSON.parse(this.dataFS2[23]) + + var colorCateg = d3.scaleOrdinal(d3.schemeAccent) + + var corrTargetFormatted = [] + for (let i = 0; i < Object.keys(corrTarget).length; i++) { + var corrTargetFormattedLoc = [] + for (let j = 0; j < Object.keys(corrTarget[i]).length; j++) { + if (j > uniqueTarget.length - 1) { + corrTargetFormattedLoc.push(Math.round(Object.values(corrTarget[i])[j] * 100)) + } + } + corrTargetFormatted.push(corrTargetFormattedLoc) + } + + var corrGlobFormatted = [] + for (let i = 0; i < Object.keys(corrGlob).length; i++) { + if (i != 0) { + corrGlobFormatted.push(Math.round(Object.values(corrGlob)[i]['0'] * 100)) + } + } + + var VIFVarFormatted = [] + for (let i = 0; i < Object.keys(VIFVar).length; i++) { + if (i != 0) { + if (Object.values(VIFVar)[i] > 10) { + VIFVarFormatted.push(2) + } else if (Object.values(VIFVar)[i] > 5) { + VIFVarFormatted.push(1) + } else { + VIFVarFormatted.push(0) + } + } + } + + function min(input) { + if (toString.call(input) !== "[object Array]") + return false; + return Math.min.apply(null, input); + } + + function max(input) { + if (toString.call(input) !== "[object Array]") + return false; + return Math.max.apply(null, input); + } + + function normalize(min, max) { + var delta = max - min; + return function (val) { + return (val - min) / delta; + }; + } + + var MIMin = min(MIVar) + var MIMax = max(MIVar) + + MIVar = MIVar.map(normalize(MIMin, MIMax)) + + var colorsScaleNodes = d3.scaleLinear() + .domain(d3.ticks(MIMin, MIMax, 5)) + .range(['#fb6a4a','#ef3b2c','#cb181d','#a50f15','#67000d']); + var svg = d3.select("#FeatureGraph2"); svg.selectAll("*").remove(); - var width = 600; - var height = 500; + var marginSVG = { top: 0, right: 50, bottom: 0, left: 50} + var width = 800; + var height = 600; var numTicks = 200; @@ -64,8 +133,8 @@ export default { var dispatch = d3.dispatch('layoutend'); svg = d3.select("#FeatureGraph2").append("svg") - .attr("width", width) - .attr("height", height); + .attr("width", width + marginSVG.left + marginSVG.right) + .attr("height", height + marginSVG.top + marginSVG.bottom); var graph = this.jsonData @@ -133,68 +202,174 @@ export default { p.graphReadability = greadability.greadability(graph.nodes, graph.links); p.graphReadability = (p.graphReadability.crossing + p.graphReadability.crossingAngle + - p.graphReadability.angularResolutionMin + p.graphReadability.angularResolutionDev) / 4 + p.graphReadability.angularResolutionMin + p.graphReadability.angularResolutionDev) / 4 p.positions = graph.nodes.map(function (n) { return {x: n.x, y: n.y}; }); dispatch.call('layoutend', forceSim, p, i); ++i; - if (i >= paramList.length) { - - var circles = node.append("circle") - .attr("r", 5); - - var drag_handler = d3.drag() - .on("start", drag_start) - .on("drag", drag_drag) - .on("end", drag_end); - - drag_handler(node); - - var labels = node.append("text") - .text(function(d) { - return d.name; - }) - .attr('x', 6) - .attr('y', 3); - - node.append('title').text(function (d) { return d.name; }); - - //add zoom capabilities - var zoom_handler = d3.zoom() - .on("zoom", zoom_actions); - - zoom_handler(svg); + if (i >= paramList.length) { + + // var data = [[ + // {value: 70, label: "", color: '#ff0000', lcolor: ''}, + // {value: 33, label: "", color: '#00ff00', lcolor: ''}, + // {value: 100, label: "44.5", color: '#000000', lcolor: 'black'} + // ];] + + var data = [] + for(let k = 0; k < uniqueTarget.length; k++) { + data.push({value: corrTargetFormatted[k][0], label: '', color: colorCateg(uniqueTarget[k]), lcolor: ''}) + } + data.push({value: 100, label: corrGlobFormatted[0], color: '#000000', lcolor: colorsScaleNodes(MIVar[0])}) + + var length = data.length + var border = VIFVarFormatted[0] + + var widthLoc = 100; + var arcSize = (6 * widthLoc / 100); + var innerRadius = arcSize * 2; + + var svgNodes = node.append('svg').attr('width', widthLoc).attr('height', widthLoc); + + var arcs = data.map(function (obj, i) { + var data = [] + for(let k = 0; k < uniqueTarget.length; k++) { + data.push({value: corrTargetFormatted[k][0], label: '', color: colorCateg(uniqueTarget[k]), lcolor: ''}) + } + data.push({value: 100, label: corrGlobFormatted[0], color: '#000000', lcolor: colorsScaleNodes(MIVar[0])}) + var length = data.length + var border = VIFVarFormatted[i] + if (i == length - 1) { + return d3.arc().innerRadius(i * arcSize + innerRadius).outerRadius((i + 1) * arcSize - (widthLoc / 100) + innerRadius + border); + } else { + return d3.arc().innerRadius(i * arcSize + innerRadius).outerRadius((i + 1) * arcSize - (widthLoc / 100) + innerRadius); + } + }); + + var arcsGrey = data.map(function (obj, i) { + return d3.arc().innerRadius(i * arcSize + (innerRadius + ((arcSize / 2) - 2))).outerRadius((i + 1) * arcSize - ((arcSize / 2)) + (innerRadius)); + }); + + var pieData = data.map(function (obj, i) { + return [ + {value: obj.value, arc: arcs[i], object: obj}, + {value: (100 - obj.value), arc: arcsGrey[i], object: obj}, + {value: 0, arc: arcs[i], object: obj}]; + }); + + var pie = d3.pie().sort(null).value(function (d) { + return d.value; + }); + + var g = svgNodes.select('g').data(pieData).enter() + .append('g') + .attr('transform', 'translate(' + widthLoc / 2 + ',' + widthLoc / 2 + ') rotate(180)'); + var gText = svgNodes.selectAll('g.textClass').data([{}]).enter() + .append('g') + .classed('textClass', true) + .attr('transform', 'translate(' + widthLoc / 2 + ',' + widthLoc / 2 + ') rotate(180)'); + + + g.selectAll('path').data(function (d) { + return pie(d); + }).enter().append('path') + .attr('id', function (d, i) { + if (i == 1) { + return "Text" + d.data.object.label + } + }) + .attr('d', function (d) { + return d.data.arc(d); + }).attr('fill', function (d, i) { + return i == 0 ? d.data.object.color : i == 1 ? '#D3D3D3' : 'none'; + }); + + svgNodes.selectAll('g').each(function (d, index) { + var el = d3.select(this); + var path = el.selectAll('path').each(function (r, i) { + if (i === 1) { + var centroid = r.data.arc.centroid({ + startAngle: r.startAngle + 0.05, + endAngle: r.startAngle + 0.001 + 0.05 + }); + var lableObj = r.data.object; + g.append('text') + .attr('font-size', ((2 * width) / 100)) + .attr('dominant-baseline', 'central') + .append("textPath") + .attr("textLength", function (d, i) { + return 0; + }) + .attr("startOffset", '5') + .attr("dy", '-3em') + .text(lableObj.value + '%'); + } + if (i === 0) { + var centroidText = r.data.arc.centroid({ + startAngle: r.startAngle, + endAngle: r.startAngle + }); + var lableObj = r.data.object; + gText.append('text') + .attr('font-size', ((2 * width) / 100)) + .text(lableObj.label) + .style('fill', lableObj.lcolor) + .attr('transform', "translate(" + (6) + "," + (0 + ") rotate(" + (180) + ")")) + .attr('dominant-baseline', 'central'); + } + }); + }); + + var drag_handler = d3.drag() + .on("start", drag_start) + .on("drag", drag_drag) + .on("end", drag_end); + + drag_handler(node); + + var labels = node.append("text") + .text(function(d) { + return d.name; + }) + .attr('x', 20) + .attr('y', 15); + + node.append('title').text(function (d) { return d.name; }); + + //add zoom capabilities + var zoom_handler = d3.zoom() + .on("zoom", zoom_actions); + + zoom_handler(svg); + + drawGraph(); + + //Zoom functions + function zoom_actions(){ + svg.attr("transform", d3.event.transform) + } + + function drag_start(d) { + if (!d3.event.active) forceSim.alphaTarget(0.3).restart(); + d.fx = d.x; + d.fy = d.y; + } - drawGraph(); + //make sure you can't drag the circle outside the box + function drag_drag(d) { + d.fx = d3.event.x; + d.fy = d3.event.y; + tickActions(); + } - //Zoom functions - function zoom_actions(){ - svg.attr("transform", d3.event.transform) - } + function drag_end(d) { + if (!d3.event.active) forceSim.alphaTarget(0); + d.fx = null; + d.fy = null; + } - function drag_start(d) { - console.log(d) - if (!d3.event.active) forceSim.alphaTarget(0.3).restart(); - d.fx = d.x; - d.fy = d.y; - } - - //make sure you can't drag the circle outside the box - function drag_drag(d) { - d.fx = d3.event.x; - d.fy = d3.event.y; - tickActions(); - } - - function drag_end(d) { - if (!d3.event.active) forceSim.alphaTarget(0); - d.fx = null; - d.fy = null; - } - - stepper.stop(); + stepper.stop(); } }); @@ -207,7 +382,9 @@ export default { .attr('y2', function (d) { return d.target.y; }); node - .attr("transform", function(d) { + .attr("transform", function(d, i) { + d.x = d.x - 50 + d.y = d.y - 50 return "translate(" + d.x + "," + d.y + ")"; }) }; @@ -298,7 +475,6 @@ export default { text { font-family: sans-serif; - font-size: 10px; } svg { diff --git a/run.py b/run.py index b3263de..d57bad5 100644 --- a/run.py +++ b/run.py @@ -509,9 +509,13 @@ def Seperation(): DataRows4 = XData.iloc[quadrant4, :] corrMatrix1 = DataRows1.corr() + corrMatrix1 = corrMatrix1.abs() corrMatrix2 = DataRows2.corr() + corrMatrix2 = corrMatrix2.abs() corrMatrix3 = DataRows3.corr() + corrMatrix3 = corrMatrix3.abs() corrMatrix4 = DataRows4.corr() + corrMatrix4 = corrMatrix4.abs() DataRows1 = DataRows1.reset_index(drop=True) DataRows2 = DataRows2.reset_index(drop=True) @@ -540,6 +544,7 @@ def Seperation(): hotEncoderDF1 = pd.DataFrame(onehotEncoder1) concatDF1 = pd.concat([DataRows1, hotEncoderDF1], axis=1) corrMatrixComb1 = concatDF1.corr() + corrMatrixComb1 = corrMatrixComb1.abs() corrMatrixComb1 = corrMatrixComb1.iloc[:,-len(uniqueTarget1):] X1 = add_constant(DataRows1.dropna()) VIF1 = pd.Series([variance_inflation_factor(X1.values, i) @@ -562,6 +567,7 @@ def Seperation(): hotEncoderDF2 = pd.DataFrame(onehotEncoder2) concatDF2 = pd.concat([DataRows2, hotEncoderDF2], axis=1) corrMatrixComb2 = concatDF2.corr() + corrMatrixComb2 = corrMatrixComb2.abs() corrMatrixComb2 = corrMatrixComb2.iloc[:,-len(uniqueTarget2):] X2 = add_constant(DataRows2.dropna()) VIF2 = pd.Series([variance_inflation_factor(X2.values, i) @@ -584,14 +590,13 @@ def Seperation(): hotEncoderDF3 = pd.DataFrame(onehotEncoder3) concatDF3 = pd.concat([DataRows3, hotEncoderDF3], axis=1) corrMatrixComb3 = concatDF3.corr() + corrMatrixComb3 = corrMatrixComb3.abs() corrMatrixComb3 = corrMatrixComb3.iloc[:,-len(uniqueTarget3):] X3 = add_constant(DataRows3.dropna()) VIF3 = pd.Series([variance_inflation_factor(X3.values, i) for i in range(X3.shape[1])], index=X3.columns) if (len(targetRows3Arr) > 2): - print(DataRows3) - print(targetRows3Arr) MI3 = mutual_info_classif(DataRows3, targetRows3Arr) MI3List = MI3.tolist() else: @@ -608,6 +613,7 @@ def Seperation(): hotEncoderDF4 = pd.DataFrame(onehotEncoder4) concatDF4 = pd.concat([DataRows4, hotEncoderDF4], axis=1) corrMatrixComb4 = concatDF4.corr() + corrMatrixComb4 = corrMatrixComb4.abs() corrMatrixComb4 = corrMatrixComb4.iloc[:,-len(uniqueTarget4):] X4 = add_constant(DataRows4.dropna()) VIF4 = pd.Series([variance_inflation_factor(X4.values, i) @@ -634,9 +640,13 @@ def Seperation(): concatAllDF4 = pd.concat([DataRows4, targetRows4ArrDF], axis=1) corrMatrixCombTotal1 = concatAllDF1.corr() + corrMatrixCombTotal1 = corrMatrixCombTotal1.abs() corrMatrixCombTotal2 = concatAllDF2.corr() + corrMatrixCombTotal2 = corrMatrixCombTotal2.abs() corrMatrixCombTotal3 = concatAllDF3.corr() + corrMatrixCombTotal3 = corrMatrixCombTotal3.abs() corrMatrixCombTotal4 = concatAllDF4.corr() + corrMatrixCombTotal4 = corrMatrixCombTotal4.abs() corrMatrixCombTotal1 = pd.concat([corrMatrixCombTotal1.tail(1)]) corrMatrixCombTotal2 = pd.concat([corrMatrixCombTotal2.tail(1)]) @@ -653,7 +663,7 @@ def Seperation(): packCorr.append(corrMatrix2.to_json()) packCorr.append(corrMatrix3.to_json()) packCorr.append(corrMatrix4.to_json()) - + packCorr.append(corrMatrixComb1.to_json()) packCorr.append(corrMatrixComb2.to_json()) packCorr.append(corrMatrixComb3.to_json())