Legofit
infers population history from nucleotide site patterns.
|
Read and write "state files", which describe the state of the optmizer. More...
#include "state.h"
#include "error.h"
#include "misc.h"
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
Data Structures | |
struct | NameList |
struct | State |
Typedefs | |
typedef enum StateFile_t | StateFile_t |
Enumerations | |
enum | StateFile_t { OLD =0 , NEW =1 , UNSET =2 } |
Functions | |
NameList * | NameList_append (NameList *self, const char *name) |
void | NameList_free (NameList *self) |
int | NameList_size (NameList *self) |
void | NameList_print (NameList *self, FILE *fp) |
int | State_npoints (State *self) |
int | State_nparameters (State *self) |
void | State_setCost (State *self, int ndx, double cost) |
double | State_getCost (State *self, int ndx) |
void | State_setVector (State *self, int ndx, int dim, double x[dim]) |
int | State_getVector (State *self, int ndx, int dim, double x[dim]) |
State * | State_new (int npts, int npar) |
void | State_free (State *self) |
State * | State_read (const char *fname, int npar, const char *const *name) |
int | State_setName (State *self, int ndx, const char *name) |
Set name of parameter with index "ndx". More... | |
int | State_print (State *self, FILE *fp) |
State * | State_readList (NameList *list, int npts, int npar, const char *const *name) |
Variables | |
static const char * | file_format_2 = "format-2" |
Read and write "state files", which describe the state of the optmizer.
This file implements classes NameList and State.
NameList stores file names in a linked list. It is used for storing the names of state files while processing command-line arguments. Then State_readList uses this list of file names to construct a single State object.
State records the parameter values and the cost value of each point in the swarm maintained by the differential evolution algorithm. There are functions for moving data into and out of the State object and for reading from and writing to files.
The format of the state file changed in early July, 2018. Before that date, the state file did not include names of parameters. Parameter values in the state file had to be arranged in the same order as the free parameters in the .lgo file. If the .lgo and state files referred to different parameters or to the same parameters in a different order, parameters would get the wrong values. No error was detected unless this misassignment resulted in a tree that was not feasible–for example, one in which a segment of the population tree was older than its parent in the tree.
The new state file format includes the names of parameters, and the input routine compares these against the names of free parameters in the .lgo file. The two lists must have the same parameters in the same order. Otherwise, legofit aborts with an error message. Old- and new-format state files can both be input using –stateIn arguments and can be intermingled in a single legofit run.
int State_setName | ( | State * | self, |
int | ndx, | ||
const char * | name | ||
) |
Set name of parameter with index "ndx".
Return 0 on success, abort on failure.