• No results found

Numerical Linear Algebra

N/A
N/A
Protected

Academic year: 2022

Share "Numerical Linear Algebra"

Copied!
54
4
0
Vis mer ( sider)

Fulltekst

(1)

Numerical Linear Algebra

with examples in geometry processing

Gaël Guennebaud

(2)

Outline

How to choose the right solver?

– dense, sparse, direct, iterative, preconditioners, FMM, etc.

Smoothness?

Quadratic constraints

Overview of other classical building-blocks

(3)

A zoo of linear solvers

(4)

SVD

Singular Value Decomposition

– Welcome default behavior:

over-constrained → Least-Square solution

rank-deficient → Least-Norm solution

– Down-side:

involve iterative decomposition algorithms

overkill for linear solving?

A = V Σ W * x = A + b = W Σ + V * b

(5)

QR

QR decomposition

– Least-square solution:

– with column-pivoting → rank revealing

rank-deficient:

→ complete orthogonalization (eliminate )

→ yields minimal norm solution :)

A P = Q R

x = P R 1 Q T b

A P = Q ( T 0 11 0 0 ) Z

A P = Q ( R 0 1 R 0 2 )

R 2

(6)

LU

LU decomposition

– based on Gaussian elimination

– good for square, non symmetric problems

– mostly useful for sparse problems

A P = L U

(7)

Cholesky

Cholesky decomposition

– For SPD matrices

– For symmetric indefinite matrices:

as fast

numerical stability:

pivoting

or 2x2 diagonal blocks

A = L L '

P T A P = L D L '

(8)

Dense solvers – Summary

QR LU

Cholesky

SVD

robustness

speed

square problem

normal equation

LS/LN symmetric

(well conditioned)

multi-dim.

analysis,

polar dec., etc.

(9)

Example

Scattered data interpolation/approximation

– problem statement

input:

sample positions

with associated values

output:

a smooth scalar field s.t.,

p

i

f

i

f : ℝ

d

→ℝ

f ( p )≈ f

(10)

unknowns

Discretization

Decomposition on a set of basis functions

– linear LS minimization:

– plus, f has to be smooth

how to mathematically defines “smooth”?

→ seek for a (poly-)harmonic solution:

f ( x )= ∑

j

α

j

ϕ

j

( x )

α= argmin ∑

i

j

α

j

ϕ

j

( p

i

)− f

i

2

Δ k f = 0

(11)

Smoothness & RBF

Solution 1: Enforce smoothness by construction

– Choose (poly-)harmonic basis functions:

– Example: Radial Basis Functions

centered at nodes :

polyharmonic splines:

thin-plate spline :

f ( x )= ∑

j

α

j

ϕ ( x q

j

)

ϕ ( t )= t

k

, k = 1,3,5, … ϕ ( t )= t

k

ln ( t ) , k = 2,4,6, …

ϕ ( t )= t

2

ln ( t ) q

j

Δ k ϕ i = 0

(12)

RBF in practice

Leads to a dense LS problem:

– Choice of the ?

take → interpolation!

– Solver choice?

square & non-symmetric → LU

– Conditioning

depends on the sampling

[ ⋯ ϕ ( p i q j ) ] ⋅α = [ f i ]

q

j

q

j

= p

j

⇔ A α = b

(13)

RBF in practice

Globally supported basis

– storage:

– solving:

– 1 evaluation:

→ very expensive for numerous nodes

max: a few thousands

– For n large: Fast Multipole Method (FMM)

iterative and hierarchical approach

somewhat complicated, rarely used in practice O ( n

3

)

O ( n )

O ( n

2

)

(14)

Global to Local Basis

Solution 2: enforce smoothness through a PDE

– the key problem is now to solve for

– subject to boundary constraints, e.g.:

– advantage:

enable locally supported basis functions (e.g., box-splines)

→ Finite Element Method (FEM) Δ k f = 0

f ( p i )= f i

(15)

Laplacian equation

Example:

– fundamental in many applications

interpolation

smoothing

regularization

deformations

parametrization

etc.

Δ f = 0 ( Δ f = ▽⋅▽ f =

2

x f

2x

+

2

y f

2y

+⋯ )

(16)

FD Discretization

Example on a 2D grid

– finite differences

– Matrix form:

Δ f ( i , j )= ( f ( i 1, j )+ f ( i + 1, j )+ f ( i , j 1 )+ f ( i , j + 1 ) )

4 − f ( i , j ) = 0

Δ ⇔ [ 0 1 0 1 1 4 1 0 0 ] f ( i , j )

L f = 0

(17)

FEM Discretization

Leads to a sparse linear system of equations

– is called the stiffness matrix

– are compactly supported → most of the

– is usually huge, e.g.

~ number of pixels of an image

~ number of vertices of a mesh

→ How to exploit sparsity in linear solvers?

L u = 0 with L i, j = < ▽ϕ i , ▽ϕ j >

ϕ L i L i , j = 0

L

(18)

FEM Discretization

On a triangular mesh

– = linear basis (aka barycentric coordinates)

– famous “cotangent formula”:

L

i , j

= < ▽ϕ

i

, ▽ϕ

j

> = cot α

ij

+ cot β

ij

L

i ,i

= − ∑

vjN1(vi)

L

i , j

ϕ i

α

ij

β

ij

v

i

v

j

v

j1

v

j+1

(19)

Sparse representation?

Naive way:

Compressed {Row,Column} Storage

– the most commonly used

– need special care to “assemble” the matrix

warning: might be time consuming!

– variant: store small blocks

std::map<pair<int,int>, double>

(20)

Sparse solver classifications

Direct methods

– Simplicial versus Super{nodal,frontal}

– Fill-in ordering

Iterative methods

– Preconditioning

Multi-grid & Hybrid methods

(21)

Direct methods

General principle

– adapt matrix decompositions to sparse storage

Cholesky, LU, QR, etc.

Main difficulties:

– matrix-updates introduce new non-zeros

→ need to predict their positions to avoid prohibitive memory reallocation/copies

→ need to reduce the number of new non-zeros (fill-in)

– scalar-level computation is slow

→ need to leverage dense matrix operations

(22)

Fill-in

Fill-in depends on row/column order!

– i.e., on the arbitrary choice of the numbering of the unknowns & constraints

– pathological example:

lu L U

sparse input dense factors :(

(23)

Fill-in

Fill-in depends on row/column order!

– i.e., on the arbitrary choice of the numbering of the unknowns & constraints

– pathological example:

lu L U

sparse input

after re-ordering sparse factors :)

(24)

Fill-in

Fill-in depends on row/column order!

– i.e., on the arbitrary choice of the numbering of the unknowns & constraints

→ re-ordering step prior to factorization

tricky:

– must be faster than the factorization!

– must trade numerical stability!

– must preserve symmetry

(25)

Fill-in ordering

Many heuristics

– Band limiting

– Nested discestion

approximate minimum degree (AMD)

symmetric and symmetric variants

(26)

Performance issue

Sparse structure

→ indirect memory accesses

bad pipelining

bad cache usage

Need to leverage dense matrix computations

– several variants: multinodal, multifrontal, etc.

– makes sense for not too sparse problems

e.g., Poisson eq. on a 3D domain

(27)

Direct solvers – summary

Typical pipeline to solve Ax=b

pre-ordering

structure analysis numerical factorization

solve

(back/forward substitutions)

A

(same structure but different numerical coefficients)

(has many as you want, can even be a matrix)

A b x

matrix assembly

problem

(28)

Direct solvers – summary

Pros

– solve for multiple right-hand sides

– very fast for very sparse problems (e.g., 2D Poisson)

Cons

– high memory consumption

ok for 2D domains

huge for 3D domains

– (very) difficult to implement

(29)

Iterative methods

Jacobi iterations, Gauss-Seidel

– stationary methods based on matrix splitting:

Jacobi :

Gauss-Seidel :

– easiest to implement but...

– slow convergence

– needs to be diagonally dominant (or SPD)

x

(i+1)

= D

1

( b − R x

(i)

) A = D + R

x

(i+1)

= L

1

( b − U x

(i)

) A = L + U

(30)

Iterative methods

Conjugate Gradient (CG)

– non-stationary method

– SPD: convergence with decreasing error

– principle

descent along a set of

optimal search directions:

with

{ d 1 , , d i }

d j T A d i = 0

(31)

Conjugate Gradient

In practice

– dominated by matrix-vector products:

– no need to “assemble” the matrix A

operator approach

easy to implement on the GPU

– much faster convergence with a pre-conditioner

Jacobi, (S)SOR → easy, matrix-free and GPU friendly

Incomplete factorization → more involved

A d i

(32)

Least-Square & CG

Conjugate Gradient for Least-Square problems

– The bad approach: form the normal equation

– LSCG

solve for the normal equation without computing

numerically more stable

matrix-free & GPU friendly

A T A x = A T b

A T A

(33)

Iterative methods

Iterative methods for non-symmetric problems

– Bi-CG(STAB)

close to CG but...

convergence not guaranteed

error may increase!

– GMRES

error monotonically decreases but...

may stall until the n-th iteration!

memory consumption

has to store a list of basis vectors (hundreds)

(34)

Sparse solvers – Summary

memory mat-free multiple rhs 2D domain 3D domain Direct

(simplicial) - - *** *** *

Direct

(with dense blocks)

- - *** * **

Iterative

methods *** *** - * ***

Symmetry Positive Definite is important

– simpler implementation

– up to an order of magnitude faster

– more robust

(35)

Solver Choice

Questions:

– Solve multiple times with the same matrix?

yes → direct methods

– Dimension of the support mesh

2D → direct methods

3D → iterative methods

– Can I trade the performance? Good initial solution?

yes → iterative methods

– Hill conditioned?

Still lost? → online sparse benchmark → demo

(36)

Let's go back to our Laplacian problem...

(37)

Laplacian problem

Laplacian matrix on a triangular mesh

– with ,

– symmetric

– conditioning depends on triangle shapes

– SPD for well shaped triangles

– solver choice: direct simplicial LDL^T

L i , j = cot α ij + cot β ij L i ,i = − ∑ L i , j

Δ u = 0 ⇔ L u = 0

(38)

Laplacian problem

This is an abstract problem

– need to add constraints to make it meaningful

Fix values at vertices, i.e., for some i

– remove smoothness constraints at these vertices

– and reorder:

– problem is still SPD :)

Δ u = 0 ⇔ L u = 0

u i = u ̄ i

[ L L 00 10 L L 01 11 ] [ u u ̄ ] = [ 0 0 ] L 00 u = L 01 ⋅̄ u

(39)

Laplacian problem

Add linear constraints:

– Solution 1:

reduce the solution space through the null-space of C

reduce problem size :)

problem is not symmetric anymore :(

C u = b

(40)

Laplacian problem

Add linear constraints:

– Solution 2:

Lagrange multipliers yields

not SPD :(

but symmetric indefinite → LDL^T if well conditioned

C u = b

[ C L C 0 T ] [ u λ ] = [ b 0 ]

(41)

Regularizing homogeneous equations with

quadratic constraints

(42)

A first example

How to fit a hyper-plane trough points?

– Search a plane with center c and normal n to a set of points

– Minimize least-square error :

– Subject to

→ at a first glance, non linear problem...

p i

E ( c , n )= ∑ i ( ( p i c ) T n ) 2

n ∥ = 1

(43)

Plane fitting

E(c,n) minimum when its derivative wrt. c vanish :

– implies that

E ( c , n )

c = ... = − 2 n n Ti ( p i c )= 0

i ( p i c )= 0 c = 1 ni p i

(44)

Plane fitting

Reformulate E(c,n):

subject to

Lagrange multiplier :

Differentiate on n yields an eigenvalue problem :

residual:

→ n is eigenvector of smallest eigenvalue

E ( c , n ) = n T ( i ( q i c )( q i c ) T ) n = n T C n min

n ∥ = 1

n T C n −λ ( n T n − 1 ) → min C n = λ n

n

T

C n

(45)

A second example

How to fit an hyper-sphere to points?

– Search a sphere with center c and radius r to a set of points

– Minimize least-square error :

non-linear energy → see previous session (need an initial guess)

numerically unstable for flat area ( )

E ( c ,r )= ∑ i ( p i c ∥− r ) 2

p i

c ,r →∞

(46)

Sphere fitting

Linearized energy:

– metric is not Euclidean anymore

– still unstable for flat area

E ( c , r )= ∑ i ( p i c 2 r 2 ) 2

= ∑ i ( c 2 r 2 2 p i T c + p i 2 ) 2

= ∑ i ( u c + p i T u l + p i 2 ) 2

(47)

Sphere fitting

Linearized energy:

– metric is not Euclidean anymore

– again, needs to avoids trivial solution E ( c , r )= ∑ i ( p i c 2 r 2 ) 2

= ∑ i ( c 2 r 2 2 p i T c + p i 2 ) 2

= ∑ i ( u c + p i T u l + p i 2 ) 2

= ∑ i ( u c + p i T u l + u q p i 2 ) 2

u = 0

(48)

Algebraic sphere fitting

Some bad ideas:

– fix some values, e.g.:

– linear equality:

– unit norm:

What do we want?

– be invariant to similarity transformations

– mimic Euclidean norm

u q = 1

j

u

j

= 1

u ∥ = 1

(49)

Algebraic sphere fitting

Solution:

– constraint

– algebraic distance close to Euclidean one nearby region of interest

In practice:

– with symmetric

– solve E over the unit ball induced by

∥▽ f ( x ) ∥ = 1 at f ( x )= 0

u T Q u = 1 Q

Q

(50)

Quadratic constraints

The general problem is now:

minimize

subject to

– through Lagrange multipliers, we end up with a generalized eigenvalue problem:

– residual =

– is the eigenvector of the smallest eigenvalue

u T Q u = 1

∥ A u2

A u = λ Q u λ

u

(51)

Quadratic Constraints

Other examples:

– Unsigned surface reconstruction

– Smooth n-direction fields

Taking home message

– the choice of the regularization norm is crucial!

– taking is unlikely the right choice! x = 1

(52)

Eigenvalue problems

How to solve?

closed forms 2x2 and 3x3

iterative algorithms otherwise

need only the largest → Power iterations

fast, easy, GPU-friendly, sparse-friendly

be careful with repeated eigenvalues

need only the smallest → Inverse Power iterations

slightly more tricky: needs a linear solver

Can-it be considered as a direct method?

numerically no, but

it provides many of the advantages of simple linear

problems such as analytic derivatives

(53)

in geometry processing

Alternate solution

– chicken-egg problems

fix one part of the equation, solve for the second part

fix the second part, solve for the first one

repeat

– ex.: ARAP energy

Barriers

– replace inequality constraints with penalty functions

– much more tricky than it looks like

(54)

in geometry processing

Smooth functions on meshes

– linear basis are unnecessarily numerous

– compute a small set of smooth eigenfunctions

typically: a few hundreds

many kernels, e.g., heat-kernel, Laplacian

– your solution becomes “smooth by construction”

– permits to work with medium-size dense algebra

– overheads: initialization, conversions, storage

Referanser

RELATERTE DOKUMENTER

This focus on themes was the initial part of a study concentrating on four areas: what is important to teach in a first course in linear algebra?; are there teaching methods which

Linear equations are modules over the skew group algebra, solutions are morphisms relating a given equation to other equations, symmetries of an equation are module en- domorphisms

We pick up the regularized Perona and Ma- lik model and rewrite the corresponding linear algebra operations as image processing operations supported by graphics hardware.. Thus they

Topology refinement For a triangle with vertex indices (k,l,m) in the control mesh, three new triangles of the refined mesh are simple arrangements of an original vertex and two

It is the purpose of this paper to demonstrate how accelerated global convergence and linear scaling may be achieved using a modified Newton-Schulz algorithm.. The remainder of

(ii) Implementation of MPI integral components into LSDALTON, improvements of optimization and scalability, interface of matrix operations to PBLAS and ScaLAPACK

Homotopy fixed points, Tate spectrum, homotopy orbits, commutative S-algebra, Dyer–Lashof operations, differentials, topological Hochschild homology, topological cyclic

Indefinite stochastic linear quadratic control and generalized differential Riccati equation, SIAM Journal on Control and Optimiza- tion, Vol.. Linear matrix inequalities,

Abstract: Efficient computation of trajectories of switched affine systems becomes possible, if for any such hybrid system, we can manage to efficiently compute the sequence

By drawing on the notions of procedural and conceptual knowledge, the research was operationalized by asking professionals in undergraduate mathematics education (n=18) to interpret

The two statements using the words ‘applications’ and ‘modelling’ had lower round 3 ranks: ‘It is important that students encounter applications of linear algebra outside of

We no longer need to use the variable matrix in Arena but have to create a logical variable matrix using the sub model which transforms the data from Excel into Arena and aligns

Fortunately, the standardized LAPACK (Linear Algebra Package) and BLAS (Basic Linear Algebra Subpro- grams) libraries [18, 2], written in Fortran 77, contains very efficient

Topological Hochschild homology, commutative S-algebra, coproduct, Hopf algebra, topological K-theory, image of J spectrum, B¨ okstedt spectral sequence, Steenrod

The theoretical basis for the numerical optimization algorithm presented in Section 3 is the fact that under the assumption of a linear LV model an optimal loading weight matrix

I Approximate implicitization combines algebraic geometry, computer aided design and linear algebra to o¤er a family of methods for the approximation of parametric curves and

Introduction and Motivation Curve and surface representation High degree implicit surfaces Approximate Implicitization..

I ordinary differential equations (ODEs): Euler method, predictor-corrector methods, Runge-Kutta method, some specific integrators;.. I basic matrix operations, linear

In this thesis, the kernel is to solve sparse linear algebra by the conjugate gradient method and the hardware is a programmable graphics card supporting CUDA.. The picture is

We abbreviate MZ/ℓ to M, and we write A ∗∗ for the motivic Steenrod algebra at ℓ, which by Theorem 1.1 is the algebra of all bistable operations in mod ℓ motivic cohomology

Note also that the steady state solution of a continuous time model and the discrete time model should be the same.. B.3 Linear transformation of state space

Given the controversial history of anthropology and the continued desire for independence among African scholars (Obbo 2006; Nkwi 2006), however, the curriculum was far from a

Introduction to numerical methods and computer programming in FORTRAN: Fundamentals of FORTRAN programming; fundamentals of numerical methods: solution of non-linear algebraic