| 249 | } |
| 250 | |
| 251 | void saveModel(const DataConfig& output) { |
| 252 | |
| 253 | if (output.format() == DataConfig::TEXT) { |
| 254 | CHECK(output.file_size()); |
| 255 | std::string file = output.file(0) + "_" + myNodeID(); |
| 256 | if (!dirExists(getPath(file))) { |
| 257 | createDir(getPath(file)); |
| 258 | } |
| 259 | std::ofstream out(file); CHECK(out.good()); |
| 260 | for (int grp : fea_grp_) { |
| 261 | auto key = model_.key(grp); |
| 262 | auto value = model_.value(grp); |
| 263 | CHECK_EQ(key.size(), value.size()); |
| 264 | // TODO use the model_file in msg |
| 265 | for (size_t i = 0; i < key.size(); ++i) { |
| 266 | double v = value[i]; |
| 267 | if (v != 0 && !(v != v)) out << key[i] << "\t" << v << "\n"; |
| 268 | } |
| 269 | } |
| 270 | LI << myNodeID() << " written the model to " << file; |
| 271 | } |
| 272 | } |
| 273 | KVBufferedVector<Key, V> model_; |
| 274 | }; |
| 275 | |