Search in sources :

Example 1 with SegmentDistanceElement

use of org.vitrivr.cineast.core.data.distance.SegmentDistanceElement 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 SegmentDistanceElement

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

the class CLIPText method getSimilar.

private List<ScoreElement> getSimilar(PrimitiveTypeProvider queryProvider, ReadableQueryConfig qc) {
    ReadableQueryConfig qcc = QueryConfig.clone(qc).setDistance(DISTANCE);
    List<SegmentDistanceElement> distances = this.selector.getNearestNeighboursGeneric(qc.getResultsPerModule(), queryProvider, FEATURE_COLUMN_QUALIFIER, SegmentDistanceElement.class, qcc);
    CorrespondenceFunction function = qcc.getCorrespondenceFunction().orElse(CORRESPONDENCE);
    return DistanceElement.toScore(distances, function);
}
Also used : ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Example 3 with SegmentDistanceElement

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

the class AbstractFeatureModule method getSimilar.

/**
 * Helper function to retrieve elements close to a generic primitive type
 */
protected List<ScoreElement> getSimilar(PrimitiveTypeProvider queryProvider, ReadableQueryConfig qc) {
    ReadableQueryConfig qcc = setQueryConfig(qc);
    List<SegmentDistanceElement> distances = this.selector.getNearestNeighboursGeneric(qc.getResultsPerModule(), queryProvider, FEATURE_COLUMN_QUALIFIER, SegmentDistanceElement.class, qcc);
    CorrespondenceFunction function = qcc.getCorrespondenceFunction().orElse(correspondence);
    return DistanceElement.toScore(distances, function);
}
Also used : ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Example 4 with SegmentDistanceElement

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

the class MetadataFeatureModule method getSimilar.

protected List<ScoreElement> getSimilar(float[] feature, ReadableQueryConfig rqc) {
    QueryConfig qc = QueryConfig.clone(rqc).setDistanceIfEmpty(this.defaultDistance());
    List<SegmentDistanceElement> sDistances = new ArrayList<>();
    List<ObjectDistanceElement> oDistances = new ArrayList<>();
    CorrespondenceFunction correspondence = qc.getCorrespondenceFunction().orElse(this.defaultCorrespondence());
    if (this.segmentRetrievalScope) {
        sDistances = this.dbSelector.getNearestNeighboursGeneric(rqc.getResultsPerModule(), feature, FEATURE_COLUMN_NAME, SegmentDistanceElement.class, qc);
        return DistanceElement.toScore(sDistances, correspondence);
    } else {
        oDistances = this.dbSelector.getNearestNeighboursGeneric(rqc.getResultsPerModule(), feature, FEATURE_COLUMN_NAME, ObjectDistanceElement.class, qc);
        return DistanceElement.toScore(oDistances, correspondence);
    }
}
Also used : QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) ArrayList(java.util.ArrayList) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) ObjectDistanceElement(org.vitrivr.cineast.core.data.distance.ObjectDistanceElement) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Example 5 with SegmentDistanceElement

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

the class MotionHistogramCalculator method getSimilar.

protected List<ScoreElement> getSimilar(float[] vector, ReadableQueryConfig qc) {
    ReadableQueryConfig qcc = setQueryConfig(qc);
    List<SegmentDistanceElement> distances = this.selector.getNearestNeighboursGeneric(qcc.getResultsPerModule(), vector, this.fieldName, SegmentDistanceElement.class, qcc);
    return DistanceElement.toScore(distances, qcc.getCorrespondenceFunction().get());
}
Also used : ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Aggregations

SegmentDistanceElement (org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)14 ReadableQueryConfig (org.vitrivr.cineast.core.config.ReadableQueryConfig)11 CorrespondenceFunction (org.vitrivr.cineast.core.data.CorrespondenceFunction)10 ArrayList (java.util.ArrayList)9 QueryConfig (org.vitrivr.cineast.core.config.QueryConfig)6 DistanceElement (org.vitrivr.cineast.core.data.distance.DistanceElement)6 ScoreElement (org.vitrivr.cineast.core.data.score.ScoreElement)6 HashMap (java.util.HashMap)5 List (java.util.List)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 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