Beispiel #1
0
        public MatrisBase <object> Head(MatrisBase <object> df,
                                        int n = 5)
        {
            if (!df.IsValid())
            {
                throw new Exception(CompilerMessage.DF_INVALID_SIZE);
            }

            n = Math.Min(n, df.Row);
            if (n <= 0 || df.Row < n)
            {
                throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("satır", 1, df.Row));
            }

            return(df.Row == n
                ? df is Dataframe ? ((Dataframe)df.Copy()) : df.Copy()
                : df is Dataframe dataframe
                    ? new Dataframe(dataframe[new Range(0, n)],
                                    dataframe.Delimiter,
                                    dataframe.NewLine,
                                    null,
                                    Dataframe.GetCopyOfLabels(dataframe.GetColLabels()),
                                    dataframe.GetRowSettings().Copy(),
                                    dataframe.GetColSettings().Copy())
                    : new MatrisBase <object>(df[new Range(0, n)]));
        }
Beispiel #2
0
        public MatrisBase <object> Set(MatrisBase <object> A,
                                       int i,
                                       int j,
                                       float value,
                                       int based = 0)
        {
            if (!A.IsValid())
            {
                throw new Exception(CompilerMessage.MAT_INVALID_SIZE);
            }
            if (i - based < 0 || i - based >= A.Row)
            {
                throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("satır", based, A.Row - 1));
            }
            if (j - based < 0 || j - based >= A.Col)
            {
                throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("sütun", based, A.Col - 1));
            }

            List <List <object> > newlis = A is Dataframe ? ((Dataframe)A.Copy()).GetValues() : A.Copy().GetValues();

            newlis[i - based][j - based] = (dynamic)value;

            return(A is Dataframe df
                ? new Dataframe(newlis,
                                df.Delimiter,
                                df.NewLine,
                                Dataframe.GetCopyOfLabels(df.GetRowLabels()),
                                Dataframe.GetCopyOfLabels(df.GetColLabels()),
                                df.GetRowSettings().Copy(),
                                df.GetColSettings().Copy())
                : new MatrisBase <object>(newlis));
        }
Beispiel #3
0
 public MatrisBase <object> Get(MatrisBase <object> A,
                                int i,
                                int j,
                                int based = 0)
 {
     return(!A.IsValid()
         ? throw new Exception(CompilerMessage.MAT_INVALID_SIZE)
         : i - based < 0 || i - based >= A.Row
         ? throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("satır", based, A.Row - 1))
         : j - based < 0 || j - based >= A.Col
         ? throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("sütun", based, A.Col - 1))
         : A is Dataframe df
             ? new Dataframe(new List <List <object> >()
     {
         new List <object>()
         {
             A[r: i - based, c: j - based]
         }
     },
                             df.Delimiter,
                             df.NewLine,
                             null,
                             null,
                             df.GetRowSettings().Copy(),
                             df.GetColSettings().Copy())
             : new MatrisBase <object>(new List <List <object> >()
     {
         new List <object>()
         {
             A[r: i - based, c: j - based]
         }
     }));
 }
Beispiel #4
0
        public MatrisBase <object> MinorMatris(MatrisBase <object> A,
                                               int row,
                                               int col,
                                               int based = 0)
        {
            if (!A.IsSquare())
            {
                throw new Exception(CompilerMessage.MAT_NOT_SQUARE);
            }

            CompilerUtils.AssertMatrixValsAreNumbers(A);

            List <List <object> > newlis = new List <List <object> >();
            List <List <object> > vals   = A.GetValues();

            row -= based;
            col -= based;

            if (row < 0 || row >= A.Row)
            {
                throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("satır", based, A.Row - based));
            }

            if (col < 0 || col >= A.Col)
            {
                throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("sütun", based, A.Col - based));
            }

            int rowindex = 0;

            for (int i = 0; i < row; i++)
            {
                newlis.Add(new List <object>());
                for (int j = 0; j < col; j++)
                {
                    newlis[rowindex].Add(vals[i][j]);
                }
                for (int j = col + 1; j < A.Col; j++)
                {
                    newlis[rowindex].Add(vals[i][j]);
                }
                rowindex++;
            }

            for (int i = row + 1; i < A.Row; i++)
            {
                newlis.Add(new List <object>());
                for (int j = 0; j < col; j++)
                {
                    newlis[rowindex].Add(vals[i][j]);
                }
                for (int j = col + 1; j < A.Col; j++)
                {
                    newlis[rowindex].Add(vals[i][j]);
                }
                rowindex++;
            }

            return(new MatrisBase <object>(newlis));
        }
Beispiel #5
0
 public MatrisBase <object> Col(MatrisBase <object> A,
                                int j,
                                int based = 0)
 {
     return(!A.IsValid()
         ? throw new Exception(CompilerMessage.MAT_INVALID_SIZE)
         : j - based < 0 || j - based >= A.Col
         ? throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("sütun", based, A.Col - 1))
         : A.ColMat(j, based));
 }
Beispiel #6
0
 public MatrisBase <object> Row(MatrisBase <object> A,
                                int i,
                                int based = 0)
 {
     return(!A.IsValid()
         ? throw new Exception(CompilerMessage.MAT_INVALID_SIZE)
         : i - based < 0 || i - based >= A.Row
         ? throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("satır", based, A.Row - 1))
         : A.RowMat(i, based));
 }
Beispiel #7
0
        public MatrisBase <object> Sample(MatrisBase <object> df,
                                          int n = 5)
        {
            if (!df.IsValid())
            {
                throw new Exception(CompilerMessage.DF_INVALID_SIZE);
            }

            int nr = df.Row;

            n = Math.Min(n, nr);
            if (n <= 0 || nr < n)
            {
                throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("satır", 1, nr));
            }

            if (nr == n)
            {
                return(df is Dataframe ? ((Dataframe)df.Copy()) : df.Copy());
            }
            else
            {
                List <List <object> > newList = new List <List <object> >();

                List <List <object> > shuffled = new MatrisArithmeticService().Shuffle(df, 0).GetValues();

                for (int i = 0; i < n; i++)
                {
                    newList.Add(shuffled[i]);
                }

                return(df is Dataframe dataframe
                    ? new Dataframe(newList,
                                    dataframe.Delimiter,
                                    dataframe.NewLine,
                                    null,
                                    Dataframe.GetCopyOfLabels(dataframe.GetColLabels()),
                                    dataframe.GetRowSettings().Copy(),
                                    dataframe.GetColSettings().Copy()
                                    )
                    : new MatrisBase <object>(newList));
            }
        }
Beispiel #8
0
        public MatrisBase <object> Sub(MatrisBase <object> A,
                                       int r1,
                                       int r2,
                                       int c1,
                                       int c2,
                                       int based = 0)
        {
            if (!A.IsValid())
            {
                throw new Exception(CompilerMessage.MAT_INVALID_SIZE);
            }

            r1 -= based;
            r2 -= based;
            if (r2 <= r1 || r1 < 0)
            {
                throw new Exception(CompilerMessage.MAT_INVALID_ROW_INDICES);
            }

            c1 -= based;
            c2 -= based;
            if (c2 <= c1 || c1 < 0)
            {
                throw new Exception(CompilerMessage.MAT_INVALID_COL_INDICES);
            }

            return(r2 > A.Row
                ? throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("satır", based, A.Row - 1))
                : c2 > A.Col
                ? throw new Exception(CompilerMessage.MAT_OUT_OF_RANGE_INDEX("sütun", based, A.Col - 1))
                : A is Dataframe df
                ? new Dataframe(A[new Range(r1, r2), new Range(c1, c2)],
                                df.Delimiter,
                                df.NewLine,
                                null,
                                null,
                                df.GetRowSettings().Copy(),
                                df.GetColSettings().Copy())
                : new MatrisBase <object>(A[new Range(r1, r2), new Range(c1, c2)]));
        }