fast_bayes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74c4fdff93961649d2374f0bb225584c6ec15e17
4
+ data.tar.gz: 983b3744a2e1c4468f7da891cfe8ad46c380c4d0
5
+ SHA512:
6
+ metadata.gz: 46cfb73466ce4e2fecb1d6398afa1f1fda0abcdbf8f6a7399cfc7030de17cb0207702a11528a3a410fd8716fed0aeaa2a56c7d301bcd9bf157df980c01864bb5
7
+ data.tar.gz: 70e2dff302cd476e78e286401f4620c4449e9e00555f55a4f1c6573d24eb42e8e81d973fb1be76f903b3c2b3039c633b36aa0a84f00834d0b48d685ba3e844f3
data/.gitignore ADDED
@@ -0,0 +1,41 @@
1
+ *.gem
2
+ *.rbc
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+
13
+ # Compiled Object files
14
+ *.slo
15
+ *.lo
16
+ *.o
17
+ *.obj
18
+
19
+ # Precompiled Headers
20
+ *.gch
21
+ *.pch
22
+
23
+ # Compiled Dynamic libraries
24
+ *.so
25
+ *.dylib
26
+ *.dll
27
+
28
+ # Fortran module files
29
+ *.mod
30
+ *.smod
31
+
32
+ # Compiled Static libraries
33
+ *.lai
34
+ *.la
35
+ *.a
36
+ *.lib
37
+
38
+ # Executables
39
+ *.exe
40
+ *.out
41
+ *.app
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fast_bayes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Chang Rajani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # FastBayes
2
+
3
+ A fast implementation of the naive Bayes classification algorithm. Written in C++ with an interface for Ruby using [Rice](https://github.com/jasonroelofs/rice).
4
+
5
+ Performs text classification with no separate training step needed, the cost of training is split between classification and observation. This is especially useful when data is an online stream, as the system can gradually improve.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fast_bayes'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fast_bayes
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fast_bayes.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rake/extensiontask"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ Rake::ExtensionTask.new "fast_bayes" do |ext|
10
+ ext.lib_dir = "lib/fast_bayes"
11
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fast_bayes"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/ext/Makefile ADDED
@@ -0,0 +1,6 @@
1
+ debug:
2
+ clang++ -std=c++11 -g ./test/*.cpp
3
+ test:
4
+ clang++ -std=c++11 -O3 ./test/*.cpp && ./a.out
5
+ main:
6
+ clang++ -std=c++11 -O3 ./src/main.cpp && ./a.out
@@ -0,0 +1,315 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ ECHO1 = $(V:1=@:)
9
+ ECHO = $(ECHO1:0=@echo)
10
+ NULLCMD = :
11
+
12
+ #### Start of system configuration section. ####
13
+
14
+ srcdir = .
15
+ topdir = /home/chang/.rbenv/versions/2.3.1/include/ruby-2.3.0
16
+ hdrdir = $(topdir)
17
+ arch_hdrdir = /home/chang/.rbenv/versions/2.3.1/include/ruby-2.3.0/x86_64-linux
18
+ PATH_SEPARATOR = :
19
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
20
+
21
+ prefix = $(DESTDIR)/home/chang/.rbenv/versions/2.3.1
22
+
23
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
24
+
25
+ rubyarchprefix = $(rubylibprefix)/$(arch)
26
+
27
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
28
+
29
+ exec_prefix = $(prefix)
30
+
31
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
32
+
33
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
34
+
35
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
36
+
37
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
38
+
39
+ sitehdrdir = $(rubyhdrdir)/site_ruby
40
+
41
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
42
+
43
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
44
+
45
+ vendorlibdir = $(vendordir)/$(ruby_version)
46
+
47
+ vendordir = $(rubylibprefix)/vendor_ruby
48
+
49
+ sitearchdir = $(sitelibdir)/$(sitearch)
50
+
51
+ sitelibdir = $(sitedir)/$(ruby_version)
52
+
53
+ sitedir = $(rubylibprefix)/site_ruby
54
+
55
+ rubyarchdir = $(rubylibdir)/$(arch)
56
+
57
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
58
+
59
+ sitearchincludedir = $(includedir)/$(sitearch)
60
+
61
+ archincludedir = $(includedir)/$(arch)
62
+
63
+ sitearchlibdir = $(libdir)/$(sitearch)
64
+
65
+ archlibdir = $(libdir)/$(arch)
66
+
67
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
68
+
69
+ mandir = $(datarootdir)/man
70
+
71
+ localedir = $(datarootdir)/locale
72
+
73
+ libdir = $(exec_prefix)/lib
74
+
75
+ psdir = $(docdir)
76
+
77
+ pdfdir = $(docdir)
78
+
79
+ dvidir = $(docdir)
80
+
81
+ htmldir = $(docdir)
82
+
83
+ infodir = $(datarootdir)/info
84
+
85
+ docdir = $(datarootdir)/doc/$(PACKAGE)
86
+
87
+ oldincludedir = $(DESTDIR)/usr/include
88
+
89
+ includedir = $(prefix)/include
90
+
91
+ localstatedir = $(prefix)/var
92
+
93
+ sharedstatedir = $(prefix)/com
94
+
95
+ sysconfdir = $(prefix)/etc
96
+
97
+ datadir = $(datarootdir)
98
+
99
+ datarootdir = $(prefix)/share
100
+
101
+ libexecdir = $(exec_prefix)/libexec
102
+
103
+ sbindir = $(exec_prefix)/sbin
104
+
105
+ bindir = $(exec_prefix)/bin
106
+
107
+ archdir = $(rubyarchdir)
108
+
109
+
110
+
111
+ CC = gcc
112
+ CXX = g++
113
+ LIBRUBY = $(LIBRUBY_SO)
114
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
115
+ LIBRUBYARG_SHARED = -Wl,-R$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)
116
+ LIBRUBYARG_STATIC = -Wl,-R/home/chang/.rbenv/versions/2.3.1/lib -L/home/chang/.rbenv/versions/2.3.1/lib -lruby-static
117
+ empty =
118
+ OUTFLAG = -o $(empty)
119
+ COUTFLAG = -o $(empty)
120
+
121
+ RUBY_EXTCONF_H =
122
+ cflags = $(optflags) $(debugflags) $(warnflags)
123
+ cxxflags = $(optflags) $(debugflags) $(warnflags)
124
+ optflags = -O3 -fno-fast-math
125
+ debugflags = -ggdb3
126
+ warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat
127
+ CCDLFLAGS = -fPIC
128
+ CFLAGS = $(CCDLFLAGS) $(cflags) -fPIC $(ARCH_FLAG)
129
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
130
+ DEFS =
131
+ CPPFLAGS = -I/home/chang/.rbenv/versions/2.3.1/include $(DEFS) $(cppflags) -I/home/chang/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rice-2.1.0/ruby/lib/include
132
+ CXXFLAGS = $(CFLAGS) -Wall -g -std=c++11
133
+ ldflags = -L. -L/home/chang/.rbenv/versions/2.3.1/lib -fstack-protector -rdynamic -Wl,-export-dynamic -L/home/chang/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rice-2.1.0/ruby/lib/lib -lrice
134
+ dldflags =
135
+ ARCH_FLAG =
136
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
137
+ LDSHARED = g++ -shared
138
+ LDSHAREDXX = $(CXX) -shared
139
+ AR = ar
140
+ EXEEXT =
141
+
142
+
143
+ RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
144
+
145
+ RUBY_SO_NAME = ruby
146
+
147
+ RUBYW_INSTALL_NAME =
148
+
149
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
150
+
151
+ RUBYW_BASE_NAME = rubyw
152
+
153
+ RUBY_BASE_NAME = ruby
154
+
155
+
156
+ arch = x86_64-linux
157
+ sitearch = $(arch)
158
+ ruby_version = 2.3.0
159
+ ruby = $(bindir)/$(RUBY_BASE_NAME)
160
+ RUBY = $(ruby)
161
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
162
+
163
+ RM = rm -f
164
+ RM_RF = $(RUBY) -run -e rm -- -rf
165
+ RMDIRS = rmdir --ignore-fail-on-non-empty -p
166
+ MAKEDIRS = /bin/mkdir -p
167
+ INSTALL = /usr/bin/install -c
168
+ INSTALL_PROG = $(INSTALL) -m 0755
169
+ INSTALL_DATA = $(INSTALL) -m 644
170
+ COPY = cp
171
+ TOUCH = exit >
172
+
173
+ #### End of system configuration section. ####
174
+
175
+ preload =
176
+
177
+
178
+ CXX = g++
179
+
180
+ libpath = . $(libdir)
181
+ LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir)
182
+ DEFFILE =
183
+
184
+ CLEANFILES = mkmf.log
185
+ DISTCLEANFILES =
186
+ DISTCLEANDIRS =
187
+
188
+ extout =
189
+ extout_prefix =
190
+ target_prefix =
191
+ LOCAL_LIBS =
192
+ LIBS = -Wl,-R/home/chang/.rbenv/versions/2.3.1/lib -L/home/chang/.rbenv/versions/2.3.1/lib -lruby -lpthread -lgmp -ldl -lcrypt -lm -lc
193
+ ORIG_SRCS = main.cpp wrapper.cpp
194
+ SRCS = $(ORIG_SRCS)
195
+ OBJS = main.o wrapper.o
196
+ HDRS = $(srcdir)/bayes.h
197
+ TARGET = fast_bayes
198
+ TARGET_NAME = fast_bayes
199
+ TARGET_ENTRY = Init_$(TARGET_NAME)
200
+ DLLIB = $(TARGET).so
201
+ EXTSTATIC =
202
+ STATIC_LIB =
203
+
204
+ TIMESTAMP_DIR = .
205
+ BINDIR = $(bindir)
206
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
207
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
208
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
209
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
210
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
211
+
212
+ TARGET_SO = $(DLLIB)
213
+ CLEANLIBS = $(TARGET).so
214
+ CLEANOBJS = *.o *.bak
215
+
216
+ all: $(DLLIB)
217
+ static: $(STATIC_LIB) install-rb
218
+ .PHONY: all install static install-so install-rb
219
+ .PHONY: clean clean-so clean-static clean-rb
220
+
221
+ clean-static::
222
+ clean-rb-default::
223
+ clean-rb::
224
+ clean-so::
225
+ clean: clean-so clean-static clean-rb-default clean-rb
226
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
227
+
228
+ distclean-rb-default::
229
+ distclean-rb::
230
+ distclean-so::
231
+ distclean-static::
232
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
233
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
234
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
235
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
236
+
237
+ realclean: distclean
238
+ install: install-so install-rb
239
+
240
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.time
241
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
242
+ clean-static::
243
+ -$(Q)$(RM) $(STATIC_LIB)
244
+ install-rb: pre-install-rb install-rb-default
245
+ install-rb-default: pre-install-rb-default
246
+ pre-install-rb: Makefile
247
+ pre-install-rb-default: Makefile
248
+ pre-install-rb-default:
249
+ @$(NULLCMD)
250
+ $(TIMESTAMP_DIR)/.RUBYARCHDIR.time:
251
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
252
+ $(Q) $(TOUCH) $@
253
+
254
+ site-install: site-install-so site-install-rb
255
+ site-install-so: install-so
256
+ site-install-rb: install-rb
257
+
258
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
259
+
260
+ .cc.o:
261
+ $(ECHO) compiling $(<)
262
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
263
+
264
+ .cc.S:
265
+ $(ECHO) translating $(<)
266
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
267
+
268
+ .mm.o:
269
+ $(ECHO) compiling $(<)
270
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
271
+
272
+ .mm.S:
273
+ $(ECHO) translating $(<)
274
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
275
+
276
+ .cxx.o:
277
+ $(ECHO) compiling $(<)
278
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
279
+
280
+ .cxx.S:
281
+ $(ECHO) translating $(<)
282
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
283
+
284
+ .cpp.o:
285
+ $(ECHO) compiling $(<)
286
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
287
+
288
+ .cpp.S:
289
+ $(ECHO) translating $(<)
290
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
291
+
292
+ .c.o:
293
+ $(ECHO) compiling $(<)
294
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
295
+
296
+ .c.S:
297
+ $(ECHO) translating $(<)
298
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $<
299
+
300
+ .m.o:
301
+ $(ECHO) compiling $(<)
302
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
303
+
304
+ .m.S:
305
+ $(ECHO) translating $(<)
306
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $<
307
+
308
+ $(DLLIB): $(OBJS) Makefile
309
+ $(ECHO) linking shared-object $(DLLIB)
310
+ -$(Q)$(RM) $(@)
311
+ $(Q) $(LDSHAREDXX) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
312
+
313
+
314
+
315
+ $(OBJS): $(HDRS) $(ruby_headers)