Esempio n. 1
0
 public override BaseVector Plus(BaseVector other)
 {
     double[] result = (double[])values.Clone();
     for (int i = 0; i < other.Length; i++)
     {
         result[i] += other[i];
     }
     return(new DoubleArrayVector(result));
 }
Esempio n. 2
0
 public override double SumSquaredDiffs(BaseVector y)
 {
     if (y is SparseFloatVector)
     {
         return(SparseFloatVector.SumSquaredDiffs(this, (SparseFloatVector)y));
     }
     if (y is DoubleArrayVector)
     {
         return(SumSquaredDiffs(this, (DoubleArrayVector)y));
     }
     if (y is BoolArrayVector)
     {
         return(BoolArrayVector.SumSquaredDiffs((BoolArrayVector)y, this));
     }
     return(SumSquaredDiffs(this, (FloatArrayVector)y));
 }
Esempio n. 3
0
 public override BaseVector Plus(BaseVector other)
 {
     if (other is DoubleArrayVector)
     {
         double[] result = new double[values.Length];
         for (int i = 0; i < result.Length; i++)
         {
             result[i] = values[i] + other[i];
         }
         return(new DoubleArrayVector(result));
     }
     float[] result1 = (float[])values.Clone();
     for (int i = 0; i < other.Length; i++)
     {
         result1[i] += (float)other[i];
     }
     return(new FloatArrayVector(result1));
 }
Esempio n. 4
0
 public override double Dot(BaseVector y)
 {
     if (y is SparseBoolVector)
     {
         return(Dot((SparseBoolVector)y, this));
     }
     if (y is FloatArrayVector)
     {
         return(Dot((FloatArrayVector)y, this));
     }
     if (y is DoubleArrayVector)
     {
         return(Dot((DoubleArrayVector)y, this));
     }
     if (y is BoolArrayVector)
     {
         return(Dot((BoolArrayVector)y, this));
     }
     return(Dot(this, (SparseFloatVector)y));
 }
Esempio n. 5
0
 public override BaseVector Minus(BaseVector other)
 {
     if (other is DoubleArrayVector)
     {
         double[] result = new double[Length];
         for (int i = 0; i < Length; i++)
         {
             if (this[i] == 1)
             {
                 result[i] = 1;
             }
             result[i] -= other[i];
         }
         return(new DoubleArrayVector(result));
     }
     if (other is FloatArrayVector)
     {
         float[] result = new float[Length];
         for (int i = 0; i < Length; i++)
         {
             if (this[i] == 1)
             {
                 result[i] = 1;
             }
             result[i] -= (float)other[i];
         }
         return(new FloatArrayVector(result));
     }
     if (other is BoolArrayVector)
     {
         float[] result = new float[Length];
         for (int i = 0; i < Length; i++)
         {
             if (this[i] == 1)
             {
                 result[i] = 1;
             }
             result[i] -= (float)other[i];
         }
         return(new FloatArrayVector(result));
     }
     if (other is SparseFloatVector)
     {
         float[] result = new float[Length];
         for (int i = 0; i < Length; i++)
         {
             if (this[i] == 1)
             {
                 result[i] = 1;
             }
             result[i] -= (float)other[i];
         }
         return(new FloatArrayVector(result));
     }
     if (other is SparseBoolVector)
     {
         float[] result = new float[Length];
         for (int i = 0; i < Length; i++)
         {
             if (this[i] == 1)
             {
                 result[i] = 1;
             }
             result[i] -= (float)other[i];
         }
         return(new FloatArrayVector(result));
     }
     throw new Exception("Never get here.");
 }
Esempio n. 6
0
 public override BaseVector Minus(BaseVector other)
 {
     if (other is DoubleArrayVector)
     {
         double[] result = new double[other.Length];
         for (int i = 0; i < result.Length; i++)
         {
             result[i] = -other[i];
         }
         for (int i = 0; i < indices.Length; i++)
         {
             result[indices[i]] += values[i];
         }
         return(new DoubleArrayVector(result));
     }
     if (other is FloatArrayVector)
     {
         float[] result = new float[other.Length];
         for (int i = 0; i < result.Length; i++)
         {
             result[i] = -(float)other[i];
         }
         for (int i = 0; i < indices.Length; i++)
         {
             result[indices[i]] += values[i];
         }
         return(new FloatArrayVector(result));
     }
     if (other is BoolArrayVector)
     {
         float[] result = new float[length];
         for (int i = 0; i < indices.Length; i++)
         {
             result[indices[i]] = values[i];
         }
         BoolArrayVector b = (BoolArrayVector)other;
         for (int i = 0; i < length; i++)
         {
             if (b.values[i])
             {
                 result[i]--;
             }
         }
     }
     if (other is SparseFloatVector)
     {
         SparseFloatVector o          = (SparseFloatVector)other;
         int[]             newIndices = ArrayUtils.UniqueValues(ArrayUtils.Concat(indices, o.indices));
         float[]           newValues  = new float[newIndices.Length];
         for (int i = 0; i < newValues.Length; i++)
         {
             int ind1 = Array.BinarySearch(indices, newIndices[i]);
             if (ind1 >= 0)
             {
                 newValues[i] += values[ind1];
             }
             int ind2 = Array.BinarySearch(o.indices, newIndices[i]);
             if (ind2 >= 0)
             {
                 newValues[i] -= o.values[ind2];
             }
         }
         return(new SparseFloatVector(newIndices, newValues, length));
     }
     if (other is SparseBoolVector)
     {
         SparseBoolVector o          = (SparseBoolVector)other;
         int[]            newIndices = ArrayUtils.UniqueValues(ArrayUtils.Concat(indices, o.indices));
         float[]          newValues  = new float[newIndices.Length];
         for (int i = 0; i < newValues.Length; i++)
         {
             int ind1 = Array.BinarySearch(indices, newIndices[i]);
             if (ind1 >= 0)
             {
                 newValues[i] += values[ind1];
             }
             int ind2 = Array.BinarySearch(o.indices, newIndices[i]);
             if (ind2 >= 0)
             {
                 newValues[i]--;
             }
         }
         return(new SparseFloatVector(newIndices, newValues, length));
     }
     throw new Exception("Never get here.");
 }
Esempio n. 7
0
 /// <summary>
 /// Determines the sum of squared differences of this vector with another one passed as the argument.
 /// </summary>
 public abstract double SumSquaredDiffs(BaseVector y1);
Esempio n. 8
0
 /// <summary>
 /// Calculates this vector plus the other.
 /// </summary>
 public abstract BaseVector Plus(BaseVector other);
Esempio n. 9
0
 /// <summary>
 /// Calculates this vector minus the other.
 /// </summary>
 public abstract BaseVector Minus(BaseVector other);
Esempio n. 10
0
 /// <summary>
 /// Determines the scalar product of this vector with another one passed as the argument.
 /// </summary>
 public abstract double Dot(BaseVector vec);