/** * Calculates local distances array. * * @param pattern feature extractor object of the pattern */ private void CalculateLocalDistances(Extractor pattern) { int patternSize = pattern.GetFramesCount(); for (int i = 0; i < from.GetFramesCount(); ++i) { Array.Resize(ref points[i], patternSize); for (int j = 0; j < patternSize; j++) { points[i][j] = new DtwPoint(i, j, distanceFn(from.GetVector(i), pattern.GetVector(j))); } } }
/** * Returns the lowest-cost path in the DTW array. * * @return path */ public LinkedList <KeyValuePair <int, int> > GetPath() { LinkedList <KeyValuePair <int, int> > path = new LinkedList <KeyValuePair <int, int> >(); int width = points.Length; int height = points[0].Length; //C++ TO C# CONVERTER TODO TASK: Pointer arithmetic is detected on this variable, so pointers on this variable are left unchanged. DtwPoint point = points[width - 1][height - 1]; while (point.previous != null) { path.AddLast(new KeyValuePair <int, int>(point.x, point.y)); //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist: //ORIGINAL LINE: point = point->previous; //point.CopyFrom(point.previous); point = point.previous; } return(path); }
/** * Calculates local distances array. * * @param pattern feature extractor object of the pattern */ private void CalculateLocalDistances(Extractor pattern) { int patternSize = pattern.GetFramesCount(); for (int i = 0; i < from.GetFramesCount(); ++i) { Array.Resize(ref points[i], patternSize); for (int j = 0; j < patternSize; j++) points[i][j] = new DtwPoint(i, j, distanceFn(from.GetVector(i), pattern.GetVector(j))); } }
public double GetDistance(Extractor pattern, NormalizationType normalization) { CalculateLocalDistances(pattern); int signalSize = from.GetFramesCount(); int patternSize = pattern.GetFramesCount(); DtwPoint top = new DtwPoint(); DtwPoint center = new DtwPoint(); DtwPoint bottom = new DtwPoint(); DtwPoint previous = new DtwPoint(); for (int i = 1; i < signalSize; ++i) { for (int j = 1; j < patternSize; ++j) { center = points[i - 1][j - 1]; if (PassType.Neighbors == passType) { top = points[i - 1][j]; bottom = points[i][j - 1]; } else // Diagonals { if (i > 1 && j > 1) { top = points[i - 2][j - 1]; bottom = points[i - 1][j - 2]; } else { top = points[i - 1][j]; bottom = points[i][j - 1]; } } if (top.dAccumulated < center.dAccumulated) previous = top; else previous = center; if (bottom.dAccumulated < previous.dAccumulated) previous = bottom; points[i][j].dAccumulated = points[i][j].dLocal + previous.dAccumulated; points[i][j].previous = previous; } } double distance = points[signalSize - 1][patternSize - 1].dAccumulated; switch (normalization) { case NormalizationType.Diagonal: distance /= Math.Sqrt(signalSize *signalSize + patternSize *patternSize); break; case NormalizationType.SumOfSides: distance /= signalSize + patternSize; break; case NormalizationType.NoNormalization: default: break; } return distance; }
public double GetDistance(Extractor pattern, NormalizationType normalization) { CalculateLocalDistances(pattern); int signalSize = from.GetFramesCount(); int patternSize = pattern.GetFramesCount(); DtwPoint top = new DtwPoint(); DtwPoint center = new DtwPoint(); DtwPoint bottom = new DtwPoint(); DtwPoint previous = new DtwPoint(); for (int i = 1; i < signalSize; ++i) { for (int j = 1; j < patternSize; ++j) { center = points[i - 1][j - 1]; if (PassType.Neighbors == passType) { top = points[i - 1][j]; bottom = points[i][j - 1]; } else // Diagonals { if (i > 1 && j > 1) { top = points[i - 2][j - 1]; bottom = points[i - 1][j - 2]; } else { top = points[i - 1][j]; bottom = points[i][j - 1]; } } if (top.dAccumulated < center.dAccumulated) { previous = top; } else { previous = center; } if (bottom.dAccumulated < previous.dAccumulated) { previous = bottom; } points[i][j].dAccumulated = points[i][j].dLocal + previous.dAccumulated; points[i][j].previous = previous; } } double distance = points[signalSize - 1][patternSize - 1].dAccumulated; switch (normalization) { case NormalizationType.Diagonal: distance /= Math.Sqrt(signalSize * signalSize + patternSize * patternSize); break; case NormalizationType.SumOfSides: distance /= signalSize + patternSize; break; case NormalizationType.NoNormalization: default: break; } return(distance); }