/** * Calculates the distance between this voice sample and the voice prints previously extracted * and returns the closest matches sorted by distance * <p> * Usage of a closed set is assumed : the speaker's voice print was extracted before and is known to the system. * This means you'll always get MatchResults even if the speaker is absolutely unknown to the system. * The MatchResult class provides a likelihood ratio in order to help determining the usefulness of the result * </p> * @param voiceSample the voice sample, values between -1.0 and 1.0 * @return a list MatchResults sorted by distance */ public IEnumerable <MatchResult <T> > Identify(double[] voiceSample) { if (store.Count == 0) { throw new InvalidOperationException("There is no voice print enrolled in the system yet"); } var voicePrint = new VoicePrint(audioProcessor.ProcessAndExtract(voiceSample)); var calculator = new EuclideanDistanceCalculator(); var matches = new List <MatchResult <T> >(store.Count); var distanceFromUniversalModel = voicePrint.GetDistance(calculator, universalModel); foreach (var entry in store) { var distance = entry.Value.GetDistance(calculator, voicePrint); // likelihood : how close is the given voice sample to the current VoicePrint // compared to the total distance between the current VoicePrint and the universal model int likelihood = 100 - (int)(distance / (distance + distanceFromUniversalModel) * 100); matches.Add(new MatchResult <T>(entry.Key, likelihood, distance)); } matches = matches.OrderBy(m => m.Distance).ToList(); return(matches); }
public void TestEuclideanDistanceBetweenElementsHavingIdenticalCoordinates() { var calculator = new EuclideanDistanceCalculator(); var element = new ClusterPoint { X = 0, Y = 0 }; var otherElement = new ClusterPoint { X = element.X, Y = element.Y }; var distance = calculator.CalculateDistance(element, otherElement); Assert.AreEqual(0.0, distance, double.Epsilon, @"The distance must be 0!"); }
public static void Main(string[] args) { string filePath = "sunflower.jpg"; string outputFile = "result.jpg"; int classNumber = 5; IImageBinarizer imageBinarizer = new MinimumErrorThresholder(); IImageProcessor imageProcessor = new ImageProcessor(filePath); ILabelingService labelingService = new IterativeLabelingService(); IDistanceCalculator<ClassificationUnit> euclidian = new EuclideanDistanceCalculator<ClassificationUnit>(); var classificationService = new ClassificationService(imageBinarizer, imageProcessor, labelingService, euclidian, classNumber); classificationService.Classify(); classificationService.Save(outputFile); }
public void Calculate_Calculates_EuclideanDistance() { var loc_a = new Location() { Longitude = 48.8584, Latitude = 2.2945 }; var loc_b = new Location() { Longitude = 40.6413, Latitude = -73.7781 }; var distance = new EuclideanDistanceCalculator().Calculate(loc_a, loc_b); var expected = 76.5151044119395; Assert.Equal(expected, distance, 5); }
public static double CalcDiagonalYZ(double width, double height) { double distance = EuclideanDistanceCalculator.CalcDistance2D(0, 0, width, height); return(distance); }