コード例 #1
0
 public void AssignRow(MathMatrix m, int r)
 {
     for (int colidx = 0; colidx < ColCount; ++colidx)
     {
         Elements[r][colidx] = m[0, colidx];
     }
 }
コード例 #2
0
 public void AssignColumn(MathMatrix m, int c)
 {
     for (int rowidx = 0; rowidx < RowCount; ++rowidx)
     {
         Elements[rowidx][c] = m[rowidx, 0];
     }
 }
コード例 #3
0
ファイル: MatrixOperations.cs プロジェクト: folnar/DACMath
        public static MathMatrix Identity(int dim)
        {
            MathMatrix retval = MathMatrix.CreateMatrix(dim, dim, 0);

            for (int idx = 0; idx < dim; ++idx)
            {
                retval[idx, idx] = 1;
            }
            return(retval);
        }
コード例 #4
0
        public MathMatrix ColumnVector(int columnindex)
        {
            MathMatrix retval = CreateMatrix(RowCount, 1);

            for (int row = 0; row < RowCount; ++row)
            {
                retval[row, 0] = Elements[row][columnindex];
            }

            return(retval);
        }
コード例 #5
0
        public MathMatrix RowVector(int rowindex)
        {
            MathMatrix retval = CreateMatrix(1, ColCount);

            for (int col = 0; col < ColCount; ++col)
            {
                retval[0, col] = Elements[rowindex][col];
            }

            return(retval);
        }
コード例 #6
0
ファイル: MatrixOperations.cs プロジェクト: folnar/DACMath
        // THE DOMAIN OF THIS FUNCTION AS OF NOW DOES NOT INCLUDE COMPLEX NUMBERS.
        public static MathMatrix Sqrt_Elmtwise(MathMatrix A)
        {
            MathMatrix sqrt = MathMatrix.CreateMatrix(A.RowCount, A.ColCount);

            for (int r = 0; r < A.RowCount; ++r)
            {
                for (int c = 0; c < A.ColCount; ++c)
                {
                    sqrt[r, c] = Math.Sqrt(A[r, c]);
                }
            }

            return(sqrt);
        }
コード例 #7
0
ファイル: MatrixOperations.cs プロジェクト: folnar/DACMath
        public static MathMatrix Transpose(MathMatrix inMatrix)
        {
            MathMatrix retval = MathMatrix.CreateMatrix(inMatrix.ColCount, inMatrix.RowCount);

            for (int m = 0; m < inMatrix.RowCount; ++m)
            {
                for (int n = 0; n < inMatrix.ColCount; ++n)
                {
                    retval[n, m] = inMatrix[m, n];
                }
            }

            return(retval);
        }
コード例 #8
0
        public static MathMatrix CreateMatrix(int r, int c, double initval)
        {
            MathMatrix mm = new MathMatrix
            {
                RowCount = r,
                ColCount = c,
                Elements = new double[r][]
            };

            for (int rowidx = 0; rowidx < r; ++rowidx)
            {
                mm.Elements[rowidx] = Enumerable.Repeat(initval, c).ToArray();
            }

            return(mm);
        }
コード例 #9
0
        public static MathMatrix CreateMatrix(int r, int c, double[] data)
        {
            MathMatrix mm = new MathMatrix
            {
                RowCount = r,
                ColCount = c,
                Elements = new double[r][]
            };

            for (int rowidx = 0; rowidx < r; ++rowidx)
            {
                mm.Elements[rowidx] = (new ArraySegment <double>(data, rowidx * c, c)).ToArray();
            }

            return(mm);
        }
コード例 #10
0
        public static MathMatrix CreateMatrix(int r, int c)
        {
            MathMatrix mm = new MathMatrix
            {
                RowCount = r,
                ColCount = c,
                Elements = new double[r][]
            };

            for (int rowidx = 0; rowidx < r; ++rowidx)
            {
                mm.Elements[rowidx] = new double[c];
            }

            return(mm);
        }
コード例 #11
0
        public static MathMatrix Normal(int count, double mu = 1, double sigmasq = 0)
        {
            MathMatrix normalvec = MathMatrix.CreateMatrix(1, count);

            for (int idx = 0; idx < count; ++idx)
            {
                Random rand          = new Random();
                double u1            = 1.0 - rand.NextDouble();
                double u2            = 1.0 - rand.NextDouble();
                double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2);
                double randNormal    = mu + Math.Sqrt(sigmasq) * randStdNormal;
                normalvec[0, idx] = randNormal;
            }

            return(normalvec);
        }
コード例 #12
0
ファイル: Sequences.cs プロジェクト: folnar/DACMath
        public static MathMatrix SteppedSequence(double begin, double end, double step)
        {
            List <decimal> seq = new List <decimal>();

            for (decimal idx = Convert.ToDecimal(begin); idx <= Convert.ToDecimal(end); idx += Convert.ToDecimal(step))
            {
                seq.Add(idx);
            }

            MathMatrix retval = MathMatrix.CreateMatrix(1, seq.Count);

            for (int idx = 0; idx < seq.Count; ++idx)
            {
                retval[0, idx] = Convert.ToDouble(seq[idx]);
            }

            return(retval);
        }
コード例 #13
0
ファイル: MatrixOperations.cs プロジェクト: folnar/DACMath
        public static MathMatrix Subtract(MathMatrix A, MathMatrix B)
        {
            if (A.RowCount != B.RowCount || A.ColCount != B.ColCount)
            {
                throw new InvalidMatrixAddDimensionsException();
            }

            MathMatrix difference = MathMatrix.CreateMatrix(A.RowCount, A.ColCount);

            for (int r = 0; r < A.RowCount; ++r)
            {
                for (int c = 0; c < B.ColCount; ++c)
                {
                    difference[r, c] = A[r, c] - B[r, c];
                }
            }

            return(difference);
        }
コード例 #14
0
ファイル: MatrixOperations.cs プロジェクト: folnar/DACMath
        public static MathMatrix Add(MathMatrix A, MathMatrix B)
        {
            if (A.RowCount != B.RowCount || A.ColCount != B.ColCount)
            {
                throw new InvalidMatrixAddDimensionsException();
            }

            MathMatrix sum = MathMatrix.CreateMatrix(A.RowCount, A.ColCount);

            for (int r = 0; r < A.RowCount; ++r)
            {
                for (int c = 0; c < B.ColCount; ++c)
                {
                    sum[r, c] = A[r, c] + B[r, c];
                }
            }

            return(sum);
        }
コード例 #15
0
ファイル: MatrixOperations.cs プロジェクト: folnar/DACMath
        public static MathMatrix Multiply(MathMatrix A, MathMatrix B)
        {
            if (A.ColCount != B.RowCount)
            {
                throw new InvalidMatrixMultiplicationDimensionsException();
            }

            MathMatrix product = MathMatrix.CreateMatrix(A.RowCount, B.ColCount, 0);

            for (int r = 0; r < A.RowCount; ++r)
            {
                for (int c = 0; c < B.ColCount; ++c)
                {
                    for (int x = 0; x < B.RowCount; ++x)
                    {
                        product[r, c] += A[r, x] * B[x, c];
                    }
                }
            }

            return(product);
        }