QInfer / python-qinfer

Library for Bayesian inference via sequential Monte Carlo for quantum parameter estimation.
BSD 3-Clause "New" or "Revised" License
92 stars 31 forks source link

Added a simple particle swarm based hyper-heuristic #125

Open Alan-Robertson opened 7 years ago

Alan-Robertson commented 7 years ago

First hyper-heuristic optimisation algorithm to be added for this pull request, an example follows: First we define a test function

f_rosenbrock = lambda x: numpy.sum([((x[i+1]  - x[i]**2)**2 + (1 - x[i])**2)/len(x) for i in range(len(x)-1)])

Next we initialise the hyper-heuristic optimiser and pass it the relevant parameters over which to optimise before calling it to perform the optimisation

hh_opt = ParticleSwarmOptimiser(['x','y'], fitness_function = f_rosenbrock)
hh_opt()

Similarly this is parrallelisable given a map function

import numpy
from ipyparallel import Client
from functools import partial
import pickle as pkl
import dill

f_rosenbrock = lambda x: numpy.sum([((x[i+1]  - x[i]**2)**2 + (1 - x[i])**2)/len(x) for i in range(len(x)-1)])

c = Client(profile='testing_profile')
c[:].use_dill()
dview = c[:]

hh_opt = ParticleSwarmOptimiser(['x','y','z','a'], fitness_function = f_rosenbrock)
hh_opt(serial_map=dview.map_sync)
coveralls commented 7 years ago

Coverage Status

Coverage decreased (-1.3%) to 70.407% when pulling 82fe4cd80eebf529cab77bdbb9259a0e6b3ccaef on Alan-Robertson:feature-hyper-heuristic-optimisation into 8118ab7adaf0bd82ea39577a08f2ad3b71bca1ae on QInfer:master.

cgranade commented 7 years ago

It seems that unrelated to the PR itself, there's build failures that are caused by Travis not being properly configured for QuTiP 4.1 (see discussion at #126). I'll work on getting that diagnosed, then, so we can include this PR ASAP.

cgranade commented 7 years ago

When you get a second, can you pull master into this PR to include #127? That should help fix build errors. Thanks!

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-1.4%) to 70.407% when pulling 0325109d54aff78704aabf8f5ba8e6911f4822f6 on Alan-Robertson:feature-hyper-heuristic-optimisation into 75f8723d0cb26199e90fdb426f654a80ab70e7a0 on QInfer:master.

cgranade commented 7 years ago

It looks like pulling in master helped fix the issues with the build, thanks again for that!

taalexander commented 7 years ago

I think some documentation on use cases for the hyper-heuristic optimiser would be nice. From this commit alone I am having trouble piecing it together. I assume this is related to the paper recently listed on the Arxiv by Alan, and Chris but I have yet to find time to read it.

cgranade commented 7 years ago

I agree entirely, the plan is to add documentation to both the guide and apiref, including descriptions of a few explicit usecases. At the moment, we wanted to start the PR as-is to get initial feedback on the design, since ideally the particle swarm optimizer will be useful outside the immediate usecases that @Alan-Robertson described in his initial comment.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-1.4%) to 70.407% when pulling 60ce342d193603af18c173674c2a056b0c460ee9 on Alan-Robertson:feature-hyper-heuristic-optimisation into 75f8723d0cb26199e90fdb426f654a80ab70e7a0 on QInfer:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.7%) to 71.108% when pulling a2762ec4b1fa15d4ffc5611f291edea105e83fb4 on Alan-Robertson:feature-hyper-heuristic-optimisation into 75f8723d0cb26199e90fdb426f654a80ab70e7a0 on QInfer:master.