-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathd_model.h
69 lines (50 loc) · 1.12 KB
/
d_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
#ifndef D_MODEL
#define D_MODEL
#include <math.h>
#include <stdint.h>
typedef struct {
double *pos;
uint8_t num;
} pos_f;
typedef struct {
pos_f *a;
uint32_t poscount;
int basecount;
float minfrac;
} all_f;
all_f * read_arr( FILE *file );
int flatten_arr( double *farr, all_f *arr );
void free_arr( all_f *arr );
//
static inline double prob_norm( double mean, double sd, double x )
{
double norm;
norm = (1/(sd * sqrt(2*M_PI))) * exp( -( pow(x - mean, 2) / (2 * pow(sd, 2)) ));
return norm;
}
static inline double prob_unif( float minfrac, double x )
{
double unif = 0.0;
float upper = 1.0 - minfrac;
if ( x >= minfrac && x <= upper ) {
unif = 1 / (upper - minfrac);
}
return unif;
}
//
typedef struct {
all_f *arr;
double a[4];
double m[3];
double w[3];
int f; // bitflag: 1-est mix; 2-est mean; 4-est sd; 8-add unif;
double ll;
} em_data;
// prototypes from em.c
void run_EM (em_data *data);
void setup_EMstr (em_data *data,
const double a[4],
const double m[3],
const double w[3],
const int f);
#endif