/// <summary>
        /// Creates a new instance of the Vector class.
        /// </summary>
        /// <param name="data">The array to create this vector from.</param>
        /// <returns>The new <c>Vector</c>.</returns>
        protected override Vector<float> CreateVector(IList<float> data)
        {
            var vector = new UserDefinedVector(data.Count);
            for (var index = 0; index < data.Count; index++)
            {
                vector[index] = data[index];
            }

            return vector;
        }
        /// <summary>
        /// Creates a <c>UserDefinedVector</c> with random values.
        /// </summary>
        /// <param name="order">The size of the vector.</param>
        /// <returns>A <c>UserDefinedVector</c> with the given dimension and random values.</returns>
        public static Vector GenerateRandomUserDefinedVector(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Normal
                {
                    RandomSource = new MersenneTwister(1)
                };
            var v = new UserDefinedVector(order);
            for (var i = 0; i < order; i++)
            {
                v[i] = (float) normal.Sample();
            }

            // Generate a matrix which is positive definite.
            return v;
        }
Пример #3
0
        public void CanCreateSparseVectorFromUserDefinedVector()
        {
            var vector = new UserDefinedVector(Data);
            var other = SparseVector.OfVector(vector);

            for (var i = 0; i < Data.Length; i++)
            {
                Assert.AreEqual(vector[i], other[i]);
            }
        }