示例#1
0
        internal static double Dot(FloatArrayVector x, SparseVector y)
        {
            double sum  = 0;
            int    xlen = x.Length;
            int    ylen = y.Length;
            int    i    = 0;
            int    j    = 0;

            while (i < xlen && j < ylen)
            {
                if (i == y.indices[j])
                {
                    sum += x.values[i++] * y.values[j++];
                }
                else
                {
                    if (i > y.indices[j])
                    {
                        ++j;
                    }
                    else
                    {
                        ++i;
                    }
                }
            }
            return(sum);
        }
 internal static double Dot(FloatArrayVector x, FloatArrayVector y)
 {
     double sum = 0;
     for (int i = 0; i < x.Length; i++) {
         sum += x.values[i] * y.values[i];
     }
     return sum;
 }
示例#3
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);
        }
示例#4
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);
        }
 public override double SumSquaredDiffs(BaseVector y)
 {
     if ((y is SparseVector))
     {
         return(SparseVector.SumSquaredDiffs(this, (SparseVector)y));
     }
     if ((y is FloatArrayVector))
     {
         return(FloatArrayVector.SumSquaredDiffs((FloatArrayVector)y, this));
     }
     return(SumSquaredDiffs(this, (DoubleArrayVector)y));
 }
 public override double Dot(BaseVector y)
 {
     if ((y is SparseVector))
     {
         return(SparseVector.Dot(this, (SparseVector)y));
     }
     if ((y is FloatArrayVector))
     {
         return(FloatArrayVector.Dot((FloatArrayVector)y, this));
     }
     return(Dot(this, (DoubleArrayVector)y));
 }
示例#7
0
        internal static double SumSquaredDiffs(FloatArrayVector x, SparseVector y)
        {
            double sum  = 0;
            int    xlen = x.Length;
            int    ylen = y.Length;
            int    i    = 0;
            int    j    = 0;

            while (i < xlen && j < ylen)
            {
                if (i == y.indices[j])
                {
                    double d = x.values[i++] - y.values[j++];
                    sum += d * d;
                }
                else if (i > y.indices[j])
                {
                    sum += y.values[j] * y.values[j];
                    ++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 += y.values[j] * y.values[j];
                ++j;
            }
            return(sum);
        }
 internal static double SumSquaredDiffs(FloatArrayVector x, FloatArrayVector 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;
 }
示例#9
0
 internal static double SumSquaredDiffs(FloatArrayVector x, SparseVector y)
 {
     double sum = 0;
     int xlen = x.Length;
     int ylen = y.Length;
     int i = 0;
     int j = 0;
     while (i < xlen && j < ylen){
         if (i == y.indices[j]){
             double d = x.values[i++] - y.values[j++];
             sum += d*d;
         } else if (i > y.indices[j]){
             sum += y.values[j]*y.values[j];
             ++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 += y.values[j]*y.values[j];
         ++j;
     }
     return sum;
 }
示例#10
0
 internal static double Dot(FloatArrayVector x, SparseVector y)
 {
     double sum = 0;
     int xlen = x.Length;
     int ylen = y.Length;
     int i = 0;
     int j = 0;
     while (i < xlen && j < ylen){
         if (i == y.indices[j]){
             sum += x.values[i++]*y.values[j++];
         } else{
             if (i > y.indices[j]){
                 ++j;
             } else{
                 ++i;
             }
         }
     }
     return sum;
 }