diff --git a/src/main/java/nl/peterbloem/motive/MotifModel.java b/src/main/java/nl/peterbloem/motive/MotifModel.java index ca854bc..e989067 100644 --- a/src/main/java/nl/peterbloem/motive/MotifModel.java +++ b/src/main/java/nl/peterbloem/motive/MotifModel.java @@ -72,6 +72,7 @@ public class MotifModel { private static ExecutorService executor = null; + private static int maxRW = -1; /** * Sets the threadpool to use (for the beta model). If not set, the beta @@ -83,6 +84,11 @@ public static void setExecutor(ExecutorService executor) { MotifModel.executor = executor; } + + public static void setMaxRW(int maxRW) + { + MotifModel.maxRW = maxRW; + } public static double size(Graph graph, Graph sub, @@ -833,7 +839,14 @@ public static double sizeEL(DGraph graph, List degrees, DGraph sub, FrequencyModel> multiEdges = new FrequencyModel>(); List> rewiring = new LinkedList>(); - List sDegrees = subbedDegrees(graph, degrees, occurrences, multiEdges, rewiring); + List sDegrees = null; + try { + sDegrees = subbedDegrees(graph, degrees, occurrences, multiEdges, rewiring); + } catch(TooManyRWLinksException e) + { + Global.log().info("Number of links rewritten too high (with "+occurrences.size()+" instances). Returning Double.POSTIVE_INFINITY."); + return Double.POSITIVE_INFINITY; + } // * store the template graph (as a simple graph) bits.add("subbed", EdgeListModel.directed(sDegrees, Prior.COMPLETE)); @@ -1344,11 +1357,9 @@ public static List subbedDegrees( multiEdges.add(Pair.p(a, b)); size ++; - if(size % 10000 == 0) - System.out.println(size + " rewritten links processed"); + if(maxRW > 0 && size > maxRW) + throw new TooManyRWLinksException(); } - - System.out.println("."); // * Add each rewritten link _once_ for(Pair link : multiEdges.tokens()) @@ -1548,4 +1559,11 @@ private static Pair ordered(int i1, int i2) return new Pair(i1, i2); return new Pair(i2, i1); } + + private static class TooManyRWLinksException extends RuntimeException + { + private static final long serialVersionUID = -2882656149269609884L; + + + } } diff --git a/src/main/java/nl/peterbloem/motive/exec/CompareLarge.java b/src/main/java/nl/peterbloem/motive/exec/CompareLarge.java index 0f86a41..a8ec476 100644 --- a/src/main/java/nl/peterbloem/motive/exec/CompareLarge.java +++ b/src/main/java/nl/peterbloem/motive/exec/CompareLarge.java @@ -85,7 +85,12 @@ public class CompareLarge { private static final int BS_SAMPLES = 10000; - + + /** + * Maximum amount of rewritten links. + */ + public int maxRW = -1; + /** * Number of samples to take to find potential motifs */ @@ -137,6 +142,8 @@ public void main() throws IOException { nl.peterbloem.kit.Global.secureRandom(42); + MotifModel.setMaxRW(maxRW); + Global.log().info("Computing motif code lengths"); final List degrees = graphLoop ? null : DSequenceEstimator.sequence(data); diff --git a/src/main/java/nl/peterbloem/motive/exec/Run.java b/src/main/java/nl/peterbloem/motive/exec/Run.java index 2ded819..c2515f6 100644 --- a/src/main/java/nl/peterbloem/motive/exec/Run.java +++ b/src/main/java/nl/peterbloem/motive/exec/Run.java @@ -31,6 +31,11 @@ public class Run usage="Output file.") private static File outFile = new File("./graph.db"); + @Option( + name="--fast.max-rw", + usage="Maximum number of rewritten links allowed. If the number is higher for a given motif, the motif is ignored. This is useful to limit the memory use for disk-backed graphs. -1 for no limit.") + private static int maxRW = -1; + @Option( name="--samples", usage="Number of samples to take.") @@ -241,6 +246,7 @@ public static void main(String[] args) CompareLarge large = new CompareLarge(); + large.maxRW = maxRW; large.dataName = file.getName(); large.data = data; large.motifMinSize = minSize;