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

Java MaxEnt类代码示例

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

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



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

示例1: createTrainer

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
public ClassifierTrainer<MaxEnt> createTrainer(String... args) {
  MaxEntTrainer trainer = new MaxEntTrainer();
  if (args != null) {
    if (args.length % 2 != 0) {
      throw new IllegalArgumentException("each argument must be supplied with a value:  "
          + getUsageMessage());
    }
    for (int i = 0; i < args.length; i += 2) {
      String optionName = args[i];
      String optionValue = args[i + 1];
      if (optionName.equals("--numIterations")) {
        int numIterations = Integer.parseInt(optionValue);
        if (numIterations > 0)
          trainer.setNumIterations(numIterations);
        else
          throw new IllegalArgumentException("numIterations must be positive.  "
              + getUsageMessage());
      }

      else if (optionName.equals("--gaussianPriorVariance"))
        trainer.setGaussianPriorVariance(Double.parseDouble(optionValue));
      else
        throw new IllegalArgumentException(String.format(
            "the argument %1$s is invalid.  ",
            optionName) + getUsageMessage());
    }
  }
  return trainer;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:30,代码来源:MaxEntTrainerFactory.java


示例2: DMRInferencer

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
public DMRInferencer (int[][] typeTopicCounts, int[] tokensPerTopic, MaxEnt dmrParameters, Alphabet alphabet,
						double beta, double betaSum) {

	this.dmrParameters = dmrParameters;
	this.numFeatures = dmrParameters.getAlphabet().size();
	this.defaultFeatureIndex = dmrParameters.getDefaultFeatureIndex();

	this.tokensPerTopic = tokensPerTopic;
	this.typeTopicCounts = typeTopicCounts;

	this.alphabet = alphabet;

	numTopics = tokensPerTopic.length;
	numTypes = typeTopicCounts.length;
	
	if (Integer.bitCount(numTopics) == 1) {
		// exact power of 2
		topicMask = numTopics - 1;
		topicBits = Integer.bitCount(topicMask);
	}
	else {
		// otherwise add an extra bit
		topicMask = Integer.highestOneBit(numTopics) * 2 - 1;
		topicBits = Integer.bitCount(topicMask);
	}

	
	this.beta = beta;
	this.betaSum = betaSum;

	cachedCoefficients = new double[numTopics];
	alpha = new double[numTopics];
	
	for (int topic=0; topic < numTopics; topic++) {
		smoothingOnlyMass += alpha[topic] * beta / (tokensPerTopic[topic] + betaSum);
		cachedCoefficients[topic] =  alpha[topic] / (tokensPerTopic[topic] + betaSum);
	}

	random = new Randoms();
}
 
开发者ID:mimno,项目名称:Mallet,代码行数:41,代码来源:DMRInferencer.java


示例3: printModel

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
public void printModel(PrintWriter out, int numOfExtremeFeatures) {
  if (classifier instanceof MaxEnt) {
    out.println("Num of features: " + classifier.getAlphabet().size());
    ((MaxEnt) classifier).printExtremeFeatures(out, Math.min(numOfExtremeFeatures, classifier.getAlphabet().size()));
    out.flush();
  } else {
    classifier.print(out);
  }
}
 
开发者ID:begab,项目名称:kpe,代码行数:10,代码来源:MalletClassifier.java


示例4: DMROptimizable

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
public DMROptimizable (InstanceList instances, MaxEnt initialClassifier) {

		this.trainingList = instances;
		Alphabet alphabet = instances.getDataAlphabet();
		Alphabet labelAlphabet = instances.getTargetAlphabet();

		this.numLabels = labelAlphabet.size();

		// Add one feature for the "default feature".
		this.numFeatures = alphabet.size() + 1; // add a spot for the intercept term
            
		//System.out.println("num features: " + numFeatures + " numLabels: " + numLabels);

		this.defaultFeatureIndex = numFeatures - 1;

		this.parameters = new double [numLabels * numFeatures];

		//this.constraints = new double [numLabels * numFeatures];
		this.cachedGradient = new double [numLabels * numFeatures];

		if (initialClassifier != null) {
			this.classifier = initialClassifier;
			this.parameters = classifier.getParameters();
			this.defaultFeatureIndex = classifier.getDefaultFeatureIndex();
			assert (initialClassifier.getInstancePipe() == instances.getPipe());
		}
		else if (this.classifier == null) {
			this.classifier =
				new MaxEnt (instances.getPipe(), parameters);
		}

		formatter = new DecimalFormat("0.###E0");

		cachedValueStale = true;
		cachedGradientStale = true;

		// Initialize the constraints

		logger.fine("Number of instances in training list = " + trainingList.size());

		for (Instance instance : trainingList) {
			FeatureVector multinomialValues = (FeatureVector) instance.getTarget();

			if (multinomialValues == null)
				continue;

			FeatureVector features = (FeatureVector) instance.getData();
			assert (features.getAlphabet() == alphabet);

			boolean hasNaN = false;

			for (int i = 0; i < features.numLocations(); i++) {
				if (Double.isNaN(features.valueAtLocation(i))) {
					logger.info("NaN for feature " + alphabet.lookupObject(features.indexAtLocation(i)).toString()); 
					hasNaN = true;
				}
			}

			if (hasNaN) {
				logger.info("NaN in instance: " + instance.getName());
			}

		}

		//TestMaximizable.testValueAndGradientCurrentParameters (this);
	}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:67,代码来源:DMROptimizable.java


示例5: getClassifier

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
@Override
public MaxEnt getClassifier() {
  return p;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:5,代码来源:MaxEntPRTrainer.java


示例6: train

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
@Override
public MaxEnt train(InstanceList trainingSet) {
  return train(trainingSet,maxIterations);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:5,代码来源:MaxEntPRTrainer.java


示例7: addInstances

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
public void addInstances (InstanceList training) {

		alphabet = training.getDataAlphabet();
		numTypes = alphabet.size();
		
		betaSum = beta * numTypes;

		Randoms random = null;
		if (randomSeed == -1) {
			random = new Randoms();
		}
		else {
			random = new Randoms(randomSeed);
		}

		alphaCache = new double[ training.size() ][numTopics];
		alphaSumCache = new double[ training.size() ];
		
		int index = 0;
		for (Instance instance : training) {
			FeatureSequence tokens = (FeatureSequence) instance.getData();
			LabelSequence topicSequence =
				new LabelSequence(topicAlphabet, new int[ tokens.size() ]);
			
			int[] topics = topicSequence.getFeatures();
			for (int position = 0; position < topics.length; position++) {

				int topic = random.nextInt(numTopics);
				topics[position] = topic;
				
			}

			TopicAssignment t = new TopicAssignment(instance, topicSequence);
			data.add(t);
			
			Arrays.fill(alphaCache[index], initialAlpha);
			alphaSumCache[index] = numTopics * initialAlpha;
			
			index++;
		}
		
		alphaCache = new double[ data.size() ][numTopics];
		alphaSumCache = new double[ data.size() ];
		
		buildInitialTypeTopicCounts();
	
		// Create a "fake" pipe with the features in the data and 
		//  an int-int hashmap of topic counts in the target.
	
		parameterPipe = new Noop();
		Alphabet featureAlphabet = training.getTargetAlphabet();
		numFeatures = featureAlphabet.size() + 1;

		parameterPipe.setDataAlphabet(featureAlphabet);
		parameterPipe.setTargetAlphabet(topicAlphabet);

		dmrParameters = new MaxEnt(parameterPipe, new double[numFeatures * numTopics]);
		defaultFeatureIndex = dmrParameters.getDefaultFeatureIndex();
		double logInitialAlpha = Math.log(initialAlpha);
		for (int topic=0; topic < numTopics; topic++) {
			dmrParameters.setParameter(topic, defaultFeatureIndex, logInitialAlpha);
		}
		
		for (int doc=0; doc < data.size(); doc++) {
			cacheAlphas(data.get(doc).instance, doc);
		}
		
		totalTokens = 0;
		for (int doc = 0; doc < data.size(); doc++) {
			FeatureSequence fs = (FeatureSequence) data.get(doc).instance.getData();
			totalTokens += fs.getLength();
		}
	}
 
开发者ID:mimno,项目名称:Mallet,代码行数:74,代码来源:DMRTopicModel.java


示例8: readObject

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
private void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException {
	
	int version = in.readInt ();

	dmrParameters = (MaxEnt) in.readObject();
	numFeatures = dmrParameters.getAlphabet().size();
	defaultFeatureIndex = dmrParameters.getDefaultFeatureIndex();

	data = (ArrayList<TopicAssignment>) in.readObject ();
	alphabet = (Alphabet) in.readObject();
	topicAlphabet = (LabelAlphabet) in.readObject();
	
	numTopics = in.readInt();
	
	topicMask = in.readInt();
	topicBits = in.readInt();
	
	numTypes = in.readInt();
	
	alpha = (double[]) in.readObject();
	alphaSum = in.readDouble();
	beta = in.readDouble();
	betaSum = in.readDouble();
	
	typeTopicCounts = (int[][]) in.readObject();
	tokensPerTopic = (int[]) in.readObject();
	
	docLengthCounts = (int[]) in.readObject();
	topicDocCounts = (int[][]) in.readObject();

	numIterations = in.readInt();
	burninPeriod = in.readInt();
	saveSampleInterval = in.readInt();
	optimizeInterval = in.readInt();
	showTopicsInterval = in.readInt();
	wordsPerTopic = in.readInt();

	saveStateInterval = in.readInt();
	stateFilename = (String) in.readObject();
	
	saveModelInterval = in.readInt();
	modelFilename = (String) in.readObject();
	
	randomSeed = in.readInt();
	formatter = (NumberFormat) in.readObject();
	printLogLikelihood = in.readBoolean();

	numThreads = in.readInt();
}
 
开发者ID:mimno,项目名称:Mallet,代码行数:50,代码来源:DMRTopicModel.java


示例9: DMROptimizable

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
public DMROptimizable (InstanceList instances, MaxEnt initialClassifier) {

		this.trainingList = instances;
		Alphabet alphabet = instances.getDataAlphabet();
		Alphabet labelAlphabet = instances.getTargetAlphabet();

		this.numLabels = labelAlphabet.size();

		// Add one feature for the "default feature".
		this.numFeatures = alphabet.size() + 1; // add a spot for the intercept term

		//System.out.println("num features: " + numFeatures + " numLabels: " + numLabels);

		this.defaultFeatureIndex = numFeatures - 1;

		this.parameters = new double [numLabels * numFeatures];

		//this.constraints = new double [numLabels * numFeatures];
		this.cachedGradient = new double [numLabels * numFeatures];

		if (initialClassifier != null) {
			this.classifier = initialClassifier;
			this.parameters = classifier.getParameters();
			this.defaultFeatureIndex = classifier.getDefaultFeatureIndex();
			assert (initialClassifier.getInstancePipe() == instances.getPipe());
		}
		else if (this.classifier == null) {
			this.classifier =
				new MaxEnt (instances.getPipe(), parameters);
		}

		formatter = new DecimalFormat("0.###E0");

		cachedValueStale = true;
		cachedGradientStale = true;

		// Initialize the constraints

		logger.fine("Number of instances in training list = " + trainingList.size());

		for (Instance instance : trainingList) {
			FeatureVector multinomialValues = (FeatureVector) instance.getTarget();

			if (multinomialValues == null)
				continue;

			FeatureVector features = (FeatureVector) instance.getData();
			assert (features.getAlphabet() == alphabet);

			boolean hasNaN = false;

			for (int i = 0; i < features.numLocations(); i++) {
				if (Double.isNaN(features.valueAtLocation(i))) {
					logger.info("NaN for feature " + alphabet.lookupObject(features.indexAtLocation(i)).toString()); 
					hasNaN = true;
				}
			}

			if (hasNaN) {
				logger.info("NaN in instance: " + instance.getName());
			}

		}

		//TestMaximizable.testValueAndGradientCurrentParameters (this);
	}
 
开发者ID:mimno,项目名称:Mallet,代码行数:67,代码来源:DMROptimizable.java


示例10: readObject

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
private void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException {

		int version = in.readInt ();

		dmrParameters = (MaxEnt) in.readObject();
		numFeatures = dmrParameters.getAlphabet().size();
		defaultFeatureIndex = dmrParameters.getDefaultFeatureIndex();
		
		alphabet = (Alphabet) in.readObject();

		numTopics = in.readInt();

		topicMask = in.readInt();
		topicBits = in.readInt();

		numTypes = in.readInt();

		alpha = (double[]) in.readObject();
		beta = in.readDouble();
		betaSum = in.readDouble();

		typeTopicCounts = (int[][]) in.readObject();
		tokensPerTopic = (int[]) in.readObject();

		random = (Randoms) in.readObject();

		smoothingOnlyMass = in.readDouble();
		cachedCoefficients = (double[]) in.readObject();
	}
 
开发者ID:mimno,项目名称:Mallet,代码行数:30,代码来源:DMRInferencer.java


示例11: getClassifier

import cc.mallet.classify.MaxEnt; //导入依赖的package包/类
public MaxEnt getClassifier () { return classifier; } 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:2,代码来源:DMROptimizable.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java DatanodeDescriptor类代码示例发布时间:2022-05-22
下一篇:
Java GenericData类代码示例发布时间: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