Commit bda0ca9e authored by Amin Bandali's avatar Amin Bandali

Initial pass at calculating an average of ratios for SSRs

TODO: potential long overflow; use BigInteger
parent 9054efae
......@@ -60,6 +60,11 @@
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
</project>
......@@ -26,4 +26,5 @@ Main-Class: org.shemshak.alloy.catalyst.MainCLI
@${repo;info.picocli:picocli}, \
@${repo;com.google.gson}, \
@${repo;org.apache.commons.codec}, \
@${repo;org.apache.commons.math3}, \
LICENSES
......@@ -12,7 +12,8 @@ Main-Class: org.shemshak.alloy.catalyst.MainCLI
org.kohsuke:github-api,\
org.apache.commons.codec;version=1.11,\
info.picocli:picocli,\
com.google.gson
com.google.gson,\
org.apache.commons.math3
Private-Package: \
org.shemshak.alloy.catalyst,\
......
......@@ -28,7 +28,6 @@ import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
......@@ -39,6 +38,7 @@ import edu.mit.csail.sdg.alloy4.Err;
import edu.mit.csail.sdg.alloy4.ErrorWarning;
import edu.mit.csail.sdg.parser.CompModule;
import edu.mit.csail.sdg.parser.CompUtil;
import org.apache.commons.math3.fraction.BigFraction;
import picocli.CommandLine.Command;
......@@ -111,16 +111,33 @@ public final class SSR extends CatalystCommand implements Runnable {
pln(String.format("time taken to analyze %s models: %dms",
corpus, cr.elapsed_time));
long ssrs = 0, ssrc = 0;
p("Calculating corpus stats...");
long ssrs = 0, ssrc = 0, num = 0, den = 0, count = 0;
BigFraction avgOfRatios = new BigFraction(0, 1);
for (FileResult fr : cr.file_results)
if (fr.ssr_result != null) { // happens when there are
// errors in analyzeFile
// and it exits early
ssrs += fr.ssr_result.sig_count;
ssrc += fr.ssr_result.ssr_candidate_count;
num = fr.ssr_result.ssr_candidate_count;
den = fr.ssr_result.sig_count;
ssrs += den;
ssrc += num;
if (den != 0) {
avgOfRatios = avgOfRatios.add(new BigFraction(num, den));
count++;
}
}
if (count != 0)
avgOfRatios = avgOfRatios.divide(count);
num = avgOfRatios.getNumeratorAsLong();
den = avgOfRatios.getDenominatorAsLong();
pln(" done");
pln(String.format("SSR candidates: %d/%d (%.2f%%)",
ssrc, ssrs, 100. * ssrc / ssrs));
if (count != 0)
pln(String.format("SSR avg of ratios: %d/%d (%.2f%%)",
num, den, 100. * num / den));
cr.ssr_result = new SSRResult();
cr.ssr_result.sig_count = ssrs;
cr.ssr_result.ssr_candidate_count = ssrc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment