ealdent-lda-ruby 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +0 -0
- data/cokus.c +145 -0
- data/cokus.h +27 -0
- data/extconf.rb +4 -0
- data/lda-alpha.c +68 -0
- data/lda-alpha.h +20 -0
- data/lda-data.c +67 -0
- data/lda-data.h +14 -0
- data/lda-inference.c +875 -0
- data/lda-inference.h +57 -0
- data/lda-model.c +238 -0
- data/lda-model.h +24 -0
- data/lda.h +54 -0
- data/lda.rb +252 -0
- data/license.txt +504 -0
- data/utils.c +111 -0
- data/utils.h +18 -0
- metadata +70 -0
data/utils.c
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
#include "utils.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* given log(a) and log(b), return log(a + b)
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
|
8
|
+
double log_sum(double log_a, double log_b)
|
9
|
+
{
|
10
|
+
double v;
|
11
|
+
|
12
|
+
if (log_a < log_b)
|
13
|
+
{
|
14
|
+
v = log_b+log(1 + exp(log_a-log_b));
|
15
|
+
}
|
16
|
+
else
|
17
|
+
{
|
18
|
+
v = log_a+log(1 + exp(log_b-log_a));
|
19
|
+
}
|
20
|
+
return(v);
|
21
|
+
}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Proc to calculate the value of the trigamma, the second
|
25
|
+
* derivative of the loggamma function. Accepts positive matrices.
|
26
|
+
* From Abromowitz and Stegun. Uses formulas 6.4.11 and 6.4.12 with
|
27
|
+
* recurrence formula 6.4.6. Each requires workspace at least 5
|
28
|
+
* times the size of X.
|
29
|
+
*
|
30
|
+
**/
|
31
|
+
|
32
|
+
double trigamma(double x)
|
33
|
+
{
|
34
|
+
double p;
|
35
|
+
int i;
|
36
|
+
|
37
|
+
x=x+6;
|
38
|
+
p=1/(x*x);
|
39
|
+
p=(((((0.075757575757576*p-0.033333333333333)*p+0.0238095238095238)
|
40
|
+
*p-0.033333333333333)*p+0.166666666666667)*p+1)/x+0.5*p;
|
41
|
+
for (i=0; i<6 ;i++)
|
42
|
+
{
|
43
|
+
x=x-1;
|
44
|
+
p=1/(x*x)+p;
|
45
|
+
}
|
46
|
+
return(p);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
/*
|
51
|
+
* taylor approximation of first derivative of the log gamma function
|
52
|
+
*
|
53
|
+
*/
|
54
|
+
|
55
|
+
double digamma(double x)
|
56
|
+
{
|
57
|
+
double p;
|
58
|
+
x=x+6;
|
59
|
+
p=1/(x*x);
|
60
|
+
p=(((0.004166666666667*p-0.003968253986254)*p+
|
61
|
+
0.008333333333333)*p-0.083333333333333)*p;
|
62
|
+
p=p+log(x)-0.5/x-1/(x-1)-1/(x-2)-1/(x-3)-1/(x-4)-1/(x-5)-1/(x-6);
|
63
|
+
return p;
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
double log_gamma(double x)
|
68
|
+
{
|
69
|
+
double z=1/(x*x);
|
70
|
+
|
71
|
+
x=x+6;
|
72
|
+
z=(((-0.000595238095238*z+0.000793650793651)
|
73
|
+
*z-0.002777777777778)*z+0.083333333333333)/x;
|
74
|
+
z=(x-0.5)*log(x)-x+0.918938533204673+z-log(x-1)-
|
75
|
+
log(x-2)-log(x-3)-log(x-4)-log(x-5)-log(x-6);
|
76
|
+
return z;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
/*
|
82
|
+
* make directory
|
83
|
+
*
|
84
|
+
*/
|
85
|
+
|
86
|
+
void make_directory(char* name)
|
87
|
+
{
|
88
|
+
mkdir(name, S_IRUSR|S_IWUSR|S_IXUSR);
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
/*
|
93
|
+
* argmax
|
94
|
+
*
|
95
|
+
*/
|
96
|
+
|
97
|
+
int argmax(double* x, int n)
|
98
|
+
{
|
99
|
+
int i;
|
100
|
+
double max = x[0];
|
101
|
+
int argmax = 0;
|
102
|
+
for (i = 1; i < n; i++)
|
103
|
+
{
|
104
|
+
if (x[i] > max)
|
105
|
+
{
|
106
|
+
max = x[i];
|
107
|
+
argmax = i;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return(argmax);
|
111
|
+
}
|
data/utils.h
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#ifndef UTILS_H
|
2
|
+
#define UTILS_H
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <math.h>
|
6
|
+
#include <float.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
#include <sys/stat.h>
|
9
|
+
#include <sys/types.h>
|
10
|
+
|
11
|
+
double log_sum(double log_a, double log_b);
|
12
|
+
double trigamma(double x);
|
13
|
+
double digamma(double x);
|
14
|
+
double log_gamma(double x);
|
15
|
+
void make_directory(char* name);
|
16
|
+
int argmax(double* x, int n);
|
17
|
+
|
18
|
+
#endif
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ealdent-lda-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason M. Adams
|
8
|
+
- David M. Blei
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-11-14 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description:
|
18
|
+
email: jasonmadams@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- README
|
27
|
+
- license.txt
|
28
|
+
- cokus.c
|
29
|
+
- cokus.h
|
30
|
+
- extconf.rb
|
31
|
+
- lda-alpha.c
|
32
|
+
- lda-alpha.h
|
33
|
+
- lda-data.c
|
34
|
+
- lda-data.h
|
35
|
+
- lda-inference.c
|
36
|
+
- lda-inference.h
|
37
|
+
- lda-model.c
|
38
|
+
- lda-model.h
|
39
|
+
- lda.h
|
40
|
+
- lda.rb
|
41
|
+
- utils.c
|
42
|
+
- utils.h
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/ealdent/lda-ruby
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: Ruby port of Latent Dirichlet Allocation by David M. Blei.
|
69
|
+
test_files: []
|
70
|
+
|