예제 #1
0
        public void CopyFrom(MatrixLabels labels)
        {
            if (labels == null)
            {
                throw new ArgumentNullException("labels");
            }

            if (labels.Count > Count)
            {
                throw new ArgumentOutOfRangeException("labels");
            }

            labels._labels.CopyTo(_labels, 0);
        }
예제 #2
0
        public Matrix(int rows, int cols, int networkId, string networkId_str)
        {
            if (rows <= 0)
            {
                throw new ArgumentOutOfRangeException("rows");
            }
            if (cols <= 0)
            {
                throw new ArgumentOutOfRangeException("cols");
            }

            colIsNonInteger = false;
            actualCol       = new List <string>();

            _rows      = rows;
            _cols      = cols;
            _rowLabels = new MatrixLabels(_rows);
            _colLabels = new MatrixLabels(_cols);

            /*
             * // testing stream writer
             * System.IO.Directory.CreateDirectory(tempDir);
             * TextWriter tw = new StreamWriter(tempDir + "/date.txt");
             *
             * // write a line of text to the file
             * string text = "Blah Blah Blah";
             * tw.WriteLine(text);
             * tw.WriteLine(text);
             * tw.Close();
             * System.IO.Directory.Delete(tempDir, true); // to delete recursively
             * //File.Delete("date.txt");
             */


            // need a double representation for the matrix size that can't be
            // represented by a 32-bit interger
            double tempRow    = _rows;
            double tempCol    = _cols;
            double matrixSize = tempRow * tempCol;

            outOfMemory = (matrixSize > Constants.MaxMatrixSize) ? true : false;

            if (outOfMemory)
            {
                this._count_id = (Matrix.count_id++).ToString() + "_";

                splitCount   = Algorithms.GetMinNumMultiples(Constants.MaxMatrixSize, matrixSize);
                splitRowSize = _rows / splitCount;
                if (rows % splitCount != 0)
                {
                    splitCount += 1;
                }

                _data = new double[splitRowSize * _cols];
                //currentFileUsed = 0;
                System.IO.Directory.CreateDirectory(Constants.tempDir);

                // create initialized matrices
                // need to check if file exists during a read

                for (int i = 0; i < splitCount; i++)
                {
                    TextWriter tw = new StreamWriter(Constants.tempDir + "/" +
                                                     Constants.TempMatrix + _count_id + i.ToString() + ".txt");
                    for (int row = 0; row < splitRowSize; row++)
                    {
                        string tempRows = "";
                        int    begin    = i * splitRowSize;
                        tempRows += (begin + row).ToString();
                        for (int col = 0; col < _cols; col++)
                        {
                            tempRows += " 0";
                        }
                        tw.WriteLine(tempRows);
                    }
                    tw.Close();
                }
                //currentFileUsed = 0;
                //_data = new double[_rows * _cols];
            }
            else
            {
                _data = new double[_rows * _cols];
            }

            /*
             * _data = new List<double>(_rows * _cols);
             * for (int i = 0; i < _data.Capacity; i++)
             *  _data.Add(0);
             */
            _standardization = StandardizationType.None;
            _networkId       = networkId;

            // Yushan
            _networkId_str = networkId_str;


            SetUpAverageArrays();
            currentFileUsed = 0;
        }
예제 #3
0
 public MatrixLabels(MatrixLabels matrixLabels)
 {
     _labels = new string[matrixLabels.Count];
     matrixLabels._labels.CopyTo(_labels, 0);
 }