Legofit
infers population history from nucleotide site patterns.
Loading...
Searching...
No Matches
diffev.c File Reference
#include "diffev.h"
#include "misc.h"
#include "simsched.h"
#include "pointbuff.h"
#include "jobqueue.h"
#include <gsl/gsl_rng.h>
#include <limits.h>
#include <float.h>
#include <math.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "dprintf.h"

Data Structures

struct  TaskArg

Macros

#define DPRINTF_ON
#define PRARRAY(nn, xx)
 Macro to print array.

Functions

static void assignd (int dim, double a[dim], double b[dim])
 Assigns dim-dimensional vector b to vector a.
void sample (int k, int rtn[k], int n, int array[n], const gsl_rng *rng)
 Choose at random k distinct integers from array of n, placing result in "rtn".
TaskArgTaskArg_new (int dim, double(*objfun)(int xdim, double x[xdim], void *jdat, void *tdat), void *jobData)
 TaskArg constructor.
static void TaskArg_setArray (TaskArg *self, int dim, double v[dim])
 Set the array within a TaskArg equal to an external array, v.
void TaskArg_free (TaskArg *self)
 TaskArg destructor.
void TaskArg_print (TaskArg *self, FILE *fp)
 Print a TaskArg.
int taskfun (void *voidPtr, void *tdat)
 Called by JobQueue.
void printState (int nPts, int nPar, double par[nPts][nPar], double cost[nPts], int imin, FILE *fp)
 Print current state. Current optimal point is printed first.
void stratDE_best_1_exp (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 DE/best/1/exp Our oldest strategy but still not bad.
void stratDE_rand_1_exp (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 DE/rand/1/exp This is one of my favourite strategies.
void stratDE_rand_to_best_1_exp (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 DE/rand-to-best/1/exp This strategy seems to be one of the best strategies.
void stratDE_best_2_exp (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 DE/best/2/exp is another powerful strategy worth trying.
void stratDE_rand_2_exp (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 DE/rand/2/exp seems to be a robust optimizer for many functions.
void stratDE_best_1_bin (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 Remaining strategies have binomial crossover.
void stratDE_rand_1_bin (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 DE/rand/1/bin.
void stratDE_rand_to_best_1_bin (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 DE/rand-to-best/1/bin.
void stratDE_best_2_bin (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 DE/best/2/bin.
void stratDE_rand_2_bin (int dim, double tmp[dim], int nPts, int ndx[nPts], double bestit[dim], double F, double CR, double(*pold)[nPts][dim], gsl_rng *rng)
 DE/rand/2/bin.
void * getStratFun (int strategy)
 Return pointer to function implementing given strategy.
void sighandle (int signo)
 Signal handler.
void handleSIGTERM (int signo)
 SIGTERM is translated to SIGINT.
const char * diffEvStrategyLbl (int i)
 Return a const pointer to the label of the i'th strategy.
DEStatus diffev (int dim, double estimate[dim], double *loCost, double *yspread, DiffEvPar dep, gsl_rng *rng)
 The diffev optimizer.

Variables

pthread_mutex_t outputLock
volatile sig_atomic_t sigstat =0
static const char * stratLbl []

Macro Definition Documentation

◆ PRARRAY

#define PRARRAY ( nn,
xx )
Value:
do { \
printf("%s:%s:%d:", __FILE__,__func__,__LINE__); \
int ii; \
for(ii=0; ii < (nn); ++ii) \
printf(" %lf", (xx)[ii]); \
putchar('\n'); \
}while(0);

Macro to print array.

Function Documentation

◆ sample()

void sample ( int k,
int rtn[k],
int n,
int array[n],
const gsl_rng * rng )

Choose at random k distinct integers from array of n, placing result in "rtn".

The function can be called repeatedly without re-initializing "array".

Side Effects:\n Re-orders entries of array.

Referenced by get_descendants1(), stratDE_best_1_bin(), stratDE_best_1_exp(), stratDE_best_2_bin(), stratDE_best_2_exp(), stratDE_rand_1_bin(), stratDE_rand_1_exp(), stratDE_rand_2_bin(), stratDE_rand_2_exp(), stratDE_rand_to_best_1_bin(), and stratDE_rand_to_best_1_exp().

◆ stratDE_best_1_bin()

void stratDE_best_1_bin ( int dim,
double tmp[dim],
int nPts,
int ndx[nPts],
double bestit[dim],
double F,
double CR,
double(*) pold[nPts][dim],
gsl_rng * rng )

Remaining strategies have binomial crossover.

DE/best/1/bin

References sample().

Referenced by getStratFun().

◆ stratDE_best_1_exp()

void stratDE_best_1_exp ( int dim,
double tmp[dim],
int nPts,
int ndx[nPts],
double bestit[dim],
double F,
double CR,
double(*) pold[nPts][dim],
gsl_rng * rng )

DE/best/1/exp Our oldest strategy but still not bad.

However, we have found several optimization problems where misconvergence occurs. strategy DE0 (not in our paper)

References sample().

Referenced by getStratFun().

◆ stratDE_rand_1_exp()

void stratDE_rand_1_exp ( int dim,
double tmp[dim],
int nPts,
int ndx[nPts],
double bestit[dim],
double F,
double CR,
double(*) pold[nPts][dim],
gsl_rng * rng )

DE/rand/1/exp This is one of my favourite strategies.

It works especially well when the "bestit[]"-schemes experience misconvergence. Try e.g. F=0.7 and CR=0.5. as a first guess. strategy DE1 in the techreport

References sample().

Referenced by getStratFun().

◆ stratDE_rand_to_best_1_exp()

void stratDE_rand_to_best_1_exp ( int dim,
double tmp[dim],
int nPts,
int ndx[nPts],
double bestit[dim],
double F,
double CR,
double(*) pold[nPts][dim],
gsl_rng * rng )

DE/rand-to-best/1/exp This strategy seems to be one of the best strategies.

Try F=0.85 and CR=1. If you get misconvergence try to increase nPts. If this doesn't help you should play around with all three control variables. similiar to DE2 but generally better

References sample().

Referenced by getStratFun().

◆ TaskArg_free()

void TaskArg_free ( TaskArg * self)

TaskArg destructor.

Doesn't free self->jobData or self->objfun, which are not locally owned.

Referenced by diffev().

Variable Documentation

◆ stratLbl

const char* stratLbl[]
static
Initial value:
=
{ "", "DE/best/1/exp", "DE/rand/1/exp", "DE/rand-to-best/1/exp",
"DE/best/2/exp", "DE/rand/2/exp", "DE/best/1/bin",
"DE/rand/1/bin", "DE/rand-to-best/1/bin", "DE/best/2/bin",
"DE/rand/2/bin"
}