Esempio n. 1
0
example_t* pylist_to_example(PyObject*input)
{
    example_t*e = 0;
    if(PyList_Check(input)) {
        int size = PyList_Size(input);
        e = example_new(size);
        int t;
        for(t=0; t<size; t++) {
            PyObject*item = PyList_GetItem(input, t);
            if(!add_item(e, t, item))
                return NULL;
        }
    } else if(PyDict_Check(input)) {
        int size = PyDict_Size(input);
        PyObject*pkey = 0;
        PyObject*pvalue = 0;
        size_t pos = 0;
        int t = 0;
        e = example_new(size);
        e->input_names = (const char**)malloc(sizeof(e->input_names[0])*size);
        while(PyDict_Next(input, &pos, &pkey, &pvalue)) {
            if(!pystring_check(pkey))
                return PY_ERROR("dict object must use strings as keys");
            const char*s = pystring_asstring(pkey);
            if(!add_item(e, t, pvalue))
                return NULL;
            e->input_names[t] = register_string(s);
            t++;
        }
    } else {
        return PY_ERROR("first argument must be a list or a dict");
    }
    return e;
}
Esempio n. 2
0
int main()
{
    config_parse_remote_servers("servers.txt");

    trainingdata_t* data = trainingdata_new();

    int t;
    for(t=0;t<256;t++) {
        example_t*e = example_new(16);
        int s;
        for(s=0;s<16;s++) {
            e->inputs[s] = variable_new_continuous((lrand48()%256)/256.0);
        }
        e->desired_response = variable_new_categorical(t%2);
        trainingdata_add_example(data, e);
    }

    trainingdata_save(data, "/tmp/data.data");
    trainingdata_destroy(data);

    data = trainingdata_load("/tmp/data.data");

    model_t*m = model_select(data);

    char*code = model_generate_code(m, "python");
    printf("%s\n", code);
    free(code);

    model_destroy(m);

    trainingdata_destroy(data);
}
Esempio n. 3
0
void core()
{
  example *e;

  e = example_new();
  assert_true(e);

  example_delete(e);
}
Esempio n. 4
0
void memory()
{
  extern int debug_out_of_memory;
  example *e;

  debug_out_of_memory = 1;
  e = example_new();
  assert_false(e);
  debug_out_of_memory = 0;
}
Esempio n. 5
0
void test()
{
    trainingdata_t* data = trainingdata_new();
    int t;
    for(t=0;t<256;t++) {
        example_t*e = example_new(16);
        int s;
        for(s=0;s<16;s++) {
            e->inputs[s] = variable_new_continuous((lrand48()%256)/256.0);
        }
        e->desired_response = variable_new_categorical(t%2);
        trainingdata_add_example(data, e);
    }

    dataset_t*dataset = trainingdata_sanitize(data);
    model_t*m = process_job_remotely("dtree", dataset);
    if(m) {
        printf("%s\n", m->name);
    }
}