/**
   * Tun ester2 speaker clr clustering.
   *
   * @param referenceClusterSet the reference cluster set
   * @param uemClusterSet the uem cluster set
   * @param partialKey the partial key
   * @param method the method
   * @param clusterSetBase the cluster set base
   * @param clusterSet the cluster set
   * @param featureSet the feature set
   * @param parameter the parameter
   * @return the diarization result list
   * @throws Exception the exception
   */
  public DiarizationResultList tunEster2SpeakerCLRClustering(
      ClusterSet referenceClusterSet,
      ClusterSet uemClusterSet,
      String partialKey,
      String method,
      ClusterSet clusterSetBase,
      ClusterSet clusterSet,
      AudioFeatureSet featureSet,
      Parameter parameter)
      throws Exception {
    String oldSpeechDetectorMethod = parameter.getParameterInputFeature().getSpeechMethodAsString();
    double oldSpeechDetectorThreshold = parameter.getParameterInputFeature().getSpeechThreshold();
    String oldModelKind = parameter.getParameterModel().getModelKindAsString();
    int oldNumberOfComponent = parameter.getParameterModel().getNumberOfComponents();
    String oldMethod = parameter.getParameterClustering().getMethodAsString();
    double oldThreshold = parameter.getParameterClustering().getThreshold();

    String oldEMControl = parameter.getParameterEM().getEMControl();
    int oldNTop = parameter.getParameterTopGaussian().getScoreNTop();
    boolean oldSaveAll = parameter.getParameterDiarization().isSaveAllStep();

    DiarizationResultList localResult = new DiarizationResultList(cMin, cMax, mult);
    DiarizationError computeError = new DiarizationError(referenceClusterSet, uemClusterSet);
    double prevScore = cMin;

    // ---- Begin NEW v 1.13 ---
    parameter.getParameterInputFeature().setSpeechMethod("E");
    parameter.getParameterInputFeature().setSpeechThreshold(0.1);

    // ---- End NEW v 1.13 ---
    String FeatureFormat = "featureSetTransformation";
    String dir = "ester2";
    InputStream ubmInputStream = getClass().getResourceAsStream(dir + "/ubm.gmm");
    GMMArrayList ubmVect =
        MainTools.readGMMContainer(ubmInputStream, parameter.getParameterModel());
    GMM ubm = ubmVect.get(0);
    /*
     * int nbCep = 16; logger.info("---> nbCep:"+nbCep); FeatureSet featureSet2 = loadFeature(parameter, clusterSet, "audio16kHz2sphinx,1:3:2:0:0:0,"+nbCep+",1:1:300:4"); logger.info("---> nbCep:"+nbCep); //logger.fine("*** nbFeaturesNorm:" +
     * clusterSetBase.getLength());
     */
    // A tester

    AudioFeatureSet featureSet2 =
        loadFeature(featureSet, parameter, clusterSet, FeatureFormat + ",1:3:2:0:0:0,13,1:1:300:4");
    // v5.14
    // FeatureSet featureSet2 = loadFeature(featureSet, parameter, clusterSet, FeatureFormat
    // + ",1:3:2:0:0:0,13,1:1:0:0");
    parameter.getParameterModel().setModelKind("DIAG");
    parameter.getParameterModel().setNumberOfComponents(ubm.getNbOfComponents());
    parameter.getParameterClustering().setMethod(method);
    // ---- Begin NEW v 1.19 ---
    // parameter.getParameterEM().setEMControl("1,1,0.01");
    // parameter.getParameterClustering().setThreshold(0);
    // ---- End NEW v 1.19 ---
    parameter.getParameterClustering().setThreshold(cMax);
    parameter.getParameterEM().setEMControl("1,5,0.01");
    parameter.getParameterTopGaussian().setScoreNTop(5);
    parameter.getParameterDiarization().setSaveAllStep(false);

    CLRHClustering clustering = new CLRHClustering(clusterSet, featureSet2, parameter, ubm);
    // int nbCluster = clusterSet.clusterGetSize();
    // logger.info("initialise clustering CLR clusterSet:"+clusterSet);
    clustering.initialize();

    double score = clustering.getScoreOfCandidatesForMerging();
    DiarizationResult error = computeError.scoreOfMatchedSpeakers(clustering.getClusterSet());
    double errorRate = error.getErrorRate();
    localResult.setResult(prevScore, score, error);
    // prevScore = Math.max(score, prevScore);
    logger.fine(
        "first "
            + parameter.show
            + " key="
            + partialKey
            + " clrScore="
            + score
            + " clrErrorRate="
            + errorRate
            + " clrSize="
            + clustering.getSize()
            + "/"
            + referenceClusterSet.clusterGetSize());
    while ((score < cMax) && (clustering.getSize() > 1)) {
      localResult.setResult(prevScore, score, error);
      prevScore = Math.max(score, prevScore);
      clustering.mergeCandidates();

      // -- start V5.16 --
      // logger.info("--> Decoding");
      // ClusterSet decodeClusterSet = MDecode.make(featureSet2, clustering.getClusterSet(),
      // clustering.getGmmList(), parameter);
      // logger.info("--> Clustering");
      // featureSet2 = loadFeature(featureSet, parameter, decodeClusterSet, FeatureFormat
      // + ",1:3:2:0:0:0,13,1:1:300:4");
      // clustering = new CLRHClustering(decodeClusterSet, featureSet2, parameter, ubm);
      // clustering.initialize();
      // -- end V5.16 --

      score = clustering.getScoreOfCandidatesForMerging();
      error = computeError.scoreOfMatchedSpeakers(clustering.getClusterSet());
      errorRate = error.getErrorRate();
      // localResult.setResult(prevScore, score, error);
      // prevScore = Math.max(score, prevScore);
      logger.fine(
          parameter.show
              + " key="
              + partialKey
              + " clrScore="
              + score
              + " clrErrorRate="
              + errorRate
              + " clrSize="
              + clustering.getSize()
              + "/"
              + referenceClusterSet.clusterGetSize());
    }
    localResult.setResult(prevScore, score, error);
    localResult.setResult(score, cMax, error);
    logger.finer(parameter.show + " key=" + partialKey + " resultat du fichier");
    localResult.log("partial result: " + parameter.show + " " + partialKey);

    clustering.reset();

    parameter.getParameterModel().setNumberOfComponents(oldNumberOfComponent);
    parameter.getParameterModel().setModelKind(oldModelKind);
    parameter.getParameterClustering().setMethod(oldMethod);
    parameter.getParameterClustering().setThreshold(oldThreshold);
    parameter.getParameterEM().setEMControl(oldEMControl);
    parameter.getParameterTopGaussian().setScoreNTop(oldNTop);
    parameter.getParameterInputFeature().setSpeechMethod(oldSpeechDetectorMethod);
    parameter.getParameterInputFeature().setSpeechThreshold(oldSpeechDetectorThreshold);
    parameter.getParameterDiarization().setSaveAllStep(oldSaveAll);

    return localResult;
  }
Exemple #2
0
  public ClusterSet make(
      AudioFeatureSet featureSet,
      ClusterSet clusterSet,
      GMMArrayList gmmList,
      GMMArrayList gmmTopList,
      Parameter parameter)
      throws DiarizationException, IOException {
    logger.info("Compute Score");
    int size = gmmList.size();
    logger.finer("GMM size:" + size);
    ArrayList<String> genderString = new ArrayList<String>();
    ArrayList<String> bandwidthString = new ArrayList<String>();
    for (int i = 0; i < size; i++) {
      String gmmName = gmmList.get(i).getName();
      if (parameter.getParameterScore().isGender() == true) {
        if (gmmName.equals("MS")) {
          genderString.add(Cluster.genderStrings[1]);
          bandwidthString.add(Segment.bandwidthStrings[2]);
        } else if (gmmName.equals("FS")) {
          genderString.add(Cluster.genderStrings[2]);
          bandwidthString.add(Segment.bandwidthStrings[2]);
        } else if (gmmName.equals("MT")) {
          genderString.add(Cluster.genderStrings[1]);
          bandwidthString.add(Segment.bandwidthStrings[1]);
        } else if (gmmName.equals("FT")) {
          genderString.add(Cluster.genderStrings[2]);
          bandwidthString.add(Segment.bandwidthStrings[1]);
        } else {
          genderString.add(Cluster.genderStrings[0]);
          bandwidthString.add(Segment.bandwidthStrings[0]);
        }
      } else {
        genderString.add(Cluster.genderStrings[0]);
        bandwidthString.add(Segment.bandwidthStrings[0]);
      }
    }

    ClusterSet clusterSetResult = new ClusterSet();
    for (Cluster cluster : clusterSet.clusterSetValue()) {
      double[] sumScoreVector = new double[size];
      int[] sumLenghtVector = new int[size];
      double ubmScore = 0.0;
      GMM gmmTop = null;
      if (parameter.getParameterTopGaussian().getScoreNTop() >= 0) {
        gmmTop = gmmTopList.get(0);
      }
      Arrays.fill(sumScoreVector, 0.0);
      Arrays.fill(sumLenghtVector, 0);
      for (Segment currantSegment : cluster) {
        Segment segment = (currantSegment.clone());
        int end = segment.getStart() + segment.getLength();
        featureSet.setCurrentShow(segment.getShowName());
        double[] scoreVector = new double[size];
        double maxScore = 0.0;
        int idxMaxScore = 0;
        for (int i = 0; i < size; i++) {
          gmmList.get(i).score_initialize();
        }
        for (int start = segment.getStart(); start < end; start++) {
          for (int i = 0; i < size; i++) {
            GMM gmm = gmmList.get(i);
            if (parameter.getParameterTopGaussian().getScoreNTop() >= 0) {
              if (i == 0) {
                gmmTop.score_getAndAccumulateAndFindTopComponents(
                    featureSet, start, parameter.getParameterTopGaussian().getScoreNTop());
              }
              gmm.score_getAndAccumulateForComponentSubset(
                  featureSet, start, gmmTop.getTopGaussianVector());
            } else {
              gmm.score_getAndAccumulate(featureSet, start);
            }
          }
        }

        if (parameter.getParameterTopGaussian().getScoreNTop() >= 0) {
          ubmScore = gmmTop.score_getMeanLog();
          gmmTop.score_getSumLog();
          gmmTop.score_getCount();
          gmmTop.score_reset();
        }
        for (int i = 0; i < size; i++) {
          GMM gmm = gmmList.get(i);
          scoreVector[i] = gmm.score_getMeanLog();
          sumLenghtVector[i] += gmm.score_getCount();
          sumScoreVector[i] += gmm.score_getSumLog();
          if (i == 0) {
            maxScore = scoreVector[0];
            idxMaxScore = 0;
          } else {
            double value = scoreVector[i];
            if (maxScore < value) {
              maxScore = value;
              idxMaxScore = i;
            }
          }
          gmm.score_reset();
        }
        if (parameter.getParameterScore().isTNorm()) {
          double sumScore = 0;
          double sum2Score = 0;
          for (int i = 0; i < size; i++) {
            sumScore += scoreVector[i];
            sum2Score += (scoreVector[i] * scoreVector[i]);
          }
          for (int i = 0; i < size; i++) {
            double value = scoreVector[i];
            double mean = (sumScore - value) / (size - 1);
            double et = Math.sqrt(((sum2Score - (value * value)) / (size - 1)) - (mean * mean));
            scoreVector[i] = (value - mean) / et;
          }
        }
        if (parameter.getParameterScore().isGender() == true) {
          segment.setBandwidth(bandwidthString.get(idxMaxScore));
          segment.setInformation("segmentGender", genderString.get(idxMaxScore));
        }
        if (parameter.getParameterScore().isBySegment()) {
          for (int k = 0; k < size; k++) {
            double score = scoreVector[k];
            GMM gmm = gmmList.get(k);
            segment.setInformation("score:" + gmm.getName(), score);
            currantSegment.setInformation("score:" + gmm.getName(), score);
          }
          if (parameter.getParameterTopGaussian().getScoreNTop() >= 0) {
            segment.setInformation("score:" + "UBM", ubmScore);
            currantSegment.setInformation("score:" + "UBM", ubmScore);
          }
        }
        String newName = cluster.getName();
        if (parameter.getParameterScore().isByCluster() == false) {
          if ((scoreVector[idxMaxScore] > parameter.getParameterSegmentation().getThreshold())
              && (parameter.getParameterScore().getLabel()
                  != ParameterScore.LabelType.LABEL_TYPE_NONE.ordinal())) {
            if (parameter.getParameterScore().getLabel()
                == ParameterScore.LabelType.LABEL_TYPE_ADD.ordinal()) {
              newName += "_";
              newName += gmmList.get(idxMaxScore).getName();
            } else {
              newName = gmmList.get(idxMaxScore).getName();
            }
          }

          Cluster temporaryCluster = clusterSetResult.getOrCreateANewCluster(newName);
          temporaryCluster.setGender(cluster.getGender());
          if (parameter.getParameterScore().isGender() == true) {
            temporaryCluster.setGender(genderString.get(idxMaxScore));
          }
          temporaryCluster.addSegment(segment);
        }
      }
      if (parameter.getParameterScore().isByCluster()) {
        for (int i = 0; i < size; i++) {
          sumScoreVector[i] /= sumLenghtVector[i];
        }
        if (parameter.getParameterScore().isTNorm()) {
          double sumScore = 0;
          double sum2Score = 0;
          for (int i = 0; i < size; i++) {
            sumScore += sumScoreVector[i];
            sum2Score += (sumScoreVector[i] * sumScoreVector[i]);
          }
          for (int i = 0; i < size; i++) {
            double value = sumScoreVector[i];
            double mean = (sumScore - value) / (size - 1);
            double et = Math.sqrt(((sum2Score - (value * value)) / (size - 1)) - (mean * mean));
            sumScoreVector[i] = (value - mean) / et;
          }
        }
        double maxScore = sumScoreVector[0];
        int idxMaxScore = 0;
        for (int i = 1; i < size; i++) {
          double s = sumScoreVector[i];
          if (maxScore < s) {
            maxScore = s;
            idxMaxScore = i;
          }
        }
        String newName = cluster.getName();
        if ((sumScoreVector[idxMaxScore] > parameter.getParameterSegmentation().getThreshold())
            && (parameter.getParameterScore().getLabel()
                != ParameterScore.LabelType.LABEL_TYPE_NONE.ordinal())) {
          if (parameter.getParameterScore().getLabel()
              == ParameterScore.LabelType.LABEL_TYPE_ADD.ordinal()) {
            newName += "_";
            newName += gmmList.get(idxMaxScore).getName();
          } else {
            newName = gmmList.get(idxMaxScore).getName();
          }
          // logger.finer("cluster name=" + cluster.getName() + " new_name=" + newName);
        }
        Cluster tempororaryCluster = clusterSetResult.getOrCreateANewCluster(newName);
        tempororaryCluster.setGender(cluster.getGender());
        if (parameter.getParameterScore().isGender() == true) {
          tempororaryCluster.setGender(genderString.get(idxMaxScore));
        }
        tempororaryCluster.setName(newName);
        for (Segment currantSegment : cluster) {
          Segment segment = (currantSegment.clone());
          if (parameter.getParameterScore().isGender() == true) {
            segment.setBandwidth(bandwidthString.get(idxMaxScore));
          }
          tempororaryCluster.addSegment(segment);
        }
        for (int k = 0; k < size; k++) {
          double score = sumScoreVector[k];
          GMM gmm = gmmList.get(k);
          // logger.finer("****clustername = " + newName + " name=" + gmm.getName() + " =" + score+"
          // k="+k);
          // logger.log(Level.SEVERE, "****clustername = " + newName + " name=" + gmm.getName() + "
          // =" + score);
          tempororaryCluster.setInformation("score:" + gmm.getName(), score);
          ClusterResult cr = new ClusterResult();
          cr.setName(newName);
          cr.getValue().put(score, gmm.getName());
          System.out.println(
              "------ clusterResultSet.putValue(newName, gmm.getName(), score)=----------------");
          System.out.println(newName + "  " + gmm.getName() + "  " + score);
          if (isName(gmm.getName())) {
            clusterResultSet.putValue(newName, gmm.getName(), score);
          } else {
            System.out.println("*****************" + gmm.getName() + " Non nome valido  ");
          }
        }

        if (parameter.getParameterTopGaussian().getScoreNTop() >= 0) {
          // tempororaryCluster.putInformation("score:" + "length", ubmSumLen);
          // tempororaryCluster.putInformation("score:" + "UBM", ubmSumScore / ubmSumLen);
        }
      }
    }
    this.clusterSetResult = clusterSetResult;
    return clusterSetResult;
  }