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


Java MaxEnt类代码示例

本文整理汇总了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;未经允许,请勿转载。