Ejemplo n.º 1
0
 public void action(ParserEvent e) {
   if (DEBUG) System.out.println(e);
   PicPoint pt = (PicPoint) e.getValue();
   pool.currentObj.setCtrlPt(
       ptNumber,
       pt.toMm(pool.get(PstricksParser.KEY_X_UNIT), pool.get(PstricksParser.KEY_Y_UNIT)),
       constraint);
 }
Ejemplo n.º 2
0
 @Override
 public T get() {
   if (Thread.currentThread() == ownerThread && super.size() > 0) {
     return super.get();
   } else {
     return synchronizedPool.get();
   }
 }
Ejemplo n.º 3
0
  /**
   * Gets the senone sequence representing the given senones.
   *
   * @param stateid is the array of senone state ids
   * @return the senone sequence associated with the states
   */
  private SenoneSequence getSenoneSequence(int[] stateid) {
    Senone[] senones = new Senone[stateid.length];

    for (int i = 0; i < stateid.length; i++) {
      senones[i] = senonePool.get(stateid[i]);
    }

    // TODO: Is there any advantage in trying to pool these?
    return new SenoneSequence(senones);
  }
Ejemplo n.º 4
0
  /**
   * Adds a model to the senone pool.
   *
   * @param pool the senone pool
   * @param stateID vector with senone ID for an HMM
   * @param distFloor the lowest allowed score
   * @param varianceFloor the lowest allowed variance
   * @return the senone pool
   */
  private void addModelToSenonePool(
      Pool<Senone> pool, int[] stateID, float distFloor, float varianceFloor) {
    assert pool != null;

    //        int numMixtureWeights = mixtureWeightsPool.size();

    /*
    int numMeans = meansPool.size();
    int numVariances = variancePool.size();
    int numSenones = mixtureWeightsPool.getFeature(NUM_SENONES, 0);
    int whichGaussian = 0;

    logger.fine("NG " + numGaussiansPerSenone);
    logger.fine("NS " + numSenones);
    logger.fine("NMIX " + numMixtureWeights);
    logger.fine("NMNS " + numMeans);
    logger.fine("NMNS " + numVariances);

    assert numMixtureWeights == numSenones;
    assert numVariances == numSenones * numGaussiansPerSenone;
    assert numMeans == numSenones * numGaussiansPerSenone;
    */
    int numGaussiansPerSenone = mixtureWeightsPool.getFeature(NUM_GAUSSIANS_PER_STATE, 0);
    assert numGaussiansPerSenone > 0;
    for (int state : stateID) {
      MixtureComponent[] mixtureComponents = new MixtureComponent[numGaussiansPerSenone];
      for (int j = 0; j < numGaussiansPerSenone; j++) {
        int whichGaussian = state * numGaussiansPerSenone + j;
        mixtureComponents[j] =
            new MixtureComponent(
                meansPool.get(whichGaussian),
                meanTransformationMatrixPool.get(0),
                meanTransformationVectorPool.get(0),
                variancePool.get(whichGaussian),
                varianceTransformationMatrixPool.get(0),
                varianceTransformationVectorPool.get(0),
                distFloor,
                varianceFloor);
      }

      Senone senone = new GaussianMixture(mixtureWeightsPool.get(state), mixtureComponents, state);

      pool.put(state, senone);
    }
  }
Ejemplo n.º 5
0
  /**
   * Loads the phone list, which possibly contains the sizes (number of states) of models.
   *
   * @param ps
   * @param useCDUnits if true, uses context dependent units
   * @param inputStream the open input stream to use
   * @param path the path to a density file @throws FileNotFoundException if a file cannot be found
   * @throws IOException if an error occurs while loading the data
   */
  private void loadPhoneList(
      PropertySheet ps, boolean useCDUnits, InputStream inputStream, String path)
      throws IOException {
    int numState = 0;
    // TODO: this should be flexible, but we're hardwiring for now
    int numStreams = 1;
    // Since we're initializing, we start simple.
    int numGaussiansPerState = 1;

    ExtendedStreamTokenizer est = new ExtendedStreamTokenizer(inputStream, '#', false);

    // Initialize the pools we'll need.
    meansPool = new Pool<float[]>("means");
    variancePool = new Pool<float[]>("variances");
    mixtureWeightsPool = new Pool<float[]>("mixtureweights");
    matrixPool = new Pool<float[][]>("transitionmatrices");
    senonePool = new Pool<Senone>("senones");

    float distFloor = ps.getFloat(PROP_MC_FLOOR);
    float mixtureWeightFloor = ps.getFloat(PROP_MW_FLOOR);
    float transitionProbabilityFloor = 0;
    float varianceFloor = ps.getFloat(PROP_VARIANCE_FLOOR);

    logger.info("Loading phone list file from: ");
    logger.info(path);

    // At this point, we only accept version 0.1
    String version = "0.1";
    est.expectString("version");
    est.expectString(version);

    est.expectString("same_sized_models");
    boolean sameSizedModels = est.getString().equals("yes");

    if (sameSizedModels) {
      est.expectString("n_state");
      numState = est.getInt("numBase");
    }

    // for this phone list version, let's assume left-to-right
    // models, with optional state skip.
    est.expectString("tmat_skip");
    boolean tmatSkip = est.getString().equals("yes");

    // Load the phones with sizes

    // stateIndex contains the absolute state index, that is, a
    // unique index in the senone pool.
    for (int stateIndex = 0, unitCount = 0; ; ) {
      String phone = est.getString();
      if (est.isEOF()) {
        break;
      }
      int size = numState;
      if (!sameSizedModels) {
        size = est.getInt("ModelSize");
      }
      phoneList.put(phone, size);
      logger.fine("Phone: " + phone + " size: " + size);
      int[] stid = new int[size];
      String position = "-";

      for (int j = 0; j < size; j++, stateIndex++) {
        stid[j] = stateIndex;
      }

      Unit unit = unitManager.getUnit(phone, phone.equals(SILENCE_CIPHONE));

      contextIndependentUnits.put(unit.getName(), unit);

      if (logger.isLoggable(Level.FINE)) {
        logger.fine("Loaded " + unit + " with " + size + " states");
      }

      // Means
      addModelToDensityPool(meansPool, stid, numStreams, numGaussiansPerState);

      // Variances
      addModelToDensityPool(variancePool, stid, numStreams, numGaussiansPerState);

      // Mixture weights
      addModelToMixtureWeightPool(
          mixtureWeightsPool, stid, numStreams, numGaussiansPerState, mixtureWeightFloor);

      // Transition matrix
      addModelToTransitionMatrixPool(
          matrixPool, unitCount, stid.length, transitionProbabilityFloor, tmatSkip);

      // After creating all pools, we create the senone pool.
      addModelToSenonePool(senonePool, stid, distFloor, varianceFloor);

      // With the senone pool in place, we go through all units, and
      // create the HMMs.

      // Create tmat
      float[][] transitionMatrix = matrixPool.get(unitCount);
      SenoneSequence ss = getSenoneSequence(stid);

      HMM hmm = new SenoneHMM(unit, ss, transitionMatrix, HMMPosition.lookup(position));
      hmmManager.put(hmm);
      unitCount++;
    }

    // If we want to use this code to load sizes/create models for
    // CD units, we need to find another way of establishing the
    // number of CI models, instead of just reading until the end
    // of file.

    est.close();
  }