private Optional mhStep()

in src/main/java/com/twitter/sbf/core/MHAlgorithm.java [839:875]


  private Optional<int[]> mhStep(SparseBinaryMatrix matrix,
                                 int myId,
                                 double multiplier,
                                 double weightCoeff) {
    int[] proposal;
    if (config.proposalStrategy == ProposalStrategy.SingleOrZeroMembershipLikelihood) {
      proposal = sampleSingleNonZeroProposal(matrix, myId, weightCoeff);
    } else if (config.proposalStrategy == ProposalStrategy.MultipleMembershipLikelihood) {
      proposal =
          sampleMultipleNonZeroProposal(matrix, myId, weightCoeff, config.maxMembershipsPerVertex);
    } else if (config.proposalStrategy == ProposalStrategy.PureRandom) {
      proposal = samplePureRandomProposal(matrix.getNumCols());
    } else {
      proposal = proposalV1orV2(matrix, myId,
          config.proposalStrategy == ProposalStrategy.FractionOfNeighbors);
    }

    if (proposal.length == 0) {
      emptyProposals++;
    }
    if (!Arrays.equals(proposal, matrix.getRow(myId))) {
      // Compute likelihood
      double newLikelihood = evalLikelihood(g, matrix, myId, proposal, weightCoeff);
      double oldLikelihood = evalLikelihood(g, matrix, myId, matrix.getRow(myId), weightCoeff);

      // Accept or reject
      double logAcceptProbability = multiplier * (newLikelihood - oldLikelihood);
      if (Math.log(config.rng.nextDouble()) < logAcceptProbability) {
        return Optional.of(proposal);
      } else {
        return Optional.empty();
      }
    } else {
      sameProposals++;
      return Optional.empty();
    }
  }