opener-opinion-detector-base 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +101 -0
  3. data/bin/opinion-detector-base +19 -0
  4. data/core/annotation.cfg.erb +9 -0
  5. data/core/packages/KafNafParser-1.4.tar.gz +0 -0
  6. data/core/packages/VUA_pylib-1.5.tar.gz +0 -0
  7. data/core/python-scripts/LICENSE +339 -0
  8. data/core/python-scripts/README.md +226 -0
  9. data/core/python-scripts/classify_kaf_naf_file.py +499 -0
  10. data/core/python-scripts/cross_validation.py +634 -0
  11. data/core/python-scripts/generate_folds.py +134 -0
  12. data/core/python-scripts/models.cfg +10 -0
  13. data/core/python-scripts/my_templates/README +33 -0
  14. data/core/python-scripts/my_templates/templates_exp.only0.txt +6 -0
  15. data/core/python-scripts/my_templates/templates_exp.pol0.txt +10 -0
  16. data/core/python-scripts/my_templates/templates_exp.red.txt +7 -0
  17. data/core/python-scripts/my_templates/templates_exp.txt +10 -0
  18. data/core/python-scripts/my_templates/templates_holder.only0.txt +11 -0
  19. data/core/python-scripts/my_templates/templates_holder.red.txt +9 -0
  20. data/core/python-scripts/my_templates/templates_holder.txt +10 -0
  21. data/core/python-scripts/my_templates/templates_target.only0.txt +11 -0
  22. data/core/python-scripts/my_templates/templates_target.red.txt +9 -0
  23. data/core/python-scripts/my_templates/templates_target.txt +10 -0
  24. data/core/python-scripts/run_all_experiments.sh +49 -0
  25. data/core/python-scripts/run_basic.py +20 -0
  26. data/core/python-scripts/run_experiment.sh +42 -0
  27. data/core/python-scripts/scripts/__init__.py +1 -0
  28. data/core/python-scripts/scripts/config_manager.py +314 -0
  29. data/core/python-scripts/scripts/crfutils.py +215 -0
  30. data/core/python-scripts/scripts/extract_feats_relations.py +295 -0
  31. data/core/python-scripts/scripts/extract_features.py +376 -0
  32. data/core/python-scripts/scripts/feats_to_crf.exp.py +105 -0
  33. data/core/python-scripts/scripts/lexicons.py +44 -0
  34. data/core/python-scripts/scripts/link_entities_distance.py +77 -0
  35. data/core/python-scripts/scripts/relation_classifier.py +250 -0
  36. data/core/python-scripts/train.py +566 -0
  37. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/PKG-INFO +10 -0
  38. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/SOURCES.txt +22 -0
  39. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/dependency_links.txt +1 -0
  40. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/installed-files.txt +47 -0
  41. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/top_level.txt +1 -0
  42. data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.py +390 -0
  43. data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.pyc +0 -0
  44. data/core/site-packages/pre_build/KafNafParser/__init__.py +14 -0
  45. data/core/site-packages/pre_build/KafNafParser/__init__.pyc +0 -0
  46. data/core/site-packages/pre_build/KafNafParser/constituency_data.py +125 -0
  47. data/core/site-packages/pre_build/KafNafParser/constituency_data.pyc +0 -0
  48. data/core/site-packages/pre_build/KafNafParser/coreference_data.py +52 -0
  49. data/core/site-packages/pre_build/KafNafParser/coreference_data.pyc +0 -0
  50. data/core/site-packages/pre_build/KafNafParser/dependency_data.py +78 -0
  51. data/core/site-packages/pre_build/KafNafParser/dependency_data.pyc +0 -0
  52. data/core/site-packages/pre_build/KafNafParser/entity_data.py +59 -0
  53. data/core/site-packages/pre_build/KafNafParser/entity_data.pyc +0 -0
  54. data/core/site-packages/pre_build/KafNafParser/external_references_data.py +41 -0
  55. data/core/site-packages/pre_build/KafNafParser/external_references_data.pyc +0 -0
  56. data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.py +2 -0
  57. data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.pyc +0 -0
  58. data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.py +205 -0
  59. data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.pyc +0 -0
  60. data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.py +309 -0
  61. data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.pyc +0 -0
  62. data/core/site-packages/pre_build/KafNafParser/features_data.py +131 -0
  63. data/core/site-packages/pre_build/KafNafParser/features_data.pyc +0 -0
  64. data/core/site-packages/pre_build/KafNafParser/header_data.py +127 -0
  65. data/core/site-packages/pre_build/KafNafParser/header_data.pyc +0 -0
  66. data/core/site-packages/pre_build/KafNafParser/opinion_data.py +211 -0
  67. data/core/site-packages/pre_build/KafNafParser/opinion_data.pyc +0 -0
  68. data/core/site-packages/pre_build/KafNafParser/references_data.py +23 -0
  69. data/core/site-packages/pre_build/KafNafParser/references_data.pyc +0 -0
  70. data/core/site-packages/pre_build/KafNafParser/span_data.py +63 -0
  71. data/core/site-packages/pre_build/KafNafParser/span_data.pyc +0 -0
  72. data/core/site-packages/pre_build/KafNafParser/term_data.py +111 -0
  73. data/core/site-packages/pre_build/KafNafParser/term_data.pyc +0 -0
  74. data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.py +42 -0
  75. data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.pyc +0 -0
  76. data/core/site-packages/pre_build/KafNafParser/text_data.py +99 -0
  77. data/core/site-packages/pre_build/KafNafParser/text_data.pyc +0 -0
  78. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/PKG-INFO +10 -0
  79. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/SOURCES.txt +14 -0
  80. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/dependency_links.txt +1 -0
  81. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/installed-files.txt +23 -0
  82. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/top_level.txt +1 -0
  83. data/core/site-packages/pre_build/VUA_pylib/__init__.py +1 -0
  84. data/core/site-packages/pre_build/VUA_pylib/__init__.pyc +0 -0
  85. data/core/site-packages/pre_build/VUA_pylib/common/__init__.py +1 -0
  86. data/core/site-packages/pre_build/VUA_pylib/common/__init__.pyc +0 -0
  87. data/core/site-packages/pre_build/VUA_pylib/common/common.py +28 -0
  88. data/core/site-packages/pre_build/VUA_pylib/common/common.pyc +0 -0
  89. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.py +1 -0
  90. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.pyc +0 -0
  91. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.py +156 -0
  92. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.pyc +0 -0
  93. data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.py +1 -0
  94. data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.pyc +0 -0
  95. data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.py +121 -0
  96. data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.pyc +0 -0
  97. data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.py +1 -0
  98. data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.pyc +0 -0
  99. data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.py +72 -0
  100. data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.pyc +0 -0
  101. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/PKG-INFO +10 -0
  102. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/SOURCES.txt +7 -0
  103. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/dependency_links.txt +1 -0
  104. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/installed-files.txt +11 -0
  105. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/top_level.txt +1 -0
  106. data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.py +165 -0
  107. data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.pyc +0 -0
  108. data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.py +439 -0
  109. data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.pyc +0 -0
  110. data/core/site-packages/pre_build/VUKafParserPy/__init__.py +7 -0
  111. data/core/site-packages/pre_build/VUKafParserPy/__init__.pyc +0 -0
  112. data/core/vendor/src/crfsuite/AUTHORS +1 -0
  113. data/core/vendor/src/crfsuite/COPYING +27 -0
  114. data/core/vendor/src/crfsuite/ChangeLog +103 -0
  115. data/core/vendor/src/crfsuite/INSTALL +236 -0
  116. data/core/vendor/src/crfsuite/Makefile.am +19 -0
  117. data/core/vendor/src/crfsuite/Makefile.in +783 -0
  118. data/core/vendor/src/crfsuite/README +183 -0
  119. data/core/vendor/src/crfsuite/aclocal.m4 +9018 -0
  120. data/core/vendor/src/crfsuite/autogen.sh +38 -0
  121. data/core/vendor/src/crfsuite/compile +143 -0
  122. data/core/vendor/src/crfsuite/config.guess +1502 -0
  123. data/core/vendor/src/crfsuite/config.h.in +198 -0
  124. data/core/vendor/src/crfsuite/config.sub +1714 -0
  125. data/core/vendor/src/crfsuite/configure +14273 -0
  126. data/core/vendor/src/crfsuite/configure.in +149 -0
  127. data/core/vendor/src/crfsuite/crfsuite.sln +42 -0
  128. data/core/vendor/src/crfsuite/depcomp +630 -0
  129. data/core/vendor/src/crfsuite/example/chunking.py +49 -0
  130. data/core/vendor/src/crfsuite/example/crfutils.py +179 -0
  131. data/core/vendor/src/crfsuite/example/ner.py +270 -0
  132. data/core/vendor/src/crfsuite/example/pos.py +78 -0
  133. data/core/vendor/src/crfsuite/example/template.py +88 -0
  134. data/core/vendor/src/crfsuite/frontend/Makefile.am +29 -0
  135. data/core/vendor/src/crfsuite/frontend/Makefile.in +640 -0
  136. data/core/vendor/src/crfsuite/frontend/dump.c +116 -0
  137. data/core/vendor/src/crfsuite/frontend/frontend.vcxproj +129 -0
  138. data/core/vendor/src/crfsuite/frontend/iwa.c +273 -0
  139. data/core/vendor/src/crfsuite/frontend/iwa.h +65 -0
  140. data/core/vendor/src/crfsuite/frontend/learn.c +439 -0
  141. data/core/vendor/src/crfsuite/frontend/main.c +137 -0
  142. data/core/vendor/src/crfsuite/frontend/option.c +93 -0
  143. data/core/vendor/src/crfsuite/frontend/option.h +86 -0
  144. data/core/vendor/src/crfsuite/frontend/readdata.h +38 -0
  145. data/core/vendor/src/crfsuite/frontend/reader.c +136 -0
  146. data/core/vendor/src/crfsuite/frontend/tag.c +427 -0
  147. data/core/vendor/src/crfsuite/genbinary.sh.in +15 -0
  148. data/core/vendor/src/crfsuite/include/Makefile.am +11 -0
  149. data/core/vendor/src/crfsuite/include/Makefile.in +461 -0
  150. data/core/vendor/src/crfsuite/include/crfsuite.h +1063 -0
  151. data/core/vendor/src/crfsuite/include/crfsuite.hpp +555 -0
  152. data/core/vendor/src/crfsuite/include/crfsuite_api.hpp +400 -0
  153. data/core/vendor/src/crfsuite/include/os.h +61 -0
  154. data/core/vendor/src/crfsuite/install-sh +520 -0
  155. data/core/vendor/src/crfsuite/lib/cqdb/COPYING +28 -0
  156. data/core/vendor/src/crfsuite/lib/cqdb/Makefile.am +21 -0
  157. data/core/vendor/src/crfsuite/lib/cqdb/Makefile.in +549 -0
  158. data/core/vendor/src/crfsuite/lib/cqdb/cqdb.vcxproj +86 -0
  159. data/core/vendor/src/crfsuite/lib/cqdb/include/cqdb.h +524 -0
  160. data/core/vendor/src/crfsuite/lib/cqdb/src/cqdb.c +587 -0
  161. data/core/vendor/src/crfsuite/lib/cqdb/src/lookup3.c +976 -0
  162. data/core/vendor/src/crfsuite/lib/crf/Makefile.am +46 -0
  163. data/core/vendor/src/crfsuite/lib/crf/Makefile.in +721 -0
  164. data/core/vendor/src/crfsuite/lib/crf/crf.vcxproj +216 -0
  165. data/core/vendor/src/crfsuite/lib/crf/src/crf1d.h +353 -0
  166. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_context.c +705 -0
  167. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_encode.c +943 -0
  168. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_feature.c +352 -0
  169. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_model.c +994 -0
  170. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_tag.c +550 -0
  171. data/core/vendor/src/crfsuite/lib/crf/src/crfsuite.c +492 -0
  172. data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_internal.h +236 -0
  173. data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_train.c +272 -0
  174. data/core/vendor/src/crfsuite/lib/crf/src/dataset.c +106 -0
  175. data/core/vendor/src/crfsuite/lib/crf/src/dictionary.c +118 -0
  176. data/core/vendor/src/crfsuite/lib/crf/src/holdout.c +80 -0
  177. data/core/vendor/src/crfsuite/lib/crf/src/logging.c +91 -0
  178. data/core/vendor/src/crfsuite/lib/crf/src/logging.h +48 -0
  179. data/core/vendor/src/crfsuite/lib/crf/src/params.c +335 -0
  180. data/core/vendor/src/crfsuite/lib/crf/src/params.h +80 -0
  181. data/core/vendor/src/crfsuite/lib/crf/src/quark.c +172 -0
  182. data/core/vendor/src/crfsuite/lib/crf/src/quark.h +46 -0
  183. data/core/vendor/src/crfsuite/lib/crf/src/rumavl.c +1107 -0
  184. data/core/vendor/src/crfsuite/lib/crf/src/rumavl.h +160 -0
  185. data/core/vendor/src/crfsuite/lib/crf/src/train_arow.c +408 -0
  186. data/core/vendor/src/crfsuite/lib/crf/src/train_averaged_perceptron.c +242 -0
  187. data/core/vendor/src/crfsuite/lib/crf/src/train_l2sgd.c +507 -0
  188. data/core/vendor/src/crfsuite/lib/crf/src/train_lbfgs.c +338 -0
  189. data/core/vendor/src/crfsuite/lib/crf/src/train_passive_aggressive.c +435 -0
  190. data/core/vendor/src/crfsuite/lib/crf/src/vecmath.h +341 -0
  191. data/core/vendor/src/crfsuite/ltmain.sh +8413 -0
  192. data/core/vendor/src/crfsuite/missing +376 -0
  193. data/core/vendor/src/crfsuite/swig/Makefile.am +13 -0
  194. data/core/vendor/src/crfsuite/swig/Makefile.in +365 -0
  195. data/core/vendor/src/crfsuite/swig/crfsuite.cpp +2 -0
  196. data/core/vendor/src/crfsuite/swig/export.i +32 -0
  197. data/core/vendor/src/crfsuite/swig/python/README +92 -0
  198. data/core/vendor/src/crfsuite/swig/python/crfsuite.py +329 -0
  199. data/core/vendor/src/crfsuite/swig/python/export_wrap.cpp +14355 -0
  200. data/core/vendor/src/crfsuite/swig/python/export_wrap.h +63 -0
  201. data/core/vendor/src/crfsuite/swig/python/prepare.sh +9 -0
  202. data/core/vendor/src/crfsuite/swig/python/sample_tag.py +52 -0
  203. data/core/vendor/src/crfsuite/swig/python/sample_train.py +68 -0
  204. data/core/vendor/src/crfsuite/swig/python/setup.py +44 -0
  205. data/core/vendor/src/crfsuite/win32/stdint.h +679 -0
  206. data/core/vendor/src/liblbfgs/AUTHORS +1 -0
  207. data/core/vendor/src/liblbfgs/COPYING +22 -0
  208. data/core/vendor/src/liblbfgs/ChangeLog +120 -0
  209. data/core/vendor/src/liblbfgs/INSTALL +231 -0
  210. data/core/vendor/src/liblbfgs/Makefile.am +10 -0
  211. data/core/vendor/src/liblbfgs/Makefile.in +638 -0
  212. data/core/vendor/src/liblbfgs/NEWS +0 -0
  213. data/core/vendor/src/liblbfgs/README +71 -0
  214. data/core/vendor/src/liblbfgs/aclocal.m4 +6985 -0
  215. data/core/vendor/src/liblbfgs/autogen.sh +38 -0
  216. data/core/vendor/src/liblbfgs/config.guess +1411 -0
  217. data/core/vendor/src/liblbfgs/config.h.in +64 -0
  218. data/core/vendor/src/liblbfgs/config.sub +1500 -0
  219. data/core/vendor/src/liblbfgs/configure +21146 -0
  220. data/core/vendor/src/liblbfgs/configure.in +107 -0
  221. data/core/vendor/src/liblbfgs/depcomp +522 -0
  222. data/core/vendor/src/liblbfgs/include/lbfgs.h +745 -0
  223. data/core/vendor/src/liblbfgs/install-sh +322 -0
  224. data/core/vendor/src/liblbfgs/lbfgs.sln +26 -0
  225. data/core/vendor/src/liblbfgs/lib/Makefile.am +24 -0
  226. data/core/vendor/src/liblbfgs/lib/Makefile.in +499 -0
  227. data/core/vendor/src/liblbfgs/lib/arithmetic_ansi.h +133 -0
  228. data/core/vendor/src/liblbfgs/lib/arithmetic_sse_double.h +294 -0
  229. data/core/vendor/src/liblbfgs/lib/arithmetic_sse_float.h +298 -0
  230. data/core/vendor/src/liblbfgs/lib/lbfgs.c +1371 -0
  231. data/core/vendor/src/liblbfgs/lib/lib.vcxproj +95 -0
  232. data/core/vendor/src/liblbfgs/ltmain.sh +6426 -0
  233. data/core/vendor/src/liblbfgs/missing +353 -0
  234. data/core/vendor/src/liblbfgs/sample/Makefile.am +15 -0
  235. data/core/vendor/src/liblbfgs/sample/Makefile.in +433 -0
  236. data/core/vendor/src/liblbfgs/sample/sample.c +81 -0
  237. data/core/vendor/src/liblbfgs/sample/sample.cpp +126 -0
  238. data/core/vendor/src/liblbfgs/sample/sample.vcxproj +105 -0
  239. data/core/vendor/src/svm_light/LICENSE.txt +59 -0
  240. data/core/vendor/src/svm_light/Makefile +105 -0
  241. data/core/vendor/src/svm_light/kernel.h +40 -0
  242. data/core/vendor/src/svm_light/svm_classify.c +197 -0
  243. data/core/vendor/src/svm_light/svm_common.c +985 -0
  244. data/core/vendor/src/svm_light/svm_common.h +301 -0
  245. data/core/vendor/src/svm_light/svm_hideo.c +1062 -0
  246. data/core/vendor/src/svm_light/svm_learn.c +4147 -0
  247. data/core/vendor/src/svm_light/svm_learn.h +169 -0
  248. data/core/vendor/src/svm_light/svm_learn_main.c +397 -0
  249. data/core/vendor/src/svm_light/svm_loqo.c +211 -0
  250. data/ext/hack/Rakefile +17 -0
  251. data/ext/hack/support.rb +88 -0
  252. data/lib/opener/opinion_detectors/base.rb +112 -0
  253. data/lib/opener/opinion_detectors/base/version.rb +7 -0
  254. data/lib/opener/opinion_detectors/configuration_creator.rb +86 -0
  255. data/lib/opener/opinion_detectors/de.rb +7 -0
  256. data/lib/opener/opinion_detectors/en.rb +7 -0
  257. data/lib/opener/opinion_detectors/it.rb +7 -0
  258. data/lib/opener/opinion_detectors/nl.rb +6 -0
  259. data/opener-opinion-detector-base.gemspec +35 -0
  260. data/pre_build_requirements.txt +3 -0
  261. metadata +374 -0
@@ -0,0 +1,81 @@
1
+ #include <stdio.h>
2
+ #include <lbfgs.h>
3
+
4
+ static lbfgsfloatval_t evaluate(
5
+ void *instance,
6
+ const lbfgsfloatval_t *x,
7
+ lbfgsfloatval_t *g,
8
+ const int n,
9
+ const lbfgsfloatval_t step
10
+ )
11
+ {
12
+ int i;
13
+ lbfgsfloatval_t fx = 0.0;
14
+
15
+ for (i = 0;i < n;i += 2) {
16
+ lbfgsfloatval_t t1 = 1.0 - x[i];
17
+ lbfgsfloatval_t t2 = 10.0 * (x[i+1] - x[i] * x[i]);
18
+ g[i+1] = 20.0 * t2;
19
+ g[i] = -2.0 * (x[i] * g[i+1] + t1);
20
+ fx += t1 * t1 + t2 * t2;
21
+ }
22
+ return fx;
23
+ }
24
+
25
+ static int progress(
26
+ void *instance,
27
+ const lbfgsfloatval_t *x,
28
+ const lbfgsfloatval_t *g,
29
+ const lbfgsfloatval_t fx,
30
+ const lbfgsfloatval_t xnorm,
31
+ const lbfgsfloatval_t gnorm,
32
+ const lbfgsfloatval_t step,
33
+ int n,
34
+ int k,
35
+ int ls
36
+ )
37
+ {
38
+ printf("Iteration %d:\n", k);
39
+ printf(" fx = %f, x[0] = %f, x[1] = %f\n", fx, x[0], x[1]);
40
+ printf(" xnorm = %f, gnorm = %f, step = %f\n", xnorm, gnorm, step);
41
+ printf("\n");
42
+ return 0;
43
+ }
44
+
45
+ #define N 100
46
+
47
+ int main(int argc, char *argv[])
48
+ {
49
+ int i, ret = 0;
50
+ lbfgsfloatval_t fx;
51
+ lbfgsfloatval_t *x = lbfgs_malloc(N);
52
+ lbfgs_parameter_t param;
53
+
54
+ if (x == NULL) {
55
+ printf("ERROR: Failed to allocate a memory block for variables.\n");
56
+ return 1;
57
+ }
58
+
59
+ /* Initialize the variables. */
60
+ for (i = 0;i < N;i += 2) {
61
+ x[i] = -1.2;
62
+ x[i+1] = 1.0;
63
+ }
64
+
65
+ /* Initialize the parameters for the L-BFGS optimization. */
66
+ lbfgs_parameter_init(&param);
67
+ /*param.linesearch = LBFGS_LINESEARCH_BACKTRACKING;*/
68
+
69
+ /*
70
+ Start the L-BFGS optimization; this will invoke the callback functions
71
+ evaluate() and progress() when necessary.
72
+ */
73
+ ret = lbfgs(N, x, &fx, evaluate, progress, NULL, &param);
74
+
75
+ /* Report the result. */
76
+ printf("L-BFGS optimization terminated with status code = %d\n", ret);
77
+ printf(" fx = %f, x[0] = %f, x[1] = %f\n", fx, x[0], x[1]);
78
+
79
+ lbfgs_free(x);
80
+ return 0;
81
+ }
@@ -0,0 +1,126 @@
1
+ #include <stdio.h>
2
+ #include <lbfgs.h>
3
+
4
+ class objective_function
5
+ {
6
+ protected:
7
+ lbfgsfloatval_t *m_x;
8
+
9
+ public:
10
+ objective_function() : m_x(NULL)
11
+ {
12
+ }
13
+
14
+ virtual ~objective_function()
15
+ {
16
+ if (m_x != NULL) {
17
+ lbfgs_free(m_x);
18
+ m_x = NULL;
19
+ }
20
+ }
21
+
22
+ int run(int N)
23
+ {
24
+ lbfgsfloatval_t fx;
25
+ lbfgsfloatval_t *m_x = lbfgs_malloc(N);
26
+
27
+ if (m_x == NULL) {
28
+ printf("ERROR: Failed to allocate a memory block for variables.\n");
29
+ return 1;
30
+ }
31
+
32
+ /* Initialize the variables. */
33
+ for (int i = 0;i < N;i += 2) {
34
+ m_x[i] = -1.2;
35
+ m_x[i+1] = 1.0;
36
+ }
37
+
38
+ /*
39
+ Start the L-BFGS optimization; this will invoke the callback functions
40
+ evaluate() and progress() when necessary.
41
+ */
42
+ int ret = lbfgs(N, m_x, &fx, _evaluate, _progress, this, NULL);
43
+
44
+ /* Report the result. */
45
+ printf("L-BFGS optimization terminated with status code = %d\n", ret);
46
+ printf(" fx = %f, x[0] = %f, x[1] = %f\n", fx, m_x[0], m_x[1]);
47
+
48
+ return ret;
49
+ }
50
+
51
+ protected:
52
+ static lbfgsfloatval_t _evaluate(
53
+ void *instance,
54
+ const lbfgsfloatval_t *x,
55
+ lbfgsfloatval_t *g,
56
+ const int n,
57
+ const lbfgsfloatval_t step
58
+ )
59
+ {
60
+ return reinterpret_cast<objective_function*>(instance)->evaluate(x, g, n, step);
61
+ }
62
+
63
+ lbfgsfloatval_t evaluate(
64
+ const lbfgsfloatval_t *x,
65
+ lbfgsfloatval_t *g,
66
+ const int n,
67
+ const lbfgsfloatval_t step
68
+ )
69
+ {
70
+ lbfgsfloatval_t fx = 0.0;
71
+
72
+ for (int i = 0;i < n;i += 2) {
73
+ lbfgsfloatval_t t1 = 1.0 - x[i];
74
+ lbfgsfloatval_t t2 = 10.0 * (x[i+1] - x[i] * x[i]);
75
+ g[i+1] = 20.0 * t2;
76
+ g[i] = -2.0 * (x[i] * g[i+1] + t1);
77
+ fx += t1 * t1 + t2 * t2;
78
+ }
79
+ return fx;
80
+ }
81
+
82
+ static int _progress(
83
+ void *instance,
84
+ const lbfgsfloatval_t *x,
85
+ const lbfgsfloatval_t *g,
86
+ const lbfgsfloatval_t fx,
87
+ const lbfgsfloatval_t xnorm,
88
+ const lbfgsfloatval_t gnorm,
89
+ const lbfgsfloatval_t step,
90
+ int n,
91
+ int k,
92
+ int ls
93
+ )
94
+ {
95
+ return reinterpret_cast<objective_function*>(instance)->progress(x, g, fx, xnorm, gnorm, step, n, k, ls);
96
+ }
97
+
98
+ int progress(
99
+ const lbfgsfloatval_t *x,
100
+ const lbfgsfloatval_t *g,
101
+ const lbfgsfloatval_t fx,
102
+ const lbfgsfloatval_t xnorm,
103
+ const lbfgsfloatval_t gnorm,
104
+ const lbfgsfloatval_t step,
105
+ int n,
106
+ int k,
107
+ int ls
108
+ )
109
+ {
110
+ printf("Iteration %d:\n", k);
111
+ printf(" fx = %f, x[0] = %f, x[1] = %f\n", fx, x[0], x[1]);
112
+ printf(" xnorm = %f, gnorm = %f, step = %f\n", xnorm, gnorm, step);
113
+ printf("\n");
114
+ return 0;
115
+ }
116
+ };
117
+
118
+
119
+
120
+ #define N 100
121
+
122
+ int main(int argc, char *argv)
123
+ {
124
+ objective_function obj;
125
+ return obj.run(N);
126
+ }
@@ -0,0 +1,105 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <ItemGroup Label="ProjectConfigurations">
4
+ <ProjectConfiguration Include="Debug|Win32">
5
+ <Configuration>Debug</Configuration>
6
+ <Platform>Win32</Platform>
7
+ </ProjectConfiguration>
8
+ <ProjectConfiguration Include="Release|Win32">
9
+ <Configuration>Release</Configuration>
10
+ <Platform>Win32</Platform>
11
+ </ProjectConfiguration>
12
+ </ItemGroup>
13
+ <PropertyGroup Label="Globals">
14
+ <ProjectGuid>{B4D7D5F5-4A4E-49D5-B38A-E5673520DE66}</ProjectGuid>
15
+ <RootNamespace>sample</RootNamespace>
16
+ <Keyword>Win32Proj</Keyword>
17
+ </PropertyGroup>
18
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
20
+ <ConfigurationType>Application</ConfigurationType>
21
+ <CharacterSet>Unicode</CharacterSet>
22
+ <WholeProgramOptimization>true</WholeProgramOptimization>
23
+ </PropertyGroup>
24
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
25
+ <ConfigurationType>Application</ConfigurationType>
26
+ <CharacterSet>Unicode</CharacterSet>
27
+ </PropertyGroup>
28
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
29
+ <ImportGroup Label="ExtensionSettings">
30
+ </ImportGroup>
31
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
32
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
33
+ </ImportGroup>
34
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
35
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
36
+ </ImportGroup>
37
+ <PropertyGroup Label="UserMacros" />
38
+ <PropertyGroup>
39
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
40
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
41
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
42
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
43
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
44
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
45
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
46
+ <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
47
+ <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
48
+ <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
49
+ <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
50
+ <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
51
+ <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
52
+ </PropertyGroup>
53
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
54
+ <ClCompile>
55
+ <Optimization>Disabled</Optimization>
56
+ <AdditionalIncludeDirectories>$(SolutionDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
57
+ <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
58
+ <MinimalRebuild>true</MinimalRebuild>
59
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
60
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
61
+ <PrecompiledHeader>
62
+ </PrecompiledHeader>
63
+ <WarningLevel>Level3</WarningLevel>
64
+ <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
65
+ </ClCompile>
66
+ <Link>
67
+ <GenerateDebugInformation>true</GenerateDebugInformation>
68
+ <SubSystem>Console</SubSystem>
69
+ <TargetMachine>MachineX86</TargetMachine>
70
+ </Link>
71
+ </ItemDefinitionGroup>
72
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
73
+ <ClCompile>
74
+ <Optimization>MaxSpeed</Optimization>
75
+ <IntrinsicFunctions>true</IntrinsicFunctions>
76
+ <AdditionalIncludeDirectories>$(SolutionDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
77
+ <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
79
+ <FunctionLevelLinking>true</FunctionLevelLinking>
80
+ <PrecompiledHeader>
81
+ </PrecompiledHeader>
82
+ <WarningLevel>Level3</WarningLevel>
83
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
84
+ </ClCompile>
85
+ <Link>
86
+ <GenerateDebugInformation>true</GenerateDebugInformation>
87
+ <SubSystem>Console</SubSystem>
88
+ <OptimizeReferences>true</OptimizeReferences>
89
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
90
+ <TargetMachine>MachineX86</TargetMachine>
91
+ </Link>
92
+ </ItemDefinitionGroup>
93
+ <ItemGroup>
94
+ <ClCompile Include="sample.c" />
95
+ </ItemGroup>
96
+ <ItemGroup>
97
+ <ProjectReference Include="..\lib\lib.vcxproj">
98
+ <Project>{c4405b73-a899-44bf-8681-04ce040b6705}</Project>
99
+ <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
100
+ </ProjectReference>
101
+ </ItemGroup>
102
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
103
+ <ImportGroup Label="ExtensionTargets">
104
+ </ImportGroup>
105
+ </Project>
@@ -0,0 +1,59 @@
1
+ SVM-Light
2
+ ---------
3
+
4
+ Available at http://svmlight.joachims.org/
5
+
6
+ Author: Thorsten Joachims
7
+ thorsten@joachims.org
8
+
9
+ Cornell University
10
+ Department of Computer Science
11
+ 4153 Upson Hall
12
+ Ithaca, NY 14853
13
+ USA
14
+
15
+ LICENSING TERMS
16
+
17
+ This program is granted free of charge for research and education
18
+ purposes. However you must obtain a license from the author to use it
19
+ for commercial purposes.
20
+
21
+ Scientific results produced using the software provided shall
22
+ acknowledge the use of SVM-Light. Please cite as
23
+
24
+ T. Joachims, Making large-Scale SVM Learning
25
+ Practical. Advances in Kernel Methods - Support Vector
26
+ Learning, B. Sch�lkopf and C. Burges and A. Smola (ed.),
27
+ MIT-Press, 1999.
28
+ http://www-ai.cs.uni-dortmund.de/DOKUMENTE/joachims_99a.pdf
29
+
30
+ Moreover shall the author of SVM-Light be informed about the
31
+ publication.
32
+
33
+ The software must not be modified and distributed without prior
34
+ permission of the author.
35
+
36
+ By using SVM-Light you agree to the licensing terms.
37
+
38
+
39
+ NO WARRANTY
40
+
41
+ BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
42
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
43
+ WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
44
+ PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND,
45
+ EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
46
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
48
+ PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
49
+ THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
50
+
51
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
52
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
53
+ REDISTRIBUTE THE PROGRAM, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
54
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF
55
+ THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO
56
+ LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
57
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
58
+ OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED
59
+ OF THE POSSIBILITY OF SUCH DAMAGES.
@@ -0,0 +1,105 @@
1
+ #
2
+ # makefile for svm_light
3
+ #
4
+ # Thorsten Joachims, 2002
5
+ #
6
+
7
+ #Use the following to compile under unix or cygwin
8
+ CC = gcc
9
+ LD = gcc
10
+
11
+ #Uncomment the following line to make CYGWIN produce stand-alone Windows executables
12
+ #SFLAGS= -mno-cygwin
13
+
14
+ CFLAGS= $(SFLAGS) -O3 # release C-Compiler flags
15
+ LFLAGS= $(SFLAGS) -O3 # release linker flags
16
+ #CFLAGS= $(SFLAGS) -pg -Wall -pedantic # debugging C-Compiler flags
17
+ #LFLAGS= $(SFLAGS) -pg # debugging linker flags
18
+ LIBS=-L. -lm # used libraries
19
+
20
+ all: svm_learn_hideo svm_classify
21
+
22
+ tidy:
23
+ rm -f *.o
24
+ rm -f pr_loqo/*.o
25
+
26
+ clean: tidy
27
+ rm -f svm_learn
28
+ rm -f svm_classify
29
+ rm -f libsvmlight.so
30
+
31
+ help: info
32
+
33
+ info:
34
+ @echo
35
+ @echo "make for SVM-light Thorsten Joachims, 1998"
36
+ @echo
37
+ @echo "Thanks to Ralf Herbrich for the initial version."
38
+ @echo
39
+ @echo "USAGE: make [svm_learn | svm_learn_loqo | svm_learn_hideo | "
40
+ @echo " libsvmlight_hideo | libsvmlight_loqo | "
41
+ @echo " svm_classify | all | clean | tidy]"
42
+ @echo
43
+ @echo " svm_learn builds the learning module (prefers HIDEO)"
44
+ @echo " svm_learn_hideo builds the learning module using HIDEO optimizer"
45
+ @echo " svm_learn_loqo builds the learning module using PR_LOQO optimizer"
46
+ @echo " svm_classify builds the classfication module"
47
+ @echo " libsvmlight_hideo builds shared object library that can be linked into"
48
+ @echo " other code using HIDEO"
49
+ @echo " libsvmlight_loqo builds shared object library that can be linked into"
50
+ @echo " other code using PR_LOQO"
51
+ @echo " all (default) builds svm_learn + svm_classify"
52
+ @echo " clean removes .o and target files"
53
+ @echo " tidy removes .o files"
54
+ @echo
55
+
56
+ # Create executables svm_learn and svm_classify
57
+
58
+ svm_learn_hideo: svm_learn_main.o svm_learn.o svm_common.o svm_hideo.o
59
+ $(LD) $(LFLAGS) svm_learn_main.o svm_learn.o svm_common.o svm_hideo.o -o svm_learn $(LIBS)
60
+
61
+ #svm_learn_loqo: svm_learn_main.o svm_learn.o svm_common.o svm_loqo.o loqo
62
+ # $(LD) $(LFLAGS) svm_learn_main.o svm_learn.o svm_common.o svm_loqo.o pr_loqo/pr_loqo.o -o svm_learn $(LIBS)
63
+
64
+ svm_classify: svm_classify.o svm_common.o
65
+ $(LD) $(LFLAGS) svm_classify.o svm_common.o -o svm_classify $(LIBS)
66
+
67
+
68
+ # Create library libsvmlight.so, so that external code can get access to the
69
+ # learning and classification functions of svm-light by linking this library.
70
+
71
+ svm_learn_hideo_noexe: svm_learn_main.o svm_learn.o svm_common.o svm_hideo.o
72
+
73
+ libsvmlight_hideo: svm_learn_main.o svm_learn.o svm_common.o svm_hideo.o
74
+ $(LD) -shared svm_learn.o svm_common.o svm_hideo.o -o libsvmlight.so
75
+
76
+ #svm_learn_loqo_noexe: svm_learn_main.o svm_learn.o svm_common.o svm_loqo.o loqo
77
+
78
+ #libsvmlight_loqo: svm_learn_main.o svm_learn.o svm_common.o svm_loqo.o
79
+ # $(LD) -shared svm_learn.o svm_common.o svm_loqo.o pr_loqo/pr_loqo.o -o libsvmlight.so
80
+
81
+ # Compile components
82
+
83
+ svm_hideo.o: svm_hideo.c
84
+ $(CC) -c $(CFLAGS) svm_hideo.c -o svm_hideo.o
85
+
86
+ #svm_loqo.o: svm_loqo.c
87
+ # $(CC) -c $(CFLAGS) svm_loqo.c -o svm_loqo.o
88
+
89
+ svm_common.o: svm_common.c svm_common.h kernel.h
90
+ $(CC) -c $(CFLAGS) svm_common.c -o svm_common.o
91
+
92
+ svm_learn.o: svm_learn.c svm_common.h
93
+ $(CC) -c $(CFLAGS) svm_learn.c -o svm_learn.o
94
+
95
+ svm_learn_main.o: svm_learn_main.c svm_learn.h svm_common.h
96
+ $(CC) -c $(CFLAGS) svm_learn_main.c -o svm_learn_main.o
97
+
98
+ svm_classify.o: svm_classify.c svm_common.h kernel.h
99
+ $(CC) -c $(CFLAGS) svm_classify.c -o svm_classify.o
100
+
101
+ #loqo: pr_loqo/pr_loqo.o
102
+
103
+ #pr_loqo/pr_loqo.o: pr_loqo/pr_loqo.c
104
+ # $(CC) -c $(CFLAGS) pr_loqo/pr_loqo.c -o pr_loqo/pr_loqo.o
105
+