• No results found

Hyper-quicksort: energy efficient sorting via the Templar framework for Template Method Hyper-heuristics

N/A
N/A
Protected

Academic year: 2019

Share "Hyper-quicksort: energy efficient sorting via the Templar framework for Template Method Hyper-heuristics"

Copied!
29
0
0

Loading.... (view fulltext now)

Full text

(1)

framework for Template Method Hyper-heuristics

.

White Rose Research Online URL for this paper:

http://eprints.whiterose.ac.uk/88239/

Version: Accepted Version

Conference or Workshop Item:

Swan, Jeremiah and Burles, Nathan John orcid.org/0000-0003-3030-1675 (2015)

Hyper-quicksort: energy efficient sorting via the Templar framework for Template Method

Hyper-heuristics. In: 39th CREST Open Workshop: Measuring, Testing and Optimising

Computational Energy Consumption, 23-24 Feb 2015, UCL.

[email protected] https://eprints.whiterose.ac.uk/

Reuse

Items deposited in White Rose Research Online are protected by copyright, with all rights reserved unless indicated otherwise. They may be downloaded and/or printed for private study, or other acts as permitted by national copyright laws. The publisher or other rights holders may allow further reproduction and re-use of the full text version. This is indicated by the licence information on the White Rose Research Online record for the item.

Takedown

If you consider content in White Rose Research Online to be in breach of UK law, please notify us by

(2)

Hyper-quicksort: energy efficient sorting

via the

Templar

framework for

Template Method Hyper-heuristics

(3)

Motivation

Scalability remains an issue for program synthesis:

We don’t yet know how to generate sizeable algorithms from scratch.

Generative approaches such asGP still work best at the scale of expressions(though some recent promising results [6]).

Formal approaches require a strongmathematical background.

. . . buthuman ingenuity already provides a vast repertoire of specialized algorithms, usually with known asymptotic

behaviour.

Given these limitations, how can we best usegenerative

(4)

3/28

The Template Method Pattern

The ‘Template Method’ Design Pattern[1] divides an algorithm into afixed skeleton with one or morevariantparts. The fixedpartsorchestrate the behaviourof the variantparts. Example: Quicksort performance depends on the quality of thepivot, so we can treat the pivot functionas a variant part:

D o u b l e A r r a y q s o r t ( D o u b l e A r r a y a r r ) { d o u b l e p i v o t = p i v o t F n ( a r r ) ;

// ˆˆˆ p i v o t F n can be v a r i e d g e n e r a t i v e l y

r e t u r n q s o r t ( a r r . f i l t e r ( < p i v o t ) ) ++ a r r . f i l t e r ( == p i v o t )

++ q s o r t ( a r r . f i l t e r ( > p i v o t ) ) ;

(5)

Template Method Hyper-heuristics [10]

So if we can express an algorithmic framework in template method terms, then we can learn good implementationsfor thevariant parts.

By ‘good’, we mean ‘biased towards the distribution to which the algorithm is exposed’.

If our algorithms are metaheuristics, this means that they are not subject to the ‘No Free Lunch’ theorem [8], since the distribution over problem instances is biased away from uniform by the training set.

(6)

5/28

A framework for generative hyper-heuristics

Generative hyper-heuristics can be specified by:

A list of variation pointsdescribing the parts of the algorithm to be automatically generated.

An algorithm templateexpressing the algorithm skeleton. The template produces acustomized version of the algorithm fromautomatically-generated implementations of the variation points.

(7)

A functional description

For algorithm with function signatureIO: VP : (I1→O1)×(I2O2

. . .×(In→On).

Template :VP →(IO).

Fitness : (IO)→V.

(8)

7/28

Why a Framework?

Generative HH arelaborious to implement on a per-case basis, but non-trivial to generalize:

The Factory is typically implemented via GP and is invoked repeatedly . . .

. . . but popular GP implementations such as ECJ [3] and PushGP [7] expect to be the ‘top’ of the system. . .

. . . hence are not easy to use for generative hyper-heuristics. Fitness of one VP depends on the other VPs, so some fiddly software engineering is required to enable ‘dependency inversion’.

Heterogeneous signatures of VPs needs special handling to retain any notion of type-safety.

(9)

Interlude - higher-order functions in Java

i n t e r f a c e Fun1<Arg , R e s u l t> {

R e s u l t a p p l y ( Arg a r g ) ;

}

i n t e r f a c e Fun2<Arg1 , Arg2 , R e s u l t> { R e s u l t a p p l y ( Arg1 arg1 , Arg2 a r g 2 ) ;

}

// We can t h e n u s e f u n c t i o n s a s p a r a m e t e r s // and r e t u r n v a l u e s :

Fun1<I n t , S t r i n g>

compose ( Fun1<I n t , Double> f , Fun1<Double , S t r i n g> g ) {

r e t u r n new Fun1<I n t , S t r i n g>() {

S t r i n g a p p l y ( I n t a r g ) {

r e t u r n g . a p p l y ( f . a p p l y ( a r g ) ) ;

} };

(10)

9/28

Core

Templar

classes

p u b l i c i n t e r f a c e AlgTemplate<I , O> { p u b l i c Fun1<I , O>

makeAlg ( P r o g r a m L i s t p r o g r a m s ) ;

}

p u b l i c c l a s s A l g F a c t o r y<I , O> {

A l g F a c t o r y ( GPConfig [ ] v a r i a t i o n P o i n t C o n f i g s , AlgTemplate<I , O> t e m p l a t e ) { . . . }

P r o g r a m L i s t r u n ( F i t n e s s C a s e s<I , O> c a s e s , LossFn<O> l o s s F n ) { . . . }

(11)

Trivial example - ‘Identity’ template

Just executes the generated program for the (sole) variation point:

c l a s s I d e n t i t y T e m p l a t e

implements AlgTemplate<Double , Double> {

p u b l i c Fun1<Double , Double> makeAlg ( P r o g r a m L i s t p r o g s ) {

// Wrap t h e VP i n a f u n c t i o n :

r e t u r n new Fun1<Double , Double>() { Double a p p l y ( Double a r g ) {

r e t u r n p r o g s . g e t ( 0 ) . e x e c u t e ( a r g ) ;

} };

(12)

11/28

Using

Templar

The end-user only needs to do this1:

// 1 . D e f i n e an A l g T e m p l a t e s u b c l a s s ( p r e v i o u s s l i d e ) . // 2 . S e t up t h e a l g o r i t h ms p e c i f i c s :

AlgTemplate<Double , Double> t e m p l a t e = new I d e n t i t y T e m p l a t e ( ) ;

GPConfig [ ] v p C o n f i g s ={new R a t i o n a l F u n c t i o n C o n f i g ( ) ;}

F i t n e s s C a s e s t r a i n i n g S e t = . . . F i t n e s s C a s e s t e s t S e t = . . .

// 3 . I n v o k e Templar:

P r o g r a m L i s t b e s t V P s = Templar . t r a i n A n d T e s t ( t e m p l a t e , v p C o n f i g s ,

t r a i n i n g S e t , t e s t S e t , new RMSLossFn<Double>() ) ; p r i n t l n ( ” b e s t VPs : ” + b e s t V P s ) ;

(13)

Next simplest example - Composition Template

c l a s s C o m p o s i t i o n T e m p l a t e

implements AlgTemplate<I n t , S t r i n g> {

Fun1<I n t , S t r i n g> makeAlg ( P r o g r a m L i s t p r o g s ) { f = new Fun1<I n t , Double>() {

Double a p p l y ( I n t a r g ) {

r e t u r n p r o g s . g e t ( 0 ) . e x e c u t e ( a r g ) ;

} };

g = new Fun1<Double , S t r i n g>() {

S t r i n g a p p l y ( Double a r g ) {

r e t u r n p r o g s . g e t ( 1 ) . e x e c u t e ( a r g ) ;

} };

// t h i s t e m p l a t e j u s t composes // t h e two v a r i a n t p r o g r a m s . . .

r e t u r n compose ( f , g ) ;

(14)

13/28

HyperQuicksort

Just follow the above steps for anyalgorithm you wish to optimize.

(15)

HyperQuicksort - Pivot Function

a b s t r a c t c l a s s P i v o t F n

e x t e n d s Fun2<D o u b l e A r r a y , I n t g e r , Double>{

Double a p p l y ( D o u b l e A r r a y a , I n t r e c u s i o n D e p t h ) ;

}

c l a s s S e d g e w i c k P i v o t F n e x t e n d s P i v o t F n {

// c o u n t e r s t h e c a s e o f s o r t e d // ( o r r e v e r s es o r t e d ) i n p u t

Double a p p l y ( D o u b l e A r r a y a , I n t r e c u s i o n D e p t h ){ r e t u r n median ( a . f i r s t , a [ a . l e n g t h / 2 ] , a . l a s t ) ;

} }

I n t q u i c k s o r t ( D o u b l e A r r a y a , P i v o t F n p i v o t F n ) ;

// ˆ i n s t r u m e n t e d t o r e t u r n some m e a s u r e

(16)

15/28

HyperQuicksort - Alg Template

c l a s s Q u i c k s o r t T e m p l a t e

implements AlgTemplate<DoubleArray, I n t> {

Fun1<DoubleArray, Int> makeAlg (ProgramList p r o g s ) −> {

PivotFn p i v o t F n = (DoubleArray a , Int r e c u r s i o n D e p t h )

−> {

i n t p r o g R e s u l t = p r o g s [ 0 ] . e x e c u t e ( a . s i z e , r e c u r s i o n D e p t h ) ;

i n t numSamples = min ( a b s ( p r o g R e s u l t ) , a . s i z e ) ; r e t u r n median ( randomSample ( a , numSamples ) ) ;

};

r e t u r n (DoubleArray a r g ) −> Q u i c k s o r t . s o r t ( arg , p i v o t F n ) ;

(17)

HyperQuicksort - Top Level

// 1 . D e f i n e an A l g T e m p l a t e s u b c l a s s ( p r e v i o u s s l i d e ) . // 2 . C o n f i g u r e GP t o g e n e r a t e p i v o t F n VP :

L i s t<Var> v a r s = {Var ( ” s i z e ” ) , Var ( ” r e c u r s i o n D e p t h ” ) ; L i s t<Node> f u n c S e t = {I f F n ( ) , L e s s F n ( ) , AddFn ( ) ,. . .}; GPParams params = . . . // c r o s s o v e r , s e l e c t i o n e t c

GPConfig v p C o n f i g s ={new GPConfig ( f u n c S e t , v a r s , params ) ;}

// 3 . I n v o k e Templar

AlgTemplate<Double , Double> t e m p l a t e = new Q u i c k s o r t T e m p l a t e ( ) ;

F i t n e s s C a s e s t r a i n i n g S e t = . . . F i t n e s s C a s e s t e s t S e t = . . .

(18)

17/28

Wait - there’s more . . .

Manual creation of GP nodes for function sets on custom solution representations (e.g. Timetable,RoutePlan,AntTrail etc) is tedious.

Following [2], Templar.FunctionSetGeneratoruses reflection to

automatically build a function set fromany Java object. By this means, a hyper-heuristic forIterated Local Search over bitstrings was up and running from scratchin under 20 minutes

By following the above steps, it’s quick and easy to create a template for your favourite algorithm here.

(19)

Experiment - Setup

EpochX for GP.

Jalen [5] for power measurement.

Monitors execution time and processor utilisation to estimate power consumption.

Non-deterministic (e.g. other processes), and accuracy limited by platform (up to nanosecond).

(20)

19/28

Experiment - Pipeorgan Distribution [4]

Training setsize: 70 (* 100).

Testing setsize: 100 (at 9 different array lengths, * 1000).

0 20 40 60 80 100 0

20 40 60 80

DoubleArray index

V

al

u

(21)

Results

8 16 32 64 128 256 512 1024 2048 0.0625 0.25 1 4 16 64 256

DoubleArray size (log2 scale)

(22)

21/28

Results - Table

Array size

Middle index Sedgewick

Hyper-quicksort (J)

J p e J p e

8 0.191 7.46e-32 0.981 0.163 8.37e-32 0.980 0.094

16 0.296 1.20e-30 0.971 0.345 1.25e-31 0.979 0.173

32 0.651 8.13e-32 0.980 0.757 7.25e-32 0.981 0.410

64 1.366 4.80e-33 0.990 1.145 1.68e-30 0.970 0.976

128 3.505 4.80e-33 0.990 4.034 4.14e-33 0.991 2.341

256 8.175 4.14e-33 0.991 7.646 3.41e-32 0.983 6.387

512 19.777 4.33e-34 0.998 21.391 3.62e-34 0.999 15.268 1024 62.961 2.52e-34 1.000 42.508 6.44e-33 0.989 33.012 2048 198.438 2.52e-34 1.000 132.663 2.52e-34 1.000 70.234 Array

size

Random index

J p e

(23)

Experiment - Conclusions

P-values (Mann-Whitney U-test) and effect sizes

(Vargha-Delaney 12) clearly show Hyper-quicksort provides significant improvement on pipeorgan distributions.

Intermediate results showed that minimal recursion doesn’t always equate to minimal power consumption, as pivot function becomes more demanding.

(24)

23/28

Conclusion and Future Work

Algorithms can be decomposed into templatesconsisting of a fixed skeleton and a collection of variant components.

By judicious choice of function signatures, we can use generative methods (GP etc) to create variant components that are tuned to some target distribution.

(25)

References I

Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.

Design patterns: elements of reusable object-oriented software.

Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1995.

Simon M. Lucas.

Exploiting reflection in object oriented genetic programming.

(26)

25/28

References II

Sean Luke, Liviu Panait, Gabriel Balan, and Et.

ECJ 16: A Java-based Evolutionary Computation Research System, 2007.

M. Douglas McIlroy.

A killer adversary for quicksort.

Softw., Pract. Exper., 29(4):341–344, 1999.

Adel Noureddine, Aurelien Bourdon, Romain Rouvoy, and Lionel Seinturier.

Runtime monitoring of software energy hotspots.

In27th IEEE/ACM Int. Conf. on Autom. Softw. Eng. 2012,

(27)

References III

Lee Spector, Kyle Harrington, and Thomas Helmuth.

Tag-based modularity in tree-based genetic programming.

InProceedings of the 14th Annual Conference on Genetic and

Evolutionary Computation, GECCO ’12, pages 815–822, New

York, NY, USA, 2012. ACM.

Lee Spector, Jon Klein, and Maarten Keijzer.

The Push3 execution stack and the evolution of control.

In Hans-Georg Beyer et al, editor,GECCO 2005: Proceedings of the 2005 conference on Genetic and evolutionary

computation, volume 2, pages 1689–1696, Washington DC,

(28)

27/28

References IV

John Woodward and Jerry Swan.

Why classifying search algorithms is essential.

In2010 International Conference on Progress in Informatics

and Computing. (PIC-2010), 2010.

John R. Woodward and Jerry Swan.

The automatic generation of mutation operators for genetic algorithms.

InProceedings of the fourteenth international conference on

Genetic and evolutionary computation conference companion,

(29)

References V

John R. Woodward and Jerry Swan.

Template method hyper-heuristics.

InProceedings of the 2014 Conference Companion on Genetic

and Evolutionary Computation Companion, GECCO Comp ’14,

pages 1437–1438, New York, NY, USA, 2014. ACM.

John Robert Woodward and Jerry Swan.

Automatically designing selection heuristics.

InProceedings of the 13th annual conference companion on

Genetic and evolutionary computation, GECCO ’11, pages

References

Related documents

• Reviewer for Journal of Water Resources Planning &amp; Management, Journal of Environmental Management, Water Resources Research, Journal of Environmental Management, Journal of

Abstract: This study aims to examine and analyze the effect of firm size, profitability, sales growth, and good corporate governance on firm value with social

The SIS had already been partially validated (having demonstrated good internal consistency, concurrent validity, and responsiveness to change in a mental

Thus, the application of fertilizers based on soil test improved the performance of rice crop along with enhanced soil organic carbon, available macronutrients and soil

A study on fast food industry conducted by Hossain and Hossain (2011) found several different factors according to the order of importance- Good wages, overall

Prior to the fi nancial market turmoil that began in 2007, the Eurosystem, the Federal Reserve System and the Bank of England had very different operational frameworks for

One of the major assumptions of the CAPM is that the market is in equilibrium and that the expected rate of return is equal to the required rate of return for a given level of

consideration of two different points of view showing informed insights and ability to apply knowledge and understanding of religion effectively.