本文整理汇总了Java中cc.mallet.util.Maths.almostEquals方法的典型用法代码示例。如果您正苦于以下问题:Java Maths.almostEquals方法的具体用法?Java Maths.almostEquals怎么用?Java Maths.almostEquals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.util.Maths
的用法示例。
在下文中一共展示了Maths.almostEquals方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例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);
}
示例3: 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;
}
示例4: 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;
}
示例5: multiplyBy
import cc.mallet.util.Maths; //导入方法依赖的package包/类
public void multiplyBy (Factor f)
{
if (f instanceof ConstantFactor) {
double val = f.value (new Assignment());
// NormalFactor must be normalized right now...
if (Maths.almostEquals (val, 1.0)) {
return; // ok, it's an identity factor
}
}
throw new UnsupportedOperationException ("Can't multiply NormalFactor by "+f);
}
示例6: multiplyBy
import cc.mallet.util.Maths; //导入方法依赖的package包/类
public void multiplyBy (Factor f)
{
if (f instanceof ConstantFactor) {
double val = f.value (new Assignment());
// NormalFactor must be normalized right now...
if (Maths.almostEquals (val, 1.0)) {
return; // ok, it's an identity factor
}
}
throw new UnsupportedOperationException ("Can't multiply BetaFactor by "+f);
}
示例7: divideBy
import cc.mallet.util.Maths; //导入方法依赖的package包/类
public void divideBy (Factor f)
{
if (f instanceof ConstantFactor) {
double val = f.value (new Assignment());
// NormalFactor must be normalized right now...
if (Maths.almostEquals (val, 1.0)) {
return; // ok, it's an identity factor
}
}
throw new UnsupportedOperationException ("Can't divide BetaFactor by "+f);
}
示例8: divideBy
import cc.mallet.util.Maths; //导入方法依赖的package包/类
public void divideBy (Factor f)
{
if (f instanceof ConstantFactor) {
double val = f.value (new Assignment());
// NormalFactor must be normalized right now...
if (Maths.almostEquals (val, 1.0)) {
return; // ok, it's an identity factor
}
}
throw new UnsupportedOperationException ("Can't divide NormalFactor by "+f);
}
示例9: multiply
import cc.mallet.util.Maths; //导入方法依赖的package包/类
public Factor multiply (Factor other)
{
// special handling of identity factor
if (Maths.almostEquals (c, 1.0)) {
return other.duplicate ();
} else if (other instanceof ConstantFactor) {
return new ConstantFactor (c * ((ConstantFactor)other).c);
} else {
return other.multiply (this);
}
}
示例10: almostEquals
import cc.mallet.util.Maths; //导入方法依赖的package包/类
public boolean almostEquals (Factor p, double epsilon)
{
return (p instanceof ConstantFactor && Maths.almostEquals (c, ((ConstantFactor)p).c, epsilon));
}
示例11: pipe
import cc.mallet.util.Maths; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
Sequence data = (Sequence) carrier.getData ();
Sequence target = (Sequence) carrier.getTarget ();
if (data.size () != target.size ())
throw new IllegalArgumentException ("Trying to print into SimpleTagger format, where data and target lengths do not match\n"
+"data.length = "+data.size()+", target.length = "+target.size ());
int N = data.size ();
if (data instanceof TokenSequence) {
throw new UnsupportedOperationException ("Not yet implemented.");
} else if (data instanceof FeatureVectorSequence) {
FeatureVectorSequence fvs = (FeatureVectorSequence) data;
Alphabet dict = (fvs.size() > 0) ? fvs.getFeatureVector (0).getAlphabet () : null;
for (int i = 0; i < N; i++) {
Object label = target.get (i);
writer.print (label);
FeatureVector fv = fvs.getFeatureVector (i);
for (int loc = 0; loc < fv.numLocations (); loc++) {
writer.print (' ');
String fname = dict.lookupObject (fv.indexAtLocation (loc)).toString ();
double value = fv.valueAtLocation (loc);
if (!Maths.almostEquals (value, 1.0)) {
throw new IllegalArgumentException ("Printing to SimpleTagger format: FeatureVector not binary at time slice "+i+" fv:"+fv);
}
writer.print (fname);
}
writer.println ();
}
} else {
throw new IllegalArgumentException ("Don't know how to print data of type "+data);
}
writer.println ();
return carrier;
}