コード例 #1
0
struct problem * csr_set_problem (char *values, npy_intp *n_indices,
	char *indices, npy_intp *n_indptr, char *indptr, char *Y,
        npy_intp n_features, double bias) {

    struct problem *problem;
    problem = malloc (sizeof (struct problem));
    if (problem == NULL) return NULL;
    problem->l = (int) n_indptr[0] -1;

    if (bias > 0){
        problem->n = (int) n_features + 1;
    } else {
        problem->n = (int) n_features;
    }

    problem->y = (double *) Y;
    problem->x = csr_to_sparse((double *) values, n_indices, (int *) indices,
			n_indptr, (int *) indptr, bias, n_features);
    problem->bias = bias;

    if (problem->x == NULL) {
        free(problem);
        return NULL;
    }

    return problem;
}
コード例 #2
0
int csr_copy_predict_values(npy_intp n_features, npy_intp *data_size,
                            char *data, npy_intp *index_size, char
                            *index, npy_intp *indptr_shape, char
                            *intptr, struct model *model_, char
                            *dec_values, int nr_class)
{
    struct feature_node **predict_nodes;
    npy_intp i;

    predict_nodes = csr_to_sparse((double *) data, index_size,
                                  (int *) index, indptr_shape, (int *) intptr, model_->bias, n_features);

    if (predict_nodes == NULL)
        return -1;
    for (i = 0; i < indptr_shape[0] - 1; ++i) {
        predict_values(model_, predict_nodes[i],
                       ((double *) dec_values) + i*nr_class);
        free(predict_nodes[i]);
    }
    free(predict_nodes);
    return 0;
}
コード例 #3
0
int csr_copy_predict_proba(npy_intp n_features, npy_intp *data_size, 
                           char *data, npy_intp *index_size,
                           char *index, npy_intp *indptr_shape, 
                           char *indptr, struct model *model_,
                           char *dec_values)
{
    struct feature_node **predict_nodes;
    int i;
    double *tx = (double *) dec_values;

    predict_nodes = csr_to_sparse((double *) data, index_size,
                                  (int *) index, indptr_shape, 
                                  (int *) indptr, model_->bias, 
                                  n_features);
    if (predict_nodes == NULL)
        return -1;
    for(i=0; i<indptr_shape[0] - 1; ++i) {
        predict_probability(model_, predict_nodes[i], tx);
        tx += model_->nr_class;
        free(predict_nodes[i]);
    }
    free(predict_nodes);
    return 0;
}