Class: Lda::Backends::Rust
- Inherits:
-
Base
- Object
- Base
- Lda::Backends::Rust
show all
- Defined in:
- lib/lda-ruby/backends/rust.rb
Constant Summary
collapse
- SETTINGS =
%i[max_iter convergence em_max_iter em_convergence num_topics init_alpha est_alpha verbose].freeze
Instance Attribute Summary
Attributes inherited from Base
#convergence, #corpus, #em_convergence, #em_max_iter, #est_alpha, #init_alpha, #max_iter, #num_topics, #verbose
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#topic_document_probability
Constructor Details
#initialize(random_seed: nil) ⇒ Rust
Returns a new instance of Rust.
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/lda-ruby/backends/rust.rb', line 31
def initialize(random_seed: nil)
super(random_seed: random_seed)
raise LoadError, "Rust backend is unavailable for this environment" unless self.class.available?
@fallback = PureRuby.new(random_seed: random_seed)
@fallback.topic_weights_kernel = method(:rust_topic_weights_for_word)
@fallback.topic_term_accumulator_kernel = method(:rust_accumulate_topic_term_counts)
@fallback.document_inference_kernel = method(:rust_infer_document)
@fallback.corpus_iteration_kernel = method(:rust_infer_corpus_iteration)
@fallback.topic_term_finalizer_kernel = method(:rust_finalize_topic_term_counts)
@fallback.gamma_shift_kernel = method(:rust_average_gamma_shift)
@fallback.topic_document_probability_kernel = method(:rust_topic_document_probability)
@fallback.topic_term_seed_kernel = method(:rust_seeded_topic_term_probabilities)
@fallback.trusted_kernel_outputs = true
end
|
Class Method Details
.available? ⇒ Boolean
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/lda-ruby/backends/rust.rb', line 8
def self.available?
return false unless defined?(::Lda::RUST_EXTENSION_LOADED) && ::Lda::RUST_EXTENSION_LOADED
return false unless defined?(::Lda::RustBackend)
if ::Lda::RustBackend.respond_to?(:available?)
::Lda::RustBackend.available?
else
true
end
rescue StandardError
false
end
|
Instance Method Details
#beta ⇒ Object
78
79
80
|
# File 'lib/lda-ruby/backends/rust.rb', line 78
def beta
@fallback.beta
end
|
#compute_phi ⇒ Object
86
87
88
|
# File 'lib/lda-ruby/backends/rust.rb', line 86
def compute_phi
@fallback.compute_phi
end
|
#corpus=(corpus) ⇒ Object
51
52
53
54
55
|
# File 'lib/lda-ruby/backends/rust.rb', line 51
def corpus=(corpus)
@corpus = corpus
@fallback.corpus = corpus
true
end
|
#em(start) ⇒ Object
73
74
75
76
|
# File 'lib/lda-ruby/backends/rust.rb', line 73
def em(start)
rust_before_em(start)
@fallback.em(start)
end
|
#fast_load_corpus_from_file(filename) ⇒ Object
57
58
59
60
61
|
# File 'lib/lda-ruby/backends/rust.rb', line 57
def fast_load_corpus_from_file(filename)
loaded = @fallback.fast_load_corpus_from_file(filename)
@corpus = @fallback.corpus
loaded
end
|
#gamma ⇒ Object
82
83
84
|
# File 'lib/lda-ruby/backends/rust.rb', line 82
def gamma
@fallback.gamma
end
|
#load_settings(settings_file) ⇒ Object
63
64
65
66
67
|
# File 'lib/lda-ruby/backends/rust.rb', line 63
def load_settings(settings_file)
loaded = @fallback.load_settings(settings_file)
@corpus = @fallback.corpus
loaded
end
|
#model ⇒ Object
90
91
92
|
# File 'lib/lda-ruby/backends/rust.rb', line 90
def model
@fallback.model
end
|
#name ⇒ Object
47
48
49
|
# File 'lib/lda-ruby/backends/rust.rb', line 47
def name
"rust"
end
|
#set_config(init_alpha, num_topics, max_iter, convergence, em_max_iter, em_convergence, est_alpha) ⇒ Object
69
70
71
|
# File 'lib/lda-ruby/backends/rust.rb', line 69
def set_config(init_alpha, num_topics, max_iter, convergence, em_max_iter, em_convergence, est_alpha)
@fallback.set_config(init_alpha, num_topics, max_iter, convergence, em_max_iter, em_convergence, est_alpha)
end
|