Package cc.mallet.util

Examples of cc.mallet.util.Randoms


  public void testLogSample ()
  {
    Variable v = new Variable (2);
    double[] vals = new double[] { -30, 0 };
    LogTableFactor ptl = LogTableFactor.makeFromLogValues (v, vals);
    int idx = ptl.sampleLocation (new Randoms (43));
    assertEquals (1, idx);
  }
View Full Code Here


  public void testVariableReordering () {

    Variable var0 = new Variable (2);
    Variable var1 = new Variable (3);

    Randoms r = new Randoms (17671);

    double[] probs = new double[] {
      r.nextDouble(),
      r.nextDouble(),
      r.nextDouble(),
      r.nextDouble(),
      r.nextDouble(),
      r.nextDouble()
    };

    TableFactor nothingReordered = new TableFactor(
      new Variable[] { var0, var1 },
      probs
View Full Code Here

    FactorGraph fg = new FactorGraph ();
    fg.multiplyBy (tbl1);
    fg.multiplyBy (tbl2);
    System.out.println (fg.dumpToString ());

    GibbsSampler gs = new GibbsSampler (new Randoms (324123), 10);
    gs.sample (fg, 10)// assert no exception
  }
View Full Code Here

  {
    Variable v = new Variable (2);
    double[] vals = new double[] { -30, 0 };
    LogTableFactor ptl = LogTableFactor.makeFromLogValues (v, vals);

    int idx = ptl.sampleLocation (new Randoms (43));
    assertEquals (1, idx);
  }
View Full Code Here

    ClassifierTrainer trainer = new MaxEntTrainer ();

    Alphabet fd = dictOfSize (3);
    String[] classNames = new String[] {"class0", "class1", "class2"};

    Randoms r = new Randoms (1);
    Iterator<Instance> iter = new RandomTokenSequenceIterator (r,  new Dirichlet(fd, 2.0),
          30, 0, 10, 200, classNames);
    training.addThruPipe (iter);

    InstanceList testing = new InstanceList (training.getPipe ());
View Full Code Here

        "A tool to train and test a Clusterer.");
    CommandOption.process(Clusterings2Clusterer.class, args);

    // TRAIN

    Randoms random = new Randoms(123);
    Clusterer clusterer = null;
    if (!loadClusterer.value.exists()) {
      Clusterings training = readClusterings(trainingFile.value);

      Alphabet fieldAlphabet = ((Record) training.get(0).getInstances()
View Full Code Here

      typeTopicCounts[type] = new int[ Math.min(numTopics, typeTotals[type]) ];
    }
   
    doc = 0;

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

    for (Instance instance : training) {
      doc++;

      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

 
 

  private void initRandom() {
    if (random == null) {
      random = new Randoms();
    }
  }
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.