private String getMaxHiddenVariable(String frame, int[] intTokNums, String[][] data) {
   THashSet<String> hiddenUnits = mFrameMap.get(frame);
   String maxHV = null;
   double maxVal = -Double.MAX_VALUE;
   DependencyParse parse = DependencyParse.processFN(data, 0.0);
   for (String unit : hiddenUnits) {
     FeatureExtractor featex = new FeatureExtractor();
     IntCounter<String> valMap =
         featex.extractFeaturesLessMemory(
             frame,
             intTokNums,
             unit,
             data,
             "test",
             mRelatedWordsForWord,
             mRevisedRelationsMap,
             mHVLemmas,
             parse);
     Set<String> features = valMap.keySet();
     double featSum = 0.0;
     for (String feat : features) {
       double val = valMap.getT(feat);
       int ind = localA.get(feat);
       double paramVal = V[ind].exponentiate();
       double prod = val * paramVal;
       featSum += prod;
     }
     double expVal = Math.exp(featSum);
     if (expVal > maxVal) {
       maxVal = expVal;
       maxHV = unit;
     }
   }
   return maxHV;
 }
Exemplo n.º 2
0
  public Combine() {
    this.context = FeatureExtractorFactory.getInstance(FeatureExtractorType.CONTEXT);
    this.single = FeatureExtractorFactory.getInstance(FeatureExtractorType.SINGLE_CONCEPT);
    this.vicinity = FeatureExtractorFactory.getInstance(FeatureExtractorType.CONCEPT_VICINITY);

    this.dimensions = context.getDimension() + single.getDimension() + vicinity.getDimension();
  }
 public static ArrayList<Interview> processInterviews(
     ArrayList<Interview> interviews, FeatureExtractor extractor) {
   ArrayList<Interview> new_interviews = new ArrayList<>();
   for (Iterator<Interview> i = interviews.iterator(); i.hasNext(); )
     new_interviews.add(extractor.update(i.next()));
   return new_interviews;
 }
Exemplo n.º 4
0
 public List<String> predictArgumentLines(Sentence sentence, List<String> idResult, int kBest)
     throws IOException {
   final List<FrameFeatures> frameFeaturesList = Lists.newArrayList();
   final FeatureExtractor featureExtractor = new FeatureExtractor();
   for (String feLine : idResult) {
     final DataPointWithFrameElements dataPoint = new DataPointWithFrameElements(sentence, feLine);
     final String frame = dataPoint.getFrameName();
     final DependencyParses parses = dataPoint.getParses();
     final int targetStartTokenIdx = dataPoint.getTargetTokenIdxs()[0];
     final int targetEndTokenIdx =
         dataPoint.getTargetTokenIdxs()[dataPoint.getTargetTokenIdxs().length - 1];
     final List<SpanAndParseIdx> spans = DataPrep.findSpans(dataPoint, 1);
     final List<String> frameElements =
         Lists.newArrayList(frameElementsForFrame.lookupFrameElements(frame));
     final List<SpanAndCorrespondingFeatures[]> featuresAndSpanByArgument = Lists.newArrayList();
     for (String frameElement : frameElements) {
       final List<SpanAndCorrespondingFeatures> spansAndFeatures = Lists.newArrayList();
       for (SpanAndParseIdx candidateSpanAndParseIdx : spans) {
         final Range0Based span = candidateSpanAndParseIdx.span;
         final DependencyParse parse = parses.get(candidateSpanAndParseIdx.parseIdx);
         final Set<String> featureSet =
             featureExtractor
                 .extractFeatures(dataPoint, frame, frameElement, span, parse)
                 .elementSet();
         final int[] featArray = convertToIdxs(featureSet);
         spansAndFeatures.add(
             new SpanAndCorrespondingFeatures(new int[] {span.start, span.end}, featArray));
       }
       featuresAndSpanByArgument.add(
           spansAndFeatures.toArray(new SpanAndCorrespondingFeatures[spansAndFeatures.size()]));
     }
     frameFeaturesList.add(
         new FrameFeatures(
             frame,
             targetStartTokenIdx,
             targetEndTokenIdx,
             frameElements,
             featuresAndSpanByArgument));
   }
   return decoder.decodeAll(frameFeaturesList, idResult, 0, kBest);
 }
 private double getValueForFrame(String frame, int[] intTokNums, String[][] data) {
   THashSet<String> hiddenUnits = mFrameMap.get(frame);
   double result = 0.0;
   DependencyParse parse = DependencyParse.processFN(data, 0.0);
   for (String unit : hiddenUnits) {
     IntCounter<String> valMap = null;
     FeatureExtractor featex = new FeatureExtractor();
     if (clusterMap == null) {
       valMap =
           featex.extractFeaturesLessMemory(
               frame,
               intTokNums,
               unit,
               data,
               "test",
               mRelatedWordsForWord,
               mRevisedRelationsMap,
               mHVLemmas,
               parse);
     } else { // not supported
       valMap =
           featex.extractFeaturesWithClusters(
               frame, intTokNums, unit, data, mWNR, "test", null, null, parse, clusterMap, K);
     }
     Set<String> features = valMap.keySet();
     double featSum = 0.0;
     for (String feat : features) {
       double val = valMap.getT(feat);
       int ind = localA.get(feat);
       double paramVal = V[ind].exponentiate();
       double prod = val * paramVal;
       featSum += prod;
     }
     double expVal = Math.exp(featSum);
     result += expVal;
   }
   return result;
 }
  public static double[] feature(AudioSamples audio, AudioFeature i) throws Exception {
    /**
     * 1. Spectral Centroid 2. Spectral Rolloff Point 3. Spectral Flux 4. Compactness 5. Spectral
     * Variability 6. Root Mean Square 7. Fration of Low Energy Windows 8. Zero Crossings 9.
     * Strongest Beat 10. Beat Sum 11. MFCC 12. ConstantQ 13. LPC 14. Method of Moments 15. Peak
     * Detection 16. Area Method of MFCCs
     */
    FeatureExtractor featureExt;
    double[] samples = audio.getSamplesMixedDown();
    double sampleRate = audio.getSamplingRateAsDouble();
    double[][] otherFeatures = audio.getSamplesChannelSegregated();

    double[][] windowSample;
    switch (i.getValue()) {
      case 1:
        featureExt = new SpectralCentroid();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);

      case 2:
        featureExt = new PowerSpectrum();
        otherFeatures[0] = featureExt.extractFeature(samples, sampleRate, otherFeatures);
        featureExt = new SpectralRolloffPoint();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);

      case 3:
        windowSample = audio.getSampleWindowsMixedDown(2);
        featureExt = new MagnitudeSpectrum();
        otherFeatures[0] = featureExt.extractFeature(windowSample[0], sampleRate, otherFeatures);
        otherFeatures[1] = featureExt.extractFeature(windowSample[1], sampleRate, otherFeatures);
        featureExt = new SpectralFlux();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);

      case 4:
        featureExt = new MagnitudeSpectrum();
        otherFeatures[0] = featureExt.extractFeature(samples, sampleRate, otherFeatures);
        featureExt = new Compactness();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);

      case 5:
        featureExt = new MagnitudeSpectrum();
        otherFeatures[0] = featureExt.extractFeature(samples, sampleRate, otherFeatures);
        featureExt = new SpectralVariability();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);

      case 6:
        featureExt = new RMS();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);
      case 7:
        featureExt = new RMS();
        windowSample = audio.getSampleWindowsMixedDown(100);
        for (int j = 0; j < 100; j++) {
          otherFeatures[j] = featureExt.extractFeature(windowSample[j], sampleRate, null);
        }
        featureExt = new FractionOfLowEnergyWindows();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);
      case 8:
        featureExt = new ZeroCrossings();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);
      case 9:
        double[][] otherFeature = new double[3][];

        featureExt = new RMS();
        /*String [] dependecies3 = featureExt.getDepenedencies();
        if(dependecies3!=null)
        for(int k=0;k<dependecies3.length;k++)
           	System.out.println(dependecies3[k]);*/
        otherFeature[0] = featureExt.extractFeature(samples, sampleRate, null);

        featureExt = new BeatHistogram();
        /*String [] dependecies1 = featureExt.getDepenedencies();
        for(int k=0;k<dependecies1.length;k++)
        	System.out.println(dependecies1[k]);*/
        double[][] RmsFeat = new double[1][];
        RmsFeat[0] = otherFeature[0];
        otherFeature[1] = featureExt.extractFeature(samples, sampleRate, RmsFeat);

        featureExt = new BeatHistogramLabels();
        /*String [] dependecies2 = featureExt.getDepenedencies();
        for(int k=0;k<de	pendecies2.length;k++)
        	System.out.println(dependecies2[k]);*/
        double[][] beatHistogramFeat = new double[1][];
        beatHistogramFeat[0] = otherFeature[1];
        otherFeature[2] = featureExt.extractFeature(samples, sampleRate, beatHistogramFeat);
        featureExt = new StrongestBeat();

        double[][] StrongestBeatFeat = new double[2][];
        StrongestBeatFeat[0] = otherFeature[1];
        StrongestBeatFeat[1] = otherFeature[2];
        /*String[] dependencies = featureExt.getDepenedencies();
         for(int k=0;k<dependencies.length;k++)
        System.out.println(dependencies[k]);*/
        return featureExt.extractFeature(samples, sampleRate, StrongestBeatFeat);
        /*	 featureExt = new BeatHistogram();
        double[][] otherFeature = new double[2][];
        otherFeature[0] = featureExt.extractFeature(samples, sampleRate, otherFeatures);
        featureExt = new BeatHistogramLabels();
        otherFeature[1] = featureExt.extractFeature(samples, sampleRate, otherFeatures);
        featureExt = new StrongestBeat();
        return featureExt.extractFeature(samples, sampleRate, otherFeature); */
      case 10:
        featureExt = new BeatHistogram();
        otherFeatures[0] = featureExt.extractFeature(samples, sampleRate, otherFeatures);
        featureExt = new BeatSum();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);

      case 11:
        featureExt = new MagnitudeSpectrum();
        otherFeatures[0] = featureExt.extractFeature(samples, sampleRate, otherFeatures);
        featureExt = new MFCC();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);
      case 12:
        featureExt = new ConstantQ();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);
      case 13:
        featureExt = new LPC();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);
      case 14:
        featureExt = new MagnitudeSpectrum();
        otherFeatures[0] = featureExt.extractFeature(samples, sampleRate, otherFeatures);
        featureExt = new Moments();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);
      case 15:
        featureExt = new MagnitudeSpectrum();
        otherFeatures[0] = featureExt.extractFeature(samples, sampleRate, otherFeatures);
        featureExt = new PeakFinder();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);
      case 16:
        featureExt = new MagnitudeSpectrum();
        windowSample = audio.getSampleWindowsMixedDown(100);
        for (int j = 0; j < 100; j++) {
          otherFeatures[j] = featureExt.extractFeature(windowSample[j], sampleRate, null);
        }
        featureExt = new AreaMoments();
        return featureExt.extractFeature(samples, sampleRate, otherFeatures);

      default:
        return null;
    }
  }