-
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.
Adding support for mean shift summarization
- Loading branch information
Showing
12 changed files
with
437 additions
and
59 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...main/java/edu/stanford/futuredata/macrobase/analysis/summary/aplinear/APLExplanation.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,46 @@ | ||
package edu.stanford.futuredata.macrobase.analysis.summary.aplinear; | ||
|
||
import edu.stanford.futuredata.macrobase.analysis.summary.aplinear.metrics.QualityMetric; | ||
import edu.stanford.futuredata.macrobase.analysis.summary.util.AttributeEncoder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class APLExplanation { | ||
private AttributeEncoder encoder; | ||
private List<String> aggregateNames; | ||
|
||
private ArrayList<QualityMetric> metrics; | ||
private List<Double> thresholds; | ||
private ArrayList<APLExplanationResult> results; | ||
|
||
public APLExplanation( | ||
AttributeEncoder encoder, | ||
List<String> aggregateNames, | ||
List<QualityMetric> metrics, | ||
List<Double> thresholds, | ||
List<APLExplanationResult> results | ||
) { | ||
this.encoder = encoder; | ||
this.aggregateNames = aggregateNames; | ||
this.metrics = new ArrayList<>(metrics); | ||
this.thresholds = new ArrayList<>(thresholds); | ||
this.results = new ArrayList<>(results); | ||
} | ||
|
||
public List<APLExplanationResult> getResults() { | ||
return results; | ||
} | ||
|
||
String prettyPrint() { | ||
StringBuilder header = new StringBuilder(String.format( | ||
"Outlier Explanation:\n" | ||
)); | ||
for (APLExplanationResult is : results) { | ||
header.append( | ||
"---\n"+is.prettyPrint(encoder, aggregateNames) | ||
); | ||
} | ||
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
110 changes: 110 additions & 0 deletions
110
...n/java/edu/stanford/futuredata/macrobase/analysis/summary/aplinear/APLMeanSummarizer.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,110 @@ | ||
package edu.stanford.futuredata.macrobase.analysis.summary.aplinear; | ||
|
||
import edu.stanford.futuredata.macrobase.analysis.summary.aplinear.metrics.GlobalRatioMetric; | ||
import edu.stanford.futuredata.macrobase.analysis.summary.aplinear.metrics.MeanDevMetric; | ||
import edu.stanford.futuredata.macrobase.analysis.summary.aplinear.metrics.QualityMetric; | ||
import edu.stanford.futuredata.macrobase.analysis.summary.aplinear.metrics.SupportMetric; | ||
import edu.stanford.futuredata.macrobase.datamodel.DataFrame; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Summarizer that works over cube-based summarization based on mean shift. | ||
*/ | ||
public class APLMeanSummarizer extends APLSummarizer { | ||
private Logger log = LoggerFactory.getLogger("APLMeanSummarizer"); | ||
|
||
private String countColumn = null; | ||
|
||
private String meanColumn = "mean"; | ||
private String stdColumn = "std"; | ||
|
||
private double minSupport = 0.1; | ||
private double minStdDev = 3.0; | ||
|
||
@Override | ||
public List<String> getAggregateNames() { | ||
return Arrays.asList("count", "m1", "m2"); | ||
} | ||
|
||
@Override | ||
public double[][] getAggregateColumns(DataFrame input) { | ||
double[] meanCol = input.getDoubleColumnByName(meanColumn); | ||
double[] stdCol = input.getDoubleColumnByName(stdColumn); | ||
|
||
int numRows = meanCol.length; | ||
double[] countCol = null; | ||
if (countColumn != null) { | ||
countCol = input.getDoubleColumnByName(countColumn); | ||
} else { | ||
countCol = new double[numRows]; | ||
for (int i = 0; i < numRows; i++) { | ||
countCol[i] = 1.0; | ||
} | ||
} | ||
|
||
double[] m1Col = new double[numRows]; | ||
double[] m2Col = new double[numRows]; | ||
for (int i = 0; i < meanCol.length; i++) { | ||
m1Col[i] = meanCol[i]*countCol[i]; | ||
m2Col[i] = (stdCol[i]*stdCol[i] + meanCol[i]*meanCol[i])*countCol[i]; | ||
} | ||
|
||
double[][] aggregateColumns = new double[3][]; | ||
aggregateColumns[0] = countCol; | ||
aggregateColumns[1] = m1Col; | ||
aggregateColumns[2] = m2Col; | ||
|
||
return aggregateColumns; | ||
} | ||
|
||
@Override | ||
public List<QualityMetric> getQualityMetricList() { | ||
List<QualityMetric> qualityMetricList = new ArrayList<>(); | ||
qualityMetricList.add( | ||
new SupportMetric(0) | ||
); | ||
qualityMetricList.add( | ||
new MeanDevMetric(0, 1, 2) | ||
); | ||
return qualityMetricList; | ||
} | ||
|
||
@Override | ||
public List<Double> getThresholds() { | ||
return Arrays.asList(minSupport, minStdDev); | ||
} | ||
|
||
@Override | ||
public APLExplanation getResults() { | ||
return explanation; | ||
} | ||
|
||
public String getCountColumn() { | ||
return countColumn; | ||
} | ||
public void setCountColumn(String countColumn) { | ||
this.countColumn = countColumn; | ||
} | ||
|
||
public void setMeanColumn(String meanColumn) { | ||
this.meanColumn = meanColumn; | ||
} | ||
|
||
public void setStdColumn(String stdColumn) { | ||
this.stdColumn = stdColumn; | ||
} | ||
|
||
public void setMinSupport(double minSupport) { | ||
this.minSupport = minSupport; | ||
} | ||
|
||
public void setMinStdDev(double minStdDev) { | ||
this.minStdDev = minStdDev; | ||
} | ||
|
||
} |
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.