-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.h
99 lines (64 loc) · 2.26 KB
/
model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef __MODEL_H__
#define __MODEL_H__
#include <glib.h>
#include <stdio.h>
#define MODEL_INIT_SZ 20
typedef struct Model_t Model;
typedef struct {
/* name of parameter */
char *name;
/* current value of paramter */
double val;
/* partial derivative of ll function wrt this param */
double deriv;
/* scaling coefficient that parameter value and deriv are multiplied
* by before being passed to minimizer in order to put parameters in
* reasonably similar range
*/
double scale;
/* TRUE if parameter has upper bound, FALSE otherwise */
int up_bound;
/* upper bound on parameter value */
double max_val;
/* TRUE if parameter is allowed to be negative */
int allow_neg;
/* TRUE if parameter is locked, FALSE otherwise */
int locked;
} ModelParam;
struct Model_t {
/* ptr to function that calculates log-likelihood */
double (*llhood) (Model *m, int, int);
/* array of parameters, n_param long */
ModelParam *param;
/* current size of parameter array (is kept >= number of param) */
int param_sz;
/* number of parameters */
int n_param;
/* number of parameters that are currently unlocked:
* value between 0 and n_param
*/
int n_unlocked;
/* ptr to data for model */
void *data;
/* ptr to model configuration information, can be NULL */
void *config;
/* table that maps parameter names to indices */
GHashTable *name2idx;
};
Model *model_new();
void model_free(Model *mdl);
ModelParam *model_get_param(const Model *mdl, const char *name);
double model_get_param_val(const Model *mdl, const char *name);
double model_get_param_deriv(const Model *mdl, const char *name);
void model_set_param_val(Model *mdl, const char *name, const double val);
void model_set_param_deriv(Model *mdl, const char *name, const double deriv);
void model_write_param(const Model *mdl, FILE *fh);
void model_write_param_ln(const Model *mdl, FILE *fh);
void model_write_grad(const Model *mdl, FILE *fh);
void model_write_grad_ln(const Model *mdl, FILE *fh);
ModelParam *model_add_param(Model *mdl, const char *name,
const int is_locked, const int allow_neg,
const double scale);
void model_lock_param(Model *mdl, const char *param_name);
GList *model_get_rand_unlocked_param(const Model *m, int n);
#endif