Beispiel #1
0
  @Override
  public void process(final DAVOptions options) {
    final String[] args = getOriginalArgs();
    final UseModality<DAVOptions> executed;
    final int maxSplitIndex = splitPlan.getMaxSplitIndex();
    final ProgressLogger logger = new ProgressLogger(LOGGER);
    logger.expectedUpdates = maxSplitIndex;
    logger.itemsName = "splits";
    logger.priority = Level.INFO;
    logger.start("Parallel split processing");

    final SplitParallelRegion region = new SplitParallelRegion(maxSplitIndex, args, logger);
    try {
      getParallelTeam().execute(region);
    } catch (Exception e) {
      LOGGER.error("An exception occurred.", e);
    }
    logger.stop();

    /** Time the duration of the sequence: */
    timeService.setModelId(modelId);
    timeService.stop();

    executed = region.getExecuted();
    if (executed != null && executed instanceof SequenceMode) {
      // if we executed SequenceMode
      final SequenceMode sequenceMode = (SequenceMode) executed;
      if (evaluateStatistics) {
        final String label = sequenceMode.getValue("label");
        final String statsFilename = sequenceMode.getValue("predictions-filename");

        if (statsFilename != null && label != null) {
          // and the sequence defined the variables "predictions-filename" and "label"
          try {
            final List<String> statsModeArgs =
                new ObjectArrayList<String>(
                    new String[] {
                      "--mode",
                      "stats",
                      "--predictions",
                      statsFilename,
                      "--submission-file",
                      labelPrefix(label) + "-maqcii-submission.txt",
                      "--label",
                      label,
                      "--model-id",
                      modelId,
                      "--dataset-name",
                      options.datasetName,
                      "--other-measures",
                      "prec,rec,F-1,MCC,binary-auc"
                    });

            if (options.adjustSignalToFloorValue) {
              statsModeArgs.add("--floor");
              statsModeArgs.add(Double.toString(options.signalFloorValue));
            }

            // extract survival options if any
            // TODO: clean this up - we should not be checking for "%survival%"
            final String survivalFileName = sequenceMode.getValue("survival");
            if (StringUtils.isNotBlank(survivalFileName)
                && !"%survival%".equals(survivalFileName)) {
              statsModeArgs.add("--survival");
              statsModeArgs.add(survivalFileName);
            }

            LOGGER.debug("Estimating statistics: " + statsModeArgs);

            // we create a new DAVMode here since we want to use the old StatsMode code
            // which is no longer exposed by DiscoverAndValidate (BDVal main method)
            final DAVMode statsMode = new DAVMode();
            statsMode.registerMode("stats", StatsMode.class);
            final DAVOptions statsModeOptions = new DAVOptions();
            statsMode.process(
                statsModeArgs.toArray(new String[statsModeArgs.size()]), statsModeOptions);
          } catch (Exception e) {
            LOGGER.error("Error executing --mode stats for all splits", e);
          }
        }
      }
    }
  }
Beispiel #2
0
  /**
   * For a specific sub-set of blocks (child nodes), find a 'base' subset of parents for which the
   * block's logLikelihood is not -Infinity
   *
   * @param candidateParentsPerNode
   * @param chosenArcsPerNode
   * @param setOfBlocks
   * @return
   */
  protected double getOutOfMinusInfinity(
      Int2ObjectOpenHashMap<IntOpenHashSet> candidateParentsPerNode,
      Int2ObjectOpenHashMap<ObjectOpenHashSet<Arc>> chosenArcsPerNode,
      IntOpenHashSet setOfBlocks,
      TIntDoubleHashMap logLPerNode) {
    double totalLogL = 0;

    ProgressLogger pl = new ProgressLogger(LOGGER, ProgressLogger.TEN_SECONDS, "blocks");
    pl.start("Begin initializing, to avoid zero likelihood, using set-cover heuristic");
    pl.expectedUpdates = setOfBlocks.size();
    int nArcs = 0;
    for (int v : setOfBlocks) {
      pl.update();

      IntOpenHashSet vParents = candidateParentsPerNode.get(v);

      Int2ObjectOpenHashMap<IntOpenHashSet> parentActions =
          new Int2ObjectOpenHashMap<IntOpenHashSet>();

      Int2ObjectOpenHashMap<IntArrayList> cPlusV = auxiliary.getCplusOnline(v);
      Int2ObjectOpenHashMap<IntArrayList> cMinusV = auxiliary.getCminusOnline(v);

      if (cPlusV != null) {
        IntSet actions = cPlusV.keySet();
        // Heuristic: first add the parents that participate in A+ for
        // most actions
        for (int action : actions) {
          for (int u : cPlusV.get(action)) {
            if (!parentActions.containsKey(u)) {
              parentActions.put(u, new IntOpenHashSet());
            }
            parentActions.get(u).add(action);
          }
        }
      }

      KeepMaximum km = new KeepMaximum();
      km.addAllKey2Listsize(parentActions);

      IntOpenHashSet baseSetOfParents = new IntOpenHashSet();
      double logL = Double.NEGATIVE_INFINITY;
      while (logL == Double.NEGATIVE_INFINITY && (km.getMaximumKey() != -1)) {
        int u = km.getMaximumKey();
        if (baseSetOfParents.contains(u)) {
          throw new IllegalStateException("Attempted to add twice the same parent");
        }
        baseSetOfParents.add(u);
        logL = blockLogLikelihood(v, cPlusV, cMinusV, baseSetOfParents);
        IntOpenHashSet uActions = parentActions.get(u);
        for (int parent : vParents) {
          parentActions.get(parent).removeAll(uActions);
        }
        vParents.remove(u);
        parentActions.remove(u);
        km.reset();
        km.addAllKey2Listsize(parentActions);
      }

      // keep track of the likelihood
      totalLogL += logL;
      if (logLPerNode != null) {
        logLPerNode.put(v, logL);
      }

      chosenArcsPerNode.put(v, new ObjectOpenHashSet<Arc>());
      for (int u : baseSetOfParents) {
        nArcs++;
        chosenArcsPerNode.get(v).add(new Arc(u, v));
      }
    }
    pl.stop("Done initialization. Added " + nArcs + " arcs, logLikelihood=" + totalLogL);
    return totalLogL;
  }