Exemplo n.º 1
0
        public static void SetupMDataForInput(IMatrixData data, int[] columnIndx, int[] nameInd, double baseVal)
        {
            data.StringColumns            = ArrayUtils.SubList(data.StringColumns, nameInd);
            data.StringColumnNames        = ArrayUtils.SubList(data.StringColumnNames, nameInd);
            data.StringColumnDescriptions = ArrayUtils.SubList(data.StringColumnDescriptions, nameInd);

            List <int> toConvert  = new List <int>();
            List <int> numList    = new List <int>();
            int        expressInd = 0;

            foreach (int i in columnIndx)
            {
                if (i < data.ColumnCount)
                {
                    toConvert.Add(i);
                    numList.Add(data.NumericColumnCount + expressInd);
                    expressInd += 1;
                }
                else
                {
                    numList.Add(i - data.ColumnCount);
                }
            }

            int[] numArr = numList.ToArray();
            //convert expression to numeric
            data.ExtractColumns(toConvert.ToArray());
            ExpressionToNumeric(Enumerable.Range(0, data.ColumnCount).ToArray(), data);

            data.NumericColumns = ArrayUtils.SubList(data.NumericColumns, numArr);


            //change data form depending whether needed
            if (baseVal > 0)
            {
                foreach (int col in numArr)
                {
                    for (int i = 0; i < data.RowCount; i++)
                    {
                        data.NumericColumns[col][i] = Math.Pow(baseVal, data.NumericColumns[col][i]);
                    }
                }
            }

            data.NumericColumnNames        = ArrayUtils.SubList(data.NumericColumnNames, numArr);
            data.NumericColumnDescriptions = ArrayUtils.SubList(data.NumericColumnDescriptions, numArr);

            NumericToString(Enumerable.Range(0, numArr.Length).ToArray(), data);


            for (int j = 0; j < data.StringColumnCount; j++)
            {
                for (int i = 0; i < data.RowCount; i++)
                {
                    data.StringColumns[j][i] = string.Equals(data.StringColumns[j][i], "NaN") ? "NA" : data.StringColumns[j][i];
                }
            }

            //clearing irrelevant info
            data.ClearMultiNumericColumns();
            data.ClearMultiNumericRows();
            data.ClearCategoryColumns();
            data.ClearCategoryRows();
        }