Skip to content

Commit

Permalink
compilable on Cygwin
Browse files Browse the repository at this point in the history
  • Loading branch information
ycjuan committed Jul 3, 2015
1 parent 2fba19e commit 423a125
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
19 changes: 13 additions & 6 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ Requirement:
LIBFFM is written in C++. It requires C++11 and OpenMP supports. If OpenMP is
not available on your platform, please refer to section `OpenMP.'

- Unix-like system:
- Unix-like systems:
To compile on Unix-like systems, type `make' in the command line.

- OS X:

The built-in compiler should be able to compile LIBFFM. However, OpenMP may
not be supported. In this case you have to compile without OpenMP. See
section `OpenMP' for detail.

- Windows:
See `Building Windows Binaries' to compile.

Expand Down Expand Up @@ -63,13 +69,14 @@ Command Line Usage
-p <path>: set path to the validation set
-v <fold>: set the number of folds for cross-validation
--quiet: quiet model (no output)
--norm: do instance-wise normalization
--no-norm: disable instance-wise normalization
--no-rand: disable random update
--on-disk: perform on-disk training

`--norm' helps you to do instance-wise normalization. When it is enabled,
you can simply assign `1' to `value' in the data.
--on-disk: perform on-disk training (a temporary file <training_set_file>.bin will be generated)

By default we do instance-wise normalization. That is, we normalize the
2-norm of each instance to 1. You can use `--no-norm' to disable this
function.

By default, our algorithm randomly select an instance for update in each
inner iteration. On some datasets you may want to do update in the original
order. You can do it by using `--no-rand' together with `-s 1.'
Expand Down
1 change: 1 addition & 0 deletions ffm-predict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cmath>
#include <stdexcept>
#include <vector>
#include <cstdlib>

#include "ffm.h"

Expand Down
21 changes: 11 additions & 10 deletions ffm-train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdexcept>
#include <string>
#include <vector>
#include <cstdlib>

#include "ffm.h"

Expand All @@ -25,9 +26,9 @@ string train_help()
"-p <path>: set path to the validation set\n"
"-v <fold>: set the number of folds for cross-validation\n"
"--quiet: quiet model (no output)\n"
"--norm: do instance-wise normalization\n"
"--no-norm: disable instance-wise normalization\n"
"--no-rand: disable random update\n"
"--on-disk: perform on-disk training\n");
"--on-disk: perform on-disk training (a temporary file <training_set_file>.bin will be generated)\n");
}

struct Option
Expand Down Expand Up @@ -68,7 +69,7 @@ Option parse_option(int argc, char **argv)
if(i == argc-1)
throw invalid_argument("need to specify number of iterations after -t");
i++;
opt.param.nr_iters = stoi(args[i]);
opt.param.nr_iters = atoi(args[i].c_str());
if(opt.param.nr_iters <= 0)
throw invalid_argument("number of iterations should be greater than zero");
}
Expand All @@ -77,7 +78,7 @@ Option parse_option(int argc, char **argv)
if(i == argc-1)
throw invalid_argument("need to specify number of factors after -k");
i++;
opt.param.k = stoi(args[i]);
opt.param.k = atoi(args[i].c_str());
if(opt.param.k <= 0)
throw invalid_argument("number of factors should be greater than zero");
}
Expand All @@ -86,7 +87,7 @@ Option parse_option(int argc, char **argv)
if(i == argc-1)
throw invalid_argument("need to specify eta after -r");
i++;
opt.param.eta = stof(args[i]);
opt.param.eta = atof(args[i].c_str());
if(opt.param.eta <= 0)
throw invalid_argument("learning rate should be greater than zero");
}
Expand All @@ -95,7 +96,7 @@ Option parse_option(int argc, char **argv)
if(i == argc-1)
throw invalid_argument("need to specify lambda after -l");
i++;
opt.param.lambda = stof(args[i]);
opt.param.lambda = atof(args[i].c_str());
if(opt.param.lambda < 0)
throw invalid_argument("regularization cost should not be smaller than zero");
}
Expand All @@ -104,7 +105,7 @@ Option parse_option(int argc, char **argv)
if(i == argc-1)
throw invalid_argument("need to specify number of threads after -s");
i++;
opt.param.nr_threads = stoi(args[i]);
opt.param.nr_threads = atoi(args[i].c_str());
if(opt.param.nr_threads <= 0)
throw invalid_argument("number of threads should be greater than zero");
}
Expand All @@ -113,7 +114,7 @@ Option parse_option(int argc, char **argv)
if(i == argc-1)
throw invalid_argument("need to specify number of folds after -v");
i++;
opt.nr_folds = stoi(args[i]);
opt.nr_folds = atoi(args[i].c_str());
if(opt.nr_folds <= 1)
throw invalid_argument("number of folds should be greater than one");
opt.do_cv = true;
Expand All @@ -125,9 +126,9 @@ Option parse_option(int argc, char **argv)
i++;
opt.va_path = args[i];
}
else if(args[i].compare("--norm") == 0)
else if(args[i].compare("--no-norm") == 0)
{
opt.param.normalization= true;
opt.param.normalization = false;
}
else if(args[i].compare("--quiet") == 0)
{
Expand Down
12 changes: 5 additions & 7 deletions ffm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ void shrink_model(ffm_model &model, ffm_int k_new)
{
for(ffm_int f = 0; f < model.m; f++)
{
ffm_float *src = model.W + (j*model.m+f)*model.k*2;
ffm_float *dst = model.W + (j*model.m+f)*k_new;
ffm_float *src = model.W + ((ffm_long)j*model.m+f)*model.k*2;
ffm_float *dst = model.W + ((ffm_long)j*model.m+f)*k_new;
copy(src, src+k_new, dst);
}
}
Expand Down Expand Up @@ -543,8 +543,6 @@ ffm_problem* ffm_read_problem(char const *path)
prob->P = nullptr;
prob->Y = nullptr;

int const kMaxLineSize = 1000000;

char line[kMaxLineSize];

ffm_long nnz = 0;
Expand Down Expand Up @@ -609,7 +607,7 @@ int ffm_read_problem_to_disk(char const *txt_path, char const *bin_path)
if(f_bin == nullptr)
return 1;

vector<char> line(1000000);
vector<char> line(kMaxLineSize);

ffm_int m = 0;
ffm_int n = 0;
Expand Down Expand Up @@ -648,7 +646,7 @@ int ffm_read_problem_to_disk(char const *txt_path, char const *bin_path)
fwrite(&max_l, sizeof(ffm_int), 1, f_bin);
fwrite(&max_nnz, sizeof(ffm_long), 1, f_bin);

while(fgets(line.data(), 1000000, f_txt))
while(fgets(line.data(), kMaxLineSize, f_txt))
{
char *y_char = strtok(line.data(), " \t");

Expand Down Expand Up @@ -797,7 +795,7 @@ ffm_parameter ffm_get_default_param()
param.k = 4;
param.nr_threads = 1;
param.quiet = false;
param.normalization = false;
param.normalization = true;
param.random = true;

return param;
Expand Down

0 comments on commit 423a125

Please sign in to comment.