// TODO: test & document this function void MaxentModel::dump_events(const string& model, bool binary) const { if (!m_es || m_es->size() == 0) throw runtime_error("empty model, no events to dump"); if (binary) throw runtime_error("binary events file not supported yet"); display("Dumping events to %s.ev%s", model.c_str() , (binary?".bin":"")); if (binary) { string file = model + ".ev.bin"; // save_events_bin(f, *m_es); } else { string file = model + ".ev"; save_events_txt(file, *m_es); } // save model MaxentModelFile f; f.set_pred_map(m_pred_map); f.set_outcome_map(m_outcome_map); f.set_params(m_params, m_n_theta, m_theta); f.save(model, binary); if (m_heldout_es->size() > 0) { display("Dumping heldout events to %s.heldout.ev%s", model.c_str() , (binary?".bin":"")); if (binary) { string file = model + ".heldout.ev.bin"; // save_events_bin(f, *m_heldout_es); } else { string file = model + ".heldout.ev"; save_events_txt(file, *m_heldout_es); } } }
/** * Save a MaxentModel to a file. * * @param model The name of the model to save. * @param binary If true, the file is saved in binary format, which is usually * smaller (if compiled with libz) and much faster to load. */ void MaxentModel::save(const string& model, bool binary) const { if (!m_params) throw runtime_error("no model to save (empty model)"); MaxentModelFile f; f.set_pred_map(m_pred_map); f.set_outcome_map(m_outcome_map); f.set_params(m_params, m_n_theta, m_theta); f.save(model, binary); }
char* test_bin_model() { MaxentModelFile f; f.load("data/me_model.txt"); f.save("data/model_temp", true); MaxentModelFile f2; f2.load("data/model_temp"); return check_model(f2); }
char* test_save() { MaxentModelFile t; // BOOST_CHECK_THROW(t.save("no this model", false), runtime_error); { MaxentModelFile f; f.load("data/me_model.txt"); f.save("data/model_temp", false); MaxentModelFile f2; f2.load("data/model_temp"); return check_model(f2); } }