Search in sources :

Example 1 with DistanceElement

use of org.vitrivr.cineast.core.data.distance.DistanceElement in project cineast by vitrivr.

the class MFCCShingle method postprocessQuery.

/**
 * This method represents the last step that's executed when processing a query. A list of partial-results (DistanceElements) returned by the lookup stage is processed based on some internal method and finally converted to a list of ScoreElements. The filtered list of ScoreElements is returned by the feature module during retrieval.
 *
 * @param partialResults List of partial results returned by the lookup stage.
 * @param qc             A ReadableQueryConfig object that contains query-related configuration parameters.
 * @return List of final results. Is supposed to be de-duplicated and the number of items should not exceed the number of items per module.
 */
@Override
protected List<ScoreElement> postprocessQuery(List<SegmentDistanceElement> partialResults, ReadableQueryConfig qc) {
    /* Prepare helper data-structures. */
    final List<ScoreElement> results = new ArrayList<>();
    final TObjectIntHashMap<String> scoreMap = new TObjectIntHashMap<>();
    /* Set QueryConfig and extract correspondence function. */
    qc = this.setQueryConfig(qc);
    final CorrespondenceFunction correspondence = qc.getCorrespondenceFunction().orElse(this.correspondence);
    for (DistanceElement hit : partialResults) {
        if (hit.getDistance() < this.distanceThreshold) {
            scoreMap.adjustOrPutValue(hit.getId(), 1, scoreMap.get(hit.getId()) / 2);
        }
    }
    /* Prepare final result-set. */
    scoreMap.forEachEntry((key, value) -> results.add(new SegmentScoreElement(key, 1.0 - 1.0 / value)));
    ScoreElement.filterMaximumScores(results.stream());
    return results;
}
Also used : SegmentScoreElement(org.vitrivr.cineast.core.data.score.SegmentScoreElement) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) SegmentScoreElement(org.vitrivr.cineast.core.data.score.SegmentScoreElement) ArrayList(java.util.ArrayList) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement)

Example 2 with DistanceElement

use of org.vitrivr.cineast.core.data.distance.DistanceElement in project cineast by vitrivr.

the class AudioFingerprint method postprocessQuery.

/**
 * This method represents the last step that's executed when processing a query. A list of partial-results (DistanceElements) returned by the lookup stage is processed based on some internal method and finally converted to a list of ScoreElements. The filtered list of ScoreElements is returned by the feature module during retrieval.
 *
 * @param partialResults List of partial results returned by the lookup stage.
 * @param qc             A ReadableQueryConfig object that contains query-related configuration parameters.
 * @return List of final results. Is supposed to be de-duplicated and the number of items should not exceed the number of items per module.
 */
@Override
protected List<ScoreElement> postprocessQuery(List<SegmentDistanceElement> partialResults, ReadableQueryConfig qc) {
    /* Prepare empty list of results. */
    final ArrayList<ScoreElement> results = new ArrayList<>();
    final HashMap<String, DistanceElement> map = new HashMap<>();
    /* Merge into map for final results; select the minimum distance. */
    for (DistanceElement result : partialResults) {
        map.merge(result.getId(), result, (d1, d2) -> {
            if (d1.getDistance() > d2.getDistance()) {
                return d2;
            } else {
                return d1;
            }
        });
    }
    /* Return immediately if no partial results are available.  */
    if (map.isEmpty()) {
        return results;
    }
    /* Prepare final results. */
    final CorrespondenceFunction fkt = qc.getCorrespondenceFunction().orElse(this.correspondence);
    map.forEach((key, value) -> results.add(value.toScore(fkt)));
    return ScoreElement.filterMaximumScores(results.stream());
}
Also used : HashMap(java.util.HashMap) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement)

Example 3 with DistanceElement

use of org.vitrivr.cineast.core.data.distance.DistanceElement in project cineast by vitrivr.

the class HPCPShingle method postprocessQuery.

/**
 * This method represents the last step that's executed when processing a query. A list of partial-results (DistanceElements) returned by the lookup stage is processed based on some internal method and finally converted to a list of ScoreElements. The filtered list of ScoreElements is returned by the feature module during retrieval.
 *
 * @param partialResults List of partial results returned by the lookup stage.
 * @param qc             A ReadableQueryConfig object that contains query-related configuration parameters.
 * @return List of final results. Is supposed to be de-duplicated and the number of items should not exceed the number of items per module.
 */
@Override
protected List<ScoreElement> postprocessQuery(List<SegmentDistanceElement> partialResults, ReadableQueryConfig qc) {
    /* Prepare helper data-structures. */
    final HashMap<String, DistanceElement> map = new HashMap<>();
    for (DistanceElement hit : partialResults) {
        if (hit.getDistance() <= this.distanceThreshold) {
            map.merge(hit.getId(), hit, (o, n) -> new SegmentDistanceElement(o.getId(), (o.getDistance() + n.getDistance()) / 2));
        }
    }
    /* Prepare final result-set. */
    final CorrespondenceFunction fkt = qc.getCorrespondenceFunction().orElse(this.correspondence);
    return ScoreElement.filterMaximumScores(map.entrySet().stream().map(e -> e.getValue().toScore(fkt)));
}
Also used : StagedFeatureModule(org.vitrivr.cineast.core.features.abstracts.StagedFeatureModule) MathHelper(org.vitrivr.cineast.core.util.math.MathHelper) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) FloatVectorImpl(org.vitrivr.cineast.core.data.FloatVectorImpl) HashMap(java.util.HashMap) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) FFTUtil(org.vitrivr.cineast.core.util.dsp.fft.FFTUtil) STFT(org.vitrivr.cineast.core.util.dsp.fft.STFT) HPCP(org.vitrivr.cineast.core.util.audio.HPCP) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) List(java.util.List) SegmentContainer(org.vitrivr.cineast.core.data.segments.SegmentContainer) Pair(org.vitrivr.cineast.core.data.Pair) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow) HashMap(java.util.HashMap) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Example 4 with DistanceElement

use of org.vitrivr.cineast.core.data.distance.DistanceElement in project cineast by vitrivr.

the class AverageHPCP method postprocessQuery.

/**
 * This method represents the last step that's executed when processing a query. A list of partial-results (DistanceElements) returned by the lookup stage is processed based on some internal method and finally converted to a list of ScoreElements. The filtered list of ScoreElements is returned by the feature module during retrieval.
 *
 * @param partialResults List of partial results returned by the lookup stage.
 * @param qc             A ReadableQueryConfig object that contains query-related configuration parameters.
 * @return List of final results. Is supposed to be de-duplicated and the number of items should not exceed the number of items per module.
 */
@Override
protected List<ScoreElement> postprocessQuery(List<SegmentDistanceElement> partialResults, ReadableQueryConfig qc) {
    /* Prepare helper data-structures. */
    final HashMap<String, DistanceElement> map = new HashMap<>();
    /* Set QueryConfig and extract correspondence function. */
    for (DistanceElement hit : partialResults) {
        map.merge(hit.getId(), hit, (o, n) -> new SegmentDistanceElement(hit.getId(), (o.getDistance() + n.getDistance()) / 2));
    }
    /* Prepare final result-set. */
    final CorrespondenceFunction fkt = qc.getCorrespondenceFunction().orElse(this.correspondence);
    return ScoreElement.filterMaximumScores(map.entrySet().stream().map(e -> e.getValue().toScore(fkt)));
}
Also used : StagedFeatureModule(org.vitrivr.cineast.core.features.abstracts.StagedFeatureModule) MathHelper(org.vitrivr.cineast.core.util.math.MathHelper) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) FloatVectorImpl(org.vitrivr.cineast.core.data.FloatVectorImpl) HashMap(java.util.HashMap) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) ArrayList(java.util.ArrayList) FFTUtil(org.vitrivr.cineast.core.util.dsp.fft.FFTUtil) STFT(org.vitrivr.cineast.core.util.dsp.fft.STFT) HPCP(org.vitrivr.cineast.core.util.audio.HPCP) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) List(java.util.List) SegmentContainer(org.vitrivr.cineast.core.data.segments.SegmentContainer) Pair(org.vitrivr.cineast.core.data.Pair) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow) HashMap(java.util.HashMap) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Example 5 with DistanceElement

use of org.vitrivr.cineast.core.data.distance.DistanceElement in project cineast by vitrivr.

the class CENS method postprocessQuery.

/**
 * This method represents the last step that's executed when processing a query. A list of partial-results (DistanceElements) returned by the lookup stage is processed based on some internal method and finally converted to a list of ScoreElements. The filtered list of ScoreElements is returned by the feature module during retrieval.
 *
 * @param partialResults List of partial results returned by the lookup stage.
 * @param qc             A ReadableQueryConfig object that contains query-related configuration parameters.
 * @return List of final results. Is supposed to be de-duplicated and the number of items should not exceed the number of items per module.
 */
@Override
protected List<ScoreElement> postprocessQuery(List<SegmentDistanceElement> partialResults, ReadableQueryConfig qc) {
    /* Prepare map to build a unique set of results. */
    final HashMap<String, DistanceElement> map = new HashMap<>();
    for (DistanceElement hit : partialResults) {
        map.merge(hit.getId(), hit, (o, n) -> o.getDistance() > n.getDistance() ? n : o);
    }
    /* Prepare final list of results. */
    final CorrespondenceFunction correspondence = qc.getCorrespondenceFunction().orElse(this.correspondence);
    return ScoreElement.filterMaximumScores(map.entrySet().stream().map((e) -> e.getValue().toScore(correspondence)));
}
Also used : StagedFeatureModule(org.vitrivr.cineast.core.features.abstracts.StagedFeatureModule) MathHelper(org.vitrivr.cineast.core.util.math.MathHelper) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) FloatVectorImpl(org.vitrivr.cineast.core.data.FloatVectorImpl) HashMap(java.util.HashMap) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) ArrayList(java.util.ArrayList) FFTUtil(org.vitrivr.cineast.core.util.dsp.fft.FFTUtil) STFT(org.vitrivr.cineast.core.util.dsp.fft.STFT) HPCP(org.vitrivr.cineast.core.util.audio.HPCP) List(java.util.List) SegmentContainer(org.vitrivr.cineast.core.data.segments.SegmentContainer) BlackmanHarrisWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.BlackmanHarrisWindow) Pair(org.vitrivr.cineast.core.data.Pair) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) HanningWindow(org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow) HashMap(java.util.HashMap) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement)

Aggregations

ArrayList (java.util.ArrayList)6 CorrespondenceFunction (org.vitrivr.cineast.core.data.CorrespondenceFunction)6 DistanceElement (org.vitrivr.cineast.core.data.distance.DistanceElement)6 SegmentDistanceElement (org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)6 ScoreElement (org.vitrivr.cineast.core.data.score.ScoreElement)6 HashMap (java.util.HashMap)5 List (java.util.List)4 ReadableQueryConfig (org.vitrivr.cineast.core.config.ReadableQueryConfig)4 FloatVectorImpl (org.vitrivr.cineast.core.data.FloatVectorImpl)4 SegmentContainer (org.vitrivr.cineast.core.data.segments.SegmentContainer)4 StagedFeatureModule (org.vitrivr.cineast.core.features.abstracts.StagedFeatureModule)4 QueryConfig (org.vitrivr.cineast.core.config.QueryConfig)3 Pair (org.vitrivr.cineast.core.data.Pair)3 HPCP (org.vitrivr.cineast.core.util.audio.HPCP)3 FFTUtil (org.vitrivr.cineast.core.util.dsp.fft.FFTUtil)3 STFT (org.vitrivr.cineast.core.util.dsp.fft.STFT)3 HanningWindow (org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow)3 MathHelper (org.vitrivr.cineast.core.util.math.MathHelper)3 SummaryStatistics (org.apache.commons.math3.stat.descriptive.SummaryStatistics)2 ImageUtil (com.twelvemonkeys.image.ImageUtil)1