-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separating fpg and apriori code, cleanup
Adding new explanation result classes that keep track of raw counts for both interpretability and extensibility. This involved separating the fpg and apriori dependencies, in the future we can merge fpgrowth to use the new code.
- Loading branch information
Showing
36 changed files
with
457 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cd lib; mvn install; cd ../core ; mvn clean ; mvn package ; cd ../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
lib/src/main/java/edu/stanford/futuredata/macrobase/analysis/summary/BatchSummarizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 4 additions & 108 deletions
112
lib/src/main/java/edu/stanford/futuredata/macrobase/analysis/summary/Explanation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,7 @@ | ||
package edu.stanford.futuredata.macrobase.analysis.summary; | ||
|
||
import edu.stanford.futuredata.macrobase.analysis.summary.itemset.result.AttributeSet; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Represents a summarization result, which contains a list of attribute values | ||
* and other statistics about the underlying process, e.g. num of tuples observed | ||
* so far. | ||
*/ | ||
public class Explanation { | ||
private final long numOutliers; | ||
private final long numInliers; | ||
private List<AttributeSet> itemsets; | ||
private final long creationTimeMs; | ||
|
||
public Explanation(List<AttributeSet> resultList, | ||
long numInliers, | ||
long numOutliers, | ||
long creationTimeMs) { | ||
itemsets = new ArrayList<>(resultList); | ||
this.numInliers = numInliers; | ||
this.numOutliers = numOutliers; | ||
this.creationTimeMs = creationTimeMs; | ||
} | ||
|
||
/** | ||
* Removes redundant explanations | ||
* @return New explanation with redundant itemsets removed. | ||
*/ | ||
public Explanation prune() { | ||
itemsets.sort((AttributeSet a, AttributeSet b) -> -a.compareTo(b)); | ||
List<AttributeSet> newItemsets = new ArrayList<>(); | ||
int n = itemsets.size(); | ||
for (int i = 0; i < n; i++) { | ||
AttributeSet aSet = itemsets.get(i); | ||
boolean redundant = false; | ||
// an explanation is redundant if it has lower risk ratio (occurs after since sorted) | ||
// than an explanation that involves a subset of the same attributes | ||
for (int j = 0; j < i; j++) { | ||
AttributeSet comparisonSet = itemsets.get(j); | ||
if (aSet.contains(comparisonSet)) { | ||
redundant = true; | ||
break; | ||
} | ||
} | ||
if (!redundant) { | ||
newItemsets.add(aSet); | ||
} | ||
} | ||
|
||
Explanation newExplanation = new Explanation( | ||
newItemsets, | ||
numInliers, | ||
numOutliers, | ||
creationTimeMs | ||
); | ||
return newExplanation; | ||
} | ||
|
||
public void sortByRiskRatio() { | ||
itemsets.sort((AttributeSet a, AttributeSet b) -> -a.compareTo(b)); | ||
} | ||
|
||
public void sortBySupport() { | ||
itemsets.sort((AttributeSet a, AttributeSet b) -> -Double.compare(a.getSupport(),b.getSupport())); | ||
} | ||
|
||
public List<AttributeSet> getItemsets() { | ||
return itemsets; | ||
} | ||
|
||
public long getNumOutliers() { | ||
return numOutliers; | ||
} | ||
|
||
public long getNumInliers() { | ||
return numInliers; | ||
} | ||
|
||
public long getCreationTimeMs() { | ||
return creationTimeMs; | ||
} | ||
|
||
public String prettyPrint() { | ||
StringBuilder header = new StringBuilder(String.format( | ||
"Outlier Explanation:\n" | ||
+ "numOutliers: %d\n" | ||
+ "numInliers: %d\n" | ||
+ "Itemsets: \n" | ||
+ "--------\n", | ||
numOutliers, | ||
numInliers)); | ||
for (AttributeSet is : itemsets) { | ||
header.append(is.prettyPrint()); | ||
} | ||
return header.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Explanation{" + | ||
"numOutliers=" + numOutliers + | ||
", numInliers=" + numInliers + | ||
", itemsets=" + itemsets + | ||
'}'; | ||
} | ||
public interface Explanation { | ||
String prettyPrint(); | ||
double numOutliers(); | ||
double numTotal(); | ||
} |
58 changes: 58 additions & 0 deletions
58
...c/main/java/edu/stanford/futuredata/macrobase/analysis/summary/apriori/APExplanation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package edu.stanford.futuredata.macrobase.analysis.summary.apriori; | ||
|
||
import edu.stanford.futuredata.macrobase.analysis.summary.Explanation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* An explanation attempts to summarize the differences between the outliers and inliers. | ||
* It is composed of multiple ExplanationResult results, each of which has a matcher which | ||
* is an atomic classifier for rows in a dataset. | ||
*/ | ||
public class APExplanation implements Explanation { | ||
private ArrayList<ExplanationResult> results; | ||
private double numOutliers; | ||
private double numTotal; | ||
|
||
public APExplanation( | ||
List<ExplanationResult> results, | ||
double numOutliers, | ||
double numTotal | ||
) { | ||
this.results = new ArrayList<>(results); | ||
this.numOutliers = numOutliers; | ||
this.numTotal = numTotal; | ||
} | ||
|
||
public void sortBySupport() { | ||
results.sort( | ||
(ExplanationResult a, ExplanationResult b) -> -Double.compare(a.support(), b.support()) | ||
); | ||
} | ||
public ArrayList<ExplanationResult> getResults() { | ||
return results; | ||
} | ||
|
||
public double numOutliers() { | ||
return numOutliers; | ||
} | ||
public double numTotal() { | ||
return numTotal; | ||
} | ||
|
||
@Override | ||
public String prettyPrint() { | ||
StringBuilder header = new StringBuilder(String.format( | ||
"Outlier Explanation:\n" | ||
+ "numOutliers: %d\n" | ||
+ "numTotal: %d\n" | ||
+ "Results: \n", | ||
(long)numOutliers, | ||
(long)numTotal)); | ||
for (ExplanationResult is : results) { | ||
header.append(is.prettyPrint()); | ||
} | ||
return header.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.