Ejemplo n.º 1
0
  /**
   * Adds a set of density arrays to a given pool.
   *
   * @param pool the pool to add densities to
   * @param stateID a vector with the senone id of the states in a model
   * @param numStreams the number of streams
   * @param numGaussiansPerState the number of Gaussians per state
   * @throws IOException if an error occurs while loading the data
   */
  private void addModelToDensityPool(
      Pool<float[]> pool, int[] stateID, int numStreams, int numGaussiansPerState)
      throws IOException {
    assert pool != null;
    assert stateID != null;

    int numStates = stateID.length;

    int numInPool = pool.getFeature(NUM_SENONES, 0);
    pool.setFeature(NUM_SENONES, numStates + numInPool);
    numInPool = pool.getFeature(NUM_STREAMS, -1);
    if (numInPool == -1) {
      pool.setFeature(NUM_STREAMS, numStreams);
    } else {
      assert numInPool == numStreams;
    }
    numInPool = pool.getFeature(NUM_GAUSSIANS_PER_STATE, -1);
    if (numInPool == -1) {
      pool.setFeature(NUM_GAUSSIANS_PER_STATE, numGaussiansPerState);
    } else {
      assert numInPool == numGaussiansPerState;
    }

    // TODO: numStreams should be any number > 0, but for now....
    assert numStreams == 1;
    for (int i = 0; i < numStates; i++) {
      int state = stateID[i];
      for (int j = 0; j < numGaussiansPerState; j++) {
        // We're creating densities here, so it's ok if values
        // are all zero.
        float[] density = new float[vectorLength];
        int id = state * numGaussiansPerState + j;
        pool.put(id, density);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Adds model to the mixture weights
   *
   * @param pool the pool to add models to
   * @param stateID vector containing state ids for hmm
   * @param numStreams the number of streams
   * @param numGaussiansPerState the number of Gaussians per state
   * @param floor the minimum mixture weight allowed
   * @throws IOException if an error occurs while loading the data
   */
  private void addModelToMixtureWeightPool(
      Pool<float[]> pool, int[] stateID, int numStreams, int numGaussiansPerState, float floor)
      throws IOException {

    int numStates = stateID.length;

    assert pool != null;

    int numInPool = pool.getFeature(NUM_SENONES, 0);
    pool.setFeature(NUM_SENONES, numStates + numInPool);
    numInPool = pool.getFeature(NUM_STREAMS, -1);
    if (numInPool == -1) {
      pool.setFeature(NUM_STREAMS, numStreams);
    } else {
      assert numInPool == numStreams;
    }
    numInPool = pool.getFeature(NUM_GAUSSIANS_PER_STATE, -1);
    if (numInPool == -1) {
      pool.setFeature(NUM_GAUSSIANS_PER_STATE, numGaussiansPerState);
    } else {
      assert numInPool == numGaussiansPerState;
    }

    // TODO: allow any number for numStreams
    assert numStreams == 1;
    for (int i = 0; i < numStates; i++) {
      int state = stateID[i];
      float[] logMixtureWeight = new float[numGaussiansPerState];
      // Initialize the weights with the same value, e.g. floor
      floorData(logMixtureWeight, floor);
      // Normalize, so the numbers are not all too low
      normalize(logMixtureWeight);
      logMath.linearToLog(logMixtureWeight);
      pool.put(state, logMixtureWeight);
    }
  }
Ejemplo n.º 3
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);
    }
  }