Ejemplo n.º 1
0
        public static void Normalize(Vector vector)
        {
            double norm = vector.Norm;

            for (int i = 0; i < vector.m_length; i++)
            {
                vector[i] = vector[i] / norm;
            }
        }
Ejemplo n.º 2
0
 public static Vector OuterProduct(Vector left, Vector right)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 3
0
        /// <summary>Matrix-scalar multiplication.</summary>
        public static Vector Multiply(Vector left, double right)
        {
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }

            Vector r = new Vector(left.m_length);
            for (int i = 0; i < left.m_length; i++)
            {
                r[i] = left.m_data[i] * right;
            }
            return r;
        }
Ejemplo n.º 4
0
 /// <summary>Unary minus.</summary>
 public static Vector Negate(Vector value)
 {
     return Multiply(value, -1.0);
 }
Ejemplo n.º 5
0
 public bool IsOrthogonal(Vector vector)
 {
     return (this * vector) == 0;
 }
Ejemplo n.º 6
0
        /// <summary>Calculates the matrix Medians vector.</summary>
        /// <param name="m">A matrix whose deviations will be calculated.</param>
        /// <returns>Returns a vector containing the medians of the given matrix.</returns>
        public static Vector Median(Matrix value)
        {
            Vector medians = new Vector(value.Columns);

            for (int i = 0; i < value.Columns; i++)
            {
                medians[i] = Median(value.GetColumn(i));
            }

            return medians;
        }
Ejemplo n.º 7
0
 public static DoubleRange GetRange(Vector vector)
 {
     return DoubleRange.GetRange(vector.m_data);
 }
Ejemplo n.º 8
0
        /// <summary>Matrix subtraction.</summary>
        public static Vector Subtract(Vector left, Vector right)
        {
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }

            if (right == null)
            {
                throw new ArgumentNullException("right");
            }

            if (!DimensionEquals(left, right))
            {
                throw new ArgumentException("Vector dimension do not match.");
            }

            Vector r = new Vector(left.m_length);
            for (int i = 0; i < left.m_length; i++)
            {
                r.m_data[i] = left.m_data[i] - right.m_data[i];
            }
            return r;
        }
Ejemplo n.º 9
0
 public static Vector Divide(Vector left, double right)
 {
     return Multiply(left, 1.0 / right);
 }
Ejemplo n.º 10
0
        /// <summary>Determines weather two instances are equal.</summary>
        public static bool Equals(Vector left, Vector right)
        {
            if (((object)left) == ((object)right))
            {
                return true;
            }

            if ((((object)left) == null) || (((object)right) == null))
            {
                return false;
            }

            if (!DimensionEquals(left, right))
            {
                return false;
            }

            for (int i = 0; i < left.Length; i++)
            {
                    if (left[i] != right[i])
                    {
                        return false;
                }
            }

            return true;
        }
Ejemplo n.º 11
0
 /// <summary>Determines weather two instances have dimension equality.</summary>
 public static bool DimensionEquals(Vector left, Vector right)
 {
     return (left.m_length == right.m_length);
 }
Ejemplo n.º 12
0
        internal static Vector Variance(Matrix value, double[] means)
        {
            Vector variance = new Vector(value.Columns);

            for (int i = 0; i < value.Columns; i++)
            {
                //TODO: Substitute this with the complete matrix variance algorithm
                variance[i] = Variance(value.GetColumn(i), means[i]);
            }

            return variance;
        }
Ejemplo n.º 13
0
        /// <summary>Calculates the matrix Modes vector.</summary>
        /// <param name="m">A matrix whose modes will be calculated.</param>
        /// <returns>Returns a vector containing the modes of the given matrix.</returns>
        public static Vector Mode(Matrix matrix)
        {
            Vector mode = new Vector(matrix.Columns);

            for (int i = 0; i < mode.Length; i++)
            {
                mode[i] = Mode(matrix.GetColumn(i));
            }

            return mode;
        }
Ejemplo n.º 14
0
 public static Vector Pow(Vector value, double power)
 {
     return new Vector(Pow(value.baseArray, power));
 }
Ejemplo n.º 15
0
        public static double InnerProduct(Vector left, Vector right)
        {
            if (!Vector.DimensionEquals(left, right))
                throw new ArgumentException("Vector lengths does not match");

            double sum = 0.0;
            for (int i = 0; i < left.m_length; i++)
            {
                sum += left[i] * right[i];
            }
            return sum;
        }
Ejemplo n.º 16
0
 public static Vector Sqrt(Vector value)
 {
     return new Vector(Sqrt(value.baseArray));
 }
Ejemplo n.º 17
0
 public static double Max(Vector vector)
 {
     return Max(vector.baseArray);
 }
Ejemplo n.º 18
0
 /// <summary>Determines weather two instances have dimension equality.</summary>
 public bool DimensionEquals(Vector value)
 {
     return DimensionEquals(this, value);
 }
Ejemplo n.º 19
0
 public static double Min(Vector vector)
 {
     return Min(vector.baseArray);
 }
Ejemplo n.º 20
0
 public Vector(Vector vector)
 {
     this.m_data = (Double[])vector.m_data.Clone();
     this.m_length = vector.m_length;
 }
Ejemplo n.º 21
0
        /// <summary>Calculates the matrix Mean vector.</summary>
        /// <param name="m">A matrix whose means will be calculated.</param>
        /// <returns>Returns a vector containing the means of the given matrix.</returns>
        public static Vector Mean(Matrix value)
        {
            Vector mean;

            mean = new Vector(value.Columns);
            for (int j = 0; j < value.Columns; j++)
            {
                for (int i = 0; i < value.Rows; i++)
                {
                    mean[j] += value[i, j];
                }

                mean[j] = mean[j] / (double)value.Rows;
            }

            return mean;
        }