コード例 #1
0
ファイル: Similarity.cs プロジェクト: GH0S1R33P0R/SimFinder
        /// <summary>
        /// Method to determine the MCD value between two tickets
        /// MCD(A,B) = max(|c(AB)-c(AA)|, |c(AB)-c(BB)|)/max(c(AA),c(BB))
        /// </summary>
        /// <param name="entity1">ICompressible ticket to operate MCD on</param>
        /// <param name="entity2">ICompressible ticket to operate MCD on</param>
        /// <returns>Double value representing the MCD value between the two tickets</returns>
        private double getMCD(ICompressible entity1, ICompressible entity2)
        {
            double MCD_numerator;
            double MCD_result;

            // Create two StringCompressible objects of the entities concatenated to themselves
            ICompressible AA = new StringCompressible (Encoding.ASCII.GetString(entity1.ToByteArray().Concat(entity1.ToByteArray()).ToArray()));
            ICompressible BB = new StringCompressible (Encoding.ASCII.GetString(entity2.ToByteArray().Concat(entity2.ToByteArray()).ToArray()));

            // Find c(AA) and c(BB)
            double MCD_AA = (double) GetComplexity(AA);
            double MCD_BB = (double) GetComplexity(BB);

            // Find c(AB)
            byte[] combinedArray = entity1.ToByteArray().Concat(entity2.ToByteArray()).ToArray();
            double MCD_AB = (double)compressionSize(combinedArray);

            // Find max( |c(AB)-c(AA)|, |c(AB)-c(BB)|)
            if (Math.Abs(MCD_AB - MCD_AA) >= Math.Abs(MCD_AB - MCD_BB))
            {
                MCD_numerator = Math.Abs(MCD_AB - MCD_AA);
            }
            else
            {
                MCD_numerator = Math.Abs(MCD_AB - MCD_BB);
            }

            // Find MCD(A,B)
            if (MCD_AA >= MCD_BB)
            {
                MCD_result = (MCD_numerator / MCD_AA);
            }
            else
            {
                MCD_result = (MCD_numerator / MCD_BB);
            }

            return MCD_result;
        }
コード例 #2
0
ファイル: Similarity.cs プロジェクト: GH0S1R33P0R/SimFinder
        /// <summary>
        /// Method to determine the NCD value between two tickets (ICompressible objects)
        /// NCD(x,y) = {Z(xy) - min[Z(x), Z(y)]} / max[Z(x), Z(y)]
        /// </summary>
        /// <param name="entity1">ICompressible ticket to operate NCD on</param>
        /// <param name="entity2">ICompressible ticket to operate NCD on</param>
        /// <returns>Double value representing the NCD value between the two tickets</returns>
        private double getNCD(ICompressible entity1, ICompressible entity2)
        {
            // Compress the tickets
            int compressedEntity1 = GetComplexity(entity1);
            int compressedEntity2 = GetComplexity(entity2);

            // Concatenate the tickets
            byte[] combinedArray = entity1.ToByteArray().Concat(entity2.ToByteArray()).ToArray();

            // NCD_A = compressed size of the two tickets concatenated
            double NCD_A = (double) compressionSize(combinedArray);

            // NCD_B = min(compressed size of ticket 1, compressed size of ticket 2)
            // NCD_C = max(compressed size of ticket 1, compressed size of ticket 2)
            double NCD_B, NCD_C;

            // Determine the values of NCD_B and NCD_C
            if (compressedEntity1 >= compressedEntity2)
            {
                NCD_B = (double) compressedEntity2;
                NCD_C = (double) compressedEntity1;
            }
            else
            {
                NCD_B = (double) compressedEntity1;
                NCD_C = (double) compressedEntity2;
            }

            // Compute and return the NCD value
            double NCD_result = (NCD_A - NCD_B) / NCD_C;
            return NCD_result;
        }
コード例 #3
0
ファイル: Similarity.cs プロジェクト: GH0S1R33P0R/SimFinder
        // Returns the size of the compressed ticket
        public int GetComplexity(ICompressible entity)
        {
            // Return the complexity of the ticket if its been set (i.e. not zero)
            if (entity.Complexity != 0)
            {
                return entity.Complexity;
            }

            // Set the complexity of the ticket for later use
            entity.Complexity = compressionSize(entity.ToByteArray());

            return entity.Complexity;
        }