Exemplo n.º 1
0
        public Matrix ReadNext(bool overwrite)
        {
            Matrix m = null;

            switch (_type)
            {
            case Type.MatrixFile:
                m = MatrixReader.ReadMatrixFromFile(_sourceFile, _networkId);
                break;

            case Type.VectorFile:
                m = MatrixReader.ReadVectorFromFile(_sourceFile, _networkId);
                break;

            case Type.RandomDiagonal:
                m           = RandomMatrix.LoadDiagonal(_rows, true);
                m.NetworkId = _networkId;
                break;

            case Type.RandomSymmetric:
                m           = RandomMatrix.LoadSymmetric(_rows, range, pmin, pmax);
                m.NetworkId = _networkId;
                break;

            case Type.RandomNonSymmetric:
                m           = RandomMatrix.LoadNonSymmetric(_rows, range, pmin, pmax);
                m.NetworkId = _networkId;
                break;

            case Type.RandomVector:
                m           = RandomMatrix.LoadVector(_rows);
                m.NetworkId = _networkId;
                break;

            case Type.RandomWithProbRange:
                m           = RandomMatrix.LoadWithProbabilisticRange(_rows, _cols, _min, _max);
                m.NetworkId = _networkId;
                break;

            case Type.NullFile:
                return(null);
            }

            _networkId = m.NetworkId + 1;

            if (!string.IsNullOrEmpty(_outputFile) && _type != Type.NullFile)
            {
                WriteMatrixToFile(m, _isdyadic, overwrite);
            }

            /*
             * if (m.NetworkId < 1000)
             *  m.NetworkId = int.Parse("1" + m.NetworkId);
             */
            //else
            //  m.NetworkId = int.Parse("2" + m.NetworkId);
            //m.NetworkId = int.Parse("1" + m.NetworkId);
            return(m);
        }
Exemplo n.º 2
0
        public static Vector EigenvectorCentrality(Matrix m)
        {
            Vector v = RandomMatrix.LoadRealUnitVector(m.Rows);

            v.Labels.CopyFrom(m.RowLabels);

            int numIter = Math.Max(Constants.MinimumNumberOfConvergenceSteps, m.Rows);

            while (numIter-- > 0)
            {
                v = m * v;
                v.Normalize();
            }

            for (int i = 0; i < v.Size; ++i)
            {
                v[i] *= 100.0 * Math.Sqrt(2);
            }

            return(v);
        }