Class: XLearn::FFM

Inherits:
Model
  • Object
show all
Defined in:
lib/xlearn/ffm.rb

Instance Method Summary collapse

Methods inherited from Model

#bias_term, #cv, finalize, finalize_file, #fit, #linear_term, #load_model, #partial_fit, #predict, #save_model, #save_txt

Constructor Details

#initialize(**options) ⇒ FFM

Returns a new instance of FFM.



3
4
5
6
# File 'lib/xlearn/ffm.rb', line 3

def initialize(**options)
  @model_type = "ffm"
  super
end

Instance Method Details

#latent_factorsObject

shape is [i, j, k] for v_i_j



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/xlearn/ffm.rb', line 10

def latent_factors
  factor = []
  current = -1
  read_txt do |line|
    if line.start_with?("v_")
      parts = line.split(": ")
      i = parts.first.split("_")[1].to_i
      if i != current
        factor << []
        current = i
      end
      factor.last << parts.last.split(" ").map(&:to_f)
    end
  end
  factor
end