SlideShare a Scribd company logo
Graph Algorithms and Applications
The global graph analytics market size is expected to
grow from USD 584 million in 2019 to USD 2,522 million
by 2024, at a Compound Annual Growth Rate (CAGR) of
34.0% during the forecast period. ... The major vendors
operating in the graph analytics market include IBM,
Oracle, Microsoft, AWS, Neo4j, TigerGraph, and Cray.
Graph Analytics Market Size, Share and Global Market ...
https://www.marketsandmarkets.com › Market-Reports
5 Major Use Cases of Graph Analytics
• Social Network Analysis
• Fraud Analysis and Identification
• Resource Management
• Money Laundering and Financial Fraud
• Finding Bot Accounts in Social Networks
Apr 24, 2020
5 Major Use Cases of Graph Analytics –
Acuvate … https://acuvate.com › blog ›
graph-analytics
Need for high-
performance
programming!
2
Understanding relationships between items
• Graph: A visual representation of a set of vertices and the connections between them (edges).
• Graph: Two sets, one for the vertices (𝑣𝑣) and one for the edges (𝑒𝑒)
𝑣𝑣 ∈ [0, 1, 2, 3, 4, 5, 6]
𝑒𝑒 ∈ [ 0,1 , 0,3 , 1,4 , 1,6 , 2,5 , 3,0 , 3,2 , 4,5 , 5,2 , 6,2 , 6,3 , (6,4)]
5
3
2
1
0
4
6
Breadth-First Traversal
5
3
2
1
0
4
6
5
3
2
1
0
4
6
5
3
2
1
0
4
6
5
3
2
1
0
4
6
Red=current wavefront and visited, Blue=next wavefront, Gray=visited, Black=unvisited
Traversing the
graph requires
pointer chasing
Many disparate
access to
memory
Data structures
are lists with
pointers, i.e.,
address of next
vertex in graph
High
performance
difficult to
achieve!
4
A graph as a matrix
• Adjacency Matrix: A square matrix (usually sparse) where rows and columns are labeled by
vertices and non-empty values are edges from a row vertex to a column vertex
- ★ - ★ - - -
- - - - ★ - ★
- - - - - ★ -
★ - ★ - - - -
- - - - - ★ -
- - ★ - - - -
- - ★ ★ ★ - -
A =
From
vertex
(rows)
To vertex
(columns)
By using a matrix, I can turn algorithms
working with graphs into linear algebra.
5
3
2
1
0
4
6
Data structures
are indexed
arrays, i.e.,
locations are
computed as
offsets from a
base
Can be
optimized by
compiler or
manually to
achieve high
performance
5
A Directed graph as a matrix
• Adjacency Matrix: A square matrix (usually sparse) where rows and columns are labeled by
vertices and non-empty values are edges from a row vertex to a column vertex
- ★ - ★ - - -
- - - - ★ - ★
- - - - - ★ -
★ - ★ - - - -
- - - - - ★ -
- - ★ - - - -
- - ★ ★ ★ - -
A =
From
vertex
(rows)
To vertex
(columns)
This is a directed graph
(the edges have arrows)
5
3
2
1
0
4
6
6
An Undirected graph as a matrix
• Adjacency Matrix: A square matrix (usually sparse) where rows and columns are labeled by
vertices and non-empty values are edges from a row vertex to a column vertex
- ★ - ★ - - -
★ - - - ★ - ★
- - - ★ - ★ ★
★ - ★ - - - ★
- ★ - - - ★ ★
- - ★ - ★ - -
- ★ ★ ★ ★ - -
A =
From
vertex
(rows)
To vertex
(columns)
This is an undirected graph (no arrows on the edges)
and the Adjacency matrix is symmetric
5
3
2
1
0
4
6
7
Graph Algorithms and Linear Algebra
• Most common graph algorithms can be
represented in terms of linear algebra.
– This is a mature field … it even has a book.
• Benefits of graphs as linear algebra
– Well suited to memory hierarchies of modern
microprocessors
– Can utilize decades of experience in
distributed/parallel computing from linear algebra
in supercomputing.
– Easier to understand … for some people.
Matrix Multiplication
Breadth-first Search
on a graph is the
same as matrix
multiplication using an
adjacency matrix that
represents the graph
Matrix operations on
sparse matrices can
be optimized to
remove unnecessary
computations (i.e.,
locations with zeros)
9
How do linear algebra people write software?
• They do so in terms of the BLAS:
– The Basic Linear Algebra Subprograms: low-level building blocks from which any linear
algebra algorithm can be written
BLAS 1 Vector/vector Lawson, Hanson, Kincaid and
Krogh, 1979
LINPACK
BLAS 2 Matrix/vector Dongarra, Du Croz, Hammarling
and Hanson, 1988
LINPACK on vector machines
BLAS 3 Matrix/matrix Dongarra, Du Croz, Hammarling
and Hanson, 1990
LAPACK on cache-based machines
• The BLAS supports a separation of concerns:
– HW/SW optimization experts tuned the BLAS for specific platforms.
– Linear algebra experts build software on top of the BLAS ... high performance “for free”.
• It is difficult to over-state the impact of the BLAS … they revolutionized the
practice of computational linear algebra.
10
GraphBLAS: building blocks for graphs as linear algebra
• Basic objects
– Matrix, vector, algebraic structures, and ”control objects”
• Fundamental operations over these objects
…plus reductions, transpose, and application of a function to each element of a matrix or vector
Matrix
multiplication
Matrix-vector
multiplication
(vxm, mxv)
Element-wise
operations
(eWiseAdd,
eWiseMult)
Extract (and
Assign)
submatrices
11
The GraphBLAS API: pygraphblas
Maps the C API onto Python
• Method: Any function that manipulates a GraphBLAS opaque object.
• Domain: the set of available values used for the elements of matrices, the elements of vectors, and when
defining operators.
– Examples are UINT64, INT32, BOOL, FP32
• Operation: a method that corresponds to an operation defined in the GraphBLAS math spec.
http://www.mit.edu/~kepner/GraphBLAS/GraphBLAS-Math-release.pdf
• Opaque object: An object manipulated strictly through the GraphBLAS API whose implementation is not
defined by the GraphBLAS specification.
Matrix.sparse  A 2D sparse array, row indices, column indices and values
Vector.sparse  A 1D sparse array
Matrix multiply C = A @ B C = A.mxm(B) or A.mxm(B, out=C)
Matrix Vector w = A @ v w = A.mxv(v) or A.mxv(v, out=w)
Element-wise add C = A + B C = A.eadd(B) or A.eadd(B, out=C)
12
Creating a matrix
• Matrices in real problems are imported into the program from a file or an external
application.
• We can build a matrix element by element
– Import pygraphblas import pygraphblas as grb
– Set size of matrix n = 3
– Build a square matrix: A = grb.Matrix.sparse(grb.UINT64,n,n)
– Set a value in the matrix A[1,2] = 4
– Look at the matrix print(A)
13
Creating a matrix
• Matrices in real problems are imported into the program from a file or an external
application.
• We can build Matrices from lists:
– Import pygraphblas: import pygraphblas as grb
– List of row indices: ri = [0, 2, 4, 5]
– List of column indices: ci = [1, 3, 5, 5]
– List of Values: val = [True]*len(ri)
– Build the matrix: A = grb.Matrix.from_lists(ri, ci, val)
– Number of columns: NUM_NODES = A.ncol
• We can look at a matrix as a matrix (with print) or as a graph:
from pygraphblas.gviz import draw_graph as draw
draw(A)
 A list of True as long as ri
14
GraphBLAS vectors and matrices
• Let’s review our Matrix and Vector Objects.
• They are opaque … the structure is not defined in the spec so implementors have maximum flexibility to
optimize their implementation
• pygraphblas defines a number of static methods to use when working with matrices and vectors
#Create a sparse vector of size N
v = grb.Vector.sparse(type, N)
#Create a sparse vector from index and value lists
v = grb.Vector.from_lists(indList, valList)
#Create a sparse matrix with Nrows and Ncols
A = grb.Matrix.sparse(type, Nrows, Ncols)
#Create a sparse matrix from index and value lists
A = grb.Matrix.from_lists(rowInd, colInd, valList)
import pygraphblas as grb
We’ve seen
these already
The vector case
is analogous to
the matrix case
15
GraphBLAS Operations (from the Math Spec*)
We use ⊙, ⊕, and ⊗
since we can change
the operators mapped
onto those symbols.
* Mathematical foundations of the GraphBLAS, Kepner et. al. HPEC’2016
Matrix Multiplication Abstraction
Structure of matrix
multiplication can be
used with different
additive, multiplicative,
and optional
accumulator operators
(optional)
Operators are
parameters to
GraphBLAS
operations
17
(R, +, *, 0, 1)
Real Field
Standard operations in linear algebra
(R U {∞},min, +, ∞, 0)
Tropical semiring
Shortest path algorithms
({0,1}, |, &, 0, 1)
Boolean Semiring
Graph traversal algorithms
(R U {∞}, min, *, ∞, 1) Selecting a subgraph or contracting
nodes to form a quotient graph.
Algebraic Semirings
• Semiring: An Algebraic structure that generalizes real arithmetic by replacing
(⊕,⊗) with binary operations (Op1, Op2)
– Op1 and Op2 have identity elements sometimes called 0 and 1
– Op1 and Op2 are associative.
– Op1 is commutative, Op2 distributes over Op1 from both left and right
– The Op1 identity is an Op2 annihilator.
18
Working with semirings
• In Graph Algorithms, changing semirings multiple times inside a single algorithm is quite common. Hence,
the semiring (and implied accumulator ⊕ by default) can be directly manipulated.
• We can do this using python’s with statement
with grb.BOOL.LOR_LAND:
w += A@v
with grb.BOOL.LOR_LAND:
w = A.mxv(u,accum=grb.BOOL.LOR)
Matrix vector product of A and v accumulating
the result with the existing elements of w using:
• ⊕ = ⊙ = Logical OR
• ⊗ = Logical AND
• Common semirings include (though pygraphblas has MANY more)
(R, +, *, 0, 1)
Real Field
Standard operations in linear
algebra
FP64.PLUS_TIMES
(R U {∞},min, +, ∞, 0)
Tropical semiring
Shortest path algorithms FP64.MIN_PLUS
({0,1}, |, &, 0, 1)
Boolean Semiring
Graph traversal algorithms BOOL.LOR_LAND
(R U {∞}, min, *, ∞, 1) Selecting a subgraph or contracting
nodes to form a quotient graph.
FP64.MIN_TIMES
19
mxv()
Multiply a matrix times a vector to produce a vector
𝑤𝑤 𝑖𝑖 = 𝑤𝑤 𝑖𝑖 ⨀ �
𝑘𝑘=0
𝑁𝑁
𝐴𝐴(𝑖𝑖, 𝑘𝑘)⨂𝑢𝑢(𝑘𝑘)
𝑤𝑤 ∈ 𝑆𝑆𝑀𝑀
𝑢𝑢 ∈ 𝑆𝑆𝑁𝑁
𝐴𝐴 ∈ 𝑆𝑆𝑀𝑀×𝑁𝑁
Definitions:
• S is the domain of the objects w, u, and A
• ⊙ is an optional accumulation operator (a binary operator)
• ⊗ and ⊕ are multiplication and addition (or generalizations thereof)
• ∑ uses the ⊕ operator
w ⨀= A⊕.⊗u
20
Matrix vector multiplication: mxv()
• The operators used are an accumulator (⊙) and the algebraic semiring operators (⊕ and ⊗). We
will say a great deal more about semirings later … for now we’ll use the default case for Boolean
data, the LOR_LAND semiring (i.e., logical OR for ⊕, Logical AND for ⊗).
w ⨀= A⊕.⊗u
import pygraphblas as grb
# A’s type taken from values
A = grb.Matrix.from_lists(rowInd, colInd, values)
N = A.ncols
# Create a vector of length N and type BOOL
u = grb.Vector.sparse(grb.BOOL, N)
u[ind] = True # set the value
w = A.mxv(u)
w = A @ u
A.mxv(u, out=w)
These three compute the same result in w.
The third reuses an existing w.
21
Finding neighbors
• A more common operation is to input a vector selecting a source and find all the neighbors one
hop away from that vertex.
• Using mxv(), how would you do this?
– The adjacency matrix elements indicate edges
–From a vertex (row index)
–To another vertex (columns index)
– Then the transpose of the adjacency matrix indicates edges
–To a vertex (row index)
–From other vertices (column index)
• Therefore, we can find the neighbors of a vertex (marked by the non-empty elements of v)
neighbors = AT⊕.⊗v
neighbors = A.T @ v
neighbors = A.mxv(v, desc=grb.descriptor.T0)
Two ways to do a transpose with
pygraphblas
22
The GraphBLAS Operations
We’ve only
covered mxv, so
far, but the same
conventions are
used across all
operations, so
we’ll have no
problem later
when we use the
others
<M, m>: write masks
(Matrix or vector).
<r>: selects “replace
or combine” for elements
not selected by the mask.
23
GraphBLAS References
GABB@IPDPS 2017
IEEE HPEC 2016
The official GraphBLAS C spec can be found at: www.graphblas.org
24
GraphBLAS Implementations
• SuiteSparse library (Texas A&M): First fully conforming GraphBLAS release.
– http://faculty.cse.tamu.edu/davis/suitesparse.html
• GraphBLAS C (IBM): the second fully conforming release,
– https://github.com/IBM/ibmgraphblas
• GBTL: GraphBLAS Template Library (CMU/PNNL): Pushing GraphBLAS into C++
– https://github.com/cmu-sei/gbtl
• GraphBLAST: A C++ implementation for GraphBLAS for GPUs (UC Davis),
– https://github.com/gunrock/graphblast
• Python bindings:
– pygraphblas: A Python Wrapper around SuiteSparse GraphBLAS
– https://github.com/Graphegon/pygraphblas
– grblas: Python wrapper around GraphBLAS (part of Anaconda’s MetaGraph work)
– https://github.com/metagraph-dev/grblas
– pyGB: A Python Wrapper around GBTL (UW/PNNL/CMU)
– https://github.com/jessecoleman/gbtl-python-binding
• pgGraphBLAS: A PostgreSQL wrapper around Suite Sparse GraphBLAS
– https://github.com/michelp/pggraphblas
• Matlab and Julia wrappers around SuiteSparse GraphBLAS
– https://aldenmath.com
Third Party names are the property of their owners
25
The GraphBLAS Vision
LAGraph
26
LAGraph: A curated collection of high level Graph Algorithms
GrAPL 2019
Graph Algorithms built on top of the GraphBLAS.
Official release of LAGraph library v1.0 later in 2021
27
SuiteSparse: C libraries for GraphBLAS and LAGraph
31
Pygraphblas Documentation at: https://graphegon.github.io/pygraphblas/pygraphblas/index.html
32
32
A Hands-On Introduction to GraphBLAS:
The Python Edition
http://graphblas.org
Tim Mattson
Intel Labs
With a special thank you to Tim Davis (Texas A&M) for GraphBLAS support in SuiteSparse
and Michel Pelletier (Graphegon) for creating pygraphblas.
≡
Scott McMillan
CMU/SEI
… and the other members of the GraphBLAS specification group:
Aydın Buluç (UC Berkeley/LBNL), Jose Moreira (IBM), and Ben Brock (UC Berkeley).
To get course materials onto your laptop:
$ git clone https://github.com/GraphBLAS-Tutorials/GraphBLAS_Python_tutorials.git

More Related Content

What's hot

Algorithem complexity in data sructure
Algorithem complexity in data sructureAlgorithem complexity in data sructure
Algorithem complexity in data sructure
Kumar
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
Dr Sandeep Kumar Poonia
 
Big oh Representation Used in Time complexities
Big oh Representation Used in Time complexitiesBig oh Representation Used in Time complexities
Big oh Representation Used in Time complexities
LAKSHMITHARUN PONNAM
 
Data streaming algorithms
Data streaming algorithmsData streaming algorithms
Data streaming algorithms
Sandeep Joshi
 
Hash tables
Hash tablesHash tables
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
Programming Homework Help
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
Marcello Missiroli
 
Clustering techniques
Clustering techniquesClustering techniques
Clustering techniques
talktoharry
 
Exploiting the query structure for efficient join ordering in SPARQL queries
Exploiting the query structure for efficient join ordering in SPARQL queriesExploiting the query structure for efficient join ordering in SPARQL queries
Exploiting the query structure for efficient join ordering in SPARQL queries
Luiz Henrique Zambom Santana
 
Faster persistent data structures through hashing
Faster persistent data structures through hashingFaster persistent data structures through hashing
Faster persistent data structures through hashing
Johan Tibell
 
Introduction to data_structure
Introduction to data_structureIntroduction to data_structure
Introduction to data_structure
Ashim Lamichhane
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
Dr Sandeep Kumar Poonia
 
Probabilistic data structures
Probabilistic data structuresProbabilistic data structures
Probabilistic data structures
shrinivasvasala
 
Data Streaming Algorithms
Data Streaming AlgorithmsData Streaming Algorithms
Data Streaming Algorithms
宇 傅
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
iqbalphy1
 
Rehashing
RehashingRehashing
Rehashing
rajshreemuthiah
 
Exceeding Classical: Probabilistic Data Structures in Data Intensive Applicat...
Exceeding Classical: Probabilistic Data Structures in Data Intensive Applicat...Exceeding Classical: Probabilistic Data Structures in Data Intensive Applicat...
Exceeding Classical: Probabilistic Data Structures in Data Intensive Applicat...
Andrii Gakhov
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
Daffodil International University
 
DATA STRUCTURE AND ALGORITHM FULL NOTES
DATA STRUCTURE AND ALGORITHM FULL NOTESDATA STRUCTURE AND ALGORITHM FULL NOTES
DATA STRUCTURE AND ALGORITHM FULL NOTES
Aniruddha Paul
 
Social network-analysis-in-python
Social network-analysis-in-pythonSocial network-analysis-in-python
Social network-analysis-in-python
Joe OntheRocks
 

What's hot (20)

Algorithem complexity in data sructure
Algorithem complexity in data sructureAlgorithem complexity in data sructure
Algorithem complexity in data sructure
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Big oh Representation Used in Time complexities
Big oh Representation Used in Time complexitiesBig oh Representation Used in Time complexities
Big oh Representation Used in Time complexities
 
Data streaming algorithms
Data streaming algorithmsData streaming algorithms
Data streaming algorithms
 
Hash tables
Hash tablesHash tables
Hash tables
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
 
Clustering techniques
Clustering techniquesClustering techniques
Clustering techniques
 
Exploiting the query structure for efficient join ordering in SPARQL queries
Exploiting the query structure for efficient join ordering in SPARQL queriesExploiting the query structure for efficient join ordering in SPARQL queries
Exploiting the query structure for efficient join ordering in SPARQL queries
 
Faster persistent data structures through hashing
Faster persistent data structures through hashingFaster persistent data structures through hashing
Faster persistent data structures through hashing
 
Introduction to data_structure
Introduction to data_structureIntroduction to data_structure
Introduction to data_structure
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Probabilistic data structures
Probabilistic data structuresProbabilistic data structures
Probabilistic data structures
 
Data Streaming Algorithms
Data Streaming AlgorithmsData Streaming Algorithms
Data Streaming Algorithms
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Rehashing
RehashingRehashing
Rehashing
 
Exceeding Classical: Probabilistic Data Structures in Data Intensive Applicat...
Exceeding Classical: Probabilistic Data Structures in Data Intensive Applicat...Exceeding Classical: Probabilistic Data Structures in Data Intensive Applicat...
Exceeding Classical: Probabilistic Data Structures in Data Intensive Applicat...
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
DATA STRUCTURE AND ALGORITHM FULL NOTES
DATA STRUCTURE AND ALGORITHM FULL NOTESDATA STRUCTURE AND ALGORITHM FULL NOTES
DATA STRUCTURE AND ALGORITHM FULL NOTES
 
Social network-analysis-in-python
Social network-analysis-in-pythonSocial network-analysis-in-python
Social network-analysis-in-python
 

Similar to Graph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahon

CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docxCSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
mydrynan
 
Large-Scale Machine Learning with Apache Spark
Large-Scale Machine Learning with Apache SparkLarge-Scale Machine Learning with Apache Spark
Large-Scale Machine Learning with Apache Spark
DB Tsai
 
Matlab
MatlabMatlab
Matlab
Maria Akther
 
141205 graphulo ingraphblas
141205 graphulo ingraphblas141205 graphulo ingraphblas
141205 graphulo ingraphblas
graphulo
 
141222 graphulo ingraphblas
141222 graphulo ingraphblas141222 graphulo ingraphblas
141222 graphulo ingraphblas
MIT
 
Mbd dd
Mbd ddMbd dd
Graph Analyses with Python and NetworkX
Graph Analyses with Python and NetworkXGraph Analyses with Python and NetworkX
Graph Analyses with Python and NetworkX
Benjamin Bengfort
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014
rolly purnomo
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
Faizan Shabbir
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
Techbuddy Consulting Pvt. Ltd.
 
Engineering Numerical Analysis-Introduction.pdf
Engineering Numerical Analysis-Introduction.pdfEngineering Numerical Analysis-Introduction.pdf
Engineering Numerical Analysis-Introduction.pdf
ssuseraae901
 
Generalized Linear Models in Spark MLlib and SparkR by Xiangrui Meng
Generalized Linear Models in Spark MLlib and SparkR by Xiangrui MengGeneralized Linear Models in Spark MLlib and SparkR by Xiangrui Meng
Generalized Linear Models in Spark MLlib and SparkR by Xiangrui Meng
Spark Summit
 
Generalized Linear Models in Spark MLlib and SparkR
Generalized Linear Models in Spark MLlib and SparkRGeneralized Linear Models in Spark MLlib and SparkR
Generalized Linear Models in Spark MLlib and SparkR
Databricks
 
Enterprise Scale Topological Data Analysis Using Spark
Enterprise Scale Topological Data Analysis Using SparkEnterprise Scale Topological Data Analysis Using Spark
Enterprise Scale Topological Data Analysis Using Spark
Alpine Data
 
Enterprise Scale Topological Data Analysis Using Spark
Enterprise Scale Topological Data Analysis Using SparkEnterprise Scale Topological Data Analysis Using Spark
Enterprise Scale Topological Data Analysis Using Spark
Spark Summit
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptxBasic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
PremanandS3
 
Week-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxWeek-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docx
helzerpatrina
 
Arrays with Numpy, Computer Graphics
Arrays with Numpy, Computer GraphicsArrays with Numpy, Computer Graphics
Arrays with Numpy, Computer Graphics
Prabu U
 
Support Vector Machines ( SVM )
Support Vector Machines ( SVM ) Support Vector Machines ( SVM )
Support Vector Machines ( SVM )
Mohammad Junaid Khan
 
Large Scale Machine Learning with Apache Spark
Large Scale Machine Learning with Apache SparkLarge Scale Machine Learning with Apache Spark
Large Scale Machine Learning with Apache Spark
Cloudera, Inc.
 

Similar to Graph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahon (20)

CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docxCSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
 
Large-Scale Machine Learning with Apache Spark
Large-Scale Machine Learning with Apache SparkLarge-Scale Machine Learning with Apache Spark
Large-Scale Machine Learning with Apache Spark
 
Matlab
MatlabMatlab
Matlab
 
141205 graphulo ingraphblas
141205 graphulo ingraphblas141205 graphulo ingraphblas
141205 graphulo ingraphblas
 
141222 graphulo ingraphblas
141222 graphulo ingraphblas141222 graphulo ingraphblas
141222 graphulo ingraphblas
 
Mbd dd
Mbd ddMbd dd
Mbd dd
 
Graph Analyses with Python and NetworkX
Graph Analyses with Python and NetworkXGraph Analyses with Python and NetworkX
Graph Analyses with Python and NetworkX
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
Engineering Numerical Analysis-Introduction.pdf
Engineering Numerical Analysis-Introduction.pdfEngineering Numerical Analysis-Introduction.pdf
Engineering Numerical Analysis-Introduction.pdf
 
Generalized Linear Models in Spark MLlib and SparkR by Xiangrui Meng
Generalized Linear Models in Spark MLlib and SparkR by Xiangrui MengGeneralized Linear Models in Spark MLlib and SparkR by Xiangrui Meng
Generalized Linear Models in Spark MLlib and SparkR by Xiangrui Meng
 
Generalized Linear Models in Spark MLlib and SparkR
Generalized Linear Models in Spark MLlib and SparkRGeneralized Linear Models in Spark MLlib and SparkR
Generalized Linear Models in Spark MLlib and SparkR
 
Enterprise Scale Topological Data Analysis Using Spark
Enterprise Scale Topological Data Analysis Using SparkEnterprise Scale Topological Data Analysis Using Spark
Enterprise Scale Topological Data Analysis Using Spark
 
Enterprise Scale Topological Data Analysis Using Spark
Enterprise Scale Topological Data Analysis Using SparkEnterprise Scale Topological Data Analysis Using Spark
Enterprise Scale Topological Data Analysis Using Spark
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptxBasic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
 
Week-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxWeek-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docx
 
Arrays with Numpy, Computer Graphics
Arrays with Numpy, Computer GraphicsArrays with Numpy, Computer Graphics
Arrays with Numpy, Computer Graphics
 
Support Vector Machines ( SVM )
Support Vector Machines ( SVM ) Support Vector Machines ( SVM )
Support Vector Machines ( SVM )
 
Large Scale Machine Learning with Apache Spark
Large Scale Machine Learning with Apache SparkLarge Scale Machine Learning with Apache Spark
Large Scale Machine Learning with Apache Spark
 

More from Christopher Conlan

Fast Python: Master the Basics to Write Faster Code
Fast Python: Master the Basics to Write Faster CodeFast Python: Master the Basics to Write Faster Code
Fast Python: Master the Basics to Write Faster Code
Christopher Conlan
 
Algorithms 101 for Data Scientists (Part 2)
Algorithms 101 for Data Scientists (Part 2)Algorithms 101 for Data Scientists (Part 2)
Algorithms 101 for Data Scientists (Part 2)
Christopher Conlan
 
Hiring in the Software & Data Science Sector - D.C. Metro Area
Hiring in the Software & Data Science Sector - D.C. Metro AreaHiring in the Software & Data Science Sector - D.C. Metro Area
Hiring in the Software & Data Science Sector - D.C. Metro Area
Christopher Conlan
 
Beyond Moneyball: Data Science for Baseball in 2019
Beyond Moneyball: Data Science for Baseball in 2019Beyond Moneyball: Data Science for Baseball in 2019
Beyond Moneyball: Data Science for Baseball in 2019
Christopher Conlan
 
Cooperative Machine Learning Network with Ahmed Masud of saf.ai
Cooperative Machine Learning Network with Ahmed Masud of saf.aiCooperative Machine Learning Network with Ahmed Masud of saf.ai
Cooperative Machine Learning Network with Ahmed Masud of saf.ai
Christopher Conlan
 
Data Visualization for the Web - How to Get Started
Data Visualization for the Web - How to Get StartedData Visualization for the Web - How to Get Started
Data Visualization for the Web - How to Get Started
Christopher Conlan
 
Data Science Applications in Finance and Investing
Data Science Applications in Finance and InvestingData Science Applications in Finance and Investing
Data Science Applications in Finance and Investing
Christopher Conlan
 

More from Christopher Conlan (7)

Fast Python: Master the Basics to Write Faster Code
Fast Python: Master the Basics to Write Faster CodeFast Python: Master the Basics to Write Faster Code
Fast Python: Master the Basics to Write Faster Code
 
Algorithms 101 for Data Scientists (Part 2)
Algorithms 101 for Data Scientists (Part 2)Algorithms 101 for Data Scientists (Part 2)
Algorithms 101 for Data Scientists (Part 2)
 
Hiring in the Software & Data Science Sector - D.C. Metro Area
Hiring in the Software & Data Science Sector - D.C. Metro AreaHiring in the Software & Data Science Sector - D.C. Metro Area
Hiring in the Software & Data Science Sector - D.C. Metro Area
 
Beyond Moneyball: Data Science for Baseball in 2019
Beyond Moneyball: Data Science for Baseball in 2019Beyond Moneyball: Data Science for Baseball in 2019
Beyond Moneyball: Data Science for Baseball in 2019
 
Cooperative Machine Learning Network with Ahmed Masud of saf.ai
Cooperative Machine Learning Network with Ahmed Masud of saf.aiCooperative Machine Learning Network with Ahmed Masud of saf.ai
Cooperative Machine Learning Network with Ahmed Masud of saf.ai
 
Data Visualization for the Web - How to Get Started
Data Visualization for the Web - How to Get StartedData Visualization for the Web - How to Get Started
Data Visualization for the Web - How to Get Started
 
Data Science Applications in Finance and Investing
Data Science Applications in Finance and InvestingData Science Applications in Finance and Investing
Data Science Applications in Finance and Investing
 

Recently uploaded

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 

Recently uploaded (20)

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 

Graph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahon

  • 1. Graph Algorithms and Applications The global graph analytics market size is expected to grow from USD 584 million in 2019 to USD 2,522 million by 2024, at a Compound Annual Growth Rate (CAGR) of 34.0% during the forecast period. ... The major vendors operating in the graph analytics market include IBM, Oracle, Microsoft, AWS, Neo4j, TigerGraph, and Cray. Graph Analytics Market Size, Share and Global Market ... https://www.marketsandmarkets.com › Market-Reports 5 Major Use Cases of Graph Analytics • Social Network Analysis • Fraud Analysis and Identification • Resource Management • Money Laundering and Financial Fraud • Finding Bot Accounts in Social Networks Apr 24, 2020 5 Major Use Cases of Graph Analytics – Acuvate … https://acuvate.com › blog › graph-analytics Need for high- performance programming!
  • 2. 2 Understanding relationships between items • Graph: A visual representation of a set of vertices and the connections between them (edges). • Graph: Two sets, one for the vertices (𝑣𝑣) and one for the edges (𝑒𝑒) 𝑣𝑣 ∈ [0, 1, 2, 3, 4, 5, 6] 𝑒𝑒 ∈ [ 0,1 , 0,3 , 1,4 , 1,6 , 2,5 , 3,0 , 3,2 , 4,5 , 5,2 , 6,2 , 6,3 , (6,4)] 5 3 2 1 0 4 6
  • 3. Breadth-First Traversal 5 3 2 1 0 4 6 5 3 2 1 0 4 6 5 3 2 1 0 4 6 5 3 2 1 0 4 6 Red=current wavefront and visited, Blue=next wavefront, Gray=visited, Black=unvisited Traversing the graph requires pointer chasing Many disparate access to memory Data structures are lists with pointers, i.e., address of next vertex in graph High performance difficult to achieve!
  • 4. 4 A graph as a matrix • Adjacency Matrix: A square matrix (usually sparse) where rows and columns are labeled by vertices and non-empty values are edges from a row vertex to a column vertex - ★ - ★ - - - - - - - ★ - ★ - - - - - ★ - ★ - ★ - - - - - - - - - ★ - - - ★ - - - - - - ★ ★ ★ - - A = From vertex (rows) To vertex (columns) By using a matrix, I can turn algorithms working with graphs into linear algebra. 5 3 2 1 0 4 6 Data structures are indexed arrays, i.e., locations are computed as offsets from a base Can be optimized by compiler or manually to achieve high performance
  • 5. 5 A Directed graph as a matrix • Adjacency Matrix: A square matrix (usually sparse) where rows and columns are labeled by vertices and non-empty values are edges from a row vertex to a column vertex - ★ - ★ - - - - - - - ★ - ★ - - - - - ★ - ★ - ★ - - - - - - - - - ★ - - - ★ - - - - - - ★ ★ ★ - - A = From vertex (rows) To vertex (columns) This is a directed graph (the edges have arrows) 5 3 2 1 0 4 6
  • 6. 6 An Undirected graph as a matrix • Adjacency Matrix: A square matrix (usually sparse) where rows and columns are labeled by vertices and non-empty values are edges from a row vertex to a column vertex - ★ - ★ - - - ★ - - - ★ - ★ - - - ★ - ★ ★ ★ - ★ - - - ★ - ★ - - - ★ ★ - - ★ - ★ - - - ★ ★ ★ ★ - - A = From vertex (rows) To vertex (columns) This is an undirected graph (no arrows on the edges) and the Adjacency matrix is symmetric 5 3 2 1 0 4 6
  • 7. 7 Graph Algorithms and Linear Algebra • Most common graph algorithms can be represented in terms of linear algebra. – This is a mature field … it even has a book. • Benefits of graphs as linear algebra – Well suited to memory hierarchies of modern microprocessors – Can utilize decades of experience in distributed/parallel computing from linear algebra in supercomputing. – Easier to understand … for some people.
  • 8. Matrix Multiplication Breadth-first Search on a graph is the same as matrix multiplication using an adjacency matrix that represents the graph Matrix operations on sparse matrices can be optimized to remove unnecessary computations (i.e., locations with zeros)
  • 9. 9 How do linear algebra people write software? • They do so in terms of the BLAS: – The Basic Linear Algebra Subprograms: low-level building blocks from which any linear algebra algorithm can be written BLAS 1 Vector/vector Lawson, Hanson, Kincaid and Krogh, 1979 LINPACK BLAS 2 Matrix/vector Dongarra, Du Croz, Hammarling and Hanson, 1988 LINPACK on vector machines BLAS 3 Matrix/matrix Dongarra, Du Croz, Hammarling and Hanson, 1990 LAPACK on cache-based machines • The BLAS supports a separation of concerns: – HW/SW optimization experts tuned the BLAS for specific platforms. – Linear algebra experts build software on top of the BLAS ... high performance “for free”. • It is difficult to over-state the impact of the BLAS … they revolutionized the practice of computational linear algebra.
  • 10. 10 GraphBLAS: building blocks for graphs as linear algebra • Basic objects – Matrix, vector, algebraic structures, and ”control objects” • Fundamental operations over these objects …plus reductions, transpose, and application of a function to each element of a matrix or vector Matrix multiplication Matrix-vector multiplication (vxm, mxv) Element-wise operations (eWiseAdd, eWiseMult) Extract (and Assign) submatrices
  • 11. 11 The GraphBLAS API: pygraphblas Maps the C API onto Python • Method: Any function that manipulates a GraphBLAS opaque object. • Domain: the set of available values used for the elements of matrices, the elements of vectors, and when defining operators. – Examples are UINT64, INT32, BOOL, FP32 • Operation: a method that corresponds to an operation defined in the GraphBLAS math spec. http://www.mit.edu/~kepner/GraphBLAS/GraphBLAS-Math-release.pdf • Opaque object: An object manipulated strictly through the GraphBLAS API whose implementation is not defined by the GraphBLAS specification. Matrix.sparse  A 2D sparse array, row indices, column indices and values Vector.sparse  A 1D sparse array Matrix multiply C = A @ B C = A.mxm(B) or A.mxm(B, out=C) Matrix Vector w = A @ v w = A.mxv(v) or A.mxv(v, out=w) Element-wise add C = A + B C = A.eadd(B) or A.eadd(B, out=C)
  • 12. 12 Creating a matrix • Matrices in real problems are imported into the program from a file or an external application. • We can build a matrix element by element – Import pygraphblas import pygraphblas as grb – Set size of matrix n = 3 – Build a square matrix: A = grb.Matrix.sparse(grb.UINT64,n,n) – Set a value in the matrix A[1,2] = 4 – Look at the matrix print(A)
  • 13. 13 Creating a matrix • Matrices in real problems are imported into the program from a file or an external application. • We can build Matrices from lists: – Import pygraphblas: import pygraphblas as grb – List of row indices: ri = [0, 2, 4, 5] – List of column indices: ci = [1, 3, 5, 5] – List of Values: val = [True]*len(ri) – Build the matrix: A = grb.Matrix.from_lists(ri, ci, val) – Number of columns: NUM_NODES = A.ncol • We can look at a matrix as a matrix (with print) or as a graph: from pygraphblas.gviz import draw_graph as draw draw(A)  A list of True as long as ri
  • 14. 14 GraphBLAS vectors and matrices • Let’s review our Matrix and Vector Objects. • They are opaque … the structure is not defined in the spec so implementors have maximum flexibility to optimize their implementation • pygraphblas defines a number of static methods to use when working with matrices and vectors #Create a sparse vector of size N v = grb.Vector.sparse(type, N) #Create a sparse vector from index and value lists v = grb.Vector.from_lists(indList, valList) #Create a sparse matrix with Nrows and Ncols A = grb.Matrix.sparse(type, Nrows, Ncols) #Create a sparse matrix from index and value lists A = grb.Matrix.from_lists(rowInd, colInd, valList) import pygraphblas as grb We’ve seen these already The vector case is analogous to the matrix case
  • 15. 15 GraphBLAS Operations (from the Math Spec*) We use ⊙, ⊕, and ⊗ since we can change the operators mapped onto those symbols. * Mathematical foundations of the GraphBLAS, Kepner et. al. HPEC’2016
  • 16. Matrix Multiplication Abstraction Structure of matrix multiplication can be used with different additive, multiplicative, and optional accumulator operators (optional) Operators are parameters to GraphBLAS operations
  • 17. 17 (R, +, *, 0, 1) Real Field Standard operations in linear algebra (R U {∞},min, +, ∞, 0) Tropical semiring Shortest path algorithms ({0,1}, |, &, 0, 1) Boolean Semiring Graph traversal algorithms (R U {∞}, min, *, ∞, 1) Selecting a subgraph or contracting nodes to form a quotient graph. Algebraic Semirings • Semiring: An Algebraic structure that generalizes real arithmetic by replacing (⊕,⊗) with binary operations (Op1, Op2) – Op1 and Op2 have identity elements sometimes called 0 and 1 – Op1 and Op2 are associative. – Op1 is commutative, Op2 distributes over Op1 from both left and right – The Op1 identity is an Op2 annihilator.
  • 18. 18 Working with semirings • In Graph Algorithms, changing semirings multiple times inside a single algorithm is quite common. Hence, the semiring (and implied accumulator ⊕ by default) can be directly manipulated. • We can do this using python’s with statement with grb.BOOL.LOR_LAND: w += A@v with grb.BOOL.LOR_LAND: w = A.mxv(u,accum=grb.BOOL.LOR) Matrix vector product of A and v accumulating the result with the existing elements of w using: • ⊕ = ⊙ = Logical OR • ⊗ = Logical AND • Common semirings include (though pygraphblas has MANY more) (R, +, *, 0, 1) Real Field Standard operations in linear algebra FP64.PLUS_TIMES (R U {∞},min, +, ∞, 0) Tropical semiring Shortest path algorithms FP64.MIN_PLUS ({0,1}, |, &, 0, 1) Boolean Semiring Graph traversal algorithms BOOL.LOR_LAND (R U {∞}, min, *, ∞, 1) Selecting a subgraph or contracting nodes to form a quotient graph. FP64.MIN_TIMES
  • 19. 19 mxv() Multiply a matrix times a vector to produce a vector 𝑤𝑤 𝑖𝑖 = 𝑤𝑤 𝑖𝑖 ⨀ � 𝑘𝑘=0 𝑁𝑁 𝐴𝐴(𝑖𝑖, 𝑘𝑘)⨂𝑢𝑢(𝑘𝑘) 𝑤𝑤 ∈ 𝑆𝑆𝑀𝑀 𝑢𝑢 ∈ 𝑆𝑆𝑁𝑁 𝐴𝐴 ∈ 𝑆𝑆𝑀𝑀×𝑁𝑁 Definitions: • S is the domain of the objects w, u, and A • ⊙ is an optional accumulation operator (a binary operator) • ⊗ and ⊕ are multiplication and addition (or generalizations thereof) • ∑ uses the ⊕ operator w ⨀= A⊕.⊗u
  • 20. 20 Matrix vector multiplication: mxv() • The operators used are an accumulator (⊙) and the algebraic semiring operators (⊕ and ⊗). We will say a great deal more about semirings later … for now we’ll use the default case for Boolean data, the LOR_LAND semiring (i.e., logical OR for ⊕, Logical AND for ⊗). w ⨀= A⊕.⊗u import pygraphblas as grb # A’s type taken from values A = grb.Matrix.from_lists(rowInd, colInd, values) N = A.ncols # Create a vector of length N and type BOOL u = grb.Vector.sparse(grb.BOOL, N) u[ind] = True # set the value w = A.mxv(u) w = A @ u A.mxv(u, out=w) These three compute the same result in w. The third reuses an existing w.
  • 21. 21 Finding neighbors • A more common operation is to input a vector selecting a source and find all the neighbors one hop away from that vertex. • Using mxv(), how would you do this? – The adjacency matrix elements indicate edges –From a vertex (row index) –To another vertex (columns index) – Then the transpose of the adjacency matrix indicates edges –To a vertex (row index) –From other vertices (column index) • Therefore, we can find the neighbors of a vertex (marked by the non-empty elements of v) neighbors = AT⊕.⊗v neighbors = A.T @ v neighbors = A.mxv(v, desc=grb.descriptor.T0) Two ways to do a transpose with pygraphblas
  • 22. 22 The GraphBLAS Operations We’ve only covered mxv, so far, but the same conventions are used across all operations, so we’ll have no problem later when we use the others <M, m>: write masks (Matrix or vector). <r>: selects “replace or combine” for elements not selected by the mask.
  • 23. 23 GraphBLAS References GABB@IPDPS 2017 IEEE HPEC 2016 The official GraphBLAS C spec can be found at: www.graphblas.org
  • 24. 24 GraphBLAS Implementations • SuiteSparse library (Texas A&M): First fully conforming GraphBLAS release. – http://faculty.cse.tamu.edu/davis/suitesparse.html • GraphBLAS C (IBM): the second fully conforming release, – https://github.com/IBM/ibmgraphblas • GBTL: GraphBLAS Template Library (CMU/PNNL): Pushing GraphBLAS into C++ – https://github.com/cmu-sei/gbtl • GraphBLAST: A C++ implementation for GraphBLAS for GPUs (UC Davis), – https://github.com/gunrock/graphblast • Python bindings: – pygraphblas: A Python Wrapper around SuiteSparse GraphBLAS – https://github.com/Graphegon/pygraphblas – grblas: Python wrapper around GraphBLAS (part of Anaconda’s MetaGraph work) – https://github.com/metagraph-dev/grblas – pyGB: A Python Wrapper around GBTL (UW/PNNL/CMU) – https://github.com/jessecoleman/gbtl-python-binding • pgGraphBLAS: A PostgreSQL wrapper around Suite Sparse GraphBLAS – https://github.com/michelp/pggraphblas • Matlab and Julia wrappers around SuiteSparse GraphBLAS – https://aldenmath.com Third Party names are the property of their owners
  • 26. 26 LAGraph: A curated collection of high level Graph Algorithms GrAPL 2019 Graph Algorithms built on top of the GraphBLAS. Official release of LAGraph library v1.0 later in 2021
  • 27. 27 SuiteSparse: C libraries for GraphBLAS and LAGraph
  • 28.
  • 29.
  • 30.
  • 31. 31 Pygraphblas Documentation at: https://graphegon.github.io/pygraphblas/pygraphblas/index.html
  • 32. 32 32 A Hands-On Introduction to GraphBLAS: The Python Edition http://graphblas.org Tim Mattson Intel Labs With a special thank you to Tim Davis (Texas A&M) for GraphBLAS support in SuiteSparse and Michel Pelletier (Graphegon) for creating pygraphblas. ≡ Scott McMillan CMU/SEI … and the other members of the GraphBLAS specification group: Aydın Buluç (UC Berkeley/LBNL), Jose Moreira (IBM), and Ben Brock (UC Berkeley). To get course materials onto your laptop: $ git clone https://github.com/GraphBLAS-Tutorials/GraphBLAS_Python_tutorials.git