Package com.meapsoft

Examples of com.meapsoft.FeatChunk


   
    for (int chunkNum = firstChunkToDraw; chunkNum < numChunks && xFeat < getWidth() && xEDL < getWidth(); chunkNum++)
    {     
      //FeatChunk fC = getFeatChunkByNumber(chunkNum);
      //EDLChunk eC = (EDLChunk)events.get(chunkNum);
      FeatChunk fC = (FeatChunk)events.get(chunkNum);
      //EDLChunk eC = (EDLChunk)edlEvents.get(chunkNum);
      EDLChunk eC = null;
     
      for (int i = 0; i < numChunks; i++)
      {
        EDLChunk edlC = (EDLChunk)edlEvents.get(i);
        if (fC.compareTo(edlC) == 0)
        {
          eC = edlC;
        }
      }
     
View Full Code Here


    double currentTime = 0.0;
   
    for (int i = 0; i < selectedChunks.size(); i++)
    {
      //featOutputFile.chunks.add(selectedChunks.elementAt(i));
      FeatChunk oldChunk = (FeatChunk)selectedChunks.elementAt(i);
   
      FeatChunk newChunk =
        new FeatChunk(oldChunk.srcFile, currentTime, oldChunk.length);
      newChunk.addFeature(oldChunk.getFeatures());
      featOutputFile.chunks.add(newChunk);
      currentTime += oldChunk.length;
    }

    int numFeatDescs = featInputFile.featureDescriptions.size();
View Full Code Here

  public EDLFile compose()
  {
    // initial chunk - pick it at random:
    // int randIdx = (int)Math.floor(featFile.chunks.size()*Math.random());
    // start with the first chunk
    FeatChunk currChunk = (FeatChunk) featFile.chunks.get(0);

    dist.setTarget(currChunk);

        Vector chunks = new Vector(featFile.chunks);

View Full Code Here

{
  public void features(FeatFile featFile, boolean clearOriginalFeatures)
  {
    int totalChunks = featFile.chunks.size();

    FeatChunk testChunk = (FeatChunk) featFile.chunks.get(0);
    double[] testChunkFeatures = testChunk.getFeatures();
    int numFeatures = testChunkFeatures.length;

    // Pass 1 - gather feature statistics
    double sumx[] = new double[numFeatures];
    double sumx2[] = new double[numFeatures];
    double meanx[] = new double[numFeatures];
    double stdx[] = new double[numFeatures];
    double mahaldist[] = new double[totalChunks];

    Arrays.fill(sumx, 0);
    Arrays.fill(sumx2, 0);
    Arrays.fill(meanx, 0);
    Arrays.fill(stdx, 0);
    Arrays.fill(mahaldist, 0);

    double N = 0.0;

    for (int chunk = 0; chunk < totalChunks; chunk++)
    {
      FeatChunk curChunk = (FeatChunk) featFile.chunks.get(chunk);
      double[] features = curChunk.getFeatures();

      for (int feature = 0; feature < numFeatures; feature++)
      {
        sumx[feature] += features[feature];
        sumx2[feature] += features[feature] * features[feature];
      }
      N = N + 1.0;
    }

    // figure mean and variance
    for (int feature = 0; feature < numFeatures; feature++)
    {
      meanx[feature] = sumx[feature] / N;
      stdx[feature] = Math.sqrt(sumx2[feature] / N - meanx[feature]
          * meanx[feature]);
    }

    // Pass 2 - figure Mahalanobis distance (= unlikeliness score)
    // under diagonal covariance Gaussian for each frame
    // (i.e. Euclidean distance to mean in a variance-normalized space)

    for (int chunk = 0; chunk < totalChunks; chunk++)
    {
      FeatChunk curChunk = (FeatChunk) featFile.chunks.get(chunk);
      double[] features = curChunk.getFeatures();

      mahaldist[chunk] = 0;

      for (int feature = 0; feature < numFeatures; feature++)
      {
        double dist = (features[feature] - meanx[feature])
            / stdx[feature];
        mahaldist[chunk] += dist * dist;
      }
      mahaldist[chunk] = Math.sqrt(mahaldist[chunk] / numFeatures);

      double value = mahaldist[chunk];
      double[] feats = new double[1];
      feats[0] = value;

      if (clearOriginalFeatures)
        curChunk.clearFeatures();

      curChunk.addFeature(feats);
    }
  }
View Full Code Here

    double[] lengths = new double[numChunks];

    //gather lenghts for all chunks
    for (int chunk = 0; chunk < numChunks; chunk++)
    {
      FeatChunk curChunk = (FeatChunk) featFile.chunks.get(chunk);
      lengths[chunk] = curChunk.length;
    }

    //sort them low to high
    Arrays.sort(lengths);
   
    double medianLength = 0.0;
   
   
    //are we even or odd?
    if (numChunks % 2 == 0)
    {
      //we have an even number of chunks, so take the average of
      //the two middle chunks
      int middle = numChunks/2;
      medianLength += lengths[middle-1];
      medianLength += lengths[middle];
      medianLength /= 2.0;
      //System.out.println("numChunks: " + numChunks + " middle: " + middle + " medianLength: " + medianLength);
    }
    else
    {
      //we're odd so just take the middle value
      int middle = (int)Math.floor(numChunks/2.0);
      medianLength = lengths[middle];
      //System.out.println("numChunks: " + numChunks + " middle: " + middle + " medianLength: " + medianLength);
    }
   
    //System.out.println("shortest: " + lengths[0] + " longest: " + lengths[numChunks - 1]);
    //write out offset values
    for (int chunk = 0; chunk < numChunks; chunk++)
    {
      FeatChunk curChunk = (FeatChunk) featFile.chunks.get(chunk);

      double value = curChunk.length - medianLength;
      double[] feats = new double[1];
      feats[0] = value;
 
      if (clearOriginalFeatures)
        curChunk.clearFeatures();
 
      curChunk.addFeature(feats);
     
      //System.out.println("chunk: " + chunk + " length: " + curChunk.length + " median: " +  medianLength + " diff: " + value);
    }
   
  }
View Full Code Here

    }
   
    for (int i = 0; i < numChunks; i++)
    {     
      //first we fill in a cVI
      FeatChunk fC = (FeatChunk) ((FeatChunk) featFile.chunks.elementAt(i)).clone();
      ChunkVisInfo cVI =
        new ChunkVisInfo(fC.srcFile, fC.startTime, fC.length, -1);
      cVI.addFeature(fC.getFeatures());
      events.add(cVI);
     
      if (eDLFile != null)
      {
        int numEDLChunks = eDLFile.chunks.size();
View Full Code Here

    for (int i = 0; i < events.size(); i++)
    {
      ChunkVisInfo cVI = (ChunkVisInfo)events.elementAt(i);
      if (cVI.selected)
      {
        FeatChunk c = new FeatChunk(cVI.srcFile, cVI.startTime,
          cVI.length);
        c.addFeature(cVI.getFeatures());
        c.comment = cVI.comment;
        v.add(c);
      }
    }
   
View Full Code Here

    // is modify the chunks in trainFile by joining every
    // beatsPerCodeword chunk into one a superchunk.
    Vector newChunks = new Vector();
    for (int x = 0; x < trainFile.chunks.size() - beatsPerCodeword + 1; x += beatsPerCodeword)
    {
      FeatChunk newChunk = (FeatChunk) ((FeatChunk) trainFile.chunks
          .get(x)).clone();

      // double length = 0;
      for (int y = 1; y < beatsPerCodeword; y++)
      {
        FeatChunk f = (FeatChunk) trainFile.chunks.get(x + y);

        newChunk.addFeature(f.getFeatures());
        newChunk.length += f.length;
      }

      newChunks.add(newChunk);
    }

    trainFile.chunks = newChunks;

    progress.setMaximum(trainFile.chunks.size());

    if (featsToQuantize != null)
    {
      if (!featsToQuantize.haveReadFile)
        featsToQuantize.readFile();

      // What if features don't match
      if (!featsToQuantize.isCompatibleWith(trainFile))
        throw new ParserException(trainFile.filename,
            "Features do not match those in "
                + featsToQuantize.filename);

      featsToQuantize = (FeatFile) featsToQuantize.clone();
      featsToQuantize.normalizeFeatures();
      featsToQuantize.applyFeatureWeights();

      // To change the number of beats per state all we have to do
      // is modify the chunks in featFile by joining every
      // beatsPerCodeword chunk into one a superchunk.
      newChunks = new Vector();
      for (int x = 0; x < featsToQuantize.chunks.size()
          - beatsPerCodeword + 1; x += beatsPerCodeword)
      {
        FeatChunk newChunk = (FeatChunk) ((FeatChunk) featsToQuantize.chunks
            .get(x)).clone();

        // double length = 0;
        for (int y = 1; y < beatsPerCodeword; y++)
        {
          FeatChunk f = (FeatChunk) featsToQuantize.chunks.get(x + y);

          newChunk.addFeature(f.getFeatures());
          newChunk.length += f.length;
        }

        newChunks.add(newChunk);
      }
View Full Code Here

    // initial codebook:
    templateChunks = new Vector(cbSize);

    // create a placeholder template chunk
    FeatChunk template0 = new FeatChunk("templateChunk0", 0, 0, null);
    template0.setFeatures(DSP.mean(DSP.transpose(features)));
    templateChunks.add(template0);

    // distortions of between each codeword and each chunk
    double[][] distortion = new double[cbSize][ndat];
    for (int x = 0; x < distortion.length; x++)
      Arrays.fill(distortion[x], Double.MAX_VALUE);
    // indicies into cbMeans for each chunk
    int[] idx = new int[ndat];

    // how much should the means be nudged when splitting
    double delta = 1e-3;

    // start from one codeword and go from there
    for (int nValidCW = 2; nValidCW <= cbSize; nValidCW = Math.min(
        2 * nValidCW, cbSize))
    {
      if (debug)
        System.out
            .println("Splitting into " + nValidCW + " codewords.");

      // split codewords
      for (int c = 0; c < nValidCW; c += 2)
      {
        FeatChunk ch = (FeatChunk) templateChunks.get(c);
        ch.setFeatures(DSP.minus(ch.getFeatures(), delta));
        templateChunks.set(c, ch);

        FeatChunk newch = new FeatChunk("templateChunk" + c, 0, 0, null);
        newch.setFeatures(DSP.plus(ch.getFeatures(), delta));
        templateChunks.add(c + 1, newch);
      }

      double currTotalDist = 0;
      double prevTotalDist = Double.MAX_VALUE;
      do
      {
        prevTotalDist = currTotalDist;
        currTotalDist = 0;
        for (int c = 0; c < nValidCW; c++)
        {
          FeatChunk cw = (FeatChunk) templateChunks.get(c);
          for (int n = 0; n < ndat; n++)
          {
            FeatChunk ch = (FeatChunk) trainFile.chunks.get(n);
            distortion[c][n] = dist.distance(cw, ch);
            currTotalDist += distortion[c][n];
          }
        }

        // quantize
        for (int n = 0; n < ndat; n++)
          idx[n] = DSP.argmin(DSP.getColumn(distortion, n));

        // update means
        double[] newCW = new double[ndim];
        for (int c = 0; c < nValidCW; c++)
        {
          FeatChunk ch = (FeatChunk) templateChunks.get(c);
          Arrays.fill(newCW, 0);
          int nmatch = 0;
          for (int n = 0; n < ndat; n++)
          {
            if (idx[n] == c)
            {
              nmatch++;

              for (int i = 0; i < ndim; i++)
                newCW[i] += features[n][i];
            }
          }

          if (nmatch != 0)
            ch.setFeatures(DSP.rdivide(newCW, nmatch));
        }
        if (debug)
          System.out.println("  distortion = "
              + Math.abs(currTotalDist - prevTotalDist));
      }
View Full Code Here

  {
    double minDist = Double.MAX_VALUE;
    int match = -1;
    for (int c = 0; c < templateChunks.size(); c++)
    {
      FeatChunk chunk = (FeatChunk) templateChunks.get(c);

      double d = dist.distance(chunk, f);

      if (d < minDist)
      {
View Full Code Here

TOP

Related Classes of com.meapsoft.FeatChunk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.