Matrix table of values

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.
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.
Module 6 Matrices & Applications Chapter 26 Matrices and Applications I.
化工應用數學 授課教師: 郭修伯 Lecture 9 Matrices
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.
Matrix Solution of Linear Systems The Gauss-Jordan Method Special Systems.
Little Linear Algebra Contents: Linear vector spaces Matrices Special Matrices Matrix & vector Norms.
Presentation on Matrices and some special matrices In partial fulfillment of the subject Vector calculus and linear algebra ( ) Submitted by: Agarwal.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall.
Solving Scale Linear Systems (Example system continued) Lecture 14 MA/CS 471 Fall 2003.
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.
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.
1 Data Structures CSCI 132, Spring 2014 Lecture 32 Tables I.
Efficiency and Flexibility of Jagged Arrays Geir Gundersen Department of Informatics University of Bergen Norway Joint work with Trond Steihaug.
Data Structure Sang Yong Han Chung-Ang University Spring
Sparse Vectors & Matrices Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
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 (
Sparse Matrices Matrix  table of values. Sparse Matrices Matrix  table of values Row 2 Column 4 4 x 5 matrix.
1. 2  Introduction  Array Operations  Number of Elements in an array One-dimensional array Two dimensional array Multi-dimensional arrays Representation.
2.5 – Determinants and Multiplicative Inverses of Matrices.
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.
A very brief introduction to Matrix (Section 2.7) Definitions Some properties Basic matrix operations Zero-One (Boolean) matrices.
MATRICES A rectangular arrangement of elements is called matrix. Types of matrices: Null matrix: A matrix whose all elements are zero is called a null.
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.
MTH108 Business Math I Lecture 20.
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
Multidimensional array
Arrays.
Arrays.
Linear Algebra Lecture 11.
Section 8.1 – Systems of Linear Equations
Matrix A matrix is a rectangular arrangement of numbers in rows and columns Each number in a matrix is called an Element. The dimensions of a matrix are.
Reminder: Array Representation In C++
Arrays and Matrices Prof. Abdul Hameed.
Presentation transcript:

Matrix table of values Sparse Matrices Matrix table of values

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 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/n2 = 1/n Tridiagonal Only elements on 3 central diagonals may be nonzero Ratio is (3n-2)/n2 = 3/n – 2/n2

Sparse Matrices Lower triangular (?) Only elements on or below diagonal may be nonzero Ratio is n(n+1)(2n2) ~ 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(n2) 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 Assume that flight(i,j) = null if there is no flight from i to j. Of the 1 million entries in the flight matrix at most 20,000 can be nonnull as each nonnull entry represents at least 1 different flight. So we need to store at most 20,000 nonnull entries.

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 analyses are done using a matrix such as web(*,*). See IEEE Computer, August 1999, p 60, for a paper that describes Web analysis based on such a matrix. Operations such as matrix transpose and multiply are used.

Web Page Matrix n = 2 billion (and growing by 1 million a day) n x n array of ints => 16 * 1018 bytes (16 * 109 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) On average, 10 entries in each row are nonzero.

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 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 list = row 1 1 2 2 4 4 column 3 5 3 4 2 3 value 3 4 5 7 2 6 The single linear list has 6 elements. Each list element is a triple (row, column, value).

One Linear List Per Row row1 = [(3, 3), (5,4)] 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 Array linear list per row.

Single Linear List Array representation 1D Array of triples of type term int row, col, value Size of 1D array generally not predictable at time of initialization. Start with some default capacity/size (say 10) Increase capacity as needed Use REALLOC

Approximate Memory Requirements 500 x 500 matrix with 1994 nonzero elements, 4 bytes per element 2D array 500 x 500 x 4 = 1million bytes 1D array of triples 3 x 1994 x 4 = 23,928 bytes

Matrix Transpose 0 0 0 0 0 0 0 2 3 5 0 6 0 7 0 0 4 0 0 0 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0

0 0 0 0 0 0 0 2 3 5 0 6 0 7 0 0 4 0 0 0 Matrix Transpose 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 row 1 1 2 2 4 4 column 3 5 3 4 2 3 value 3 4 5 7 2 6 2 3 3 3 4 5 4 1 2 4 2 1 2 3 5 6 7 4

0 0 0 0 0 0 0 2 3 5 0 6 0 7 0 0 4 0 0 0 Matrix Transpose 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 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. row 1 1 2 2 4 4 column 3 5 3 4 2 3 value 3 4 5 7 2 6

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) Step 1: initialize array rowSize to 0, n values then stream through nonzero list of original matrix left to right Step 2: O(n) Step 3: O(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