Skip to content

Commit

Permalink
Fixed gradle conf and test 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
m.gardellini committed Sep 20, 2017
1 parent d4a540c commit 1d23111
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,36 @@ package com.springernature.ctree4k

data class SplitHalf(val instances: List<Instance>)

class GiniImpurityScore: (Pair<SplitHalf, SplitHalf>, InstanceClasses) -> GiniScore {
class GiniImpurityScore : (Pair<SplitHalf, SplitHalf>, InstanceClasses) -> GiniScore {

override fun invoke(bothSplits: Pair<SplitHalf, SplitHalf>, allClasses: InstanceClasses): GiniScore {
return GiniScore(-1.0)
// (1 - (C0LS^2 + C1LS^2)) * LSC/TC
val leftSideCount = bothSplits.first.instances.size.toDouble()
val rightSideCount= bothSplits.second.instances.size.toDouble()
val totalCount = leftSideCount + rightSideCount

val class0OnLeftSide = bothSplits.first.instances.filter { it: Instance ->
it.instanceClass == allClasses.value.elementAt(0) }.count().toDouble()
val C0LS: Double = class0OnLeftSide/leftSideCount.toDouble()

val class1OnLeftSide = bothSplits.first.instances.filter { it: Instance ->
it.instanceClass == allClasses.value.elementAt(1) }.count().toDouble()
val C1LS = class1OnLeftSide/leftSideCount.toDouble()

val class0OnRightSide = bothSplits.second.instances.filter { it: Instance ->
it.instanceClass == allClasses.value.elementAt(0) }.count().toDouble()
val C0RS = class0OnRightSide/rightSideCount.toDouble()

val class1OnRightSide = bothSplits.second.instances.filter { it: Instance ->
it.instanceClass == allClasses.value.elementAt(1) }.count().toDouble()
val C1RS = class1OnRightSide/rightSideCount.toDouble()

val scoreForLeft = ((1.0 - (C0LS*C0LS + C1LS*C1LS)) * leftSideCount/totalCount)
val scoreForRight = ((1.0 - (C0RS*C0RS + C1RS*C1RS)) * rightSideCount/totalCount)

val score = scoreForLeft + scoreForRight

return GiniScore(score)
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Sep 15 12:54:40 BST 2017
#Wed Sep 20 12:43:49 BST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

0 comments on commit 1d23111

Please sign in to comment.