Esempio n. 1
0
        internal static double Dot(FloatArrayVector x, SparseBoolVector y)
        {
            double sum  = 0;
            int    xlen = x.Length;
            int    ylen = y.indices.Length;
            int    i    = 0;
            int    j    = 0;

            while (i < xlen && j < ylen)
            {
                if (i == y.indices[j])
                {
                    j++;
                    sum += x.values[i++];
                }
                else
                {
                    if (i > y.indices[j])
                    {
                        ++j;
                    }
                    else
                    {
                        ++i;
                    }
                }
            }
            return(sum);
        }
Esempio n. 2
0
        internal static double Dot(FloatArrayVector x, DoubleArrayVector y)
        {
            double sum = 0;

            for (int i = 0; i < x.Length; i++)
            {
                sum += x.values[i] * y.values[i];
            }
            return(sum);
        }
Esempio n. 3
0
        internal static double SumSquaredDiffs(FloatArrayVector x, DoubleArrayVector y)
        {
            double sum = 0;

            for (int i = 0; i < x.Length; i++)
            {
                double d = x.values[i] - y.values[i];
                sum += d * d;
            }
            return(sum);
        }
Esempio n. 4
0
        internal static double Dot(BoolArrayVector x, FloatArrayVector y)
        {
            double sum = 0;

            for (int i = 0; i < x.Length; i++)
            {
                if (x.values[i])
                {
                    sum += y.values[i];
                }
            }
            return(sum);
        }
Esempio n. 5
0
        internal static double SumSquaredDiffs(BoolArrayVector x, FloatArrayVector y)
        {
            double sum = 0;

            for (int i = 0; i < x.Length; i++)
            {
                double d = y.values[i];
                if (x.values[i])
                {
                    d -= 1;
                }
                sum += d * d;
            }
            return(sum);
        }
Esempio n. 6
0
 public override double SumSquaredDiffs(BaseVector y)
 {
     if (y is SparseFloatVector)
     {
         return(SparseFloatVector.SumSquaredDiffs(this, (SparseFloatVector)y));
     }
     if (y is FloatArrayVector)
     {
         return(FloatArrayVector.SumSquaredDiffs((FloatArrayVector)y, this));
     }
     if (y is BoolArrayVector)
     {
         return(BoolArrayVector.SumSquaredDiffs((BoolArrayVector)y, this));
     }
     return(SumSquaredDiffs(this, (DoubleArrayVector)y));
 }
Esempio n. 7
0
 public override double Dot(BaseVector y)
 {
     if (y is SparseFloatVector)
     {
         return(SparseFloatVector.Dot(this, (SparseFloatVector)y));
     }
     if (y is SparseBoolVector)
     {
         return(SparseBoolVector.Dot(this, (SparseBoolVector)y));
     }
     if (y is FloatArrayVector)
     {
         return(FloatArrayVector.Dot((FloatArrayVector)y, this));
     }
     if (y is BoolArrayVector)
     {
         return(BoolArrayVector.Dot((BoolArrayVector)y, this));
     }
     return(Dot(this, (DoubleArrayVector)y));
 }
Esempio n. 8
0
        internal static double SumSquaredDiffs(FloatArrayVector x, SparseBoolVector y)
        {
            double sum  = 0;
            int    xlen = x.Length;
            int    ylen = y.indices.Length;
            int    i    = 0;
            int    j    = 0;

            while (i < xlen && j < ylen)
            {
                if (i == y.indices[j])
                {
                    double d = x.values[i++] - 1;
                    j++;
                    sum += d * d;
                }
                else if (i > y.indices[j])
                {
                    sum += 1;
                    ++j;
                }
                else
                {
                    sum += x.values[i] * x.values[i];
                    ++i;
                }
            }
            while (i < xlen)
            {
                sum += x.values[i] * x.values[i];
                ++i;
            }
            while (j < ylen)
            {
                sum += 1;
                ++j;
            }
            return(sum);
        }