Skip to content

Commit

Permalink
Add check for number of rewritten links.
Browse files Browse the repository at this point in the history
  • Loading branch information
pbloem committed Oct 26, 2016
1 parent 028611b commit d10f0b2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
28 changes: 23 additions & 5 deletions src/main/java/nl/peterbloem/motive/MotifModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -83,6 +84,11 @@ public static void setExecutor(ExecutorService executor)
{
MotifModel.executor = executor;
}

public static void setMaxRW(int maxRW)
{
MotifModel.maxRW = maxRW;
}


public static <L> double size(Graph<L> graph, Graph<L> sub,
Expand Down Expand Up @@ -833,7 +839,14 @@ public static double sizeEL(DGraph<?> graph, List<D> degrees, DGraph<?> sub,
FrequencyModel<Pair<Integer, Integer>> multiEdges = new FrequencyModel<Pair<Integer, Integer>>();
List<List<Integer>> rewiring = new LinkedList<List<Integer>>();

List<D> sDegrees = subbedDegrees(graph, degrees, occurrences, multiEdges, rewiring);
List<D> 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));
Expand Down Expand Up @@ -1344,11 +1357,9 @@ public static List<D> 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<Integer, Integer> link : multiEdges.tokens())
Expand Down Expand Up @@ -1548,4 +1559,11 @@ private static Pair<Integer, Integer> ordered(int i1, int i2)
return new Pair<Integer, Integer>(i1, i2);
return new Pair<Integer, Integer>(i2, i1);
}

private static class TooManyRWLinksException extends RuntimeException
{
private static final long serialVersionUID = -2882656149269609884L;


}
}
9 changes: 8 additions & 1 deletion src/main/java/nl/peterbloem/motive/exec/CompareLarge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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<D> degrees = graphLoop ? null : DSequenceEstimator.sequence(data);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/nl/peterbloem/motive/exec/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d10f0b2

Please sign in to comment.