/** Tests whether working with different types transformations works properly. */
  @Test
  public void testUnivariateMeanTransformation() {
    float mean = 20;
    float var = 0.001f;

    MixtureComponent gaussian =
        new MixtureComponent(
            new float[] {mean},
            new float[][] {{2}},
            new float[] {5},
            new float[] {var},
            null,
            null);
    Assert.assertTrue(
        LogMath.getLogMath().logToLinear(gaussian.getScore(new float[] {2 * mean + 5})) > 10);
  }
  public void newProperties(PropertySheet ps) throws PropertyException {
    logMath = LogMath.getLogMath();
    logger = ps.getLogger();

    unitManager = (UnitManager) ps.getComponent(PROP_UNIT_MANAGER);

    hmmManager = new HMMManager();
    contextIndependentUnits = new LinkedHashMap<String, Unit>();
    phoneList = new LinkedHashMap<String, Integer>();

    meanTransformationMatrixPool = createDummyMatrixPool("meanTransformationMatrix");
    meanTransformationVectorPool = createDummyVectorPool("meanTransformationMatrix");
    varianceTransformationMatrixPool = createDummyMatrixPool("varianceTransformationMatrix");
    varianceTransformationVectorPool = createDummyVectorPool("varianceTransformationMatrix");

    String modelName = ps.getString(MODEL_NAME);

    String location = ps.getString(LOCATION);
    String phone = ps.getString(PHONE_LIST);
    String dataDir = ps.getString(DATA_DIR);

    logger.info("Creating Sphinx3 acoustic model: " + modelName);
    logger.info("    Path      : " + location);
    logger.info("    phonelist : " + phone);
    logger.info("    dataDir   : " + dataDir);

    // load the HMM model file
    boolean useCDUnits = ps.getBoolean(PROP_USE_CD_UNITS);

    assert !useCDUnits;
    try {
      loadPhoneList(
          ps,
          useCDUnits,
          StreamFactory.getInputStream(location, phone),
          location + File.separator + phone);
    } catch (StreamCorruptedException sce) {
      printPhoneListHelp();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  /**
   * Compute the density values of a sampled interval with an univariate <code>MixtureComponent
   * </code> and compare values with the precomputed-computed ones.
   */
  @Test
  public void testUnivariateDensity() {

    float minX = 10;
    float maxX = 30;
    float resolution = 0.1f;

    float mean = 20;
    float var = 3;

    MixtureComponent gaussian = new MixtureComponent(new float[] {mean}, new float[] {var});

    for (float curX = minX; curX <= maxX; curX += resolution) {
      double gauLogScore = gaussian.getScore(new FloatData(new float[] {curX}, 16000, 0));

      double manualScore =
          (1 / sqrt(var * 2 * PI)) * exp((-0.5 / var) * (curX - mean) * (curX - mean));
      double gauScore = LogMath.getLogMath().logToLinear((float) gauLogScore);

      Assert.assertEquals(manualScore, gauScore, 1E-5);
    }
  }