📄 fe.h
字号:
/* fe.h fe.c handles purely the inference problem A s + n = z by free energy minimization fe2.h has very minor changes; in fact, SCRAP IT and use the old fe.h *//* Control parameters */typedef struct { /* fe_min_control */#include "fe_var_str.h"/* if there are multiple runs with different settings, some things stay the same: */ int init_given ; /* whether an initial condition has been given in the accompanying fe_min_param */ double sdx ; /* initial standard deviation */ int verbose ; int seqverbose ; int CG ; /* CG = 1 causes gradient to be checked */ char outfile[50] ; int printout ; long int seed ; /* used for randomization of the initial condition of the optimization */ double epsilon ; int pheading_count , pheading_period ; int DEMO ; int NORDER ; double betap ; /* and some things change */ double beta0 ; double beta1 ; double betaf ; /* if annealing is used then beta goes from beta0 to beta1 by uniform steps either arithmetic or geometric */ int betastyle ; int NL ; /* Number of loops. (annealing happens within these) */ int rich ; int opt ; /* seq_opt is 3 */ int iter , itmax ; double ftol ; double flintol ; int seq_period ; /* how frequently the free energy is evaluated to decide whether to stop the sequential optimizer */ int zero_temperature ; /* whether we are at zero temperature, in which case, the entropy and prior are ignored, and only the likelihood term is evaluated */ /* in old fe.c this was put in p not c */ macopt_args macarg ;} fe_min_control ; /* Definition of the FE problem */typedef struct { /* fe_min_param */ /* The sizes of everything. */ int M ; /* number of rows in the matrix A */ int N ; /* number of columns in A */ int m , n ; /* used to keep track of which row / column we are up to during complex optimizations */ /* The matrix A is represented in a list structure */ alist_matrix a ; /* this rep includes the norder vector that specifies in what order the sequential updates should occur */ double *bias ; /* the prior on the s vector */ unsigned char *s ; /* the true binary state vector s[n] */ unsigned char *so ; /* the answer so[1..N] returned by the algm. */ unsigned char *t ; /* the binary vector t[m] = A s mod 2 */ unsigned char *z ; /* this may be set up, not necessarily */ double *g ; /* log odds g[m] = +/- log er[m]/(1-er[m]) depending whether z[m] = 1 or 0 . Some optimizers (where the noise is fictitious) make use of this as a vector for shovelling derivative information around instead */ double *x ; /* can give an initial condition for x in here */ double *q0 , *q1 ; /* q1 = 1 / 1+ exp ( - x ) , etc. */ double *qd ; /* q0-q1 *//* double *q0q1 ; */ double *p0 , *p1 ; /* probabilities used in the forward and backward passes, p0[0..N+1], p1[0..N+1] */ double *pd ; double **mp0 , **mp1 ; /* mega-probabilities mp0[1..M][0..N+1] */ double **mpd ; double S , EL , EP ; /* entropy and energies of solution ; EP is the prior energy bit, EL is the likelihood *//* NB, EL, EP and S are back to front in sign, by an absurd convention of this program */ double F ; double beta ; /* the temperature of the party */ double betap ; /* factor for the prior bit of the energy, set this to zero if there is no prior, and set bias[n] to zero too */ double h_bar , h_ms , h_var ; /* mean , mean square and variance of the quantity h=log 1/p(s,n) */ double h_soln ; double h_dev ; /* deviation of our solution's h from typicality */ int count ; /* count of number of differences between the state and the true answer */ int count_high ; /* number of high bits in the s vector */ int count_s ; /* number of high bits in the true s vector */ int true_s ; /* whether the true s is supplied */ int viols ; /* number of violations by the reconstructed s vector */ double v ; /* the score of the final state relative to the truth */ int zero_temperature ; /* whether we are at zero temperature, in which case, the entropy and prior are ignored, and only the likelihood term is evaluated - THis is now obsolete in mnc5.c / fed2.c ; this is put in c instead of in p */ fe_min_control *c ; } fe_min_param;/* memory and so forth */void fe_allocate ( fe_min_param * , fe_min_control * ) ;void fe_allocate2 ( fe_min_param * , int ) ;void fe_defaults ( fe_min_param * , fe_min_control * ) ;void fe_defaults_p ( fe_min_param * ) ;void fe_defaults_c ( fe_min_control * ) ;void fe_free ( fe_min_param * , fe_min_control * ) ;void fe_free2 ( fe_min_param * , int ) ;/* the main routine */int fe_min ( fe_min_param * , fe_min_control * ) ;/* gradient evaluation */double forward_pass ( fe_min_param * ) ;void new_forward_pass ( fe_min_param * ) ;void backward_pass ( double * , fe_min_param *) ;void mega_forward_pass ( fe_min_param * ) ;void mega_backward_step ( int , fe_min_param *); void find_q_S ( double * , int, fe_min_param * ) ;void find_qd_S ( double * , int, fe_min_param * ) ;double x_to_q ( double , double * , double * , int ) ;double x_to_qd ( double , double * , int ) ;double objective ( double *, void * ) ;void d_objective ( double *, double *, void * ) ;double dd_objective ( double *, double *, void * ) ;/* either the routines objective and d_objective can be fed to another optimizer such as mac_opt or we can use an all in one optimizer */void jump_opt (double *, fe_min_param *, fe_min_control * ) ; /* optimization by `reestimation' */void seq_opt (double * , fe_min_param *, fe_min_control * ) ; /* other routines */void print_state ( double , double , double *, fe_min_param * ) ;void fprint_state ( double , double * , double *, fe_min_param * ) ;void printall ( FILE * , fe_min_param * ) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -