public static double CompareActivities(ActivityRecord record, ActivityWindow window, DynamicTimeWarpingCalculationType dtwType, DynamicTimeWarpingPathTypes pathType = DynamicTimeWarpingPathTypes.Standart, bool toUseSakoeChibaBand = false, double bandWidthInProcentage = 0.1)
        {
            double similarity = 0.0f;
            double[,] DTW = new double[record.Frames.Count, window.Frames.Count];

            for (int i = 1; i < window.Frames.Count; i++)
            {
                DTW[0, i] = double.PositiveInfinity;
            }

            for (int i = 1; i < record.Frames.Count; i++)
            {
                DTW[i, 0] = double.PositiveInfinity;
            }

            DTW[0, 0] = 0;

            var windowPresentedByImportedSkeletons = new List<ImportedSkeleton>();

            foreach (var skeleton in window.Frames)
            {
                windowPresentedByImportedSkeletons.Add(new ImportedSkeleton(skeleton));
            }

            int bandWidth = (int)(windowPresentedByImportedSkeletons.Count * bandWidthInProcentage);

            if (toUseSakoeChibaBand)
            {
                for (int i = 1; i < record.Frames.Count; i++)
                {
                    for (int j = 1; j < windowPresentedByImportedSkeletons.Count; j++)
                    {
                        int currentCellOnMiddleDiagonal = (int)((j * windowPresentedByImportedSkeletons.Count) / record.Frames.Count);
                        if (j > currentCellOnMiddleDiagonal - bandWidth && j < currentCellOnMiddleDiagonal + bandWidth) // Checking if the current cell is in the range
                        {
                            similarity = SkeletonComparer.CompareWithSMIJ(record.Frames[i], windowPresentedByImportedSkeletons[j], record.MostInformativeJoints);
                            FillDTWTableCell(pathType, DTW, i, j, similarity);
                        }

                    }
                }
            }

            else //Start a DTW search without using Sakoe-Chiba band
            {
                for (int i = 1; i < record.Frames.Count; i++)
                {
                    for (int j = 1; j < windowPresentedByImportedSkeletons.Count; j++)
                    {
                        similarity = SkeletonComparer.CompareWithSMIJ(record.Frames[i], windowPresentedByImportedSkeletons[j], record.MostInformativeJoints);
                        FillDTWTableCell(pathType, DTW, i, j, similarity);
                    }

                }
            }

            return DTW[record.Frames.Count - 1, window.Frames.Count - 1] / record.MostInformativeJoints.Count;
        }
示例#2
0
        private static void FillDTWTableCell(DynamicTimeWarpingPathTypes pathType, double[,] DTW, int i, int j, double similarity)
        {
            if (pathType == DynamicTimeWarpingPathTypes.Standart)
            {
                DTW[i, j] = similarity +
                            Math.Min(
                    Math.Min(
                        DTW[i - 1, j],
                        DTW[i, j - 1]),
                    DTW[i - 1, j - 1]
                    );
            }
            else if (pathType == DynamicTimeWarpingPathTypes.AlwaysDiagonally)
            {
                if (i == 1 || j == 1)
                {
                    DTW[i, j] = similarity +
                                Math.Min(
                        Math.Min(
                            DTW[i - 1, j],
                            DTW[i, j - 1]),
                        DTW[i - 1, j - 1]
                        );
                }

                else
                {
                    DTW[i, j] = similarity +
                                Math.Min(
                        Math.Min(
                            DTW[i - 1, j - 2],
                            DTW[i - 2, j - 1]),
                        DTW[i - 1, j - 1]
                        );
                }
            }
        }
        private static void FillDTWTableCell(DynamicTimeWarpingPathTypes pathType, double[,] DTW, int i, int j, double similarity)
        {
            if (pathType == DynamicTimeWarpingPathTypes.Standart)
            {
                DTW[i, j] = similarity +
                    Math.Min(
                        Math.Min(
                        DTW[i - 1, j],
                        DTW[i, j - 1]),
                        DTW[i - 1, j - 1]
                    );
            }
            else if (pathType == DynamicTimeWarpingPathTypes.AlwaysDiagonally)
            {

                if (i == 1 || j == 1)
                {
                    DTW[i, j] = similarity +
                    Math.Min(
                        Math.Min(
                        DTW[i - 1, j],
                        DTW[i, j - 1]),
                        DTW[i - 1, j - 1]
                    );
                }

                else
                {
                    DTW[i, j] = similarity +
                    Math.Min(
                        Math.Min(
                        DTW[i - 1, j - 2],
                        DTW[i - 2, j - 1]),
                        DTW[i - 1, j - 1]
                    );
                }
            }
        }
 public double DTW(ActivityRecord record, ActivityWindow window, DynamicTimeWarpingCalculationType calcType = DynamicTimeWarpingCalculationType.Standart, DynamicTimeWarpingPathTypes stepPattern = DynamicTimeWarpingPathTypes.Standart, bool toUseSakoeChiba = true, double bandWidth = 0.1)
 {
     return (double)DynamicTimeWarping.CompareActivities(record, window, calcType, stepPattern, toUseSakoeChiba, bandWidth);
 }
示例#5
0
 public double DTW(ActivityRecord record, ActivityWindow window, DynamicTimeWarpingCalculationType calcType = DynamicTimeWarpingCalculationType.Standart, DynamicTimeWarpingPathTypes stepPattern = DynamicTimeWarpingPathTypes.Standart, bool toUseSakoeChiba = true, double bandWidth = 0.1)
 {
     return((double)DynamicTimeWarping.CompareActivities(record, window, calcType, stepPattern, toUseSakoeChiba, bandWidth));
 }
示例#6
0
        public static double CompareActivities(ActivityRecord record, ActivityWindow window, DynamicTimeWarpingCalculationType dtwType, DynamicTimeWarpingPathTypes pathType = DynamicTimeWarpingPathTypes.Standart, bool toUseSakoeChibaBand = false, double bandWidthInProcentage = 0.1)
        {
            double similarity = 0.0f;

            double[,] DTW = new double[record.Frames.Count, window.Frames.Count];

            for (int i = 1; i < window.Frames.Count; i++)
            {
                DTW[0, i] = double.PositiveInfinity;
            }

            for (int i = 1; i < record.Frames.Count; i++)
            {
                DTW[i, 0] = double.PositiveInfinity;
            }

            DTW[0, 0] = 0;

            var windowPresentedByImportedSkeletons = new List <ImportedSkeleton>();

            foreach (var skeleton in window.Frames)
            {
                windowPresentedByImportedSkeletons.Add(new ImportedSkeleton(skeleton));
            }

            int bandWidth = (int)(windowPresentedByImportedSkeletons.Count * bandWidthInProcentage);

            for (int i = 1; i < record.Frames.Count; i++)
            {
                for (int j = 1; j < windowPresentedByImportedSkeletons.Count; j++)
                {
                    if (toUseSakoeChibaBand)
                    {
                        int currentCellOnMiddleDiagonal = (int)((j * windowPresentedByImportedSkeletons.Count) / record.Frames.Count);
                        if (j > currentCellOnMiddleDiagonal - bandWidth && j < currentCellOnMiddleDiagonal + bandWidth)                         // Checking if the current cell is in the range
                        {
                            if (dtwType == DynamicTimeWarpingCalculationType.Standart)
                            {
                                similarity = SkeletonComparer.CompareWithSMIJ(record.Frames[i], windowPresentedByImportedSkeletons[j], record.MostInformativeJoints);
                            }
                            else if (dtwType == DynamicTimeWarpingCalculationType.Derivative)
                            {
                                if (i != record.Frames.Count)
                                {
                                    ImportedSkeleton mainSkeletonDerivatives      = CalculateSkeletonDerivative(record.Frames, i, record.MostInformativeJoints);
                                    ImportedSkeleton secondarySkeletonDerivatives = CalculateSkeletonDerivative(windowPresentedByImportedSkeletons, i, record.MostInformativeJoints);
                                    similarity = SkeletonComparer.CompareWithSMIJ(mainSkeletonDerivatives, secondarySkeletonDerivatives, record.MostInformativeJoints);
                                }
                            }
                        }
                    }
                    else                     //Start a DTW search without using Sakoe-Chiba band
                    {
                        if (dtwType == DynamicTimeWarpingCalculationType.Derivative)
                        {
                            if (i != record.Frames.Count)
                            {
                                ImportedSkeleton mainSkeletonDerivatives      = CalculateSkeletonDerivative(record.Frames, i, record.MostInformativeJoints);
                                ImportedSkeleton secondarySkeletonDerivatives = CalculateSkeletonDerivative(windowPresentedByImportedSkeletons, i, record.MostInformativeJoints);
                                similarity = SkeletonComparer.CompareWithSMIJ(mainSkeletonDerivatives, secondarySkeletonDerivatives, record.MostInformativeJoints);
                            }
                        }
                        else if (dtwType == DynamicTimeWarpingCalculationType.Standart)
                        {
                            similarity = SkeletonComparer.CompareWithSMIJ(record.Frames[i], windowPresentedByImportedSkeletons[j], record.MostInformativeJoints);
                        }
                    }
                    FillDTWTableCell(pathType, DTW, i, j, similarity);
                }
            }

            return(DTW[record.Frames.Count - 1, window.Frames.Count - 1] / record.MostInformativeJoints.Count);
        }