Skip to content

Commit

Permalink
provide groupings for similarity calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
reality committed Oct 2, 2021
1 parent 44989f1 commit 8cd1164
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion klarigi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ jacocoTestReport {
}
}

version = '0.0.11'
version = '0.0.12-SNAPSHOT'
55 changes: 32 additions & 23 deletions klarigi/src/main/groovy/klarigi/App.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class App {
_ longOpt: 'save-ic', 'Save the IC values to the given file', args:1

g longOpt: 'group', 'The group to explain.', args: 1
gf longOpt: 'group-file', 'You can pass a file with a list of groups to: one per line. If you do this, the --group argument will be ignored.', args: 1

_ longOpt: 'max-ic', 'Max IC to use in stepdown algorithm. Default: 0.8', args: 1
_ longOpt: 'min-ic', 'Min IC to use in stepdown algorithm. Default: 0.4', args: 1
Expand Down Expand Up @@ -80,36 +81,44 @@ class App {

def k = new Klarigi(o)
if(!o['similarity-mode']) {
if(!o['group'] || (o['group'] && o['group'] == '*')) {
def allExplanations = k.explainAllClusters(o['output-scores'], o['power'], threads)
allExplanations.each {
k.output(it.cluster, it.results, o['output-type'], o['print-members'], o['output'])
def allExplanations
if(o['group-file']) {
def groups
try {
groups = new File(o['group-file']).text.split('\n')
} catch(e) {
println "Could not handle the --group-file: ${e.toString()}"
System.exit(1)
}

if(o['output-exp-dataframe']) {
k.writeDataframe('train', allExplanations)
}

if(o['reclassify']) {
k.reclassify(allExplanations, o['output-classification-scores'])
}
if(o['classify']) {
k.classify(o['classify'], allExplanations, o['output-classification-scores'])

if(o['output-exp-dataframe']) {
k.writeDataframe('test', allExplanations)
}
}
allExplanations = k.explainClusters(groups, o['output-scores'], o['power'], threads)
} else if(o['group'] && o['group'] != '*') {
allExplanations = k.explainClusters([o['group']], o['output-scores'], o['power'], threads)
} else {
def r = k.explainCluster(o['group'], o['power'], o['output-scores'], threads)
k.output(o['group'], r, o['output-type'], o['print-members'], o['output'])
allExplanations = k.explainAllClusters(o['output-scores'], o['power'], threads)
}

if(o['reclassify'] || o['output-exp-dataframe']) {
println "Must explain all groups for --reclassify or --output-exp-dataframe"
allExplanations.each {
k.output(it.cluster, it.results, o['output-type'], o['print-members'], o['output'])
}

if(o['output-exp-dataframe']) {
k.writeDataframe('train', allExplanations)
}

if(o['reclassify']) {
k.reclassify(allExplanations, o['output-classification-scores'])
}
if(o['classify']) {
k.classify(o['classify'], allExplanations, o['output-classification-scores'])

if(o['output-exp-dataframe']) {
k.writeDataframe('test', allExplanations)
}
}

} else {
k.genSim(o['output'])
k.genSim(o['output'], o['group'])
}
}
}
5 changes: 3 additions & 2 deletions klarigi/src/main/groovy/klarigi/InformationContent.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ public class InformationContent {
}

// this should really go to a diff class
def compareEntities(assoc) {
def compareEntities(assoc, groupings, group) {
def smConfPairwise = new SMconf(SMConstants.FLAG_SIM_PAIRWISE_DAG_NODE_RESNIK_1995, icConf)
def smConfGroupwise = new SMconf(SMConstants.FLAG_SIM_GROUPWISE_BMA, icConf)

def results = [:]
assoc.each { k1, v1 ->
if(group && !groupings[group].contains(k1)) { return; }
if(!results.containsKey(k1)) { results[k1] = [:] }
assoc.each { k2, v2 ->
if(k1 == k2) { return; }
Expand All @@ -134,7 +135,7 @@ public class InformationContent {
results
}

static def WriteSimilarity(results, groups, toFile) {
static def WriteSimilarity(results, toFile) {
def out = []

results.each { k1, v1 ->
Expand Down
10 changes: 8 additions & 2 deletions klarigi/src/main/groovy/klarigi/Klarigi.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ public class Klarigi {
}
}

def explainClusters(groups, outputScores, powerMode, threads) {
data.groupings.findAll { g, v -> groups.contains(g) }.collect { g, v ->
[ cluster: g, results: explainCluster(g, powerMode, outputScores, threads) ]
}
}

def explainAllClusters(outputScores, powerMode, threads) {
data.groupings.collect { g, v ->
[ cluster: g, results: explainCluster(g, powerMode, outputScores, threads) ]
Expand Down Expand Up @@ -210,12 +216,12 @@ public class Klarigi {
}
}

def genSim(toFile) {
def genSim(toFile, group) {
if(!icFactory) {
println "Error: IC class not loaded (--similarity and --ic are not compatible)"
System.exit(1)
}
def results = icFactory.compareEntities(data.associations)
def results = icFactory.compareEntities(data.associations, data.groupings, group)
InformationContent.WriteSimilarity(results, toFile)
}

Expand Down

0 comments on commit 8cd1164

Please sign in to comment.