libffm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +32 -0
- data/README.md +91 -0
- data/ext/libffm/ext.cpp +110 -0
- data/ext/libffm/extconf.rb +21 -0
- data/lib/libffm.rb +13 -0
- data/lib/libffm/model.rb +45 -0
- data/lib/libffm/version.rb +3 -0
- data/vendor/libffm/COPYRIGHT +31 -0
- data/vendor/libffm/Makefile +26 -0
- data/vendor/libffm/Makefile.win +26 -0
- data/vendor/libffm/README +294 -0
- data/vendor/libffm/ffm-predict.cpp +105 -0
- data/vendor/libffm/ffm-train.cpp +173 -0
- data/vendor/libffm/ffm.cpp +699 -0
- data/vendor/libffm/ffm.h +51 -0
- data/vendor/libffm/timer.cpp +31 -0
- data/vendor/libffm/timer.h +14 -0
- metadata +74 -0
data/vendor/libffm/ffm.h
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#ifndef _LIBFFM_H
|
2
|
+
#define _LIBFFM_H
|
3
|
+
|
4
|
+
#include <string>
|
5
|
+
|
6
|
+
namespace ffm {
|
7
|
+
|
8
|
+
using namespace std;
|
9
|
+
|
10
|
+
typedef float ffm_float;
|
11
|
+
typedef double ffm_double;
|
12
|
+
typedef int ffm_int;
|
13
|
+
typedef long long ffm_long;
|
14
|
+
|
15
|
+
struct ffm_node {
|
16
|
+
ffm_int f; // field index
|
17
|
+
ffm_int j; // feature index
|
18
|
+
ffm_float v; // value
|
19
|
+
};
|
20
|
+
|
21
|
+
struct ffm_model {
|
22
|
+
ffm_int n; // number of features
|
23
|
+
ffm_int m; // number of fields
|
24
|
+
ffm_int k; // number of latent factors
|
25
|
+
ffm_float *W = nullptr;
|
26
|
+
bool normalization;
|
27
|
+
void release();
|
28
|
+
};
|
29
|
+
|
30
|
+
struct ffm_parameter {
|
31
|
+
ffm_float eta = 0.2; // learning rate
|
32
|
+
ffm_float lambda = 0.00002; // regularization parameter
|
33
|
+
ffm_int nr_iters = 15;
|
34
|
+
ffm_int k = 4; // number of latent factors
|
35
|
+
bool normalization = true;
|
36
|
+
bool auto_stop = false;
|
37
|
+
};
|
38
|
+
|
39
|
+
void ffm_read_problem_to_disk(string txt_path, string bin_path);
|
40
|
+
|
41
|
+
void ffm_save_model(ffm_model &model, string path);
|
42
|
+
|
43
|
+
ffm_model ffm_load_model(string path);
|
44
|
+
|
45
|
+
ffm_model ffm_train_on_disk(string Tr_path, string Va_path, ffm_parameter param);
|
46
|
+
|
47
|
+
ffm_float ffm_predict(ffm_node *begin, ffm_node *end, ffm_model &model);
|
48
|
+
|
49
|
+
} // namespace ffm
|
50
|
+
|
51
|
+
#endif // _LIBFFM_H
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#include <string>
|
2
|
+
#include "timer.h"
|
3
|
+
|
4
|
+
Timer::Timer()
|
5
|
+
{
|
6
|
+
reset();
|
7
|
+
}
|
8
|
+
|
9
|
+
void Timer::reset()
|
10
|
+
{
|
11
|
+
begin = std::chrono::high_resolution_clock::now();
|
12
|
+
duration =
|
13
|
+
std::chrono::duration_cast<std::chrono::milliseconds>(begin-begin);
|
14
|
+
}
|
15
|
+
|
16
|
+
void Timer::tic()
|
17
|
+
{
|
18
|
+
begin = std::chrono::high_resolution_clock::now();
|
19
|
+
}
|
20
|
+
|
21
|
+
float Timer::toc()
|
22
|
+
{
|
23
|
+
duration += std::chrono::duration_cast<std::chrono::milliseconds>
|
24
|
+
(std::chrono::high_resolution_clock::now()-begin);
|
25
|
+
return get();
|
26
|
+
}
|
27
|
+
|
28
|
+
float Timer::get()
|
29
|
+
{
|
30
|
+
return (float)duration.count() / 1000;
|
31
|
+
}
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: libffm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rice
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
description:
|
28
|
+
email: andrew@chartkick.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- CHANGELOG.md
|
34
|
+
- LICENSE.txt
|
35
|
+
- README.md
|
36
|
+
- ext/libffm/ext.cpp
|
37
|
+
- ext/libffm/extconf.rb
|
38
|
+
- lib/libffm.rb
|
39
|
+
- lib/libffm/model.rb
|
40
|
+
- lib/libffm/version.rb
|
41
|
+
- vendor/libffm/COPYRIGHT
|
42
|
+
- vendor/libffm/Makefile
|
43
|
+
- vendor/libffm/Makefile.win
|
44
|
+
- vendor/libffm/README
|
45
|
+
- vendor/libffm/ffm-predict.cpp
|
46
|
+
- vendor/libffm/ffm-train.cpp
|
47
|
+
- vendor/libffm/ffm.cpp
|
48
|
+
- vendor/libffm/ffm.h
|
49
|
+
- vendor/libffm/timer.cpp
|
50
|
+
- vendor/libffm/timer.h
|
51
|
+
homepage: https://github.com/ankane/libffm
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.5'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.1.4
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Field-aware factorization machines for Ruby
|
74
|
+
test_files: []
|