public void AddNewMatchForTrack(IModelReference trackReference, MatchedWith match) { candidates.AddOrUpdate(trackReference, reference => new List <MatchedWith> { match }, (reference, old) => { old.Add(match); return(old); }); }
public void AddOrUpdateNewMatch(IModelReference trackReference, MatchedWith match) { candidates.AddOrUpdate(trackReference, reference => match, (reference, old) => { if (old.HammingSimilarity > match.HammingSimilarity) { return(old); } return(match); }); }
private static MaxAt[] MaxIncreasingQuerySequenceOptimal(IReadOnlyList <MatchedWith> matches, double maxGap, out int max, out int maxIndex) { var maxs = matches.Select(_ => new MaxAt(1, _)).ToArray(); var dp = new MatchedWith[matches.Count]; int len = 0; max = 1; maxIndex = 0; var comparer = Comparer <MatchedWith> .Create((a, b) => a.QuerySequenceNumber.CompareTo(b.QuerySequenceNumber)); for (int j = 0; j < matches.Count; ++j) { var x = matches[j]; int i = Array.BinarySearch(dp, 0, len, x, comparer); if (i < 0) { i = -(i + 1); } if (i > 0 && !IsSameSequence(dp[i - 1], x, maxGap)) { continue; } if (i == 0 && dp[i] != null && !IsSameSequence(dp[0], x, maxGap)) { continue; } dp[i] = x; if (i >= len - 1) { // the sequence has increased or found an equal element at the very end len = i == len ? len + 1 : len; maxs[j] = new MaxAt(len, x); maxIndex = j; } else { // the sequence does not increase maxs[j] = new MaxAt(i + 1, x); } } max = maxs[maxIndex].Length; return(maxs); }
private static Matches GetMatches(float startQueryAt, float startTrackAt, double length, float stride, int startIndex = 0) { const int hammingSimilarity = 100; float startAt = 0f; var matches = new List <MatchedWith>(); uint index = (uint)startIndex; while (startAt <= length) { var match = new MatchedWith(index, startQueryAt + startAt, index, startTrackAt + startAt, hammingSimilarity); matches.Add(match); startAt += stride; index++; } return(new Matches(matches)); }
public void FindGapsFloatingPointEdgeCase() { const double permittedGap = 0; const double fingerprintLength = 8192 / 5512d; uint startsAtSeqNum = 20; float startsAt = 3.71552968025207519531250000000f; var start = new MatchedWith(startsAtSeqNum, startsAt, 0, 0, 0); uint endsAtSeqNum = 28; float endsAt = 5.20174169540405273437500000000f; var end = new MatchedWith(endsAtSeqNum, endsAt, 0, 0, 0); var entries = new[] { start, end }; Assert.DoesNotThrow(() => entries.FindQueryGaps(permittedGap, fingerprintLength).ToList()); }
private static bool IsSameSequence(MatchedWith a, MatchedWith b, double maxGap) { return(Math.Abs(a.QueryMatchAt - b.QueryMatchAt) <= maxGap && Math.Abs(a.TrackMatchAt - b.TrackMatchAt) <= maxGap); }
public MaxAt(int length, MatchedWith matchedWith) { Length = length; MatchedWith = matchedWith; }
private static double GetTrackStartsAt(MatchedWith bestMatch) { return(bestMatch.QueryAt - bestMatch.ResultAt); }
private static double GetNotCoveredLength(List <MatchedWith> orderedByResultAt, TrackRegion trackRegion, double fingerprintLengthInSeconds, out MatchedWith bestMatch) { double notCovered = 0d; bestMatch = orderedByResultAt[trackRegion.StartAt]; for (int i = trackRegion.StartAt + 1; i <= trackRegion.EndAt; ++i) { if (orderedByResultAt[i].ResultAt - orderedByResultAt[i - 1].ResultAt > fingerprintLengthInSeconds) { notCovered += orderedByResultAt[i].ResultAt - (orderedByResultAt[i - 1].ResultAt + fingerprintLengthInSeconds); } if (bestMatch.HammingSimilarity < orderedByResultAt[i].HammingSimilarity) { bestMatch = orderedByResultAt[i]; } } return(notCovered); }
public bool TryGetMatchesForTrack(IModelReference trackReference, out MatchedWith matchedWith) { return(candidates.TryGetValue(trackReference, out matchedWith)); }