• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Multinomial类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createRandomChain

import cc.mallet.types.Multinomial; //导入依赖的package包/类
public static FactorGraph createRandomChain (cc.mallet.util.Randoms r, int length)
{
  Variable[] vars = new Variable[length];
  for (int i = 0; i < length; i++)
    vars[i] = new Variable (2);

  Dirichlet dirichlet = new Dirichlet (new double[] { 1, 1, 1, 1 });

  FactorGraph mdl = new FactorGraph (vars);
  for (int i = 0; i < length - 1; i++) {
    Multinomial m = dirichlet.randomMultinomial (r);
    double[] probs = m.getValues ();
    mdl.addFactor (vars[i], vars[i + 1], probs);
  }

  return mdl;
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:18,代码来源:RandomGraphs.java


示例2: reset

import cc.mallet.types.Multinomial; //导入依赖的package包/类
@Deprecated
public void reset() {
	emissionEstimator = new Multinomial.LaplaceEstimator[numStates()];
	transitionEstimator = new Multinomial.LaplaceEstimator[numStates()];
	emissionMultinomial = new Multinomial[numStates()];
	transitionMultinomial = new Multinomial[numStates()];
	Alphabet transitionAlphabet = getTransitionAlphabet();
	for (int i = 0; i < numStates(); i++) {
		emissionEstimator[i] = new Multinomial.LaplaceEstimator(
				inputAlphabet);
		transitionEstimator[i] = new Multinomial.LaplaceEstimator(
				transitionAlphabet);
		emissionMultinomial[i] = new Multinomial(
				getUniformArray(inputAlphabet.size()), inputAlphabet);
		transitionMultinomial[i] = new Multinomial(
				getUniformArray(transitionAlphabet.size()),
				transitionAlphabet);
	}
	initialMultinomial = new Multinomial(getUniformArray(transitionAlphabet
			.size()), transitionAlphabet);
	initialEstimator = new Multinomial.LaplaceEstimator(transitionAlphabet);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:23,代码来源:HMM.java


示例3: initTransitions

import cc.mallet.types.Multinomial; //导入依赖的package包/类
/**
 * Separate initialization of initial/transitions and emissions. All
 * probabilities are proportional to (1+Uniform[0,1])^noise.
 * 
 * @author kedarb
 * @param random
 *            Random object (if null use uniform distribution)
 * @param noise
 *            Noise exponent to use. If zero, then uniform distribution.
 */
public void initTransitions(Random random, double noise) {
	Alphabet transitionAlphabet = getTransitionAlphabet();
	initialMultinomial = new Multinomial(getRandomArray(transitionAlphabet
			.size(), random, noise), transitionAlphabet);
	initialEstimator = new Multinomial.LaplaceEstimator(transitionAlphabet);
	transitionMultinomial = new Multinomial[numStates()];
	transitionEstimator = new Multinomial.LaplaceEstimator[numStates()];
	for (int i = 0; i < numStates(); i++) {
		transitionMultinomial[i] = new Multinomial(getRandomArray(
				transitionAlphabet.size(), random, noise),
				transitionAlphabet);
		transitionEstimator[i] = new Multinomial.LaplaceEstimator(
				transitionAlphabet);
		// set state's initial weight
		State s = (State) getState(i);
		s.setInitialWeight(initialMultinomial.logProbability(s.getName()));
	}
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:29,代码来源:HMM.java


示例4: estimate

import cc.mallet.types.Multinomial; //导入依赖的package包/类
public void estimate() {
	Alphabet transitionAlphabet = getTransitionAlphabet();
	initialMultinomial = initialEstimator.estimate();
	initialEstimator = new Multinomial.LaplaceEstimator(transitionAlphabet);
	for (int i = 0; i < numStates(); i++) {
		State s = (State) getState(i);
		emissionMultinomial[i] = emissionEstimator[i].estimate();
		transitionMultinomial[i] = transitionEstimator[i].estimate();
		s.setInitialWeight(initialMultinomial.logProbability(s.getName()));
		// reset estimators
		emissionEstimator[i] = new Multinomial.LaplaceEstimator(
				inputAlphabet);
		transitionEstimator[i] = new Multinomial.LaplaceEstimator(
				transitionAlphabet);
	}
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:17,代码来源:HMM.java


示例5: setTrainable

import cc.mallet.types.Multinomial; //导入依赖的package包/类
public void setTrainable (boolean f)
{
	trainable = f;
	if (f) {
		// This wipes away any previous counts we had.
		// It also potentially allocates an esimator of a new size if
		// the number of states has increased.
		initialStateCounts = new Multinomial.LaplaceEstimator (states.size());
		finalStateCounts = new Multinomial.LaplaceEstimator (states.size());
	} else {
		initialStateCounts = null;
		finalStateCounts = null;
	}
	for (int i = 0; i < numStates(); i++)
		((State)getState(i)).setTrainable(f);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:17,代码来源:FeatureTransducer.java


示例6: readObject

import cc.mallet.types.Multinomial; //导入依赖的package包/类
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
  int version = in.readInt();
  if (version != CURRENT_SERIAL_VERSION)
    throw new ClassNotFoundException("Mismatched NaiveBayesTrainer versions: wanted " +
                                     CURRENT_SERIAL_VERSION + ", got " +
                                     version);

  //default selections for the kind of Estimator used
  featureEstimator = (Multinomial.Estimator) in.readObject();
  priorEstimator = (Multinomial.Estimator) in.readObject();

  // These are the counts formed after NaiveBayes training.
  me = (Multinomial.Estimator []) in.readObject();
  pe = (Multinomial.Estimator) in.readObject();

  // pipe and alphabets
  instancePipe = (Pipe) in.readObject();
  dataAlphabet = (Alphabet) in.readObject();
  targetAlphabet = (Alphabet) in.readObject();
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:21,代码来源:NaiveBayesTrainer.java


示例7: initEmissions

import cc.mallet.types.Multinomial; //导入依赖的package包/类
public void initEmissions(Random random, double noise) {
	emissionMultinomial = new Multinomial[numStates()];
	emissionEstimator = new Multinomial.LaplaceEstimator[numStates()];
	for (int i = 0; i < numStates(); i++) {
		emissionMultinomial[i] = new Multinomial(getRandomArray(
				inputAlphabet.size(), random, noise), inputAlphabet);
		emissionEstimator[i] = new Multinomial.LaplaceEstimator(
				inputAlphabet);
	}
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:11,代码来源:HMM.java


示例8: estimate

import cc.mallet.types.Multinomial; //导入依赖的package包/类
public void estimate ()
{
	if (initialStateCounts == null || finalStateCounts == null)
		throw new IllegalStateException ("This transducer not currently trainable.");
	Multinomial initialStateDistribution = initialStateCounts.estimate ();
	Multinomial finalStateDistribution = finalStateCounts.estimate ();
	for (int i = 0; i < states.size(); i++) {
		State s = states.get (i);
		s.initialWeight = initialStateDistribution.logProbability (i);
		s.finalWeight = finalStateDistribution.logProbability (i);
		s.estimate ();
	}
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:14,代码来源:FeatureTransducer.java


示例9: testIncrement

import cc.mallet.types.Multinomial; //导入依赖的package包/类
public void testIncrement ()
{
	transducer.setTrainable (true);
	SumLatticeDefault lattice = new SumLatticeDefault (transducer, seq); // used to have third argument: true
	double oldWeight = lattice.getTotalWeight ();
	System.out.println ("State 0 transition estimator");
	Multinomial.Estimator est
		= ((FeatureTransducer.State)transducer.getState(0)).getTransitionEstimator();
	est.print();
	assertTrue (est.getCount(0) == 2.0);
	assertTrue (est.getCount(1) == 1.0);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:13,代码来源:TestFeatureTransducer.java


示例10: Estimator

import cc.mallet.types.Multinomial; //导入依赖的package包/类
public Estimator (Collection<Multinomial> multinomialsTraining)
{
	this.multinomials = new ArrayList<Multinomial>(multinomialsTraining);
	for (int i = 1; i < multinomials.size(); i++)
		if (((Multinomial)multinomials.get(i-1)).size()
				!= ((Multinomial)multinomials.get(i)).size()
				|| ((Multinomial)multinomials.get(i-1)).getAlphabet()
				!= ((Multinomial)multinomials.get(i)).getAlphabet())
			throw new IllegalArgumentException
			("All multinomials must have same size and Alphabet.");
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:Dirichlet.java


示例11: testEstimating

import cc.mallet.types.Multinomial; //导入依赖的package包/类
public void testEstimating ()
{
	Alphabet dict = new Alphabet ();
	Multinomial.Estimator e = new Multinomial.LaplaceEstimator (dict);
	FeatureSequence fs = new FeatureSequence (dict);
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("n"));
	fs.add (dict.lookupIndex ("d"));
	fs.add (dict.lookupIndex ("r"));
	fs.add (dict.lookupIndex ("e"));
	fs.add (dict.lookupIndex ("w"));
	fs.add (dict.lookupIndex ("m"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("u"));
	fs.add (dict.lookupIndex ("m"));
	//System.out.println (fs.toString());
	e.increment (fs);
	assertTrue (e.size() == 10);

	Multinomial m = e.estimate ();
	assertTrue (m.size() == 10);
	assertTrue (m.probability (dict.lookupIndex ("a")) == (2.0+1)/(14.0+10));
	assertTrue (m.probability ("w") == (1.0+1)/(14.0+10));
	Multinomial.Logged ml = new Multinomial.Logged (m);
	assertTrue (m.logProbability ("w") == ml.logProbability ("w"));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:31,代码来源:TestMultinomial.java


示例12: estimateFeatureMultinomials

import cc.mallet.types.Multinomial; //导入依赖的package包/类
private Multinomial[] estimateFeatureMultinomials () {
  int numLabels = targetAlphabet.size();
  Multinomial[] m = new Multinomial[numLabels];
  for (int li = 0; li < numLabels; li++) {
    //me[li].print (); // debugging
    m[li] = me[li].estimate();
  }
  return m;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:10,代码来源:NaiveBayesTrainer.java


示例13: readObject

import cc.mallet.types.Multinomial; //导入依赖的package包/类
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
  int version = in.readInt();
  if (version != CURRENT_SERIAL_VERSION)
    throw new ClassNotFoundException("Mismatched NaiveBayesTrainer versions: wanted " +
                                     CURRENT_SERIAL_VERSION + ", got " +
                                     version);

  //default selections for the kind of Estimator used
  featureEstimator = (Multinomial.Estimator) in.readObject();
  priorEstimator = (Multinomial.Estimator) in.readObject();
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:NaiveBayesEMTrainer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DataSource类代码示例发布时间:2022-05-22
下一篇:
Java RegisterApplicationMasterResponseProtoOrBuilder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap