From b38659682ace637a6a39bc136cfb6d58828990d8 Mon Sep 17 00:00:00 2001 From: Angelos Chatzimparmpas Date: Thu, 6 Aug 2020 14:54:25 +0200 Subject: [PATCH] new transformation --- __pycache__/run.cpython-37.pyc | Bin 18163 -> 18569 bytes frontend/src/components/FeatureSpace1.vue | 103 ++++++++++++++++++++-- frontend/src/components/FeatureSpace2.vue | 2 +- frontend/src/components/FeatureSpace3.vue | 2 +- frontend/src/components/FeatureSpace4.vue | 2 +- frontend/src/components/Main.vue | 5 +- run.py | 49 +++++++--- 7 files changed, 143 insertions(+), 20 deletions(-) diff --git a/__pycache__/run.cpython-37.pyc b/__pycache__/run.cpython-37.pyc index 9e55b2ae94c2106df54f3e7f2153f0bcef95318a..a8d727869f7e770ab5ab835360e0f5b35b82929d 100644 GIT binary patch delta 3818 zcmbuBU2Ggz702(rGrL~z?3Z`fPQ3Oy-o#tm-L+k>V>fMF@2+D4;sH<#LJCQX@i-xF zm5<3pgz5|%X^UtPsZ!<@(OIFs&@YP1mmq}_0un;Jfsn;BJo12qcq*K8c6PGkHfa%F z&414S+}XS5cjn&l{PTu<;U$?`PbT96|Ni{%%2R*4{#GhoOl8m}@Hm0Tl|Qj;Wg#kCE4(A3RHTWyFlD^Ajm zn^8!Ph_-Z6w$T=l8Wm0&5<3Ykay2Mn^eWD0p$m;*pT>xP7#5I!7^xSSe*vS1m|ug30{%r{}Jj@ZTjbj{9mmcBX2v`Yv z^C)K|%sm{Wj&n-Eu^_X`84VukW!!I0A8x@aceMcx?rH-bW8Z`(`zEXf^{rv-KXJ?) zz0NpmP!C4y7>7se&5y<4nCTQ|C;h zFVo;mvoF)c8?g@S-a-67HQEvM&y=0fbuHf}LW9YWD~8-u$W=nF7IJGLR}Z;{?^@kz znxVmokSm8=HRP81on7$8V6ua~>O!%f-sk7T{!_3VPQb`Me_)?KxX+LF{1aj}?>;$e z%Bp*N_C+blpk|nt$a@Iy0SWDJgM+S0uK?D?z@#bXY=lJ)r|3# z4;rZ*wNB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1ux^ z5ol#rnj_X$7(v!nBphMZ5sXHe)qv69vW~$RqmIKkqmH{U-oUyt#5#_whRARt}UFAurbJ7%^3xog3L9XF<^6$xfZr`aXZRT=600fYW9;bNnXzk_Pco2 zBu=+um*rlGXD@SRvLQ3cnW=`%6lbOzGSkR612f)AeEa6>g1!~l#X>F~atUuA47u@;D~H@<$W4XZbfa?$UI(S!5m3i>0U3jM6_&-7MeH zH;k-NJCt6W-j3!hngbWj$mp8 zw@=oTFm!!*K}jC^6noK029+2~XyoB*Cef`XhF8zM6$4Fi#d7tD1k`GCqBsooT zhGc=nB>9NsW0E5z_mi9@$&!3Ra*m`<@+rv+B=m#b{*2^vlnc>=-Mbg|&taSG7b!__ z_Ln3Tk}vee*(1&8Dg0{bwb`635oIxA|5g7l#BaLi;63(kXWzXCzFzui>pr}V_0G!c zZLd;mBY3cAiYi-ScaP@vU6s6Ezil%0JDq?gvBy$Bux(ZPWN3Fozq;*cff{g{^88PT v5i#N_DotshS-N)ql(&e`WuFj{h4T{d_*!KGpn@!o}irYJ49kD+EFj+X) diff --git a/frontend/src/components/FeatureSpace1.vue b/frontend/src/components/FeatureSpace1.vue index 1c59e08..4cce411 100644 --- a/frontend/src/components/FeatureSpace1.vue +++ b/frontend/src/components/FeatureSpace1.vue @@ -17,6 +17,7 @@ export default { data () { return { dataFS1: [], + dataFS1Trans: [], jsonData: [], } }, @@ -25,9 +26,102 @@ export default { var listofNodes = this.dataFS1[0] var dataLoc = JSON.parse(this.dataFS1[2]) + var pushEachFinal = [] + var pushEach + var oldVal + var newVal + var outcome + var countLoc + + this.dataFS1Trans.forEach(function(element, index) { + var round = element.round + round = JSON.parse(round[0]) + oldVal = 0 + newVal = 0 + outcome = 0 + countLoc = 0 + pushEach = [] + Object.entries(round).forEach( + function ([feature, value]) { + var key = Object.keys(value) + var search = Object.values(dataLoc[key]) + oldVal = Math.abs(search[countLoc]) + oldVal + newVal = Math.abs(Object.values(value)[0]) + newVal + countLoc++ + }) + oldVal = oldVal / listofNodes.length + newVal = newVal / listofNodes.length + outcome = oldVal - newVal + pushEach.push({keyIns: "round", valueIns: outcome}) + + var roundLogE = element.roundLogE + roundLogE = JSON.parse(roundLogE[0]) + oldVal = 0 + newVal = 0 + outcome = 0 + countLoc = 0 + Object.entries(roundLogE).forEach( + function ([feature, value]) { + var key = Object.keys(value) + var search = Object.values(dataLoc[key]) + oldVal = Math.abs(search[countLoc]) + oldVal + newVal = Math.abs(Object.values(value)[0]) + newVal + countLoc++ + }) + oldVal = oldVal / listofNodes.length + newVal = newVal / listofNodes.length + outcome = oldVal - newVal + pushEach.push({keyIns: "roundLogE", valueIns: outcome}) + + var roundLog2 = element.roundLog2 + roundLog2 = JSON.parse(roundLog2[0]) + oldVal = 0 + newVal = 0 + outcome = 0 + countLoc = 0 + Object.entries(roundLog2).forEach( + function ([feature, value]) { + var key = Object.keys(value) + var search = Object.values(dataLoc[key]) + oldVal = Math.abs(search[countLoc]) + oldVal + newVal = Math.abs(Object.values(value)[0]) + newVal + countLoc++ + }) + oldVal = oldVal / listofNodes.length + newVal = newVal / listofNodes.length + outcome = oldVal - newVal + pushEach.push({keyIns: "roundLog2", valueIns: outcome}) + + var roundLog10 = element.roundLog10 + roundLog10 = JSON.parse(roundLog10[0]) + oldVal = 0 + newVal = 0 + outcome = 0 + countLoc = 0 + Object.entries(roundLog10).forEach( + function ([feature, value]) { + var key = Object.keys(value) + var search = Object.values(dataLoc[key]) + oldVal = Math.abs(search[countLoc]) + oldVal + newVal = Math.abs(Object.values(value)[0]) + newVal + countLoc++ + }) + oldVal = oldVal / listofNodes.length + newVal = newVal / listofNodes.length + outcome = oldVal - newVal + pushEach.push({keyIns: "roundLog10", valueIns: outcome}) + pushEachFinal.push({key: listofNodes[index], value: pushEach}) + }) var nodes = [] - listofNodes.forEach(element => nodes.push({"name": element})) + listofNodes.forEach( function(element) { + nodes.push({"name": element, "children": [ + {"name": element+"_round"}, + {"name": element+"_roundLogE"}, + {"name": element+"_roundLog2"}, + {"name": element+"_roundLog10"}, + ]}) + }) var links = [] @@ -36,9 +130,7 @@ export default { Object.entries(value).forEach( function ([featureInside, value]) { if (feature != featureInside) { if (value >= 0) { - links.push({"source": listofNodes.indexOf(feature), "target": listofNodes.indexOf(featureInside), "value": Math.abs(value) * 30, "group": 1}) - } else { - links.push({"source": listofNodes.indexOf(feature), "target": listofNodes.indexOf(featureInside), "value": Math.abs(value) * 30, "group": 2}) + links.push({"source": listofNodes.indexOf(feature), "target": listofNodes.indexOf(featureInside), "value": Math.abs(value) * 30}) } } }) @@ -117,7 +209,7 @@ export default { var colorsScaleNodes = d3.scaleLinear() .domain([MIMin, MIMax]) - .range(['#6baed6','#4292c6','#2171b5','#08519c','#08306b']); + .range(['#a6bddb','#74a9cf','#3690c0','#0570b0','#045a8d','#023858']); var svg = d3.select("#FeatureGraph1"); svg.selectAll("*").remove(); @@ -465,6 +557,7 @@ export default { }, }, mounted () { + EventBus.$on('quadTrans1', data => { this.dataFS1Trans = data }) EventBus.$on('quad1', data => { this.dataFS1 = data }) EventBus.$on('quad1', this.initializeNetwork) } diff --git a/frontend/src/components/FeatureSpace2.vue b/frontend/src/components/FeatureSpace2.vue index 0fc643d..c38b6c4 100644 --- a/frontend/src/components/FeatureSpace2.vue +++ b/frontend/src/components/FeatureSpace2.vue @@ -117,7 +117,7 @@ export default { var colorsScaleNodes = d3.scaleLinear() .domain([MIMin, MIMax]) - .range(['#6baed6','#4292c6','#2171b5','#08519c','#08306b']); + .range(['#a6bddb','#74a9cf','#3690c0','#0570b0','#045a8d','#023858']); var svg = d3.select("#FeatureGraph2"); svg.selectAll("*").remove(); diff --git a/frontend/src/components/FeatureSpace3.vue b/frontend/src/components/FeatureSpace3.vue index 9d18f5d..20a1a0b 100644 --- a/frontend/src/components/FeatureSpace3.vue +++ b/frontend/src/components/FeatureSpace3.vue @@ -117,7 +117,7 @@ export default { var colorsScaleNodes = d3.scaleLinear() .domain([MIMin, MIMax]) - .range(['#6baed6','#4292c6','#2171b5','#08519c','#08306b']); + .range(['#a6bddb','#74a9cf','#3690c0','#0570b0','#045a8d','#023858']); var svg = d3.select("#FeatureGraph3"); svg.selectAll("*").remove(); diff --git a/frontend/src/components/FeatureSpace4.vue b/frontend/src/components/FeatureSpace4.vue index f046b72..665d786 100644 --- a/frontend/src/components/FeatureSpace4.vue +++ b/frontend/src/components/FeatureSpace4.vue @@ -117,7 +117,7 @@ export default { var colorsScaleNodes = d3.scaleLinear() .domain([MIMin, MIMax]) - .range(['#6baed6','#4292c6','#2171b5','#08519c','#08306b']); + .range(['#a6bddb','#74a9cf','#3690c0','#0570b0','#045a8d','#023858']); var svg = d3.select("#FeatureGraph4"); svg.selectAll("*").remove(); diff --git a/frontend/src/components/Main.vue b/frontend/src/components/Main.vue index 54843b6..80e77a6 100755 --- a/frontend/src/components/Main.vue +++ b/frontend/src/components/Main.vue @@ -520,7 +520,10 @@ export default Vue.extend({ .then(response => { console.log('Server successfully send the correlation matrices!') this.correlResulTranformed = response.data.correlResulTranformed - console.log(this.correlResulTranformed) + EventBus.$emit('quadTrans1', this.correlResulTranformed) + EventBus.$emit('quadTrans2', this.correlResulTranformed) + EventBus.$emit('quadTrans3', this.correlResulTranformed) + EventBus.$emit('quadTrans4', this.correlResulTranformed) this.returnCorrel() }) .catch(error => { diff --git a/run.py b/run.py index 37c83b8..83a8083 100644 --- a/run.py +++ b/run.py @@ -484,7 +484,7 @@ def Transformation(quadrant1, quadrant2, quadrant3, quadrant4): global packCorrTransformed packCorrTransformed = [] - for i in columns: + for count, i in enumerate(columns): dicTransf = {} @@ -495,7 +495,7 @@ def Transformation(quadrant1, quadrant2, quadrant3, quadrant4): quadrantVariable = str('quadrant%s' % number) illusion = locals()[quadrantVariable] d["DataRows{0}".format(number)] = XDataNumericCopy.iloc[illusion, :] - dicTransf["round"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4) + dicTransf["round"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4, i, count) d={} XDataNumericCopy = XDataNumeric.copy() @@ -505,7 +505,7 @@ def Transformation(quadrant1, quadrant2, quadrant3, quadrant4): quadrantVariable = str('quadrant%s' % number) illusion = locals()[quadrantVariable] d["DataRows{0}".format(number)] = XDataNumericCopy.iloc[illusion, :] - dicTransf["roundLogE"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4) + dicTransf["roundLogE"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4, i, count) d={} XDataNumericCopy = XDataNumeric.copy() @@ -515,7 +515,7 @@ def Transformation(quadrant1, quadrant2, quadrant3, quadrant4): quadrantVariable = str('quadrant%s' % number) illusion = locals()[quadrantVariable] d["DataRows{0}".format(number)] = XDataNumericCopy.iloc[illusion, :] - dicTransf["roundLog2"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4) + dicTransf["roundLog2"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4, i, count) d={} XDataNumericCopy = XDataNumeric.copy() @@ -525,13 +525,13 @@ def Transformation(quadrant1, quadrant2, quadrant3, quadrant4): quadrantVariable = str('quadrant%s' % number) illusion = locals()[quadrantVariable] d["DataRows{0}".format(number)] = XDataNumericCopy.iloc[illusion, :] - dicTransf["roundLog10"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4) + dicTransf["roundLog10"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4, i, count) packCorrTransformed.append(dicTransf) return 'Everything Okay' -def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, quadrant2, quadrant3, quadrant4): +def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, quadrant2, quadrant3, quadrant4, feature, count): # Main Features corrMatrix1 = DataRows1.corr() @@ -543,6 +543,11 @@ def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, corrMatrix4 = DataRows4.corr() corrMatrix4 = corrMatrix4.abs() + corrMatrix1 = corrMatrix1.loc[[feature]] + corrMatrix2 = corrMatrix2.loc[[feature]] + corrMatrix3 = corrMatrix3.loc[[feature]] + corrMatrix4 = corrMatrix4.loc[[feature]] + DataRows1 = DataRows1.reset_index(drop=True) DataRows2 = DataRows2.reset_index(drop=True) DataRows3 = DataRows3.reset_index(drop=True) @@ -576,9 +581,11 @@ def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, VIF1 = pd.Series([variance_inflation_factor(X1.values, i) for i in range(X1.shape[1])], index=X1.columns) + VIF1 = VIF1.loc[[feature]] if (len(targetRows1Arr) > 2): MI1 = mutual_info_classif(DataRows1, targetRows1Arr) MI1List = MI1.tolist() + MI1List = MI1List[count] else: MI1List = [] else: @@ -599,9 +606,11 @@ def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, VIF2 = pd.Series([variance_inflation_factor(X2.values, i) for i in range(X2.shape[1])], index=X2.columns) + VIF2 = VIF2.loc[[feature]] if (len(targetRows2Arr) > 2): MI2 = mutual_info_classif(DataRows2, targetRows2Arr) MI2List = MI2.tolist() + MI2List = MI2List[count] else: MI2List = [] else: @@ -622,9 +631,11 @@ def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, VIF3 = pd.Series([variance_inflation_factor(X3.values, i) for i in range(X3.shape[1])], index=X3.columns) + VIF3 = VIF3.loc[[feature]] if (len(targetRows3Arr) > 2): MI3 = mutual_info_classif(DataRows3, targetRows3Arr) MI3List = MI3.tolist() + MI3List = MI3List[count] else: MI3List = [] else: @@ -645,9 +656,11 @@ def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, VIF4 = pd.Series([variance_inflation_factor(X4.values, i) for i in range(X4.shape[1])], index=X4.columns) + VIF4 = VIF4.loc[[feature]] if (len(targetRows4Arr) > 2): MI4 = mutual_info_classif(DataRows4, targetRows4Arr) MI4List = MI4.tolist() + MI4List = MI4List[count] else: MI4List = [] else: @@ -655,6 +668,11 @@ def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, VIF4 = pd.Series() MI4List = [] + corrMatrixComb1 = corrMatrixComb1.loc[[feature]] + corrMatrixComb2 = corrMatrixComb2.loc[[feature]] + corrMatrixComb3 = corrMatrixComb3.loc[[feature]] + corrMatrixComb4 = corrMatrixComb4.loc[[feature]] + targetRows1ArrDF = pd.DataFrame(targetRows1Arr) targetRows2ArrDF = pd.DataFrame(targetRows2Arr) targetRows3ArrDF = pd.DataFrame(targetRows3Arr) @@ -674,6 +692,15 @@ def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, corrMatrixCombTotal4 = concatAllDF4.corr() corrMatrixCombTotal4 = corrMatrixCombTotal4.abs() + corrMatrixCombTotal1 = corrMatrixCombTotal1.loc[[feature]] + corrMatrixCombTotal1 = corrMatrixCombTotal1.iloc[:,-1] + corrMatrixCombTotal2 = corrMatrixCombTotal2.loc[[feature]] + corrMatrixCombTotal2 = corrMatrixCombTotal2.iloc[:,-1] + corrMatrixCombTotal3 = corrMatrixCombTotal3.loc[[feature]] + corrMatrixCombTotal3 = corrMatrixCombTotal3.iloc[:,-1] + corrMatrixCombTotal4 = corrMatrixCombTotal4.loc[[feature]] + corrMatrixCombTotal4 = corrMatrixCombTotal4.iloc[:,-1] + corrMatrixCombTotal1 = pd.concat([corrMatrixCombTotal1.tail(1)]) corrMatrixCombTotal2 = pd.concat([corrMatrixCombTotal2.tail(1)]) corrMatrixCombTotal3 = pd.concat([corrMatrixCombTotal3.tail(1)]) @@ -696,11 +723,6 @@ def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, packCorrLoc.append(corrMatrixCombTotal3.to_json()) packCorrLoc.append(corrMatrixCombTotal4.to_json()) - packCorrLoc.append(json.dumps(uniqueTarget1)) - packCorrLoc.append(json.dumps(uniqueTarget2)) - packCorrLoc.append(json.dumps(uniqueTarget3)) - packCorrLoc.append(json.dumps(uniqueTarget4)) - packCorrLoc.append(VIF1.to_json()) packCorrLoc.append(VIF2.to_json()) packCorrLoc.append(VIF3.to_json()) @@ -711,6 +733,11 @@ def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, packCorrLoc.append(json.dumps(MI3List)) packCorrLoc.append(json.dumps(MI4List)) + packCorrLoc.append(json.dumps(uniqueTarget1)) + packCorrLoc.append(json.dumps(uniqueTarget2)) + packCorrLoc.append(json.dumps(uniqueTarget3)) + packCorrLoc.append(json.dumps(uniqueTarget4)) + return packCorrLoc @cross_origin(origin='localhost',headers=['Content-Type','Authorization'])