public static void CosineSimilarityKernel(
            Index index,
            ArrayView2D <int> dataset,
            ArrayView2D <double> distances)
        {
            int rows = dataset.Rows;
            int i    = index / rows;
            int j    = index % rows;

            if (i < j)
            {
                return;
            }

            double dotProduct   = 0;
            double magnitudeOne = 0;
            double magnitudeTwo = 0;

            for (int k = 0; k < dataset.Columns; k++)
            {
                dotProduct   += (dataset[i, k] * dataset[j, k]);
                magnitudeOne += (dataset[i, k] * dataset[i, k]);
                magnitudeTwo += (dataset[j, k] * dataset[j, k]);
            }
            double distance = double.NaN;
            double divisor  = GPUMath.Sqrt(magnitudeOne * magnitudeTwo);

            if (divisor != 0)
            {
                distance = GPUMath.Max(0, 1 - (dotProduct / divisor));
            }
            distances[i, j] = distance;
            distances[j, i] = distance;
        }
Exemple #2
0
 /// <summary>
 /// Computes max(first, second).
 /// </summary>
 /// <param name="first">The first argument.</param>
 /// <param name="second">The second argument.</param>
 /// <returns>The maximum of first and second value.</returns>
 public static Index3 Max(Index3 first, Index3 second)
 {
     return(new Index3(
                GPUMath.Max(first.X, second.X),
                GPUMath.Max(first.Y, second.Y),
                GPUMath.Max(first.Z, second.Z)));
 }
Exemple #3
0
 /// <summary>
 /// Computes max(first, second).
 /// </summary>
 /// <param name="first">The first argument.</param>
 /// <param name="second">The second argument.</param>
 /// <returns>The maximum of first and second value.</returns>
 public static Index Max(Index first, Index second)
 {
     return(new Index(GPUMath.Max(first.X, second.X)));
 }
Exemple #4
0
 /// <summary>
 /// Computes max(first, second).
 /// </summary>
 /// <param name="first">The first argument.</param>
 /// <param name="second">The second argument.</param>
 /// <returns>The maximum of first and second value.</returns>
 public static Index2 Max(Index2 first, Index2 second)
 {
     return(new Index2(
                GPUMath.Max(first.X, second.X),
                GPUMath.Max(first.Y, second.Y)));
 }
        public static void _V_Max(Index size, ArrayView <float> output, ArrayView <float> v, ArrayView <float> v1)
        {
            int x = size.X;

            output[x] = GPUMath.Max(v[x], v1[x]);
        }