/** * 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); } }
/** * 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); } } }