Ejemplo n.º 1
0
static void checkCorrect3(int ID, size_t num)
{
    el_t *els, *el;
    int *ids;
    bor_pairheap_t *heap;
    bor_pairheap_node_t *n;
    size_t i;
    FILE *fout1, *fout2;
    char fn[300];
    bor_rand_t r;

    borRandInit(&r);

    sprintf(fn, "regressions/tmp.TSPairHeap.rand-%d.out", ID);
    fout1 = fopen(fn, "w");
    sprintf(fn, "regressions/TSPairHeap.rand-%d.out", ID);
    fout2 = fopen(fn, "w");

    els = randomEls(num);
    ids = BOR_ALLOC_ARR(int, num);

    heap = borPairHeapNew(ltEl, NULL);
    for (i = 0; i < num; i++){
        borPairHeapAdd(heap, &els[i].node);
    }

    for (i = 0; i < num; i += 10){
        els[i].val += borRand(&r, 1, 100);
        borPairHeapUpdate(heap, &els[i].node);
    }

    i = 0;
    while (!borPairHeapEmpty(heap)){
        n = borPairHeapExtractMin(heap);
        el = bor_container_of(n, el_t, node);
        fprintf(fout1, "%d\n", el->val);

        el = bor_container_of(n, el_t, node);
        ids[i] = el->id;
        i++;
    }

    qsort(els, num, sizeof(el_t), cmpIncEl);
    for (i = 0; i < num; i++){
        fprintf(fout2, "%d\n", els[i].val);
    }


    borPairHeapDel(heap);
    free(els);
    free(ids);

    fclose(fout1);
    fclose(fout2);
}
Ejemplo n.º 2
0
static void _svoGNGInit(svo_gng_t *gng)
{
    const void *is;
    svo_gng_node_t *n1 = NULL, *n2 = NULL;
    size_t i;
    bor_real_t maxbeta;

    gng->cycle = 1L;

    // initialize error heap
    if (gng->err_heap)
        borPairHeapDel(gng->err_heap);
    gng->err_heap = borPairHeapNew(errHeapLT, (void *)gng);

    // precompute beta^n
    if (gng->beta_n)
        BOR_FREE(gng->beta_n);
    gng->beta_n = BOR_ALLOC_ARR(bor_real_t, gng->params.lambda);
    gng->beta_n[0] = gng->params.beta;
    for (i = 1; i < gng->params.lambda; i++){
        gng->beta_n[i] = gng->beta_n[i - 1] * gng->params.beta;
    }

    // precompute beta^(n * lambda)
    if (gng->beta_lambda_n)
        BOR_FREE(gng->beta_lambda_n);

    maxbeta = gng->beta_n[gng->params.lambda - 1];

    gng->beta_lambda_n_len = 1000;
    gng->beta_lambda_n = BOR_ALLOC_ARR(bor_real_t, gng->beta_lambda_n_len);
    gng->beta_lambda_n[0] = maxbeta;
    for (i = 1; i < gng->beta_lambda_n_len; i++){
        gng->beta_lambda_n[i] = gng->beta_lambda_n[i - 1] * maxbeta;
    }


    if (gng->ops.init){
        OPS(gng, init)(&n1, &n2, OPS_DATA(gng, init));
    }else{
        is = OPS(gng, input_signal)(OPS_DATA(gng, input_signal));
        n1 = OPS(gng, new_node)(is, OPS_DATA(gng, new_node));

        is = OPS(gng, input_signal)(OPS_DATA(gng, input_signal));
        n2 = OPS(gng, new_node)(is, OPS_DATA(gng, new_node));
    }

    nodeAdd(gng, n1);
    nodeAdd(gng, n2);
    edgeNew(gng, n1, n2);
}
Ejemplo n.º 3
0
svo_gng_eu_t *svoGNGEuNew(const svo_gng_eu_ops_t *ops,
                     const svo_gng_eu_params_t *params)
{
    svo_gng_eu_t *gng_eu;
    bor_nn_params_t nnp;
    size_t i;
    bor_real_t maxbeta;

    gng_eu = BOR_ALLOC(svo_gng_eu_t);

    gng_eu->net = borNetNew();

    gng_eu->ops    = *ops;
    gng_eu->params = *params;

    // set up ops data pointers
    if (!gng_eu->ops.new_node_data)
        gng_eu->ops.new_node_data = gng_eu->ops.data;
    if (!gng_eu->ops.del_node_data)
        gng_eu->ops.del_node_data = gng_eu->ops.data;
    if (!gng_eu->ops.input_signal_data)
        gng_eu->ops.input_signal_data = gng_eu->ops.data;
    if (!gng_eu->ops.terminate_data)
        gng_eu->ops.terminate_data = gng_eu->ops.data;
    if (!gng_eu->ops.callback_data)
        gng_eu->ops.callback_data = gng_eu->ops.data;


    // initialize error heap
    gng_eu->err_heap = borPairHeapNew(errHeapLT, (void *)gng_eu);

    // precompute beta^n
    gng_eu->beta_n = BOR_ALLOC_ARR(bor_real_t, gng_eu->params.lambda);
    gng_eu->beta_n[0] = gng_eu->params.beta;
    for (i = 1; i < gng_eu->params.lambda; i++){
        gng_eu->beta_n[i] = gng_eu->beta_n[i - 1] * gng_eu->params.beta;
    }

    // precompute beta^(n * lambda)
    maxbeta = gng_eu->beta_n[gng_eu->params.lambda - 1];
    gng_eu->beta_lambda_n_len = 1000;
    gng_eu->beta_lambda_n = BOR_ALLOC_ARR(bor_real_t, gng_eu->beta_lambda_n_len);
    gng_eu->beta_lambda_n[0] = maxbeta;
    for (i = 1; i < gng_eu->beta_lambda_n_len; i++){
        gng_eu->beta_lambda_n[i] = gng_eu->beta_lambda_n[i - 1] * maxbeta;
    }

    gng_eu->cycle = 1L;
    gng_eu->step  = 1;


    // initialize nncells
    nnp = params->nn;
    nnp.gug.dim = params->dim;
    nnp.vptree.dim = params->dim;
    nnp.linear.dim = params->dim;
    gng_eu->nn = borNNNew(&nnp);

    // initialize temporary vector
    if (gng_eu->params.dim == 2){
        gng_eu->tmpv = (bor_vec_t *)borVec2New(BOR_ZERO, BOR_ZERO);
    }else if (gng_eu->params.dim == 3){
        gng_eu->tmpv = (bor_vec_t *)borVec3New(BOR_ZERO, BOR_ZERO, BOR_ZERO);
    }else{
        gng_eu->tmpv = borVecNew(gng_eu->params.dim);
    }

    return gng_eu;
}
Ejemplo n.º 4
0
svo_gng_t *svoGNGNew(const svo_gng_ops_t *ops,
                     const svo_gng_params_t *params)
{
    svo_gng_t *gng;
    size_t i;
    bor_real_t maxbeta;

    gng = BOR_ALLOC(svo_gng_t);

    gng->net = borNetNew();

    gng->ops    = *ops;
    gng->params = *params;

    // set up ops data pointers
    if (!gng->ops.init_data)
        gng->ops.init_data = gng->ops.data;
    if (!gng->ops.new_node_data)
        gng->ops.new_node_data = gng->ops.data;
    if (!gng->ops.new_node_between_data)
        gng->ops.new_node_between_data = gng->ops.data;
    if (!gng->ops.del_node_data)
        gng->ops.del_node_data = gng->ops.data;
    if (!gng->ops.input_signal_data)
        gng->ops.input_signal_data = gng->ops.data;
    if (!gng->ops.nearest_data)
        gng->ops.nearest_data = gng->ops.data;
    if (!gng->ops.dist2_data)
        gng->ops.dist2_data = gng->ops.data;
    if (!gng->ops.move_towards_data)
        gng->ops.move_towards_data = gng->ops.data;
    if (!gng->ops.terminate_data)
        gng->ops.terminate_data = gng->ops.data;
    if (!gng->ops.callback_data)
        gng->ops.callback_data = gng->ops.data;


    // initialize error heap
    gng->err_heap = borPairHeapNew(errHeapLT, (void *)gng);

    // precompute beta^n
    gng->beta_n = BOR_ALLOC_ARR(bor_real_t, gng->params.lambda);
    gng->beta_n[0] = gng->params.beta;
    for (i = 1; i < gng->params.lambda; i++){
        gng->beta_n[i] = gng->beta_n[i - 1] * gng->params.beta;
    }

    // precompute beta^(n * lambda)
    maxbeta = gng->beta_n[gng->params.lambda - 1];
    gng->beta_lambda_n_len = 1000;
    gng->beta_lambda_n = BOR_ALLOC_ARR(bor_real_t, gng->beta_lambda_n_len);
    gng->beta_lambda_n[0] = maxbeta;
    for (i = 1; i < gng->beta_lambda_n_len; i++){
        gng->beta_lambda_n[i] = gng->beta_lambda_n[i - 1] * maxbeta;
    }

    gng->cycle = 1L;
    gng->step  = 1;

    return gng;
}