jashmenn-apriori 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +121 -0
  4. data/README.txt +139 -0
  5. data/Rakefile +4 -0
  6. data/TODO.txt +60 -0
  7. data/attic/c_ext_test1/MyTest/MyTest.c +23 -0
  8. data/attic/c_ext_test1/MyTest/extconf.rb +11 -0
  9. data/attic/c_ext_test1/mytest.rb +10 -0
  10. data/attic/test.c +12 -0
  11. data/config/hoe.rb +77 -0
  12. data/config/requirements.rb +15 -0
  13. data/examples/01_simple_example.rb +23 -0
  14. data/examples/02_small_file_example.rb +17 -0
  15. data/examples/03_large_file_example.rb +22 -0
  16. data/examples/test_data/market_basket_basic_test.dat +9 -0
  17. data/ext/Apriori.c +149 -0
  18. data/ext/Makefile +149 -0
  19. data/ext/apriori/doc/apriori.html +1301 -0
  20. data/ext/apriori/doc/arem.gp +68 -0
  21. data/ext/apriori/doc/c_rev.gp +89 -0
  22. data/ext/apriori/doc/chi2.tex +156 -0
  23. data/ext/apriori/doc/copying +504 -0
  24. data/ext/apriori/doc/line.gif +0 -0
  25. data/ext/apriori/doc/uparrow.gif +0 -0
  26. data/ext/apriori/ex/flg2set +15 -0
  27. data/ext/apriori/ex/hdr2set +13 -0
  28. data/ext/apriori/ex/readme +71 -0
  29. data/ext/apriori/ex/row2set +7 -0
  30. data/ext/apriori/ex/rulesort +24 -0
  31. data/ext/apriori/ex/tab2set +9 -0
  32. data/ext/apriori/ex/test.app +2 -0
  33. data/ext/apriori/ex/test.rul +9 -0
  34. data/ext/apriori/ex/test1.rul +43 -0
  35. data/ext/apriori/ex/test1.tab +10 -0
  36. data/ext/apriori/ex/test2.tab +10 -0
  37. data/ext/apriori/ex/test3.tab +30 -0
  38. data/ext/apriori/ex/test4.tab +11 -0
  39. data/ext/apriori/ex/test5.tab +39 -0
  40. data/ext/apriori/ex/tid2set +23 -0
  41. data/ext/apriori/ex/xhdr2set +33 -0
  42. data/ext/apriori/src/apriori.c +750 -0
  43. data/ext/apriori/src/apriori.dsp +120 -0
  44. data/ext/apriori/src/apriori.dsw +29 -0
  45. data/ext/apriori/src/apriori.mak +99 -0
  46. data/ext/apriori/src/istree.c +1411 -0
  47. data/ext/apriori/src/istree.h +160 -0
  48. data/ext/apriori/src/makefile +105 -0
  49. data/ext/apriori/src/tract.c +870 -0
  50. data/ext/apriori/src/tract.h +261 -0
  51. data/ext/apriori_wrapper.c +757 -0
  52. data/ext/apriori_wrapper.h +10 -0
  53. data/ext/extconf.rb +32 -0
  54. data/ext/math/doc/copying +504 -0
  55. data/ext/math/src/chi2.c +151 -0
  56. data/ext/math/src/chi2.h +27 -0
  57. data/ext/math/src/choose.c +71 -0
  58. data/ext/math/src/choose.h +16 -0
  59. data/ext/math/src/gamma.c +446 -0
  60. data/ext/math/src/gamma.h +39 -0
  61. data/ext/math/src/intexp.c +35 -0
  62. data/ext/math/src/intexp.h +15 -0
  63. data/ext/math/src/makefile +164 -0
  64. data/ext/math/src/math.mak +48 -0
  65. data/ext/math/src/normal.c +387 -0
  66. data/ext/math/src/normal.h +44 -0
  67. data/ext/math/src/radfn.c +113 -0
  68. data/ext/math/src/radfn.h +34 -0
  69. data/ext/math/src/zeta.c +49 -0
  70. data/ext/math/src/zeta.h +15 -0
  71. data/ext/pre-clean.rb +8 -0
  72. data/ext/pre-setup.rb +9 -0
  73. data/ext/util/doc/copying +504 -0
  74. data/ext/util/src/listops.c +76 -0
  75. data/ext/util/src/listops.h +26 -0
  76. data/ext/util/src/makefile +103 -0
  77. data/ext/util/src/memsys.c +84 -0
  78. data/ext/util/src/memsys.h +42 -0
  79. data/ext/util/src/nstats.c +288 -0
  80. data/ext/util/src/nstats.h +69 -0
  81. data/ext/util/src/params.c +86 -0
  82. data/ext/util/src/params.h +19 -0
  83. data/ext/util/src/parse.c +133 -0
  84. data/ext/util/src/parse.h +81 -0
  85. data/ext/util/src/scan.c +767 -0
  86. data/ext/util/src/scan.h +111 -0
  87. data/ext/util/src/symtab.c +443 -0
  88. data/ext/util/src/symtab.h +121 -0
  89. data/ext/util/src/tabscan.c +279 -0
  90. data/ext/util/src/tabscan.h +99 -0
  91. data/ext/util/src/util.mak +91 -0
  92. data/ext/util/src/vecops.c +317 -0
  93. data/ext/util/src/vecops.h +42 -0
  94. data/lib/apriori/adapter.rb +13 -0
  95. data/lib/apriori/association_rule.rb +85 -0
  96. data/lib/apriori/version.rb +9 -0
  97. data/lib/apriori.rb +133 -0
  98. data/script/console +10 -0
  99. data/script/destroy +14 -0
  100. data/script/generate +14 -0
  101. data/script/txt2html +82 -0
  102. data/setup.rb +1585 -0
  103. data/tasks/apriori.rake +20 -0
  104. data/tasks/attic.rake +28 -0
  105. data/tasks/deployment.rake +34 -0
  106. data/tasks/environment.rake +7 -0
  107. data/tasks/install.rake +6 -0
  108. data/tasks/website.rake +17 -0
  109. data/test/apriori_test.rb +13 -0
  110. data/test/fixtures/market_basket_results_test.txt +5 -0
  111. data/test/fixtures/market_basket_string_test.txt +7 -0
  112. data/test/fixtures/results.txt +2 -0
  113. data/test/fixtures/sample.txt +7 -0
  114. data/test/test_helper.rb +5 -0
  115. data/test/unit/test_apriori.rb +68 -0
  116. data/test/unit/test_itemsets_and_parsing.rb +82 -0
  117. data/website/index.html +233 -0
  118. data/website/index.txt +142 -0
  119. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  120. data/website/stylesheets/screen.css +142 -0
  121. data/website/template.html.erb +49 -0
  122. metadata +188 -0
@@ -0,0 +1,151 @@
1
+ /*----------------------------------------------------------------------
2
+ File : chi2.c
3
+ Contents: chi^2 distribution function
4
+ Author : Christian Borgelt
5
+ History : 2003.05.19 file created as quantile.c
6
+ 2008.03.14 main programs added
7
+ ----------------------------------------------------------------------*/
8
+ #if defined(CHI2PDF_MAIN) \
9
+ || defined(CHI2CDF_MAIN) \
10
+ || defined(CHI2QTL_MAIN)
11
+ #include <stdio.h>
12
+ #include <stdlib.h>
13
+ #endif
14
+ #ifdef CHI2QTL_MAIN
15
+ #ifndef CHI2QTL
16
+ #define CHI2QTL
17
+ #endif
18
+ #ifndef GAMMAQTL
19
+ #define GAMMAQTL
20
+ #endif
21
+ #endif
22
+ #include <assert.h>
23
+ #include <math.h>
24
+ #include "gamma.h"
25
+ #ifdef CHI2QTL
26
+ #include "normal.h"
27
+ #endif
28
+ #include "chi2.h"
29
+
30
+ /*----------------------------------------------------------------------
31
+ Functions
32
+ ----------------------------------------------------------------------*/
33
+
34
+ double chi2pdf (double x, double df)
35
+ { /* --- probability density function */
36
+ assert(df > 0); /* check the function arguments */
37
+ if (x <= 0) return 0; /* only non-zero for positive arg. */
38
+ if (df == 2) return 0.5 *exp(-0.5*x);
39
+ df *= 0.5; /* compute probability density */
40
+ return 0.5 *exp((df-1) *log(0.5*x) -0.5*x -logGamma(df));
41
+ } /* chi2pdf() */
42
+
43
+ /*--------------------------------------------------------------------*/
44
+
45
+ double chi2cdfP (double x, double df)
46
+ { /* --- cumulative distribution fn. */
47
+ assert(df > 0); /* check the function arguments */
48
+ return GammaP(0.5*df, 0.5*x); /* compute regularized Gamma function */
49
+ } /* chi2cdfP() */
50
+
51
+ /*--------------------------------------------------------------------*/
52
+
53
+ double chi2cdfQ (double x, double df)
54
+ { /* --- cumulative distribution fn. */
55
+ assert(df > 0); /* check the function arguments */
56
+ return GammaQ(0.5*df, 0.5*x); /* compute regularized Gamma function */
57
+ } /* chi2cdfQ() */
58
+
59
+ /*--------------------------------------------------------------------*/
60
+ #ifdef CHI2QTL
61
+
62
+ double chi2qtlP (double prob, double df)
63
+ { /* --- quantile of chi2 distribution */
64
+ return GammaqtlP(prob, 0.5*df, 2);
65
+ } /* chi2qtlP() */
66
+
67
+ /*--------------------------------------------------------------------*/
68
+
69
+ double chi2qtlQ (double prob, double df)
70
+ { /* --- quantile of chi2 distribution */
71
+ return GammaqtlQ(prob, 0.5*df, 2);
72
+ } /* chi2qtlQ() */
73
+
74
+ #endif
75
+ /*----------------------------------------------------------------------
76
+ Main Functions
77
+ ----------------------------------------------------------------------*/
78
+ #ifdef CHI2PDF_MAIN
79
+
80
+ int main (int argc, char *argv[])
81
+ { /* --- main function */
82
+ double df = 1; /* degrees of freedom */
83
+ double x; /* argument value */
84
+
85
+ if ((argc < 2) || (argc > 3)){/* if wrong number of arguments */
86
+ printf("usage: %s arg [df]\n", argv[0]);
87
+ printf("compute probability density function of the\n"
88
+ "chi^2 distribution with df degrees of freedom\n");
89
+ return 0; /* print a usage message */
90
+ } /* and abort the program */
91
+ x = atof(argv[1]); /* get the argument value */
92
+ if (argc > 2) df = atof(argv[2]);
93
+ if (df <= 0) { /* get the degrees of freedom */
94
+ printf("%s: invalid degrees of freedom\n", argv[0]); return -1; }
95
+ printf("chi^2: f(%.16g; %.16g) = %.16g\n", x, df, chi2pdf(x, df));
96
+ return 0; /* compute and print density */
97
+ } /* main() */
98
+
99
+ #endif
100
+ /*--------------------------------------------------------------------*/
101
+ #ifdef CHI2CDF_MAIN
102
+
103
+ int main (int argc, char *argv[])
104
+ { /* --- main function */
105
+ double df = 1; /* degrees of freedom */
106
+ double x; /* argument value */
107
+
108
+ if ((argc < 2) || (argc > 3)){/* if wrong number of arguments */
109
+ printf("usage: %s arg [df]\n", argv[0]);
110
+ printf("compute cumulative distribution function of the\n"
111
+ "chi^2 distribution with df degrees of freedom\n");
112
+ return 0; /* print a usage message */
113
+ } /* and abort the program */
114
+ x = atof(argv[1]); /* get the argument value */
115
+ if (argc > 2) df = atof(argv[2]);
116
+ if (df <= 0) { /* get the degrees of freedom */
117
+ printf("%s: invalid degrees of freedom\n", argv[0]); return -1; }
118
+ printf("chi^2: F(%.16g; %.16g) = %.16g\n", x, df, chi2cdfP(x, df));
119
+ printf(" 1 - F(%.16g; %.16g) = %.16g\n", x, df, chi2cdfQ(x, df));
120
+ return 0; /* compute and print probability */
121
+ } /* main() */
122
+
123
+ #endif
124
+ /*--------------------------------------------------------------------*/
125
+ #ifdef CHI2QTL_MAIN
126
+
127
+ int main (int argc, char *argv[])
128
+ { /* --- main function */
129
+ double df = 1; /* degrees of freedom */
130
+ double prob; /* probability */
131
+
132
+ if ((argc < 2) || (argc > 3)){/* if wrong number of arguments */
133
+ printf("usage: %s prob [df]\n", argv[0]);
134
+ printf("compute quantile of the chi^2 distribution "
135
+ "with df degrees of freedom\n");
136
+ return 0; /* print a usage message */
137
+ } /* and abort the program */
138
+ prob = atof(argv[1]); /* get the probability */
139
+ if ((prob < 0) || (prob > 1)) {
140
+ printf("%s: invalid probability\n", argv[0]); return -1; }
141
+ if (argc > 2) df = atof(argv[2]);
142
+ if (df <= 0) { /* get the degrees of freedom */
143
+ printf("%s: invalid degrees of freedom\n", argv[0]); return -1; }
144
+ printf("chi^2: F(%.16g; %.16g) = %.16g\n",
145
+ chi2qtlP(prob, df), df, prob);
146
+ printf(" 1 - F(%.16g; %.16g) = %.16g\n",
147
+ chi2qtlQ(prob, df), df, prob);
148
+ return 0; /* compute and print quantile */
149
+ } /* main() */
150
+
151
+ #endif
@@ -0,0 +1,27 @@
1
+ /*----------------------------------------------------------------------
2
+ File : chi2.h
3
+ Contents: chi^2 distribution functions
4
+ Author : Christian Borgelt
5
+ History : 2003.05.19 file created as quantile.h
6
+ ----------------------------------------------------------------------*/
7
+ #ifndef __CHI2__
8
+ #define __CHI2__
9
+
10
+ /*----------------------------------------------------------------------
11
+ Functions
12
+ ----------------------------------------------------------------------*/
13
+ extern double chi2pdf (double x, double df);
14
+ extern double chi2cdf (double x, double df);
15
+ extern double chi2cdfP (double x, double df);
16
+ extern double chi2cdfQ (double x, double df);
17
+ extern double chi2qtl (double prob, double df);
18
+ extern double chi2qtlP (double prob, double df);
19
+ extern double chi2qtlQ (double prob, double df);
20
+
21
+ /*----------------------------------------------------------------------
22
+ Preprocessor Definitions
23
+ ----------------------------------------------------------------------*/
24
+ #define chi2cdf(x,d) chi2cdfP(x,d)
25
+ #define chi2qtl(p,d) chi2qtlP(p,d)
26
+
27
+ #endif
@@ -0,0 +1,71 @@
1
+ /*----------------------------------------------------------------------
2
+ File : choose.c
3
+ Contents: compute n choose k
4
+ Author : Christian Borgelt
5
+ History : 1996.04.29 file created
6
+ 2003.05.17 (n-i+1) replaced by n--
7
+ 2008.03.14 main function added
8
+ ----------------------------------------------------------------------*/
9
+ #ifdef CHOOSE_MAIN
10
+ #include <stdio.h>
11
+ #include <stdlib.h>
12
+ #endif
13
+ #include <limits.h>
14
+ #include "choose.h"
15
+
16
+ /*----------------------------------------------------------------------
17
+ Functions
18
+ ----------------------------------------------------------------------*/
19
+
20
+ unsigned int choose (unsigned int n, unsigned int k)
21
+ { /* --- compute n choose k */
22
+ unsigned int i, t; /* loop variable, buffer */
23
+ unsigned int r = 1; /* result */
24
+
25
+ if (k > n) return 0; /* check range of k */
26
+ for (i = 1; i <= k; i++) { /* calculation loop */
27
+ t = n--; /* calculate next factor in numerator */
28
+ if (UINT_MAX /t < r) /* if result of multiplication */
29
+ return 0; /* is out of range, abort */
30
+ r = (r *t) /i; /* calculate \prod_{i=1}^k (n-i+1)/i */
31
+ }
32
+ return r; /* return result */
33
+ } /* choose() */
34
+
35
+ /*--------------------------------------------------------------------*/
36
+
37
+ double dchoose (unsigned int n, unsigned int k)
38
+ { /* --- compute n choose k */
39
+ unsigned int i; /* loop variable, buffer */
40
+ double r = 1.0; /* result */
41
+
42
+ if (k > n) return 0; /* check range of k */
43
+ for (i = 1; i <= k; i++) /* calculation loop */
44
+ r = (r *n--) /i; /* calculate \prod_{i=1}^k (n-i+1)/i */
45
+ return r; /* return result */
46
+ } /* dchoose() */
47
+
48
+ /*--------------------------------------------------------------------*/
49
+ #ifdef CHOOSE_MAIN
50
+
51
+ int main (int argc, char *argv[])
52
+ { /* --- main function */
53
+ int n, k; /* arguments */
54
+ unsigned int r; /* result */
55
+
56
+ if (argc != 3) { /* if number of arguments is wrong */
57
+ printf("usage: %s <n> <k>\n", argv[0]);
58
+ printf("calculate n choose k, i.e. n!/(k!(n-k)!)\n");
59
+ return 0; /* print a usage message */
60
+ } /* and abort the program */
61
+ n = atoi(argv[1]); /* get argument 1, i.e. n */
62
+ k = atoi(argv[2]); /* get argument 2, i.e. k */
63
+ if ((n < 0) || (k < 0)) { /* check range of n and k */
64
+ printf("%s: value out of range\n", argv[0]); return 1; }
65
+ r = choose(n, k); /* calculate n choose k */
66
+ if (r > 0) printf("%d choose %d: %d\n", n, k, r);
67
+ else printf("%d choose %d: %.0f\n", n, k, dchoose(n, k));
68
+ return 0; /* print result and terminate program */
69
+ } /* main() */
70
+
71
+ #endif
@@ -0,0 +1,16 @@
1
+ /*----------------------------------------------------------------------
2
+ File : choose.h
3
+ Contents: compute n choose k
4
+ Author : Christian Borgelt
5
+ History : 29.04.1996 file created
6
+ ----------------------------------------------------------------------*/
7
+ #ifndef __CHOOSE__
8
+ #define __CHOOSE__
9
+
10
+ /*----------------------------------------------------------------------
11
+ Functions
12
+ ----------------------------------------------------------------------*/
13
+ extern unsigned int choose (unsigned int n, unsigned int k);
14
+ extern double dchoose (unsigned int n, unsigned int k);
15
+
16
+ #endif