Package cc.mallet.util

Examples of cc.mallet.util.Randoms


    }
   
    public void initialize () {

  if (random == null) {
      random = new Randoms();
  }

  gammaSum = gamma * numStates;
 
  stateTopicCounts = new int[numStates][numTopics];
View Full Code Here


  public PolylingualTopicModel (int numberOfTopics) {
    this (numberOfTopics, numberOfTopics);
  }
 
  public PolylingualTopicModel (int numberOfTopics, double alphaSum) {
    this (numberOfTopics, alphaSum, new Randoms());
  }
View Full Code Here

    this.showTopicsInterval = interval;
    this.wordsPerTopic = n;
  }

  public void setRandomSeed(int seed) {
    random = new Randoms(seed);
  }
View Full Code Here

    int numTopWords = args.length > 2 ? Integer.parseInt(args[2]) : 20;
    int numSuperTopics = args.length > 3 ? Integer.parseInt(args[3]) : 10;
    int numSubTopics = args.length > 4 ? Integer.parseInt(args[4]) : 10;
    System.out.println ("Data loaded.");
    PAM4L pam = new PAM4L (numSuperTopics, numSubTopics);
    pam.estimate (ilist, numIterations, 50, 0, 50, null, new Randoms())// should be 1100
    pam.printTopWords (numTopWords, true);
//    pam.printDocumentTopics (new File(args[0]+".pam"));
  }
View Full Code Here

      if (clusterings.size() > 1)
        throw new IllegalArgumentException("Expect one clustering to do train/test split, not " + clusterings.size());
      Clustering clustering = clusterings.get(0);
      int targetTrainSize = (int)(trainingProportion.value * clustering.getNumInstances());
      TIntHashSet clustersSampled = new TIntHashSet();
      Randoms random = new Randoms(123);
      LabelAlphabet lalph = new LabelAlphabet();
      InstanceList trainingInstances = new InstanceList(new Noop(null, lalph));
      while (trainingInstances.size() < targetTrainSize) {
        int cluster = random.nextInt(clustering.getNumClusters());
        if (!clustersSampled.contains(cluster)) {
          clustersSampled.add(cluster);
          InstanceList instances = clustering.getCluster(cluster);
          for (int i = 0; i < instances.size(); i++) {
            Instance inst = instances.get(i);
View Full Code Here

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

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

    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);
View Full Code Here

        // some docs may be missing at the end due to integer division
        if (thread == numThreads - 1) {
          docsPerThread = data.size() - offset;
        }
       
        Randoms random = null;
        if (randomSeed == -1) {
          random = new Randoms();
        }
        else {
          random = new Randoms(randomSeed);
        }

        runnables[thread] = new WorkerRunnable(numTopics,
                             alpha, alphaSum, beta,
                             random, data,
                             runnableCounts, runnableTotals,
                             offset, docsPerThread);
       
        runnables[thread].initializeAlphaStatistics(docLengthCounts.length);
       
        offset += docsPerThread;
     
      }
    }
    else {
     
      // If there is only one thread, copy the typeTopicCounts
      //  arrays directly, rather than allocating new memory.

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

      runnables[0] = new WorkerRunnable(numTopics,
                        alpha, alphaSum, beta,
                        random, data,
View Full Code Here

        throw new IllegalArgumentException ("--input-model not supported with --use-pam.");
      PAM4L pam = new PAM4L(pamNumSupertopics.value, pamNumSubtopics.value);
      pam.estimate (ilist, numIterations.value, /*optimizeModelInterval*/50,
              showTopicsInterval.value,
              outputModelInterval.value, outputModelFilename.value,
              randomSeed.value == 0 ? new Randoms() : new Randoms(randomSeed.value));
      pam.printTopWords(topWords.value, true);
      if (stateFile.value != null)
        pam.printState (new File(stateFile.value));
      if (docTopicsFile.value != null) {
        PrintWriter out = new PrintWriter (new FileWriter ((new File(docTopicsFile.value))));
        pam.printDocumentTopics (out, docTopicsThreshold.value, docTopicsMax.value);
        out.close();
      }

     
      if (outputModelFilename.value != null) {
        assert (pam != null);
        try {
          ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream (outputModelFilename.value));
          oos.writeObject (pam);
          oos.close();
        } catch (Exception e) {
          e.printStackTrace();
          throw new IllegalArgumentException ("Couldn't write topic model to filename "+outputModelFilename.value);
        }
      }
     

    }
   
    else if (useNgrams.value) {
      InstanceList ilist = InstanceList.load (new File(inputFile.value));
      System.out.println ("Data loaded.");
      if (inputModelFilename.value != null)
        throw new IllegalArgumentException ("--input-model not supported with --use-ngrams.");
      TopicalNGrams tng = new TopicalNGrams(numTopics.value,
                          alpha.value,
                          beta.value,
                          gamma.value,
                          delta.value,
                          delta1.value,
                          delta2.value);
      tng.estimate (ilist, numIterations.value, showTopicsInterval.value,
              outputModelInterval.value, outputModelFilename.value,
              randomSeed.value == 0 ? new Randoms() : new Randoms(randomSeed.value));
      tng.printTopWords(topWords.value, true);
      if (stateFile.value != null)
        tng.printState (new File(stateFile.value));
      if (docTopicsFile.value != null) {
        PrintWriter out = new PrintWriter (new FileWriter ((new File(docTopicsFile.value))));
View Full Code Here

    hlda.setTopicDisplay(showTopicsInterval.value(), topWords.value());
    hlda.setProgressDisplay(showProgress.value());

    // Initialize random number generator

    Randoms random = null;
    if (randomSeed.value() == 0) {
      random = new Randoms();
    }
    else {
      random = new Randoms(randomSeed.value());
    }

    // Initialize and start the sampler

    hlda.initialize(instances, testing, numLevels.value(), random);
View Full Code Here

   
    this.alphaSum = alphaSum;
    this.alpha = alpha;
    this.beta = beta;
    this.betaSum = beta * typeTopicCounts.length;
    this.random = new Randoms();
   
    cachedCoefficients = new double[ numTopics ];

    // Initialize the smoothing-only sampling bucket
    smoothingOnlyMass = 0;
View Full Code Here

TOP

Related Classes of cc.mallet.util.Randoms

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.