Sparse Matrices Matrix  table of values. Sparse Matrices Matrix  table of values 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 Row 2 Column 4 4 x 5 matrix.

Slides:



Advertisements
Similar presentations
Sparse Matrices sparse … many elements are zero dense … few elements are zero.
Advertisements

Elementary Linear Algebra Anton & Rorres, 9th Edition
Arrays and Matrices CSE, POSTECH. 2 2 Introduction Data is often available in tabular form Tabular data is often represented in arrays Matrix is an example.
Matrices CSE, POSTECH.
Arrays.
Arrays. 1D Array Representation In C 1-dimensional array x = [a, b, c, d] map into contiguous memory locations Memory abcd start location(x[i]) = start.
1.7 Diagonal, Triangular, and Symmetric Matrices.
Autar Kaw Benjamin Rigsby Transforming Numerical Methods Education for STEM Undergraduates.
Sparse Matrix Storage Lecture #3 EEE 574 Dr. Dan Tylavsky.
Matrices. Special Matrices Matrix Addition and Subtraction Example.
Chapter 2. C++ Class A class name Data members Member functions Levels of program access –Public: section of a class can be accessed by anyone –Private:
Solving systems using matrices
Fill Lecture #9 EEE 574 Dr. Dan Tylavsky. Fill © Copyright 1999 Daniel Tylavsky 4 When we solve Ax=b, (A sparse), fill-in will occur in the L,U factor.
Chapter 2 Matrices Definition of a matrix.
Matrix table of values
Module 6 Matrices & Applications Chapter 26 Matrices and Applications I.
化工應用數學 授課教師: 郭修伯 Lecture 9 Matrices
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
CS Data Structures Chapter 2 Arrays and Structures.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
Section 8.1 – Systems of Linear Equations
1.7 Diagonal, Triangular, and Symmetric Matrices 1.
Matrices Write and Augmented Matrix of a system of Linear Equations Write the system from the augmented matrix Solve Systems of Linear Equations using.
How to find the inverse of a matrix
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
Euclidean m-Space & Linear Equations Row Reduction of Linear Systems.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall.
Arrays and Matrices 황승원 Fall 2010 CSE, POSTECH. 2 2 Any real-life matrix you know?
Using Matrices A matrix is a rectangular array that can help us to streamline the solving of a system of equations The order of this matrix is 2 × 3 If.
Lesson 13-1: Matrices & Systems Objective: Students will: State the dimensions of a matrix Solve systems using matrices.
A.Abhari CPS1251 Multidimensional Arrays Multidimensional array is the array with two or more dimensions. For example: char box [3] [3] defines a two-dimensional.
CSCE 3110 Data Structures & Algorithm Analysis Arrays and Lists.
Data Structure (Part II) Chapter 2 – Arrays. Matrix A matrix with 5 rows and 3 columns can be represented by n = 3 m = 5 We say this is a 5×3 matrix.
SNU IDB Lab. Ch8. Arrays and Matrices © copyright 2006 SNU IDB Lab.
Lecture 7 Matrices CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Matrices. Definitions  A matrix is an m x n array of scalars, arranged conceptually as m rows and n columns.  m is referred to as the row dimension.
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Data Structure Sang Yong Han Chung-Ang University Spring
Sparse Vectors & Matrices Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Prepared by Deluar Jahan Moloy Lecturer Northern University Bangladesh
Notes 7.2 – Matrices I. Matrices A.) Def. – A rectangular array of numbers. An m x n matrix is a matrix consisting of m rows and n columns. The element.
Algebra II Honors Problem of the Day Homework page eoo The following system has been solved and there are infinite solutions in the form of (
1. 2  Introduction  Array Operations  Number of Elements in an array One-dimensional array Two dimensional array Multi-dimensional arrays Representation.
Section 2.1 Determinants by Cofactor Expansion. THE DETERMINANT Recall from algebra, that the function f (x) = x 2 is a function from the real numbers.
Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such.
Table of Contents Matrices - Definition and Notation A matrix is a rectangular array of numbers. Consider the following matrix: Matrix B has 3 rows and.
Precalculus Section 14.1 Add and subtract matrices Often a set of data is arranged in a table form A matrix is a rectangular.
1 ARRAYS AND STRUCTURES. 2 Arrays Array: a set of index and value data structure For each index, there is a value associated with that index. representation.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
Introduction Types of Matrices Operations
Arrays. 1D Array Representation In C++ 1-dimensional array x = [a, b, c, d] map into contiguous memory locations Memory abcd start location(x[i]) = start.
Windows Programming Lecture 03. Pointers and Arrays.
Matrices. Matrix A matrix is an ordered rectangular array of numbers. The entry in the i th row and j th column is denoted by a ij. Ex. 4 Columns 3 Rows.
1 Numerical Methods Solution of Systems of Linear Equations.
Data Structure Sang Yong Han
1.5 Matricies.
Arrays.
Abstract Data Types Sparse Matrices CSCI 240
Chapter 8: Lesson 8.1 Matrices & Systems of Equations
Reminder: Array Representation In C++
بردارها و ماتريس ها ساختمان داده ها
Reminder: Array Representation In C++
Lecture 11 Matrices and Linear Algebra with MATLAB
Determinant of a Matrix
Arrays.
Arrays.
Linear Algebra Lecture 11.
Reminder: Array Representation In C++
Arrays and Matrices Prof. Abdul Hameed.
Presentation transcript:

Sparse Matrices Matrix  table of values

Sparse Matrices Matrix  table of values Row 2 Column 4 4 x 5 matrix 4 rows 5 columns 20 elements 6 nonzero elements

Sparse Matrices Sparse matrix  #nonzero elements/#elements is small. Examples: Diagonal  Only elements along diagonal may be nonzero  n x n matrix  ratio is n/n 2 = 1/n Tridiagonal Only elements on 3 central diagonals may be nonzero Ratio is (3n-2)/n 2 = 3/n – 2/n 2

Sparse Matrices Lower triangular (?) Only elements on or below diagonal may be nonzero Ratio is n(n+1)(2n 2 ) ~ 0.5 These are structured sparse matrices. Nonzero elements are in a well-defined portion of the matrix.

Sparse Matrices An n x n matrix may be stored as an n x n array. This takes O(n 2 ) space. The example structured sparse matrices may be mapped into a 1D array so that a mapping function can be used to locate an element quickly; the space required by the 1D array is less than that required by an n x n array (next lecture).

Unstructured Sparse Matrices Airline flight matrix.  airports are numbered 1 through n  flight(i,j) = list of nonstop flights from airport i to airport j  n = 1000 (say)  n x n array of list pointers => 4 million bytes  total number of nonempty flight lists = 20,000 (say)  need at most 20,000 list pointers => at most 80,000 bytes

Unstructured Sparse Matrices Web page matrix. web pages are numbered 1 through n web(i,j) = number of links from page i to page j Web analysis. authority page … page that has many links to it hub page … links to many authority pages

Web Page Matrix  n = 2 billion (and growing by 1 million a day)  n x n array of ints => 16 * bytes (16 * 10 9 GB)  each page links to 10 (say) other pages on average  on average there are 10 nonzero entries per row  space needed for nonzero elements is approximately 20 billion x 4 bytes = 80 billion bytes (80 GB)

Representation Of Unstructured Sparse Matrices Single linear list in row-major order. scan the nonzero elements of the sparse matrix in row- major order (i.e., scan the rows left to right beginning with row 1 and picking up the nonzero elements) each nonzero element is represented by a triple (row, column, value) the list of triples is stored in a 1D array

Single Linear List Example list = row column value

One Linear List Per Row row1 = [(3, 3), (5,4)] row2 = [(3,5), (4,7)] row3 = [] row4 = [(2,2), (3,6)]

Single Linear List Class SparseMatrix –Array smArray of triples of type MatrixTerm int row, col, value –int rows, // number of rows cols, // number of columns terms, // number of nonzero elements capacity; // size of smArray Size of smArray generally not predictable at time of initialization. –Start with some default capacity/size (say 10) –Increase capacity as needed

Approximate Memory Requirements 500 x 500 matrix with 1994 nonzero elements, 4 bytes per element 2D array 500 x 500 x 4 = 1million bytes Class SparseMatrix 3 x 1994 x x 4 = 23,944 bytes

Array Resizing if (newSize < terms) throw “Error”; MatrixTerm *temp = new MatrixTerm[newSize]; copy(smArray, smArray+terms, temp); delete [] smArray; smArray = temp; capacity = newSize;

Array Resizing To avoid spending too much overall time resizing arrays, we generally set newSize = c * oldSize, where c >0 is some constant. Quite often, we use c = 2 (array doubling) or c = 1.5. Now, we can show that the total time spent in resizing is O(s), where s is the maximum number of elements added to smArray.

Matrix Transpose

Matrix Transpose row column value

Matrix Transpose row column value Step 1: #nonzero in each row of transpose. = #nonzero in each column of original matrix = [0, 1, 3, 1, 1] Step2: Start of each row of transpose = sum of size of preceding rows of transpose = [0, 0, 1, 4, 5] Step 3: Move elements, left to right, from original list to transpose list.

Matrix Transpose Step 1: #nonzero in each row of transpose. = #nonzero in each column of original matrix = [0, 1, 3, 1, 1] Step2: Start of each row of transpose = sum of size of preceding rows of transpose = [0, 0, 1, 4, 5] Step 3: Move elements, left to right, from original list to transpose list. Complexity m x n original matrix t nonzero elements Step 1: O(n+t) Step 2: O(n) Step 3: O(t) Overall O(n+t)

Runtime Performance Matrix Transpose 500 x 500 matrix with 1994 nonzero elements Run time measured on a 300MHz Pentium II PC 2D array 210 ms SparseMatrix 6 ms

Performance Matrix Addition. 500 x 500 matrices with 1994 and 999 nonzero elements 2D array 880 ms SparseMatrix 18 ms