Пример #1
0
        public void Scale(INumberTable nTable, bool attributeMode, IList <string> itemList, double factor)
        {
            double[][]  m       = (double[][])nTable.Matrix;
            IList <int> idxList = ToIndexList(nTable, attributeMode, itemList);

            if (factor == 0)
            {
                double maxValue = double.MinValue;
                foreach (int i in idxList)
                {
                    if (attributeMode)
                    {
                        for (int row = 0; row < nTable.Rows; row++)
                        {
                            maxValue = Math.Max(maxValue, m[row][i]);
                        }
                    }
                    else
                    {
                        for (int col = 0; col < nTable.Columns; col++)
                        {
                            maxValue = Math.Max(maxValue, m[i][col]);
                        }
                    }
                }

                if (maxValue != 0)
                {
                    factor = Math.Abs(nTable.MaximumValue()) / Math.Abs(maxValue);
                }
            }

            foreach (int i in idxList)
            {
                if (attributeMode)
                {
                    for (int row = 0; row < nTable.Rows; row++)
                    {
                        m[row][i] *= factor;
                    }
                }
                else
                {
                    for (int col = 0; col < nTable.Columns; col++)
                    {
                        m[i][col] *= factor;
                    }
                }
            }
        }