/**
  * 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;
 }
        /**
         * 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)));
                }
            }
        }
Exemple #3
0
		/**
		 * 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;
		}
Exemple #4
0
		/**
		 * 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)));
			}
		}
Exemple #5
0
		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);
        }