Identical to {@link #outcomeToAssignment(List, List)}, but with
arrays.

@param factorVariables
@param outcome
@return
175254
public Assignment outcomeToAssignment(String[] factorVariables, Object[] outcome) {
    return outcomeToAssignment(Arrays.asList(factorVariables), Arrays.asList(outcome));
  }
1282091
public DynamicAssignment fixedVariableOutcomeToAssignment(List<? extends Object> values) {
    return DynamicAssignment.fromAssignment(fixedVariables.outcomeToAssignment(values));
  }
238884
public MatlabResult addResult(String name, MatlabValue result) {
        checkNotNull(name);
        checkNotNull(result);
        this.results.put(name, result);
        return this;
    }
298228
public static String product(String... factors) {

        if (factors == null || factors.length == 0) {
            return null;
        }

        BigDecimal prodcut;
        try {
            prodcut = new BigDecimal(factors[0]);
            for (int i = 1; i < factors.length; i++) {
                prodcut = prodcut.multiply(new BigDecimal(factors[i]));
            }
            return prodcut.toString();
        } catch (Exception e) {
            return null;
        }
    }
8984
public String describeAssignments(List<Assignment> assignments, boolean includeZeros) {
    StringBuilder sb = new StringBuilder();
    for (Assignment assignment : assignments) {
      double unnormalizedProb = getUnnormalizedProbability(assignment);
      if (unnormalizedProb != 0.0 || includeZeros) {
        Outcome outcome = new Outcome(assignment, unnormalizedProb);
        sb.append(outcome.toString());
        sb.append("\n");
      }
    }
    return sb.toString();
  }
913857
public void add(String outcome, double p) {
    outcomes.add(outcome);
    probs.add(new Double(p));
    score += Math.log(p);
  }
683076
public void addUnreplicatedFactor(String factorName, T factor, VariableNumMap vars) {
    parametricFactors.add(factor);
    factorPatterns.add(new WrapperVariablePattern(vars));
    parametricFactorNames.add(factorName);
  }
942054
public void addFactor(String factorName, T factor, VariablePattern factorPattern) {
    parametricFactors.add(factor);
    factorPatterns.add(factorPattern);
    parametricFactorNames.add(factorName);
  }
535258
private LNGVector<Variable> initializeConstraint(final EncodingResult result, final Variable[] vars) {
    result.reset();
    this.result = result;
    this.cardinalityInvars = new LNGVector<>(vars.length);
    final LNGVector<Variable> cardinalityOutvars = new LNGVector<>(vars.length);
    for (final Variable var : vars) {
      this.cardinalityInvars.push(var);
      cardinalityOutvars.push(this.result.newVariable());
    }
    return cardinalityOutvars;
  }
511105
public FactorGraph addFactor(String factorName, Factor factor) {
    Preconditions.checkArgument(getVariables().containsAll(factor.getVars()));

    Factor[] newFactors = Arrays.copyOf(factors, factors.length + 1);
    String[] newFactorNames = Arrays.copyOf(factorNames, factorNames.length + 1);
    ;
    newFactors[factors.length] = factor;
    newFactorNames[factors.length] = factorName;
    return new FactorGraph(variables, newFactors, newFactorNames, conditionedVariables,
        conditionedValues, inferenceHint);
  }
1152866
private Pair<Factor, Assignment> getRegressableFactorForFamily(BoostingFactorFamily family, VariableMatch match,
      List<Integer> conditionedVariables, MarginalSet marginals) {
    VariableNumMap marginalVars = match.getMatchedVariables().removeAll(conditionedVariables);
    VariableNumMap fixedVars = match.getMatchedVariables().intersection(conditionedVariables);
    Factor factorMarginal = marginals.getMarginal(marginalVars.getVariableNums())
        .relabelVariables(match.getMappingToTemplate());

    Assignment assignment = marginals.getConditionedValues().intersection(fixedVars)
        .mapVariables(match.getMappingToTemplate().getVariableIndexReplacementMap());

    VariableNumMap outerProductVars = family.getUnconditionalVariables().removeAll(factorMarginal.getVars());
    if (outerProductVars.size() > 0) {
      factorMarginal = factorMarginal.outerProduct(TableFactor.pointDistribution(outerProductVars,
          assignment.intersection(outerProductVars)));
      assignment = assignment.removeAll(outerProductVars.getVariableNumsArray());
    }

    return Pair.of(factorMarginal, assignment);
  }
1162832
public void add(IVector b, IVector result) {
        if ((b == null) || (size != b.size)) return;

        if (result.size != size) result.reshape(size);

        int i;
        for (i = 0; i < size; i++) {
            result.realvector[i] = realvector[i] + b.realvector[i];
            result.imagvector[i] = imagvector[i] + b.imagvector[i];
        }
    }
697325
public Assignment mapVariables(Map<Integer, Integer> varMap) {
    int[] newVarNums = new int[vars.length];
    Object[] newValues = new Object[vars.length];

    int numFilled = 0;
    for (int i = 0; i < vars.length; i++) {
      if (varMap.containsKey(vars[i])) {
        newVarNums[numFilled] = varMap.get(vars[i]);
        newValues[numFilled] = values[i];
        numFilled++;
      }
    }
    
    if (numFilled < newVarNums.length) {
      newVarNums = Arrays.copyOf(newVarNums, numFilled);
      newValues = Arrays.copyOf(newValues, numFilled);
    }
    return Assignment.fromUnsortedArrays(newVarNums, newValues);
  }
277094
@Override
  public MarginalSet computeMarginals(FactorGraph factorGraph) {
    VariableNumMap variables = factorGraph.getVariables();
    Preconditions.checkArgument(variables.getDiscreteVariables().size() == variables.size());

    // Initialize the mean field distribution to the uniform distribution over
    // all variables.
    long curTime = System.currentTimeMillis();
    System.out.println("init: " + (System.currentTimeMillis() - curTime)); 
    int numVars = variables.size();
    IndexedList<Integer> variableNums = new IndexedList<Integer>(variables.getVariableNums());
    List<DiscreteVariable> variableTypes = variables.getDiscreteVariables();
    List<Tensor> variableMarginals = Lists.newArrayListWithCapacity(numVars);
    for (int i = 0; i < numVars; i++) {
      int[] dimensions = new int[] { variableNums.get(i) };
      int[] sizes = new int[] { variableTypes.get(i).numValues() };
      variableMarginals.add(DenseTensor.constant(dimensions, sizes, 1.0 / sizes[0]));
    }
    System.out.println("logweights: "  + (System.currentTimeMillis() - curTime));
    // Get the log weights for each factor in the original factor graph.
    List<Tensor> logWeights = Lists.newArrayList();
    for (Factor factor : factorGraph.getFactors()) {
      logWeights.add(factor.coerceToDiscrete().getWeights().elementwiseLog());
    }
    System.out.println("done: " +  + (System.currentTimeMillis() - curTime)); 

    double updateL2 = Double.POSITIVE_INFINITY;
    int numIterations = 0;
    while (updateL2 > CONVERGENCE_DELTA) {
      updateL2 = 0.0;
      for (int i = 0; i < numVars; i++) {
        int curVarNum = variableNums.get(i);
        // Accumulate the messages from each factor containing this variable.
        DenseTensorBuilder messageAccumulator = new DenseTensorBuilder(
            variableMarginals.get(i).getDimensionNumbers(), variableMarginals.get(i).getDimensionSizes());
        Set<Integer> factorIndexes = factorGraph.getFactorsWithVariable(curVarNum);
        // System.out.println(i + " " + curVarNum + ": " + factorIndexes);
        for (int factorIndex : factorIndexes) {
          Tensor factorMessage = getFactorMessage(curVarNum, logWeights.get(factorIndex),
              variableMarginals, variableNums);
          // System.out.println("factorMessage: " +
          // Arrays.toString(factorMessage.getDimensionNumbers()));
          // System.out.println("messageAccumulator: " +
          // Arrays.toString(messageAccumulator.getDimensionNumbers()));
          messageAccumulator.increment(factorMessage);
        }

        // Update the marginal based on the inbound messages, setting
        // marginal equal to the logistic function of the accumulated messages.
        messageAccumulator.exp();
        double normalizingConstant = messageAccumulator.getTrace();
        messageAccumulator.multiply(1.0 / normalizingConstant);
        Tensor newMarginal = messageAccumulator.buildNoCopy();

        // Compute the convergence criteria
        Tensor delta = newMarginal.elementwiseAddition(
            variableMarginals.get(i).elementwiseProduct(SparseTensor.getScalarConstant(-1.0)));
        updateL2 += delta.getL2Norm();

        variableMarginals.set(i, newMarginal);
      }
      numIterations++;
      System.out.println("update L2: " + updateL2);
    }
    
    System.out.println("iterations:" + numIterations);
    // Format output as factors.
    List<Factor> marginals = Lists.newArrayList();
    for (int i = 0; i < numVars; i++) {
      marginals.add(new TableFactor(variables.intersection(variableNums.get(i)),
          variableMarginals.get(i)));
    }

    System.out.println("really done: " +  + (System.currentTimeMillis() - curTime));
    return new FactorMarginalSet(marginals, 1.0, factorGraph.getConditionedVariables(),
        factorGraph.getConditionedValues());
  }
880148
@Override
    public void fit(INDArray examples, int[] labels) {
        INDArray outcomeMatrix = FeatureUtil.toOutcomeMatrix(labels, numLabels());
        fit(examples, outcomeMatrix);

    }
81409
public void setWeightList(List<? extends Object> varValues, double weight) {
    Preconditions.checkNotNull(varValues);
    Preconditions.checkArgument(getVars().size() == varValues.size());
    setWeight(vars.outcomeToAssignment(varValues), weight);
  }
944140
public void addConstantFactor(String factorName, Factor factor) {
    if (variables.containsAll(factor.getVars())) {
      int factorNum = factors.size();
      factors.add(factor);
      factorNames.add(factorName);

      VariableNumMap factorVars = factor.getVars();
      for (Integer varNum : factorVars.getVariableNums()) {
        variableFactorMap.put(varNum, factorNum);
        factorVariableMap.put(factorNum, varNum);
      }
    } else {
      Preconditions.checkState(!isRoot);
      crossingFactors.add(factor);
    }
  }