Example #1
0
/**
 * 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);
}
Example #2
0
// 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);
        }
    }
}
Example #3
0
/**
 * 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);
}
Example #4
0
/*
 * 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;
}
Example #5
0
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);
}
Example #6
0
//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);
}
Example #7
0
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);
    }
}
Example #8
0
MaxentModelFile* 
load_model(const string& file) {
    MaxentModelFile* f = new MaxentModelFile();
    f->load(file);
    return f;
}