public AdjacencyMatrix getMatrixIdentityComplement()
        {
            Matrix <double>     matrix       = this.getMatrix();
            MatrixCoordinateMap newClassMap1 = this.getClassMap1();
            MatrixCoordinateMap newClassMap2 = this.getClassMap2();

            int size  = matrix.RowCount;
            int size2 = matrix.ColumnCount;

            if (size != size2)
            {
                Console.WriteLine("row=" + size + ",col=" + size2);
            }

            Matrix <double> matrixIdentityComplement = matrix.Clone();

            double valueOriginal = 0.0;
            double valueReplace  = 0.0;

            for (int i = 0; i < size; i++)
            {
                valueOriginal = matrixIdentityComplement.At(i, i);
                valueReplace  = 1 - valueOriginal;
                matrixIdentityComplement.At(i, i, valueReplace);
            }

            return(new AdjacencyMatrix(newClassMap1, newClassMap2, matrixIdentityComplement));
        }
 public AdjacencyMatrix(MatrixCoordinateMap classMap, string pathLibrary, string pathInput, bool isOneDimension)
 {
     setClassMap1(classMap);
     setIsOneDimension(isOneDimension);
     IO.createMatrixMarketFile(pathLibrary, pathInput, ' ', classMap, isOneDimension);
     setMatrix(IO.createMatrixFromMatrixMarketFile(pathInput));
 }
        public AdjacencyMatrix getPseudoInverseDiagonal()
        {
            Matrix <double>     matrix       = this.getMatrix();
            MatrixCoordinateMap newClassMap1 = this.getClassMap1();
            MatrixCoordinateMap newClassMap2 = this.getClassMap2();

            int size  = matrix.ColumnCount;
            int size2 = matrix.ColumnCount;

            if (size != size2)
            {
                Console.WriteLine("row=" + size + ",col=" + size2);
            }

            Matrix <double> matrixPseudoInverseDiagonal = matrix.Clone();

            for (int i = 0; i < size; i++)
            {
                double valueOriginal = matrixPseudoInverseDiagonal.At(i, i);
                double valueReplace  = 0;
                if (valueOriginal != 0)
                {
                    valueReplace = 1 / valueOriginal;
                }

                matrixPseudoInverseDiagonal.At(i, i, valueReplace);
            }

            return(new AdjacencyMatrix(newClassMap1, newClassMap2, matrixPseudoInverseDiagonal));
        }
        public AdjacencyMatrix getMatrixColumnVectorSum()
        {
            Matrix <double>     matrix       = this.getMatrix();
            MatrixCoordinateMap newClassMap1 = this.getClassMap1();
            MatrixCoordinateMap newClassMap2 = this.getClassMap2();

            int             size = matrix.ColumnCount;
            Matrix <double> matrixColumnVectorSum = Matrix <double> .Build.SparseIdentity(size);

            for (int j = 0; j < size; j++)
            {
                Vector <double> vector    = matrix.Column(j);
                double          vectorSum = vector.Sum();

                if (vectorSum > 0)
                {
                    matrixColumnVectorSum.At(j, j, 1);
                }
                else
                {
                    matrixColumnVectorSum.At(j, j, 0);
                }
            }

            return(new AdjacencyMatrix(newClassMap1, newClassMap2, matrixColumnVectorSum));
        }
 public AdjacencyMatrix(MatrixCoordinateMap classMap1, MatrixCoordinateMap classMap2, string pathLibrary, string pathInput)
 {
     setClassMap1(classMap1);
     setClassMap2(classMap2);
     setIsOneDimension(false);
     IO.createMatrixMarketFile(pathLibrary, pathInput, ' ', classMap1, classMap2);
     setMatrix(IO.createMatrixFromMatrixMarketFile(pathInput));
 }
        public AdjacencyMatrix transpose()
        {
            Matrix <double>     matrix       = this.getMatrix();
            MatrixCoordinateMap newClassMap1 = this.getClassMap1();
            MatrixCoordinateMap newClassMap2 = this.getClassMap2();

            Matrix <double> matrixTransposed = matrix.Transpose();

            return(new AdjacencyMatrix(newClassMap2, newClassMap1, matrixTransposed));
        }
        public AdjacencyMatrix computeAdjacencyMatrixAddition(AdjacencyMatrix aMatrix2)
        {
            Matrix <double> matrix1 = this.getMatrix();
            Matrix <double> matrix2 = aMatrix2.getMatrix();
            Matrix <double> matrix  = matrix1.Add(matrix2);

            MatrixCoordinateMap newClassMap1 = this.getClassMap1();
            MatrixCoordinateMap newClassMap2 = aMatrix2.getClassMap2();

            return(new AdjacencyMatrix(newClassMap1, newClassMap2, matrix));
        }
        public AdjacencyMatrix computeAdjacencyMatrixProduct(AdjacencyMatrix aMatrix2)
        {
            Matrix <double> matrix1 = this.getMatrix();
            Matrix <double> matrix2 = aMatrix2.getMatrix();

            Matrix <double> matrix = matrix1.Multiply(matrix2);

            MatrixCoordinateMap newClassMap1 = this.getClassMap1();
            MatrixCoordinateMap newClassMap2 = aMatrix2.getClassMap2();

            return(new AdjacencyMatrix(newClassMap1, newClassMap2, matrix));
        }
Exemplo n.º 9
0
        public MatrixCoordinateMap copyAndReverseMap()
        {
            MatrixCoordinateMap newMap = new MatrixCoordinateMap();

            newMap.hashMap = new ConcurrentDictionary <string, string>();

            ConcurrentDictionary <string, string> oldHashMap = this.getHashMap();

            foreach (var entry in oldHashMap)
            {
                newMap.setHashMap(entry.Value, entry.Key);
            }

            return(newMap);
        }
Exemplo n.º 10
0
        public void copyCoordinateToLabelMatrixMarketFile(string pathOutputCoordinate, string pathOutputLabel)
        {
            MatrixCoordinateMap classMap1 = this.getClassMap1();
            MatrixCoordinateMap classMap2 = this.getClassMap2();
            bool isOneDimension           = this.getIsOneDimension();

            if (isOneDimension)
            {
                MatrixCoordinateMap classMapReverse1 = classMap1.copyAndReverseMap();
                IO.createMatrixMarketFile(pathOutputCoordinate, pathOutputLabel, ' ', classMapReverse1, isOneDimension);
            }
            else
            {
                MatrixCoordinateMap classMapReverse1 = classMap1.copyAndReverseMap();
                MatrixCoordinateMap classMapReverse2 = classMap2.copyAndReverseMap();
                IO.createMatrixMarketFile(pathOutputCoordinate, pathOutputLabel, ' ', classMapReverse1, classMapReverse2);
            }
        }
Exemplo n.º 11
0
        public AdjacencyMatrix(MatrixCoordinateMap classMap1, MatrixCoordinateMap classMap2, Matrix <double> matrix)
        {
            setClassMap1(classMap1);
            setClassMap2(classMap2);

            int  columnCount = matrix.ColumnCount;
            bool isOneDimension;

            if (columnCount == 1)
            {
                isOneDimension = true;
            }
            else
            {
                isOneDimension = false;
            }

            setIsOneDimension(isOneDimension);
            setMatrix(matrix);
        }
Exemplo n.º 12
0
        public AdjacencyMatrix getMatrixColumnVectorRatio()
        {
            Matrix <double>     matrix       = this.getMatrix();
            MatrixCoordinateMap newClassMap1 = this.getClassMap1();
            MatrixCoordinateMap newClassMap2 = this.getClassMap2();

            int             size = matrix.ColumnCount;
            Matrix <double> matrixColumnVectorRatio = matrix.Clone();

            for (int j = 0; j < size; j++)   //start at column 0

            {
                Vector <double> vector    = matrixColumnVectorRatio.Column(j);
                double          vectorSum = vector.Sum();

                if (vectorSum > 0)
                {
                    Vector <double> vectorRatio = vector.Multiply(1 / vectorSum);
                    matrixColumnVectorRatio.SetColumn(j, vectorRatio);
                }
            }

            return(new AdjacencyMatrix(newClassMap1, newClassMap2, matrixColumnVectorRatio));
        }
Exemplo n.º 13
0
 void setClassMap2(MatrixCoordinateMap map)
 {
     classMap2 = map;
 }
Exemplo n.º 14
0
        public static void createMatrixMarketFile(string pathReadMm, string pathWriteMm, Char delimiter, MatrixCoordinateMap replaceMap1, MatrixCoordinateMap replaceMap2)
        {
            string originalStr = IO.getString(pathReadMm);
            int    countLine   = 0;
            string originalLine;
            string updatedLine;
            string line;

            StringReader scanner = new StringReader(originalStr);
            StreamWriter outText = new StreamWriter(pathWriteMm, true);

            while ((line = scanner.ReadLine()) != null)
            {
                if (line.Length > 0)
                {
                    countLine++;
                    originalLine = line;

                    if (countLine > 2)
                    {
                        updatedLine = parseAndReplaceStringByHashMap(originalLine, delimiter, replaceMap1, replaceMap2);
                    }
                    else
                    {
                        updatedLine = originalLine;
                    }

                    outText.WriteLine(updatedLine);
                }
            }

            scanner.Close();
            outText.Close();
        }
Exemplo n.º 15
0
        static string parseAndReplaceStringByHashMap(string originalStr, Char delimiter, MatrixCoordinateMap replaceMap1, MatrixCoordinateMap replaceMap2)
        {
            ConcurrentDictionary <string, string> hashMap1 = replaceMap1.getHashMap();
            ConcurrentDictionary <string, string> hashMap2 = replaceMap2.getHashMap();

            StringBuilder buffer = new StringBuilder();

            char[]   charSeparators = new char[] { delimiter };
            string[] tokens         = originalStr.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
            int      length         = tokens.Length;

            string value1 = hashMap1[tokens[0].Trim()];

            if (value1 != null)
            {
                tokens[0] = value1;
            }

            if (length > 1)
            {
                string value2 = hashMap2[tokens[1].Trim()];
                if (value2 != null)
                {
                    tokens[1] = value2;
                }
            }

            for (int i = 0; i < length; i++)
            {
                if (i == 0)
                {
                    buffer.Append(tokens[i].Trim());
                }
                else
                {
                    buffer.Append(delimiter);
                    buffer.Append(tokens[i].Trim());
                }
            }

            string updatedStr = buffer.ToString();

            return(updatedStr);
        }