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


Java ModelReader类代码示例

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


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

示例1: main

import cc.mallet.grmm.util.ModelReader; //导入依赖的package包/类
public static void main (String[] args) throws Exception {
   BufferedReader r = new BufferedReader (new StringReader (mdlExample));
   FactorGraph fg = new ModelReader().readModel (r);
   fg.dump();

   Inferencer inf = new JunctionTreeInferencer();
   inf.computeMarginals (fg);
   for (int vi = 0; vi < 4; vi++) {
 Variable var = fg.getVariable (vi);
 System.out.println (inf.lookupMarginal (var).dumpToString());
   }

   System.out.println("+++++++++");
   OutputStreamWriter osw = new OutputStreamWriter(System.out);
   ModelWriter.writeModel (fg, osw);
   osw.close();
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:18,代码来源:ModelReaderExample.java

示例2: testContinousSample

import cc.mallet.grmm.util.ModelReader; //导入依赖的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.grmm.util.ModelReader; //导入依赖的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: testSliceInFg

import cc.mallet.grmm.util.ModelReader; //导入依赖的package包/类
public void testSliceInFg () throws IOException
{
  ModelReader reader = new ModelReader ();
  FactorGraph fg = reader.readModel (new BufferedReader (new StringReader (mdlstr)));
  Variable u1 = fg.findVariable ("u1");
  Variable u2 = fg.findVariable ("u2");
  Assignment assn = new Assignment (new Variable[] { u1, u2 }, new double[] { 6.0, 6.0 });

  FactorGraph fg2 = (FactorGraph) fg.slice (assn);
  fg2.dump ();
  assertEquals (2, fg2.factors ().size ());
  assertEquals (1.0/20, fg2.value (new Assignment ()), 1e-5);

  fg2.addFactor (new ConstantFactor (10.0));
  assertEquals (0.5, fg2.value (new Assignment ()), 1e-5);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:17,代码来源:TestUniformFactor.java

示例5: ignoretestContinousSample

import cc.mallet.grmm.util.ModelReader; //导入依赖的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

示例6: ignoretestContinousSample2

import cc.mallet.grmm.util.ModelReader; //导入依赖的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

示例7: testSliceInFg

import cc.mallet.grmm.util.ModelReader; //导入依赖的package包/类
public void testSliceInFg () throws IOException
{
  ModelReader reader = new ModelReader ();
  FactorGraph fg = reader.readModel (new BufferedReader (new StringReader (TestBetaFactor.mdlstr)));
  Variable u1 = fg.findVariable ("u1");
  Variable u2 = fg.findVariable ("u2");
  Assignment assn = new Assignment (new Variable[] { u1, u2 }, new double[] { 0.25, 0.85 });

  FactorGraph fg2 = (FactorGraph) fg.slice (assn);
  assertEquals (2, fg2.factors ().size ());
  assertEquals (0.59261 * 1.13202, fg2.value (new Assignment ()), 1e-5);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:13,代码来源:TestBetaFactor.java

示例8: testAllFactorsOf

import cc.mallet.grmm.util.ModelReader; //导入依赖的package包/类
public void testAllFactorsOf () throws IOException
{
  ModelReader reader = new ModelReader ();
  FactorGraph fg = reader.readModel (new BufferedReader (new StringReader (uniformMdlstr2)));
  Variable var = new Variable (2);
  var.setLabel ("v0");
  List lst = fg.allFactorsOf (var);
  assertEquals (0, lst.size ());
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:10,代码来源:TestFactorGraph.java

示例9: testJtConstant

import cc.mallet.grmm.util.ModelReader; //导入依赖的package包/类
public void testJtConstant () throws IOException
{
  FactorGraph masterFg = new ModelReader ().readModel (new BufferedReader (new StringReader (gridStr)));
  JunctionTreeInferencer jt = new JunctionTreeInferencer ();
  Assignment assn = masterFg.sampleContinuousVars (new cc.mallet.util.Randoms (3214));
  FactorGraph fg = (FactorGraph) masterFg.slice (assn);
  jt.computeMarginals (fg);
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:9,代码来源:TestInference.java


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