-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathslda.h
87 lines (68 loc) · 2.93 KB
/
slda.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
// (C) Copyright 2009, Chong Wang, David Blei and Li Fei-Fei
// written by Chong Wang, [email protected]
// This file is part of slda.
// slda is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// slda is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
#ifndef SLDA_H
#define SLDA_H
#include "settings.h"
#include "corpus.h"
typedef struct {
double * z_bar_m;
double * z_bar_var;
} z_stat;
typedef struct {
double ** word_ss;
double * word_total_ss;
int num_docs;
z_stat * z_bar;
int * labels;
int * tot_labels;
} suffstats;
class slda
{
public:
slda();
~slda();
void free_model();
void init(double alpha_, int num_topics_, const corpus * c);
void v_em(corpus * c, const settings * setting,
const char * start, const char * directory);
void save_model(const char * filename);
void save_model_text(const char * filename);
void load_model(const char * model_filename);
void infer_only(corpus * c, const settings * setting,
const char * directory);
suffstats * new_suffstats(int num_docs);
void free_suffstats(suffstats * ss);
void zero_initialize_ss(suffstats * ss);
void random_initialize_ss(suffstats * ss, corpus * c);
void corpus_initialize_ss(suffstats* ss, corpus * c);
void load_model_initialize_ss(suffstats* ss, corpus * c);
void mle(suffstats * ss, int eta_update, const settings * setting);
double doc_e_step(document* doc, double* gamma, double** phi, suffstats * ss, int eta_update, const settings * setting);
double lda_inference(document* doc, double* var_gamma, double** phi, const settings * setting);
double lda_compute_likelihood(document* doc, double** phi, double* var_gamma);
double slda_inference(document* doc, double* var_gamma, double** phi, const settings * setting);
double slda_compute_likelihood(document* doc, double** phi, double* var_gamma);
void save_gamma(char* filename, double** gamma, int num_docs);
void write_word_assignment(FILE* f, document* doc, double** phi);
public:
double alpha; // the parameter for the dirichlet
int num_topics;
int num_classes;
int size_vocab;
double ** log_prob_w; //the log of the topic distribution
double ** eta; //softmax regression, in general, there are num_classes-1 etas, we don't need a intercept here, since \sum_i \bar{z_i} = 1
};
#endif // SLDA_H