forked from khigashi1987/Labeled-LDA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwriter.c
36 lines (32 loc) · 1.12 KB
/
writer.c
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
/*
writer.c
an implementation of matrix writer
*/
#include <stdio.h>
#include "writer.h"
void llda_write(FILE *pp, FILE *tp, FILE *n_mzp, FILE *n_wzp, double **phi, double **theta, int **n_mz, int **n_zw, int nclass, int nlex, int ndoc){
printf("writing model...\n"); fflush(stdout);
write_matrix(pp, phi, nlex, nclass);
write_matrix(tp, theta, ndoc, nclass);
write_n_mz(n_mzp, n_mz, ndoc, nclass);
write_n_zw(n_wzp, n_zw, nclass, nlex);
printf("done.\n"); fflush(stdout);
}
void write_matrix(FILE *fp, double **matrix, int rows, int cols){
int i, j;
for(i = 0;i < rows;i++)
for(j = 0;j < cols;j++)
fprintf(fp, "%.7e%s", matrix[i][j], (j == cols - 1)? "\n":" ");
}
void write_n_mz(FILE *fp, int **n_mz, int rows, int cols){
int i, j;
for(i = 0;i < rows;i++)
for(j = 0;j < cols;j++)
fprintf(fp, "%d%s", n_mz[i][j], (j == cols - 1)? "\n":" ");
}
void write_n_zw(FILE *fp, int **n_zw, int rows, int cols){
int i, j;
for(j = 0;j < cols;j++)
for(i = 0;i < rows;i++)
fprintf(fp, "%d%s", n_zw[i][j], (i == rows -1)? "\n":" ");
}