Esempio n. 1
0
  protected JSAPResult parseParameters(String[] args) throws Exception {
    jsap = buildCommandLineOptions();

    JSAPResult config = jsap.parse(args);
    if (!config.success() || jsap.messagePrinted()) {
      Iterator<?> messageIterator = config.getErrorMessageIterator();
      while (messageIterator.hasNext()) System.err.println(messageIterator.next());
      System.err.println(jsap.getHelp());
      System.exit(1);
    }

    return config;
  }
Esempio n. 2
0
 public Demo(String[] args) throws Exception {
   commandLineOptions = parseParameters(args);
   String nodeType = commandLineOptions.getString("nodeType");
   isMaster = nodeType != null && nodeType.equals("master");
   cfgFile = commandLineOptions.getString("configFile");
   if (cfgFile == null) {
     System.err.println(jsap.getHelp());
     System.exit(1);
   }
 }
Esempio n. 3
0
  public static void main(String[] args) throws Exception {
    int port = 8077;
    boolean useSsl = false;
    boolean requirePeerAuthentication = false;

    // TODO: add more options for SSL to configure CRT etc.
    SimpleJSAP commandLineOptions =
        new SimpleJSAP(
            "NettyServer",
            "Runs a simple SSL or non-SSL netty server",
            new Parameter[] {
              new FlaggedOption(
                  "port",
                  JSAP.INTEGER_PARSER,
                  "8077",
                  JSAP.NOT_REQUIRED,
                  'p',
                  "port",
                  "listener port"),
              new Switch("ssl", 's', "ssl", "enforces SSL connection"),
              new Switch(
                  "peer", 'p', "peer", "enforces peer certification authentication (in SSL mode)")
            });
    JSAPResult cmd = commandLineOptions.parse(args);
    if (commandLineOptions.messagePrinted()) {
      System.err.println("(use option --help for usage)");
      System.exit(1);
    }

    port = cmd.getInt("port");
    useSsl = cmd.getBoolean("ssl");
    requirePeerAuthentication = cmd.getBoolean("peer");

    if (args.length > 0) {
      port = Integer.parseInt(args[0]);
    }
    System.out.println("Starting an SSL test server on port " + port);
    new SslServer(port, useSsl, requirePeerAuthentication).run();
  }
  public static void main(final String[] arg)
      throws IOException, JSAPException, ConfigurationException, ClassNotFoundException {

    SimpleJSAP jsap =
        new SimpleJSAP(
            WeightedPageRankPowerMethod.class.getName(),
            "Computes PageRank of a graph with given graphBasename using the power method."
                + "The resulting doubles are stored in binary form in rankFile."
                + "\n[STOPPING CRITERION] The computation is stopped as soon as two successive iterates have"
                + "an L2-distance smaller than a given threshold (-t option); in any case no more than a fixed"
                + "number of iterations (-i option) is performed.",
            new Parameter[] {
              new FlaggedOption(
                  "alpha",
                  JSAP.DOUBLE_PARSER,
                  Double.toString(WeightedPageRank.DEFAULT_ALPHA),
                  JSAP.NOT_REQUIRED,
                  'a',
                  "alpha",
                  "Damping factor."),
              new FlaggedOption(
                  "maxIter",
                  JSAP.INTEGER_PARSER,
                  Integer.toString(WeightedPageRank.DEFAULT_MAX_ITER),
                  JSAP.NOT_REQUIRED,
                  'i',
                  "max-iter",
                  "Maximum number of iterations."),
              new FlaggedOption(
                  "threshold",
                  JSAP.DOUBLE_PARSER,
                  Double.toString(WeightedPageRank.DEFAULT_THRESHOLD),
                  JSAP.NOT_REQUIRED,
                  't',
                  "threshold",
                  "Threshold to determine whether to stop."),
              new FlaggedOption(
                  "coeff",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  'c',
                  "coeff",
                  "Save the k-th coefficient of the Taylor polynomial using this basename."),
              new FlaggedOption(
                      "derivative",
                      JSAP.INTEGER_PARSER,
                      JSAP.NO_DEFAULT,
                      JSAP.NOT_REQUIRED,
                      'd',
                      "derivative",
                      "The order(s) of the the derivative(s) to be computed (>0).")
                  .setAllowMultipleDeclarations(true),
              new FlaggedOption(
                  "preferenceVector",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  'p',
                  "preference-vector",
                  "A preference vector stored as a vector of binary doubles."),
              new FlaggedOption(
                  "preferenceObject",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  'P',
                  "preference-object",
                  "A preference vector stored as a serialised DoubleList."),
              new FlaggedOption(
                  "startFilename",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  '1',
                  "start",
                  "Start vector filename."),
              new FlaggedOption(
                  "buckets",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  'b',
                  "buckets",
                  "The buckets of the graph; if supplied, buckets will be treated as dangling nodes."),
              new Switch("offline", 'o', "offline", "use loadOffline() to load the graph"),
              new Switch(
                  "strongly",
                  'S',
                  "strongly",
                  "use the preference vector to redistribute the dangling rank."),
              new Switch(
                  "sortedRank",
                  's',
                  "sorted-ranks",
                  "Store the ranks (from highest to lowest) into <rankBasename>-sorted.ranks."),
              new FlaggedOption(
                  "norm",
                  JSAP.STRING_PARSER,
                  WeightedPageRank.Norm.INFTY.toString(),
                  JSAP.NOT_REQUIRED,
                  'n',
                  "norm",
                  "Norm type. Possible values: " + Arrays.toString(WeightedPageRank.Norm.values())),
              new UnflaggedOption(
                  "graphBasename",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.REQUIRED,
                  JSAP.NOT_GREEDY,
                  "The basename of the graph."),
              new UnflaggedOption(
                  "rankBasename",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.REQUIRED,
                  JSAP.NOT_GREEDY,
                  "The filename where the resulting rank (doubles in binary form) are stored.")
            });

    JSAPResult jsapResult = jsap.parse(arg);
    if (jsap.messagePrinted()) return;

    final boolean offline = jsapResult.getBoolean("offline", false);
    final boolean strongly = jsapResult.getBoolean("strongly", false);
    final boolean sorted = jsapResult.getBoolean("sortedRank", false);
    final int[] order = jsapResult.getIntArray("derivative");
    final String graphBasename = jsapResult.getString("graphBasename");
    final String rankBasename = jsapResult.getString("rankBasename");
    final String buckets = jsapResult.getString("buckets");
    final String startFilename = jsapResult.getString("startFilename", null);
    final String coeffBasename = jsapResult.getString("coeff");
    final String norm = jsapResult.getString("norm");
    final ProgressLogger progressLogger = new ProgressLogger(LOGGER, "nodes");

    ArcLabelledImmutableGraph graph =
        offline
            ? ArcLabelledImmutableGraph.loadOffline(graphBasename, progressLogger)
            : ArcLabelledImmutableGraph.loadSequential(graphBasename, progressLogger);

    DoubleList preference = null;
    String preferenceFilename = null;
    if (jsapResult.userSpecified("preferenceVector"))
      preference =
          DoubleArrayList.wrap(
              BinIO.loadDoubles(preferenceFilename = jsapResult.getString("preferenceVector")));

    if (jsapResult.userSpecified("preferenceObject")) {
      if (jsapResult.userSpecified("preferenceVector"))
        throw new IllegalArgumentException("You cannot specify twice the preference vector");
      preference =
          (DoubleList)
              BinIO.loadObject(preferenceFilename = jsapResult.getString("preferenceObject"));
    }

    if (strongly && preference == null)
      throw new IllegalArgumentException("The 'strongly' option requires a preference vector");

    DoubleList start = null;
    if (startFilename != null) {
      LOGGER.debug("Loading start vector \"" + startFilename + "\"...");
      start = DoubleArrayList.wrap(BinIO.loadDoubles(startFilename));
      LOGGER.debug("done.");
    }

    WeightedPageRankPowerMethod pr = new WeightedPageRankPowerMethod(graph);
    pr.alpha = jsapResult.getDouble("alpha");
    pr.preference = preference;
    pr.buckets = (BitSet) (buckets == null ? null : BinIO.loadObject(buckets));
    pr.stronglyPreferential = strongly;
    pr.start = start;
    pr.norm = WeightedPageRank.Norm.valueOf(norm);
    pr.order = order != null ? order : null;
    pr.coeffBasename = coeffBasename;

    // cycle until we reach maxIter interations or the norm is less than the given threshold
    // (whichever comes first)
    pr.stepUntil(
        or(
            new WeightedPageRank.NormDeltaStoppingCriterion(jsapResult.getDouble("threshold")),
            new WeightedPageRank.IterationNumberStoppingCriterion(jsapResult.getInt("maxIter"))));

    System.err.print("Saving ranks...");
    BinIO.storeDoubles(pr.rank, rankBasename + ".ranks");
    if (pr.numNodes < 100) {
      for (int i = 0; i < pr.rank.length; i++) {
        System.err.println("PageRank[" + i + "]=" + pr.rank[i]);
      }
    }
    Properties prop = pr.buildProperties(graphBasename, preferenceFilename, startFilename);
    prop.save(rankBasename + ".properties");

    if (order != null) {
      System.err.print("Saving derivatives...");
      for (int i = 0; i < order.length; i++)
        BinIO.storeDoubles(pr.derivative[i], rankBasename + ".der-" + order[i]);
    }

    final double[] rank = pr.rank;
    pr = null; // Let us free some memory...
    graph = null;

    if (sorted) {
      System.err.print("Sorting ranks...");
      Arrays.sort(rank);
      final int n = rank.length;
      int i = n / 2;
      double t;
      // Since we need the ranks from highest to lowest, we invert their order.
      while (i-- != 0) {
        t = rank[i];
        rank[i] = rank[n - i - 1];
        rank[n - i - 1] = t;
      }
      System.err.print(" saving sorted ranks...");
      BinIO.storeDoubles(rank, rankBasename + "-sorted.ranks");
      System.err.println(" done.");
    }
  }
Esempio n. 5
0
  @SuppressWarnings("unchecked")
  public static <T> JsapResultsWithObject<T> constructObject(
      Class<T> clazz, String[] rawArguments, String mainHelp, Parameter[] otherParameters)
      throws JSAPException, IOException, IllegalArgumentException, ReflectiveOperationException {
    Constructor<T> constructor = null;
    for (Constructor<?> constr : clazz.getConstructors()) {
      boolean annotationPresent = constr.isAnnotationPresent(CommandLine.class);
      if (annotationPresent) {
        constructor = (Constructor<T>) constr;
        break;
      }
    }
    if (constructor == null)
      throw new IllegalAccessError(
          "Class " + clazz + " must have a constructor annotated with @CommandLine");

    String[] argNames = constructor.getAnnotation(CommandLine.class).argNames();
    if (argNames.length != constructor.getParameterCount())
      throw new IllegalAnnotationException(
          "Annotation @CommandLine argNames are out of sync with the constructor arguments.");

    boolean[] isSerializedFile = new boolean[argNames.length];

    SimpleJSAP jsap = new SimpleJSAP(clazz.getName(), mainHelp, otherParameters);
    int i = 0;
    for (java.lang.reflect.Parameter x : constructor.getParameters()) {
      Parameter option;
      if (x.getType().equals(boolean.class)) {
        isSerializedFile[i] = false;
        option =
            new Switch(
                argNames[i],
                JSAP.NO_SHORTFLAG,
                argNames[i],
                "Set the value of " + argNames[i] + " for " + clazz.getSimpleName() + " as true.");
      } else {
        StringParser parser;
        String help;
        try {
          parser = getParserFor(x.getType());
          isSerializedFile[i] = false;
          help = "The " + x.getType().getSimpleName() + " value of " + argNames[i];
        } catch (NoJSAPParserForThisTypeException e) {
          parser = JSAP.STRING_PARSER;
          isSerializedFile[i] = true;
          help =
              "A serialized " + x.getType().getSimpleName() + " file to initialize " + argNames[i];
        }
        option = new UnflaggedOption(argNames[i], parser, JSAP.REQUIRED, help);
      }

      jsap.registerParameter(option);

      i++;
    }

    JSAPResult args = jsap.parse(rawArguments);
    if (jsap.messagePrinted()) System.exit(1);

    LOGGER.info("Initializing...");
    Object[] arguments = new Object[argNames.length];
    i = 0;
    for (String argName : argNames) {
      if (isSerializedFile[i]) arguments[i] = SerializationUtils.read(args.getString(argName));
      else arguments[i] = args.getObject(argName);
      i++;
    }
    T object = constructor.newInstance(arguments);
    LOGGER.info("Ready.");

    return new JsapResultsWithObject<T>(args, object);
  }
Esempio n. 6
0
  public static void main(final String[] arg)
      throws IOException, JSAPException, NoSuchMethodException {

    final SimpleJSAP jsap =
        new SimpleJSAP(
            BloomFilter.class.getName(),
            "Creates a Bloom filter reading from standard input a newline-separated list of terms.",
            new Parameter[] {
              new FlaggedOption(
                  "bufferSize",
                  IntSizeStringParser.getParser(),
                  "64Ki",
                  JSAP.NOT_REQUIRED,
                  'b',
                  "buffer-size",
                  "The size of the I/O buffer used to read terms."),
              new FlaggedOption(
                  "encoding",
                  ForNameStringParser.getParser(Charset.class),
                  "UTF-8",
                  JSAP.NOT_REQUIRED,
                  'e',
                  "encoding",
                  "The term file encoding."),
              new UnflaggedOption(
                  "bloomFilter",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.REQUIRED,
                  JSAP.NOT_GREEDY,
                  "The filename for the serialised front-coded list."),
              new UnflaggedOption(
                  "size",
                  JSAP.INTSIZE_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.REQUIRED,
                  JSAP.NOT_GREEDY,
                  "The size of the filter (i.e., the expected number of elements in the filter; usually, the number of terms)."),
              new UnflaggedOption(
                  "precision",
                  JSAP.INTEGER_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.REQUIRED,
                  JSAP.NOT_GREEDY,
                  "The precision of the filter.")
            });

    JSAPResult jsapResult = jsap.parse(arg);
    if (jsap.messagePrinted()) return;

    final int bufferSize = jsapResult.getInt("bufferSize");
    final String filterName = jsapResult.getString("bloomFilter");
    final Charset encoding = (Charset) jsapResult.getObject("encoding");

    BloomFilter filter = new BloomFilter(jsapResult.getInt("size"), jsapResult.getInt("precision"));
    final ProgressLogger pl = new ProgressLogger();
    pl.itemsName = "terms";
    pl.start("Reading terms...");
    MutableString s = new MutableString();
    FastBufferedReader reader =
        new FastBufferedReader(new InputStreamReader(System.in, encoding), bufferSize);
    while (reader.readLine(s) != null) {
      filter.add(s);
      pl.lightUpdate();
    }
    pl.done();

    BinIO.storeObject(filter, filterName);
  }
Esempio n. 7
0
  /**
   * Sample program params for a class 52 with some specified modules Report3 -c:52
   * -f:u:/formality/Greenfield2010/CyczReport3-GeoProbGraph.csv
   * -m:237,246,247,250,252,259,261,265,268
   *
   * @param args
   */
  public static void main(String[] args) {
    Report3 r = new Report3();
    try {
      SimpleJSAP jsap =
          new SimpleJSAP(
              "Report3",
              "Report 3",
              new Parameter[] {
                new QualifiedSwitch(
                    "beginUserId",
                    JSAP.INTEGER_PARSER,
                    JSAP.NO_DEFAULT,
                    JSAP.NOT_REQUIRED,
                    'b',
                    "buid",
                    "Takes a begin Id.  Must be combined with -e --euid"),
                new QualifiedSwitch(
                    "endUserId",
                    JSAP.INTEGER_PARSER,
                    JSAP.NO_DEFAULT,
                    JSAP.NOT_REQUIRED,
                    'e',
                    "euid",
                    "Takes a end Id (must be combined with -b --buid"),
                new QualifiedSwitch(
                    "classId",
                    JSAP.INTEGER_PARSER,
                    JSAP.NO_DEFAULT,
                    JSAP.NOT_REQUIRED,
                    'c',
                    "classId",
                    "Takes the course id."),
                new QualifiedSwitch(
                    "outfile",
                    FileStringParser.getParser(),
                    JSAP.NO_DEFAULT,
                    JSAP.REQUIRED,
                    'f',
                    "file",
                    "The output file (full path) to a comma separated value file."),
                new QualifiedSwitch(
                        "modules",
                        JSAP.INTEGER_PARSER,
                        JSAP.NO_DEFAULT,
                        JSAP.NOT_REQUIRED,
                        'm',
                        "modules",
                        "Module IDs to report on")
                    .setList(true)
                    .setListSeparator(',')
              });
      JSAPResult config = jsap.parse(args);
      if (jsap.messagePrinted()) System.exit(1);

      File f = config.getFile("outfile");
      FileWriter fw = new FileWriter(f);
      Connection conn = null;
      conn = r.getConnection();
      StringBuffer sb = new StringBuffer();
      int beginId = 0, endId = 0, courseId;
      List<List<String>> rows = null;
      int[] modules = config.getIntArray("modules");
      r.modIds = modules;
      if (config.getBoolean("beginUserId") && config.getBoolean("endUserId")) {
        beginId = config.getInt("beginUserId");
        endId = config.getInt("endUserId");
        rows = r.writeUsers(beginId, endId, conn);
      } else if (config.getBoolean("classId")) {
        courseId = config.getInt("classId");
        r.courseName = r.getCourseName(conn, courseId);
        rows = r.writeCourse(courseId, conn);
      }
      r.toCSV(rows, sb);
      System.out.println(sb.toString());
      fw.write(sb.toString());
      fw.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 8
0
  public static void main(String[] args) throws Exception {

    final SimpleJSAP jsap =
        new SimpleJSAP(
            Sparsifier.class.getName(),
            "Estimates and sparsifies a propagation model from a set of observations.",
            new Parameter[] {
              new FlaggedOption(
                  "social-network",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.REQUIRED,
                  's',
                  "social-network",
                  "The file containing the social network graph"),
              new FlaggedOption(
                  "probabilities",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.REQUIRED,
                  'p',
                  "probabilities",
                  "The file containing the propagation probabilities"),
              new FlaggedOption(
                  "candidate-selection-policy",
                  JSAP.STRING_PARSER,
                  CandidateSelectionPolicy.DEFAULT_CANDIDATE_SELECTION_POLICY
                      .getClass()
                      .getSimpleName(),
                  JSAP.REQUIRED,
                  'c',
                  "candidate-selection-policy",
                  "The name of the candidate selection policy"),
              new FlaggedOption(
                  "auxiliary-basename",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  JSAP.NO_SHORTFLAG,
                  "auxiliary-basename",
                  "The base name for reading a pre-computed auxiliary structure"),
              new FlaggedOption(
                  "input",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.REQUIRED,
                  'i',
                  "input",
                  "The file containing the observations"),
              new FlaggedOption(
                  "sparsifier",
                  JSAP.STRING_PARSER,
                  DEFAULT_SPARSIFIER.getSimpleName(),
                  JSAP.NOT_REQUIRED,
                  'f',
                  "sparsifier",
                  "The sparsifier to run, from this list: "
                      + StringUtils.join(Reflection.subClasses(Sparsifier.class), ',')),
              new FlaggedOption(
                  "sparse-model-size",
                  JSAP.INTEGER_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  'k',
                  "sparse-model-size",
                  "The size of the sparse model"),
              new FlaggedOption(
                  "number-of-chunks",
                  JSAP.INTEGER_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  'r',
                  "number-of-chunks",
                  "The number of chunks to be sparsified in parralel"),
              new FlaggedOption(
                  "output",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  'o',
                  "output",
                  "File to dump sparsified model to"),
              new FlaggedOption(
                  "measures-file",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  'z',
                  "measures-file",
                  "Save measures of partial models to file"),
              new FlaggedOption(
                  "debug-file",
                  JSAP.STRING_PARSER,
                  JSAP.NO_DEFAULT,
                  JSAP.NOT_REQUIRED,
                  'd',
                  "debug-file",
                  "Save debug information to file"),
              new Switch(
                  "with-fraction",
                  'n',
                  "with-fraction",
                  "Disable the computation of the 'fraction of covered propagations'."),
              new Switch(
                  "incremental-likelihood",
                  JSAP.NO_SHORTFLAG,
                  "incremental-likelihood",
                  "Performs incremental computation of likelihood, for sparsifications methods that support this option (faster, experimental)."),
            });

    final JSAPResult jsapResult = jsap.parse(args);
    if (jsap.messagePrinted()) {
      return;
    }

    // Load social network and input
    String snFilename = jsapResult.getString("social-network");
    SocialNetwork socNet = new SocialNetwork(Utilities.getIterator(snFilename));
    String obsFilename = jsapResult.getString("input");
    ObservationsReader observations = new ObservationsReader(obsFilename);

    // Load original model
    ICModel originalModel =
        new ICModel(socNet, Utilities.getIterator(jsapResult.getString("probabilities")));

    // Load candidate selection policy
    String selectionPolicyName = jsapResult.getString("candidate-selection-policy");
    Class<?> selectionPolicyClass =
        Class.forName(
            CandidateSelectionPolicy.class.getPackage().getName() + "." + selectionPolicyName);
    CandidateSelectionPolicy candidateSelectionPolicy =
        (CandidateSelectionPolicy)
            selectionPolicyClass.getConstructor(new Class[] {}).newInstance(new Object[] {});

    // Create sparsifier
    String sparsifierName = jsapResult.getString("sparsifier");
    Class<?> sparsifierClass =
        Class.forName(Sparsifier.class.getPackage().getName() + "." + sparsifierName);
    Sparsifier sparsifier =
        (Sparsifier)
            sparsifierClass
                .getConstructor(new Class[] {originalModel.getClass()})
                .newInstance(new Object[] {originalModel});
    LOGGER.info("Created a " + sparsifier.getClass().getSimpleName());

    // Set sparsifier options
    if (!jsapResult.getBoolean("with-fraction")) {
      sparsifier.disableComputationOfPartialFractionOfPropagations();
      LOGGER.info("Disabled the computation of fraction of propagations");
    }
    if (jsapResult.getBoolean("incremental-likelihood")) {
      if (sparsifier instanceof GreedySparsifier) {
        ((GreedySparsifier) sparsifier).setIncrementalLikelihoodComputation();
        LOGGER.info("Enabled incremental computation of likelihood (faster, experimental)");
      } else {
        LOGGER.warn(
            "This type of sparsifier does not accept the --incrementa-likelihood switch, ignoring");
      }
    }

    if (jsapResult.userSpecified("auxiliary-basename")) {
      // Use existing auxiliary file
      String auxiliaryBasename = jsapResult.getString("auxiliary-basename");
      ICEstimateAuxiliary auxiliary = new ICEstimateAuxiliary(socNet, observations, null);
      LOGGER.info("Loading pre-computed auxiliary variables");
      auxiliary.read(auxiliaryBasename);
      sparsifier.useAuxiliary(auxiliary);
      if (auxiliary
          .getCandidateSelectionPolicy()
          .toSpec()
          .equals(candidateSelectionPolicy.toSpec())) {
        LOGGER.info(
            "Candidate selection policy: " + auxiliary.getCandidateSelectionPolicy().toSpec());
      } else {
        throw new IllegalArgumentException(
            "The candidate selection policies do not match: auxiliary has '"
                + auxiliary.getCandidateSelectionPolicy().toSpec()
                + "', sparsifier has '"
                + candidateSelectionPolicy.toSpec()
                + "'");
      }
    } else {
      // Compute auxiliary variables
      LOGGER.info("Computing auxiliary variables");
      sparsifier.computeAuxiliary(observations, candidateSelectionPolicy);
    }

    int maxSparseSize;
    if (jsapResult.userSpecified("sparse-model-size")) {
      maxSparseSize = jsapResult.getInt("sparse-model-size");
    } else {
      maxSparseSize = originalModel.getProbs().cardinality();
      LOGGER.info(
          "Setting target number of arcs to number of arcs with non-zero probability in the original model");
    }

    // Open debug file
    if (jsapResult.userSpecified("debug-file")) {
      String debugFilename = jsapResult.getString("debug-file");
      LOGGER.info("Will write debug output to " + debugFilename);
      sparsifier.openDebugFile(debugFilename);
    }

    int numOfChunks = 1;
    if (jsapResult.userSpecified("number-of-chunks")) {
      numOfChunks = jsapResult.getInt("number-of-chunks");
    }

    ICModel sparseModel =
        runSparsifier(
            socNet, observations, originalModel, maxSparseSize, sparsifier, numOfChunks, true);

    // Write partial results to file if necessary
    if (jsapResult.userSpecified("measures-file")) {
      for (Measure m : sparsifier.partialResults.keySet()) {
        String logFilename = jsapResult.getString("measures-file");
        switch (m) {
          case LOG_L:
            logFilename = logFilename + ".logL";
            break;
          case FRACTION_OF_PROPAGATIONS:
            logFilename = logFilename + ".frac";
            break;
          default:
            break;
        }
        PrintWriter report =
            new PrintWriter(new BufferedWriter(new FileWriter(new File(logFilename))));
        LOGGER.info("Writing partial " + m.toString() + " results to " + logFilename);
        report.println("#k\t" + m.toString());
        int[] ks = sparsifier.partialResults.get(m).keySet().toArray(new int[] {});
        Arrays.sort(ks);
        for (int k : ks) {
          report.println(k + "\t" + sparsifier.partialResults.get(m).get(k));
        }
        report.close();
      }
    }

    // Dump probabilities
    if (jsapResult.userSpecified("output")) {
      String probsFilename = jsapResult.getString("output");
      PrintWriter pw = Utilities.getPW(probsFilename);
      LOGGER.info("Dumping probabilities to " + probsFilename);
      sparseModel.dumpProbabilities(pw);
      pw.close();
    }

    sparsifier.closeDebugFile();
  }