/** * Checks whether the two extractor objects are compatible with each other. * * @param other another Extractor object * @return true, if two extractors are compatible */ public bool IsCompatible(Extractor other) { return(GetType() == other.GetType() && GetParamsPerFrame() == other.GetParamsPerFrame() && GetFrameLength() == other.GetFrameLength()); }
/** * 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))); } }
/** * Creates the DTW object and sets signal feature object. * * @param signal feature extractor object */ public Dtw(Extractor signal) { from = signal; points = new DtwPoint[signal.GetFramesCount()][]; distanceFn = new distanceFunction(Functions.euclideanDistance); passType = PassType.Neighbors; }
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; }
/** * Computes the DTW distance between signal and pattern. * * @param pattern feature extractor object for the pattern * @param normalization normalization type (default by diagonal) * @return double DTW distance */ public double GetDistance(Extractor pattern) { return GetDistance(pattern, NormalizationType.Diagonal); }
/** * Checks whether the two extractor objects are compatible with each other. * * @param other another Extractor object * @return true, if two extractors are compatible */ public bool IsCompatible(Extractor other) { return GetType() == other.GetType() && GetParamsPerFrame() == other.GetParamsPerFrame() && GetFrameLength() == other.GetFrameLength(); }
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); }
/** * Computes the DTW distance between signal and pattern. * * @param pattern feature extractor object for the pattern * @param normalization normalization type (default by diagonal) * @return double DTW distance */ public double GetDistance(Extractor pattern) { return(GetDistance(pattern, NormalizationType.Diagonal)); }