示例#1
0
Problem read_problem(std::string const path) {
    if(path.empty())
        return Problem(0, 0);
    Problem prob(get_nr_line(path), get_nr_field(path));

    FILE *f = open_c_file(path.c_str(), "r");
    char line[kMaxLineSize];

    uint64_t p = 0;
    for(uint32_t i = 0; fgets(line, kMaxLineSize, f) != nullptr; ++i) {
        char *y_char = strtok(line, " \t");
        float const y = (atoi(y_char)>0)? 1.0f : -1.0f;
        prob.Y[i] = y;
        for(; ; ++p) {
            char *idx_char = strtok(nullptr," \t");
            if(idx_char == nullptr || *idx_char == '\n') break;
            uint32_t idx = static_cast<uint32_t>(atoi(idx_char));
            prob.nr_feature = std::max(prob.nr_feature, idx);
            prob.J[p] = idx-1;
        }
    }

    fclose(f);

    return prob;
}
示例#2
0
Problem read_data(std::string const &dense_path, std::string const &sparse_path)
{
    Problem prob(get_nr_line(dense_path), get_nr_field(dense_path));

    read_dense(prob, dense_path);

    read_sparse(prob, sparse_path);

    return prob;
}