46
© 2009 The MathWorks, Inc. Jörg-M. Sautter Application Engineer The MathWorks MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009

MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

  • Upload
    others

  • View
    40

  • Download
    1

Embed Size (px)

Citation preview

Page 1: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

©20

09 T

he M

athW

orks

, Inc

.

Jörg-M. SautterApplication Engineer

The MathWorks

MATLAB Based Optimization Techniques and Parallel Computing

BratislavaJune 4, 2009

Page 2: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

2

IntroductionLocal and Smooth OptimizationExample:

Portfolio Optimization, part 1Expected ShortfallGARCH

Global or Non-Smooth OptimizationExample:

Portfolio Optimization, part 2Parallel ComputingSummary

Agenda

Page 3: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

3

�� � ��� � ���

���

Major steps

Define your problem Solve your problem possibly subject to constraints Analyze and visualize the result

Demands

Appropriate solver Fast solver Robust solver Customizable solver settings Easy to use …

Optimization workflow

Page 4: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

4

What you have to doSituation

You know your objective function You know the constraints (if there are any)

What you have to do Code your objective function (in MATLAB, C, C++, Excel,…) Code your constraints Determine the type of optimization problem Call the appropriate solver

Note: there are exceptions which are even easier to handle…

Page 5: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

5

Classification

Stochastic Stochastic ProgrammingProgramming

Integer Integer ProgrammingProgramming

NonlinearNonlinearMinimizationMinimization

ContinuousContinuous DiscreteDiscrete

UnconstrainedUnconstrainedConstrainedConstrained

Nonlinear Nonlinear EquationsEquations

NonlinearNonlinearLeastLeast--SquaresSquares

Global Global OptimizationOptimization

LinearLinearProgrammingProgramming

NonlinearlyNonlinearlyConstrainedConstrained

QuadraticQuadraticProgrammingProgramming

NondifferentiableNondifferentiableOptimizationOptimization

ConstrainedConstrainedLinear Linear

LeastLeast--SquaresSquares

BoundBoundConstrainedConstrained

OptimizationOptimization

Global Global OptimizationOptimization

Page 6: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

6

MATLAB Based Optimization Tools MATLAB Curve Fitting Toolbox Optimization Toolbox Genetic Algorithms and Direct Search Toolbox

as well as

Statistics Toolbox Symbolic Math Toolbox

Page 7: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

7

Optimization with MATLAB Direct methods for linear systems

– square systems LU-decomposition Cholesky-decomposition QR-decomposition

– underdetermined systems– overdetermined systems

Iterative methods for linear systems– cg-method (and variants)– GMRES, QMR, MINRES,…

Polynomial approximation

Page 8: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

8

IntroductionLocal and Smooth OptimizationExample:

Portfolio Optimization, part 1Expected ShortfallGARCH

Global or Non-Smooth OptimizationExample:

Portfolio Optimization, part 2Parallel ComputingSummary

Agenda

Page 9: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

9

Optimization Toolbox

Graphical user interface and command line functions for:

– Linear and nonlinear programming– Quadratic programming– Nonlinear least squares and nonlinear

equations– Multi-objective optimization– Binary integer programming

Customizable algorithm options Standard and large-scale

algorithms Output diagnostics

Page 10: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

10

Example:Minimum of a smooth function

Page 11: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

11

IntroductionLocal and Smooth OptimizationExample:

Portfolio Optimization, part 1Expected ShortfallGARCH

Global or Non-Smooth OptimizationExample:

Portfolio Optimization, part 2Parallel ComputingSummary

Agenda

Page 12: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

12

Example: Portfolio Optimization

Page 13: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

13

Classic Mean-Variance

A portfolio is MV optimal if it has least risk for a given level ofreturns:

minimize

subject to

� � �� � � � � ��� � ��

��� � �� �� ��� �

���

� � �

�� �� � �� ����

and possibly

Page 14: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

14

Example: Expected Shortfall

Page 15: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

15

IntroductionLocal and Smooth OptimizationExample:

Portfolio Optimization, part 1Expected ShortfallGARCH

Global or Non-Smooth OptimizationExample:

Portfolio Optimization, part 2Parallel ComputingSummary

Agenda

Page 16: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

16

Genetic Algorithm and Direct Search Toolbox Graphical user interface and

command line functions for:– Genetic algorithm solver– Direct search solver– Simulated annealing solver

Useful for problems not easily addressed with Optimization Toolbox:

– Discontinuous– Highly nonlinear– Stochastic– Discrete or custom data types

Page 17: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

17

What is a Genetic Algorithm? Genetic Algorithms use concepts from evolutionary

biology to find exact or approximate solutions to optimization problems

Start with an initial generation of candidate solutions that are tested against the objective function

Subsequent generations evolve from the 1st

through selection, crossover and mutation

The individual that best minimizes the given objective is returned as the ideal solution

Page 18: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

18

Example:Minimum of a stochastic function

Page 19: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

19

IntroductionLocal and Smooth OptimizationExample:

Portfolio Optimization, part 1Expected ShortfallGARCH

Global or Non-Smooth OptimizationExample:

Portfolio Optimization, part 2Parallel ComputingSummary

Agenda

Page 20: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

20

Example: Custom Evolution Algorithms Encode which subset of

equities to test using bit strings of 1’s and 0’s

In this case, there are 30bits with exactly 6 bits equal to 1

In general, each bit string will have N bits with exactly K bits equal to 1

It is inefficient to test every possible bit string. For N = 30, K = 6, there are 593,775 possible combinations!

Page 21: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

21

Example: Custom Evolution Algorithms

Selection– Retain the best performing bit strings from one generation

to the next. Favor these for reproduction

Crossover– parent1 = [ 1 0 1 0 0 1 1 0 0 0 ]– parent2 = [ 1 0 0 1 0 0 1 0 1 0 ]– child = [ 1 0 0 0 0 1 1 0 1 0 ]

Mutation– parent = [ 1 0 1 0 0 1 1 0 0 0 ]– child = [ 0 1 0 1 0 1 0 0 0 1 ]

Page 22: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

22

Optimization Toolbox

Genetic Algorithm and

Direct Search Toolbox

Faster

Can handle larger problems Better on non smooth, noisy, stochastic problems More likely to find global solution Can solve problems that involve custom data types

Toolbox Comparison

Page 23: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

23

IntroductionLocal and Smooth OptimizationExample:

Portfolio Optimization, part 1Expected ShortfallGARCH

Global or Non-Smooth OptimizationExample:

Portfolio Optimization, part 2Parallel ComputingSummary

Agenda

Page 24: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

24

Parallel Computing with MATLAB

Why parallel computing?

How easy is it to use?

Licensing

Do I need special hardware?

Parallel computing and optimization

Page 25: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

25

Large Data Set HandlingWorkarounds Reduce Data

Wait

Solutions Increase

Addressable Memory

Add Processors

Page 26: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

26

number of machines

calc

ulat

ion

time

Number of machines increases

Page 27: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

27

number of machines

calc

ulat

ion

time

Calculation time decreases

Page 28: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

28

Parallel Computing with MATLAB

Why parallel computing?

How easy is it to use?

Licensing

Do I need special hardware?

Parallel computing and optimization

Page 29: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

29

Parallel Computing with MATLAB and Simulink

MATLAB DistributedComputing Server

MATLAB DistributedComputing Server

ParallelComputing

Toolbox

JobManager

CPUWorker

CPUWorker

CPUWorker

CPUWorker

Job

Task

Task

Task

Task

Result

Result

Result

Result

Result Toolboxes

Blocksets

Client MachineClient Machine

MPI supportMPI support

Page 30: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

30

Distributing Tasks (Task Parallel)

Time Time

Pro

cess

es

Page 31: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

31

Parallel for loops

parfor (i = 1 : n)% do something with i

end

Mix task parallel and serial code in the same function Run loops on a pool of MATLAB resources Iterations must be order-independent M-Lint analysis helps to identify if existing for loops can

be changed to parfor

Page 32: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

32

Large Data Sets (Data Parallel)

1111 2626 4141

1212 2727 4242

1313 2828 4343

1414 2929 4444

1515 3030 4545

1616 3131 4646

1717 3232 4747

1717 3333 4848

1919 3434 4949

2020 3535 5050

2121 3636 5151

2222 3737 5252

1111 2626 4141

1212 2727 4242

1313 2828 4343

1414 2929 4444

1515 3030 4545

1616 3131 4646

1717 3232 4747

1717 3333 4848

1919 3434 4949

2020 3535 5050

2121 3636 5151

2222 3737 5252

Page 33: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

33

Parallel Computing with MATLAB

Why parallel computing?

How easy is it to use?

Licensing

Do I need special hardware?

Parallel computing and optimization

Page 34: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

34

Run eight local workers with a PCT license

Easy to experiment with explicit parallelism on multi-core machines

Rapidly develop distributed and parallel applications on local computer

Take full advantage of desktop power

No separate compute cluster required

Parallel Computing

Toolbox

Parallel Computing

Toolbox

Page 35: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

35

Compute clusterCompute cluster

CPU

CPU

CPU

CPU

MATLAB Distributed Computing ServerMATLAB Distributed Computing Server

Scheduler

Worker

Worker

Worker

Worker

Scale up to cluster configuration with no code changes

Task

Task

Task

Task

Result

Result

Result

Result

Parallel Computing

Toolbox

Parallel Computing

Toolbox

Result

Job

Page 36: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

36

Computer ClusterComputer Cluster

Scheduler

Dynamic Licensing

CPU

CPU

CPU

CPU

Worker

Worker

Worker

Worker

Page 37: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

37

Computer ClusterComputer Cluster

Scheduler

Dynamic Licensing

CPU

CPU

CPU

CPU

Worker

Worker

Worker

Worker

Page 38: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

38

Dynamic Licensing

Computer ClusterComputer Cluster

Scheduler

CPU

CPU

CPU

CPU

Worker

Worker

Worker

Worker

Page 39: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

39

Dynamic Licensing – Multiple Users

Computer ClusterComputer Cluster

Scheduler

CPU

CPU

CPU

CPU

Worker

Worker

Worker

Worker

Page 40: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

40

Parallel Computing with MATLAB

Why parallel computing?

How easy is it to use?

Licensing

Do I need special hardware?

Parallel computing and optimization

Page 41: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

41

Supported on all MATLAB platforms

Page 42: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

42

Parallel Computing with MATLAB

Why parallel computing?

How easy is it to use?

Licensing

Do I need special hardware?

Parallel computing and optimization

Page 43: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

43

Parallel Computing and OptimizationParallel Computing and Optimization

Both,

– the Optimization Toolbox and– the Genetic Algorithms and Direct Search Toolbox

contain solvers which incorporate

– parallel optimization functionality,– parallel estimation of gradients,– nested parallel functions

provided the Parallel Computing Toolbox is available.

Page 44: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

44

Parallel Computing with MATLAB

Why parallel computing?– Process large amounts of data faster

How easy is it to use?– Small modifications to your existing MATLAB programs

Licensing– Dynamic!

Do I need special hardware?– Windows, Linux, Solaris, or Mac are fine

Parallel computing and optimization– Nicely integrated

Page 45: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

45

IntroductionLocal and Smooth OptimizationExample:

Portfolio Optimization, part 1Expected ShortfallGARCH

Global or Non-Smooth OptimizationExample:

Portfolio Optimization, part 2Parallel ComputingSummary

Agenda

Page 46: MATLAB Based Optimization Techniques and Parallel Computing · MATLAB Based Optimization Techniques and Parallel Computing Bratislava June 4, 2009. 2 Introduction Local and Smooth

46

BenefitsBenefits

Solvers for a wide range of optimization problems

Easy to use

Optimization supported by parallel computing