Skip to content

Commit

Permalink
AdaptSynapses and JaccardSimilarity
Browse files Browse the repository at this point in the history
  • Loading branch information
sahithkumar1999 committed May 23, 2024
1 parent 3f49b3c commit 7e68920
Show file tree
Hide file tree
Showing 3 changed files with 1,341 additions and 1 deletion.
34 changes: 34 additions & 0 deletions source/NeoCortexApi/Utility/MathHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,40 @@ public static double Factorial(int n)

return fact;
}

/// <summary>
/// Calculates the Jaccard similarity coefficient between two binary arrays. This Function is used to measure
/// the similarity between the Encoded array and Reconstruced Normalize Array.
/// </summary>
/// <param name="arr1">The first binary array.</param>
/// <param name="arr2">The second binary array.</param>
/// <returns>The Jaccard similarity coefficient between the two binary arrays.</returns>
/// <exception cref="ArgumentException">Thrown when the input arrays have different lengths.</exception>

public static double JaccardSimilarityofBinaryArrays(int[] arr1, int[] arr2)
{
if (arr1.Length != arr2.Length)
{
throw new ArgumentException("Arrays must have the same length.");
}

int intersectionCount = 0;
int unionCount = 0;

for (int i = 0; i < arr1.Length; i++)
{
if (arr1[i] == 1 && arr2[i] == 1)
{
intersectionCount++;
}
if (arr1[i] == 1 || arr2[i] == 1)
{
unionCount++;
}
}

return (double)intersectionCount / unionCount;
}
}
}

Loading

0 comments on commit 7e68920

Please sign in to comment.