当前位置: 首页>>代码示例>>Java>>正文


Java Maths类代码示例

本文整理汇总了Java中cc.mallet.util.Maths的典型用法代码示例。如果您正苦于以下问题:Java Maths类的具体用法?Java Maths怎么用?Java Maths使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Maths类属于cc.mallet.util包,在下文中一共展示了Maths类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: marginalizeInternal

import cc.mallet.util.Maths; //导入依赖的package包/类
protected Factor marginalizeInternal (AbstractTableFactor result)
  {

    result.setAll (Double.NEGATIVE_INFINITY);
    int[] projection = largeIdxToSmall (result);

    /* Add each element of the single array of the large potential
to the correct element in the small potential. */
    int numLocs = probs.numLocations ();
    for (int largeLoc = 0; largeLoc < numLocs; largeLoc++) {

      /* Convert a single-index from this distribution to
 one for the smaller distribution */
      int smallIdx = projection[largeLoc];

      /* Whew! Now, add it in. */
      double oldValue = this.probs.valueAtLocation (largeLoc);
      double currentValue = result.probs.singleValue (smallIdx);
      result.probs.setValueAtLocation (smallIdx,
              Maths.sumLogProb (oldValue, currentValue));

    }
    Flops.sumLogProb (numLocs);

    return result;
  }
 
开发者ID:mimno,项目名称:GRMM,代码行数:27,代码来源:LogTableFactor.java

示例2: divideByInternal

import cc.mallet.util.Maths; //导入依赖的package包/类
protected void divideByInternal (DiscreteFactor ptl)
{
  int[] projection = largeIdxToSmall (ptl);
  int numLocs = probs.numLocations ();
  for (int singleLoc = 0; singleLoc < numLocs; singleLoc++) {
    int smallIdx = projection[singleLoc];
    double prev = this.probs.valueAtLocation (singleLoc);
    double newVal = ptl.value (smallIdx);
    double product = prev / newVal;
    /* by convention, let dividing by zero just return 0 */
    if (Maths.almostEquals (newVal, 0)) {
      product = 0;
    }
    this.probs.setValueAtLocation (singleLoc, product);
  }
  Flops.increment (numLocs);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:18,代码来源:TableFactor.java

示例3: hyberbolicPrior

import cc.mallet.util.Maths; //导入依赖的package包/类
/** Return the log(p(parameters)) according to a a hyperbolic curve that is a smooth approximation to an L1 prior. */
public double hyberbolicPrior (double slope, double sharpness) {
	double value = 0;
	assert (initialWeights.length == finalWeights.length);
	for (int i = 0; i < initialWeights.length; i++) {
		if (!Double.isInfinite(initialWeights[i]))
			value -= (slope / sharpness	* Math.log (Maths.cosh (sharpness * -initialWeights[i])));
		if (!Double.isInfinite(finalWeights[i]))
			value -= (slope / sharpness * Math.log (Maths.cosh (sharpness * -finalWeights[i])));
	}
	double w;
	for (int i = 0; i < weights.length; i++) {
		value -= (slope / sharpness	* Math.log (Maths.cosh (sharpness * defaultWeights[i])));
		for (int j = 0; j < weights[i].numLocations(); j++) {
			w = weights[i].valueAtLocation(j);
			if (!Double.isInfinite(w))
				value -= (slope / sharpness	* Math.log (Maths.cosh (sharpness * w)));
		}
	}
	return value;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:22,代码来源:CRF.java

示例4: plusEqualsHyperbolicPriorGradient

import cc.mallet.util.Maths; //导入依赖的package包/类
public void plusEqualsHyperbolicPriorGradient (Factors other, double slope, double sharpness) {
	// TODO This method could use some careful checking over, especially for flipped negations
	assert (initialWeights.length == finalWeights.length);
	double ss = slope * sharpness;
	for (int i = 0; i < initialWeights.length; i++) {
		// gsc: checking initial/final weights of crf.parameters as well since we could
      // have a state machine where some states have infinite initial and/or final weight
		if (!Double.isInfinite(initialWeights[i]) && !Double.isInfinite(other.initialWeights[i]))
        initialWeights[i] += ss * Maths.tanh (-other.initialWeights[i]);
		if (!Double.isInfinite(finalWeights[i]) && !Double.isInfinite(other.finalWeights[i]))
        finalWeights[i] += ss * Maths.tanh (-other.finalWeights[i]);
	}
	double w, ow;
	for (int i = 0; i < weights.length; i++) {
		if (weightsFrozen[i]) continue;
		// TODO Note that there doesn't seem to be a way to freeze the initialWeights and finalWeights 
		// TODO Should we also obey FeatureSelection here?  No need; it is enforced by the creation of the weights.
		if (!Double.isInfinite(defaultWeights[i])) defaultWeights[i] += ss * Maths.tanh(-other.defaultWeights[i]);
		for (int j = 0; j < weights[i].numLocations(); j++) {
			w = weights[i].valueAtLocation (j);
			ow = other.weights[i].valueAtLocation (j);
			if (!Double.isInfinite(w)) weights[i].setValueAtLocation(j, w + (ss * Maths.tanh(-ow)));
		}
	}
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:26,代码来源:CRF.java

示例5: almostEquals

import cc.mallet.util.Maths; //导入依赖的package包/类
public boolean almostEquals (ConstantMatrix m2) {
	if (getNumDimensions () != m2.getNumDimensions ()) {
		return false;
	}
	if (numLocations () != m2.numLocations ()) {
		return false;
	}
	int[] dims1 = new int [getNumDimensions ()];
	int[] dims2 = new int [getNumDimensions ()];
	getDimensions (dims1);
	m2.getDimensions (dims2);
	for (int i = 0; i < dims1.length; i++) {
		if (dims1 [i] != dims2 [i]) {
			return false;
		}
	}
	for (int i = 0; i < numLocations(); i++) {
		if (!Maths.almostEquals (valueAtLocation (i), m2.valueAtLocation (i))) {
			return false;
		}
	}
	return true;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:24,代码来源:DenseMatrix.java

示例6: splitTree

import cc.mallet.util.Maths; //导入依赖的package包/类
protected void splitTree(C45.Node node, int depth)
{
	// Stop growing the tree when any of the following is true:
	//   1.  We care about tree depth and maximum depth is reached
	//   2.  The entropy of the node is too small (i.e., all 
	//       instances belong to the same class)
	//   3.  The gain ratio of the best split available is too small
	if (m_depthLimited && depth == m_maxDepth) {
		logger.info("Splitting stopped: maximum depth reached (" + m_maxDepth + ")");
		return;
	}       
	else if (Maths.almostEquals(node.getGainRatio().getBaseEntropy(), 0)) {
		logger.info("Splitting stopped: entropy of node too small (" + node.getGainRatio().getBaseEntropy() + ")");
		return;
	}
	else if (Maths.almostEquals(node.getGainRatio().getMaxValue(), 0)) {
		logger.info("Splitting stopped: node has insignificant gain ratio (" + node.getGainRatio().getMaxValue() + ")");
		return;
	}
	logger.info("Splitting feature \""+node.getSplitFeature()
			+"\" at threshold=" + node.getGainRatio().getMaxValuedThreshold() 
			+ " gain ratio="+node.getGainRatio().getMaxValue());
	node.split();
	splitTree(node.getLeftChild(), depth+1);
	splitTree(node.getRightChild(), depth+1);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:27,代码来源:C45Trainer.java

示例7: computeCostAndPrune

import cc.mallet.util.Maths; //导入依赖的package包/类
public double computeCostAndPrune()
{
	double costS = getMDL();

	if (isLeaf())
		return costS + 1;

	double minCost1 = getLeftChild().computeCostAndPrune();
	double minCost2 = getRightChild().computeCostAndPrune();
	double costSplit = Math.log(m_gainRatio.getNumSplitPointsForBestFeature()) / GainRatio.log2;
	double minCostN = Math.min(costS+1, costSplit+1+minCost1+minCost2);

	if (Maths.almostEquals(minCostN, costS+1))
		m_leftChild = m_rightChild = null;

	return minCostN;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:18,代码来源:C45.java

示例8: testSumLogProb

import cc.mallet.util.Maths; //导入依赖的package包/类
public void testSumLogProb ()
{
  double[] vals = { 53.0, 1.56e4, 0.0045, 672.563, 1e-15 };
  double[] logVals = new double [vals.length];
  for (int i = 0; i < vals.length; i++)
    logVals [i] = Math.log (vals[i]);

  double sum = MatrixOps.sum (vals);

  double lsum2 = Double.NEGATIVE_INFINITY;
  for (int i = 0; i < logVals.length; i++) {
    lsum2 = Maths.sumLogProb (lsum2, logVals [i]);
  }
  assertEquals (sum, Math.exp(lsum2), 1e-5);

  double lsum = Maths.sumLogProb (logVals);
  assertEquals (sum, Math.exp (lsum), 1e-5);

}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:20,代码来源:TestMaths.java


注:本文中的cc.mallet.util.Maths类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。