int Classemes_get_descriptor(Classemes* obj, Matrix** f_out)
{
	Matrix* temp_M = NULL;
	Matrix* PsiX = NULL;
	int res;

	assert(obj);
	assert(f_out);

	/* if the feature has been already computed, we return it */
	if (obj->desc) {
		*f_out = obj->desc;
		return 0;
	}

	res = ImageData_get_low_level_feature_concatenation_IK(obj->img_data, &PsiX);;
	if (res) {
		return res;
	}
	/* compute classemes */
	/* the following line is temp_M = 1.0*Phi*PsiX + 1.0*Tau */
	temp_M = matrix_clone(Tau);
	matrix_times_matrix(temp_M, Phi, false, PsiX, false, 1.0, 1.0);

	obj->desc = temp_M;
	*f_out = obj->desc;

	return 0;
}
int Classemes_get_descriptorBIN(Classemes* obj, Matrix** f_out)
{
	Matrix* temp_M = NULL;
	int res;

	assert(obj);
	assert(f_out);

	/* if the feature has been already computed, we return it */
	if (obj->desc_bin) {
		*f_out = obj->desc_bin;
		return 0;
	}

	res = Classemes_get_descriptor(obj, &temp_M);
	if (res) {
		return res;
	}
	obj->desc_bin = matrix_clone(temp_M);
	matrix_op_binarize(obj->desc_bin, 0.0);

	*f_out = obj->desc_bin;

	return 0;
}
void glScale3f(float x, float y, float z)
{
	matrix_t matrix_scale;
	matrix_t matrix_res;

	transform_scale(&matrix_scale, x, y, z);
	matrix_mul(&matrix_main, &matrix_scale, &matrix_res);
	matrix_clone(&matrix_main, &matrix_res);
}
void glTransform3f(float x, float y, float z)
{
	matrix_t matrix_move;
	matrix_t matrix_res;

	transform_move(&matrix_move, x, y, z);
	matrix_mul(&matrix_main, &matrix_move, &matrix_res);
	matrix_clone(&matrix_main, &matrix_res);
}
Exemple #5
0
Correction *
back_propagate(
  NetworkState *network_state,
  Activation   *activity,
  Matrix        expected
) {
  int32_t     layers     = network_state->layers;
  int32_t     last_layer = layers - 1;
  Correction *correction = correction_new(layers - 1);
  Matrix      error, weight_correction, input_gradient, output_gradient;

  error = network_state->error(
    expected,
    activity->output[last_layer],
    activity->input[last_layer],
    network_state->derivative[last_layer]
  );

  correction->biases[last_layer - 1] = error;

  weight_correction = matrix_new(
    network_state->weights[last_layer][0], network_state->weights[last_layer][1]
  );
  matrix_dot_tn(activity->output[last_layer - 1], error, weight_correction);

  correction->weights[last_layer - 1] = weight_correction;

  for (int32_t layer = layers - 2; layer > 0; layer -= 1) {
    output_gradient = matrix_new(error[0], network_state->weights[layer + 1][0]);
    matrix_dot_nt(error, network_state->weights[layer + 1], output_gradient);

    input_gradient = matrix_new(activity->input[layer][0], activity->input[layer][1]);
    matrix_clone(input_gradient, activity->input[layer]);
    activation_closure_call(network_state->derivative[layer], input_gradient);

    error = matrix_new(network_state->biases[layer][0], network_state->biases[layer][1]);
    matrix_multiply(output_gradient, input_gradient, error);

    if (activity->mask[layer] != NULL) {
      matrix_multiply(error, activity->mask[layer], error);
    }

    correction->biases[layer - 1] = error;

    weight_correction = matrix_new(
      network_state->weights[layer][0], network_state->weights[layer][1]
    );
    matrix_dot_tn(activity->output[layer - 1], error, weight_correction);

    correction->weights[layer - 1] = weight_correction;
  }

  return correction;
}
Exemple #6
0
int main(int argc, char * argv[])
{
    int n, n_threads = 0;
    matrix_t * A,
             * A_orig;
    vector_t * b,
             * b_orig,
             * x,
             * check_res_mat;
             
    double t_start, t_end;
    
    
    get_input_params(argc, argv, &n);
    initialize_global_state();
    
    /* initialize data */
    A_orig          = matrix_create_rand(n, n),
    A               = matrix_clone(A_orig),
    b_orig          = vector_create_rand(n),
    b               = vector_clone(b_orig),
    x               = vector_create(n),
    check_res_mat   = vector_create(n);
    
    t_start = get_time_in_sec();
    
    perform_gaussian_elimination_on_matrix(A, b);
    perform_back_substitution(A, x, b);
    
    t_end  = get_time_in_sec();
    
    /* calculate Ax - b and find it's l2norm to test for correctness */
    matrix_mult_vector(A_orig, x, check_res_mat);
    
    vector_subtract(check_res_mat, check_res_mat, b_orig); /* c = c - b */
    
    printf("num-procs   = %d\n", omp_get_num_procs());

#pragma omp parallel num_threads(num_threads)
#pragma omp single
    n_threads = omp_get_num_threads();

    printf("num-threads = %d\n", n_threads);

    printf("Performed Gaussian Elimination in %.12lfs\n", t_end - t_start);
    printf("Ax-b l2norm = %.6le\n", vector_l2norm(check_res_mat));
    
    puts("done");   
    return 0;
}
void glRotate3f(float angle, float x, float y, float z)
{
	matrix_t matrix_rot_x;
	matrix_t matrix_rot_y;
	matrix_t matrix_rot_z;

	matrix_t matrix_res1;
	matrix_t matrix_res2;
	matrix_t matrix_res3;

	transform_rotate_x(&matrix_rot_x, (2*M_PI/360)*(x*angle));
	transform_rotate_y(&matrix_rot_y, (2*M_PI/360)*(y*angle));
	transform_rotate_z(&matrix_rot_z, (2*M_PI/360)*(z*angle));

	matrix_mul(&matrix_rot_x, &matrix_rot_y, &matrix_res1);
	matrix_mul(&matrix_res1, &matrix_rot_z, &matrix_res2);
	matrix_mul(&matrix_main, &matrix_res2, &matrix_res3);

	matrix_clone(&matrix_main, &matrix_res3);
}
Exemple #8
0
/*
 * Cache the Local Likelihood distributions for Q
 */
void hll_cache(hll_t *hll, double **Q, int n)
{
  int i;

  // allocate space, build kdtree
  double **X = new_matrix2(n, hll->dx);
  double ***S;
  safe_calloc(S, n, double**);
  for (i = 0; i < n; i++)
    S[i] = new_matrix2(hll->dx, hll->dx);
  kdtree_t *Q_kdtree = kdtree(Q, n, hll->dq);

  // precompute LL distributions
  hll_sample(X, S, Q, hll, n);

  // cache in hll
  hll->cache.Q_kdtree = Q_kdtree;
  hll->cache.Q = matrix_clone(Q, n, hll->dq);
  hll->cache.X = X;
  hll->cache.S = S;
  hll->cache.n = n;
}