# crossover - Adaptive crossover support¶

 Crossover Fixed weight crossover ratios. BaseAdaptiveCrossover Adapted weight crossover ratios. AdaptiveCrossover Adapted weight crossover ratios. LogAdaptiveCrossover Adapted weight crossover ratios, log-spaced.

Crossover ratios

The crossover ratio (CR) determines what percentage of parameters in the target vector are updated with difference vector selected from the population. In traditional differential evolution a CR value is chosen somewhere in [0, 1] at the start of the search and stays constant throughout. DREAM extends this by allowing multiple CRs at the same time with different probabilities. Adaptive crossover adjusts the relative weights of the CRs based on the average distance of the steps taken when that CR was used. This distance will be zero for unsuccessful metropolis steps, and so the relative weights on those CRs which generate many unsuccessful steps will be reduced.

## Usage¶

crossover = Crossover(CR=CR)

2. Weighted crossover ratios:

crossover = Crossover(CR=[CR1, CR2, ...], weight=[weight1, weight2, ...])


The weights are normalized to one, and default to equally weighted CRs.

crossover = AdaptiveCrossover(N)


The CRs are set to [1/N, 2/N, … 1], and start out equally weighted. The weights are adapted during burn-in (10% of the runs) and fixed for the remainder of the analysis.

## Compatibility Notes¶

For Extra.pCR == ‘Update’ in the matlab interface use:

CR = AdaptiveCrossover(Ncr=MCMCPar.nCR)


For Extra.pCR != ‘Update’ in the matlab interface use:

CR = Crossover(CR=[1./Ncr], pCR=[1])

class bumps.dream.crossover.Crossover(CR, weight=None)[source]

Bases: object

Fixed weight crossover ratios.

CR is a scalar if there is a single crossover ratio, or a vector of numbers in (0, 1].

weight is the relative weighting of each CR, or None for equal weights.

adapt()[source]

Update CR weights based on the available adaptation data.

reset()[source]
update(xold, xnew, used)[source]

Gather adaptation data on xold, xnew for each CR that was used in step N.

class bumps.dream.crossover.BaseAdaptiveCrossover[source]

Bases: object

adapt()[source]

Update CR weights based on the available adaptation data.

reset()[source]
update(xold, xnew, used)[source]

Gather adaptation data on xold, xnew for each CR that was used in step N.

weight = None
class bumps.dream.crossover.AdaptiveCrossover(N)[source]

N is the number of CRs to use. CR is set to [1/N, 2/N, …, 1], with initial weights [1/N, 1/N, …, 1/N].

adapt()

Update CR weights based on the available adaptation data.

reset()
update(xold, xnew, used)

Gather adaptation data on xold, xnew for each CR that was used in step N.

weight = None
class bumps.dream.crossover.LogAdaptiveCrossover(dim, N=4.5)[source]

dim is the number of dimensions in the problem. N is the number of CRs to use per decade.

CR is set to [k/dim] where k is log-spaced from 1 to dim. The CRs start equally weighted as [1, …, 1]/len(CR).

N should be around 4.5. This gives good low end density, with 1, 2, 3, and 5 parameters changed at a time, and proceeds up to 60% and 100% of parameters each time. Lower values of N give too few high density CRs, and higher values give too many low density CRs.

adapt()

Update CR weights based on the available adaptation data.

reset()
update(xold, xnew, used)

Gather adaptation data on xold, xnew for each CR that was used in step N.

weight = None