/** * Load a MaxentModel from a file. * * @param model The name of the model to load */ void MaxentModel::load(const string& model) { MaxentModelFile f; f.load(model); m_pred_map = f.pred_map(); m_outcome_map = f.outcome_map(); f.params(m_params, m_n_theta, m_theta); }
// 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); }
/* * Load training data. * * @param events the file name of */ void Trainer::load_training_data(const string& events, const string& model) { shared_ptr<MEEventSpace> e(new MEEventSpace); load_events_txt(events, *e); MaxentModelFile f; f.load(model); f.params(m_params, m_n_theta, m_theta); m_es = e; }
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); }
//S: void MaxentModel::save_paremeter_on_decrease(const char* filepath){ 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_paremeter_on_decrease(filepath); }
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); } }
MaxentModelFile* load_model(const string& file) { MaxentModelFile* f = new MaxentModelFile(); f->load(file); return f; }