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


Java MatrixOps.sum方法代码示例

本文整理汇总了Java中cc.mallet.types.MatrixOps.sum方法的典型用法代码示例。如果您正苦于以下问题:Java MatrixOps.sum方法的具体用法?Java MatrixOps.sum怎么用?Java MatrixOps.sum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cc.mallet.types.MatrixOps的用法示例。


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

示例1: testSample

import cc.mallet.types.MatrixOps; //导入方法依赖的package包/类
public void testSample ()
{
  Variable v = new Variable (3);
  double[] vals = new double[] { 1, 3, 2 };
  TableFactor ptl = new TableFactor (v, vals);
  int[] sampled = new int [100];

  Randoms r = new Randoms (32423);
  for (int i = 0; i < sampled.length; i++) {
    sampled[i] = ptl.sampleLocation (r);
  }

  double sum = MatrixOps.sum (vals);
  double[] counts = new double [vals.length];
  for (int i = 0; i < vals.length; i++) {
    counts[i] = ArrayUtils.count (sampled, i);
  }

  MatrixOps.print (counts);
  for (int i = 0; i < vals.length; i++) {
    double prp = counts[i] / ((double) sampled.length);
    assertEquals (vals[i] / sum, prp, 0.1);
  }
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:25,代码来源:TestTableFactor.java

示例2: testContinousSample

import cc.mallet.types.MatrixOps; //导入方法依赖的package包/类
public void testContinousSample () throws IOException
{
  ModelReader reader = new ModelReader ();
  FactorGraph fg = reader.readModel (new BufferedReader (new StringReader (uniformMdlstr)));
  Randoms r = new Randoms (324143);
  Assignment allAssn = new Assignment ();
  for (int i = 0; i < 10000; i++) {
    Assignment row = fg.sample (r);
    allAssn.addRow (row);
  }

  Variable x1 = fg.findVariable ("x1");
  Assignment assn1 = (Assignment) allAssn.marginalize (x1);
  int[] col = assn1.getColumnInt (x1);
  double mean = MatrixOps.sum (col) / ((double)col.length);
  assertEquals (0.5, mean, 0.025);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:18,代码来源:TestFactorGraph.java

示例3: testContinousSample2

import cc.mallet.types.MatrixOps; //导入方法依赖的package包/类
public void testContinousSample2 () throws IOException
{
  ModelReader reader = new ModelReader ();
  FactorGraph fg = reader.readModel (new BufferedReader (new StringReader (uniformMdlstr2)));
  Randoms r = new Randoms (324143);
  Assignment allAssn = new Assignment ();
  for (int i = 0; i < 10000; i++) {
    Assignment row = fg.sample (r);
    allAssn.addRow (row);
  }

  Variable x1 = fg.findVariable ("x2");
  Assignment assn1 = (Assignment) allAssn.marginalize (x1);
  int[] col = assn1.getColumnInt (x1);
  double mean = MatrixOps.sum (col) / ((double)col.length);
  assertEquals (0.5, mean, 0.01);

  Variable x2 = fg.findVariable ("x2");
  Assignment assn2 = (Assignment) allAssn.marginalize (x2);
  int[] col2 = assn2.getColumnInt (x2);
  double mean2 = MatrixOps.sum (col2) / ((double)col2.length);
  assertEquals (0.5, mean2, 0.025);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:24,代码来源:TestFactorGraph.java

示例4: getValue

import cc.mallet.types.MatrixOps; //导入方法依赖的package包/类
public double getValue () {
	if (cacheIndicator.isValueStale()) {
		// compute values again
		try {
			// run all threads and wait for them to finish
			List<Future<Double>> results = executor.invokeAll(valueTasks);

			// compute final log probability
			int batch = 0;
			for (Future<Double> f : results) {
				try {
					batchCachedValue[batch++] = f.get();
				} catch (ExecutionException ee) {
					ee.printStackTrace();
				}
			}
		} catch (InterruptedException ie) {
			ie.printStackTrace();
		}
		double cachedValue = MatrixOps.sum(batchCachedValue);
		logger.info("getValue() (loglikelihood, optimizable by label likelihood) =" + cachedValue);
		return cachedValue;
	}
	return MatrixOps.sum(batchCachedValue);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:26,代码来源:ThreadedOptimizable.java

示例5: testSumLogProb

import cc.mallet.types.MatrixOps; //导入方法依赖的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

示例6: ignoretestContinousSample

import cc.mallet.types.MatrixOps; //导入方法依赖的package包/类
public void ignoretestContinousSample () throws IOException
{
  ModelReader reader = new ModelReader ();
  FactorGraph fg = reader.readModel (new BufferedReader (new StringReader (uniformMdlstr)));
  Randoms r = new Randoms (324143);
  Assignment allAssn = new Assignment ();
  for (int i = 0; i < 10000; i++) {
    Assignment row = fg.sample (r);
    allAssn.addRow (row);
  }

  Variable x1 = fg.findVariable ("x1");
  Assignment assn1 = (Assignment) allAssn.marginalize (x1);
  int[] col = assn1.getColumnInt (x1);
  double mean = MatrixOps.sum (col) / ((double)col.length);
  assertEquals (0.5, mean, 0.025);
}
 
开发者ID:cmoen,项目名称:mallet,代码行数:18,代码来源:TestFactorGraph.java

示例7: ignoretestContinousSample2

import cc.mallet.types.MatrixOps; //导入方法依赖的package包/类
public void ignoretestContinousSample2 () throws IOException
{
  ModelReader reader = new ModelReader ();
  FactorGraph fg = reader.readModel (new BufferedReader (new StringReader (uniformMdlstr2)));
  Randoms r = new Randoms (324143);
  Assignment allAssn = new Assignment ();
  for (int i = 0; i < 10000; i++) {
    Assignment row = fg.sample (r);
    allAssn.addRow (row);
  }

  Variable x1 = fg.findVariable ("x2");
  Assignment assn1 = (Assignment) allAssn.marginalize (x1);
  int[] col = assn1.getColumnInt (x1);
  double mean = MatrixOps.sum (col) / ((double)col.length);
  assertEquals (0.5, mean, 0.01);

  Variable x2 = fg.findVariable ("x2");
  Assignment assn2 = (Assignment) allAssn.marginalize (x2);
  int[] col2 = assn2.getColumnInt (x2);
  double mean2 = MatrixOps.sum (col2) / ((double)col2.length);
  assertEquals (0.5, mean2, 0.025);
}
 
开发者ID:cmoen,项目名称:mallet,代码行数:24,代码来源:TestFactorGraph.java

示例8: toString

import cc.mallet.types.MatrixOps; //导入方法依赖的package包/类
public String toString () {
	StringBuffer sb = new StringBuffer ();
	int maxLabelNameLength = 0;
	LabelAlphabet labelAlphabet = trial.getClassifier().getLabelAlphabet();
	for (int i = 0; i < numClasses; i++) {
		int len = labelAlphabet.lookupLabel(i).toString().length();
		if (maxLabelNameLength < len) {
			maxLabelNameLength = len;
		}
	}

	// These counts will be integers, but we'll keep them as doubles so we can divide later
	double[] correctLabelCounts = new double[values.length];

	for (int i = 0; i < correctLabelCounts.length; i++){
		// This sum is the number of instances whose correct class is i
		correctLabelCounts[i] = MatrixOps.sum(values[i]);
	}
	// Find the count of the most frequent class and divide that by 
	//  the total number of instances.
	double baselineAccuracy = MatrixOps.max(correctLabelCounts) / MatrixOps.sum(correctLabelCounts);
	
	sb.append ("Confusion Matrix, row=true, column=predicted  accuracy="+trial.getAccuracy()+" most-frequent-tag baseline="+baselineAccuracy+"\n");
	
	for (int i = 0; i < maxLabelNameLength-5+4; i++) { sb.append (' '); }
	sb.append ("label");
	for (int c2 = 0; c2 < Math.min(10,numClasses); c2++) { sb.append ("   "+c2); }
	for (int c2 = 10; c2 < numClasses; c2++) { sb.append ("  " + c2); }
	sb.append ("  |total\n");
	for (int c = 0; c < numClasses; c++) {
		appendJustifiedInt (sb, c, false);
		String labelName = labelAlphabet.lookupLabel(c).toString();
		for (int i = 0; i < maxLabelNameLength-labelName.length(); i++) { sb.append (' '); }
		sb.append (" "+labelName+" ");
		for (int c2 = 0; c2 < numClasses; c2++) {
			appendJustifiedInt (sb, values[c][c2], true);
			sb.append (' ');
		}
		sb.append (" |"+ MatrixOps.sum(values[c]));
		sb.append ('\n');
	}
	return sb.toString();
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:44,代码来源:ConfusionMatrix.java


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