Gets the unnormalized factor beleifs.
439340
private VarTensor calcFactorBeliefs(Factor factor) {
        if (factor instanceof GlobalFactor) {
            log.warn("Getting marginals of a global factor is not supported."
                    + " This will require exponential space to store the resulting factor."
                    + " This should only be used for testing.");
        }        
        // Compute the product of all messages sent to this factor.
        VarTensor prod = safeNewVarTensor(factor);
        calcProductAtFactor(factor.getId(), prod, -1, -1);
        return prod;
    }
1173898
private BigDecimal getSunTrueLongitude(BigDecimal meanAnomaly) {
        BigDecimal sinMeanAnomaly = new BigDecimal(Math.sin(convertDegreesToRadians(meanAnomaly).doubleValue()));
        BigDecimal sinDoubleMeanAnomaly = new BigDecimal(Math.sin(multiplyBy(convertDegreesToRadians(meanAnomaly), BigDecimal.valueOf(2))
                .doubleValue()));

        BigDecimal firstPart = meanAnomaly.add(multiplyBy(sinMeanAnomaly, new BigDecimal("1.916")));
        BigDecimal secondPart = multiplyBy(sinDoubleMeanAnomaly, new BigDecimal("0.020")).add(new BigDecimal("282.634"));
        BigDecimal trueLongitude = firstPart.add(secondPart);

        if (trueLongitude.doubleValue() > 360) {
            trueLongitude = trueLongitude.subtract(BigDecimal.valueOf(360));
        }
        return setScale(trueLongitude);
    }
612711
def obfn_f(self):
        
        """

        obf = 0.0
        for i in range(self.Nb):
            obf += self.obfn_fi(self.obfn_fvar(i), i)
        return obf
973071
public static int cudnnDivisiveNormalizationForward(
        cudnnHandle handle, 
        cudnnLRNDescriptor normDesc, 
        int mode, 
        Pointer alpha, 
        cudnnTensorDescriptor xDesc, /** same desc for means, temp, temp2 */
        Pointer x, 
        Pointer means, /** if NULL, means are assumed to be zero */
        Pointer temp, 
        Pointer temp2, 
        Pointer beta, 
        cudnnTensorDescriptor yDesc, 
        Pointer y)
    {
        return checkResult(cudnnDivisiveNormalizationForwardNative(handle, normDesc, mode, alpha, xDesc, x, means, temp, temp2, beta, yDesc, y));
    }
103956
def Eg(self, **kwargs):
        '''
        
        '''
        return self.unstrained.Eg(**kwargs) + self.Eg_strain_shift(**kwargs)
24351
def obfn_cns(self):
        
        """

        return np.linalg.norm((self.Pcn(self.obfn_gvar()) - self.obfn_gvar()))
691154
public double getVariance() {
        if (!DATA_LIST.isEmpty()) {
            double sum = 0;
            double sumOfSquares = 0;
            double average = 0;
            for (DataPoint dataPoint : DATA_LIST) {
                sumOfSquares += (dataPoint.getValue() * dataPoint.getValue());
                sum += dataPoint.getValue();
            }
            average = sum / DATA_LIST.size();
            return (sumOfSquares / DATA_LIST.size()) - average * average;
        }
        return 0;
    }
1343199
public float getNormalizedValue() {
    if (Measure_Type.featOkTst && ((Measure_Type)jcasType).casFeat_normalizedValue == null)
      jcasType.jcas.throwFeatMissing("normalizedValue", "ch.epfl.bbp.uima.types.Measure");
    return jcasType.ll_cas.ll_getFloatValue(addr, ((Measure_Type)jcasType).casFeatCode_normalizedValue);}
549583
def normalization_factor(self):
        
        return 1.0 / (self.num_atoms - self.composition.get('H', 0)
                      - self.composition.get('O', 0))
533335
public void addUnreplicatedFactor(String factorName, ParametricFactor factor) {
    super.addUnreplicatedFactor(factorName, factor, factor.getVars());
  }
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);
  }
890270
private function normalizeQualityFactor($qFactor)
    {
        if (!is_numeric($qFactor)) {
            $qFactor = 1.0;

        } elseif ($qFactor < 0) {
            $qFactor = 0.0;

        } elseif ($qFactor > 1) {
            $qFactor = 1.0;

        } else {
            $qFactor = floatval($qFactor);
        }

        return $qFactor;
    }
724666
private static int[] getFactors(int _value, int _max) {
      final int factors[] = new int[MAX_GROUP_SIZE];
      int factorIdx = 0;

      for (int possibleFactor = 1; possibleFactor <= _max; possibleFactor++) {
         if ((_value % possibleFactor) == 0) {
            factors[factorIdx++] = possibleFactor;
         }
      }

      return (Arrays.copyOf(factors, factorIdx));
   }
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());
  }
1004459
private int gradientUpdate(List<TensorBuilder> factors,
      List<TensorBuilder> unaryFactors, double stepSize) {
    // The best assignment, as computed from only the unary factors.
    int[] variableNums = new int[unaryFactors.size()];
    int[] variableSizes = new int[unaryFactors.size()];
    int[] variableValues = new int[unaryFactors.size()];
    locallyDecodeFactors(unaryFactors, variableNums, variableSizes, variableValues);

    // Identify where unary factors disagree with larger factors to compute the
    // subgradient.
    List<Integer> variableDisagreementList = Lists.newArrayList();
    List<Integer> factorDisagreementList = Lists.newArrayList();
    List<Integer> factorValueList = Lists.newArrayList();
    for (int i = 0; i < factors.size(); i++) {
      TensorBuilder factor = factors.get(i);
      int[] bestFactorValues = factor.keyNumToDimKey(factor.getLargestValues(1)[0]);
      int[] factorVariableNums = factor.getDimensionNumbers();

      for (int j = 0; j < factorVariableNums.length; j++) {
        int index = Arrays.binarySearch(variableNums, factorVariableNums[j]);
        if (bestFactorValues[j] != variableValues[index]) {
          // Factor and unary assignments disagree on variableNums[index].
          // Store the disagreement, used later to compute the subgradient.
          variableDisagreementList.add(index);
          factorDisagreementList.add(i);
          factorValueList.add(bestFactorValues[j]);

          /*
          System.out.println("Disagreement " + Arrays.toString(factorVariableNums) + "=" + Arrays.toString(bestFactorValues) + ", "
              + variableNums[index] + "=" + variableValues[index]);
              */
        }
      }
    }

    // Update the factor lagrange multipliers based on the disagreements.
    // For each disagreement, the subgradient update decreases the weight of
    // each factor's maximum weight assignment, and increases the weight of
    // the disagreeing factor's maximum weight assignment.
    for (int i = 0; i < variableDisagreementList.size(); i++) {
      int variableIndex = variableDisagreementList.get(i);
      int factorNum = factorDisagreementList.get(i);

      TensorBuilder factor = factors.get(factorNum);
      TensorBuilder unaryFactor = unaryFactors.get(variableIndex);

      int variableNum = variableNums[variableIndex];
      int variableSize = variableSizes[variableIndex];
      int bestFactorValue = factorValueList.get(i);
      int bestUnaryValue = variableValues[variableIndex];

      SparseTensor unaryGradient = SparseTensor.singleElement(new int[] { variableNum },
          new int[] { variableSize }, new int[] { bestUnaryValue }, 1);
      SparseTensor factorGradient = SparseTensor.singleElement(new int[] { variableNum },
          new int[] { variableSize }, new int[] { bestFactorValue }, 1);

      unaryFactor.incrementWithMultiplier(unaryGradient, -1.0 * stepSize);
      unaryFactor.incrementWithMultiplier(factorGradient, stepSize);
      factor.incrementWithMultiplier(unaryGradient, stepSize);
      factor.incrementWithMultiplier(factorGradient, -1.0 * stepSize);
    }

    return variableDisagreementList.size();
  }
614842
public Factor getFactorByName(String name) {
    int index = getFactorIndexByName(name);
    if (index == -1) {
      return null;
    }
    return factors[index];
  }
541344
def ad_unif_inf(statistic):
    
    z = statistic
    if z < 2:
        return (exp(-1.2337141 / z) / sqrt(z) *
                                (2.00012 + (.247105 - (.0649821 - (.0347962 -
                                (.011672 - .00168691 * z) * z) * z) * z) * z))
    else:
        return exp(-exp(1.0776 - (2.30695 - (.43424 - (.082433 -
                                (.008056 - .0003146 * z) * z) * z) * z) * z))