public double GetSimilarity(ICase caseA, ICase caseB, ReasonerContext context) { if (covarianceMatrix == null) { covarianceMatrix = GetCovarianceMatrix(context.Cases); } if (caseA == null) { throw new ArgumentNullException(nameof(caseA)); } if (caseB == null) { throw new ArgumentNullException(nameof(caseB)); } var differenceVector = new DenseMatrix(1, caseA.Schema.Count); for (var i = 0; i < caseA.Schema.Count; i++) { differenceVector[0, i] = caseA.GetAttribute <double>(caseA.Schema[i]) - caseB.GetAttribute <double>(caseA.Schema[i]); } var distance = differenceVector * covarianceMatrix.Transpose() * differenceVector.Transpose(); return(Math.Sqrt(distance[0, 0])); }
private static Vector GetAttributesVector(ICase targetCase) { var attributes = new double[targetCase.Schema.Count]; for (var i = 0; i < targetCase.Schema.Count; i++) { attributes[i] = targetCase.GetAttribute <double>(targetCase.Schema[i]); } return(new DenseVector(attributes)); }
public double GetSimilarity(ICase caseA, ICase caseB) { if (caseA == null) { throw new ArgumentNullException(nameof(caseA)); } if (caseB == null) { throw new ArgumentNullException(nameof(caseB)); } double result = 0; foreach (var attribute in caseA.Schema) { result += attribute.Type == typeof(double) ? Math.Pow(Math.Abs(caseA.GetAttribute <double>(attribute) - caseB.GetAttribute <double>(attribute)), order) : 0; } return(Math.Pow(result, 1 / order)); }
public double GetSimilarity(ICase caseA, ICase caseB, ReasonerContext context) { if (caseA == null) { throw new ArgumentNullException(nameof(caseA)); } if (caseB == null) { throw new ArgumentNullException(nameof(caseB)); } double result = 0; foreach (var attribute in caseA.Schema) { if (targetAttributes.Length > 0 && !targetAttributes.Contains(attribute.Name)) { continue; } result += Math.Pow(Math.Abs(caseA.GetAttribute <double>(attribute) - caseB.GetAttribute <double>(attribute)), order); } return(Math.Pow(result, 1 / order)); }