Ejemplo n.º 1
0
        /// <summary>
        /// Combine vectors as columns to create new matrix
        /// </summary>
        /// <param name="cvecs">Column vector list</param>
        public static Matrix <double> CBind(Vector <double>[] cvecs)
        {
            var          v1  = cvecs [0];
            IIndexByName idx = (v1 is IndexedVector) ? ((IndexedVector)v1).Indices : null;

            var mat = new IndexedMatrix(v1.Count, cvecs.Length, idx, null);

            for (int ci = 0; ci < cvecs.Length; ci++)
            {
                var v = cvecs [ci];
                for (int ri = 0; ri < v1.Count; ri++)
                {
                    mat [ri, ci] = v [ri];
                }
            }

            return(mat);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the underlying matrix data
        /// </summary>
        /// <param name='m'>
        /// M.
        /// </param>
        public static double[] DataOf(Matrix <double> matrix)
        {
            IndexedMatrix imat = matrix as IndexedMatrix;

            if (imat != null)
            {
                return(imat.Data);
            }

            DenseMatrix dmat = matrix as DenseMatrix;

            if (dmat != null)
            {
                return(dmat.Values);
            }
            else
            {
                throw new ArgumentException("cannot get underlying data for matrix of type: " + matrix.GetType());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines whether indexed matrix contains a seried of quotes, based on column headers
        /// </summary>
        public static bool IsQuotes(IndexedMatrix m)
        {
            IIndexByName colnames = m.ColIndices;

            if (colnames == null)
            {
                return(false);
            }

            var ordering = colnames.Ordering;

            if (ordering.ContainsKey("bid") || ordering.ContainsKey("Bid"))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }