void FluxTensorMethod :: update(const Mat & input, Mat & result_frame)
{
	Mat temp_res[TENSOR_COMPONENTS_NUM+2];

	Mat gray_frame;
	convert2grayscale(input, gray_frame);
	result_frame = gray_frame.clone();

	compute_Ixt(gray_frame, temp_res[0]);
	compute_Iyt(gray_frame, temp_res[1]);
	if(compute_Itt(gray_frame, temp_res[2]) == 1)
		return;

	temp_res[3] = gray_frame.clone();
	compute_trace(temp_res, temp_res[3]);

	if(apply_averaging_filters(temp_res[3], temp_res[4]) == 1)
		return;



   // double rgb[3];
    const uchar * input_pixel_ptr;
    uchar * result_pixel_ptr;
    uchar mask;

    int height = gray_frame.rows;
    int width = gray_frame.cols;
    for(int row = 0; row < height; ++row)
    {
    	input_pixel_ptr = temp_res[4].ptr(row);
        result_pixel_ptr = result_frame.ptr(row);
        for(int col = 0; col < width; ++col)
        {
            //RGB reverted order
           // rgb[2] = (double) *input_pixel_ptr++;
           // rgb[1] = (double) *input_pixel_ptr++;
           // rgb[0] = (double) *input_pixel_ptr++;
           // double avr = (rgb[0]+rgb[1]+rgb[2])/3;
            double avr = (double) *input_pixel_ptr++;
        	mask = (avr>threshold) ? WHITE : BLACK;

            for(int i = 0; i < 1; ++i)
                *result_pixel_ptr++ = mask;
        }
    }
}
Beispiel #2
0
void simulator_ctt::execute_assert(
  statet &state,
  const program_formulat::formula_goto_programt::instructiont &instruction)
{
  std::cout << "CHECKING ASSERTION\n";

  formulat condition=
    instantiate(state, 0, instruction.guard);
    
  formulat property=
    formula_container.gen_and(
      state.data().guard,
      formula_container.gen_not(condition));

  // see if it is reachable
  if(!property.is_false() &&
     is_satisfiable(property))
  {
    tracet trace;

    compute_trace(state, trace, true);
    dump_trace(trace, instruction);
    std::cout << "Assertion violated" << std::endl;
    std::cout << std::endl;

    error_state_found=true;
  }
  
  #if 0
  else
  {
    // otherwise, treat this like an assumption
    state.data_w().guard=
      formula_container.gen_and(state.data().guard, condition);
  }
  #endif
}
Beispiel #3
0
int sscf (basis_set_t *basis, erd_t *erd_inp, double *H, double * S, double *S_sinv, int n, int n_ele, int maxit, 
	int diis_lim, double *D_old, 
	double *D_new, double *F) 
{
	double *int_buffer;
	double *tmp;
	double *tmp2;
	double *F_tt;
	double *F_t;
	double *D_t;
	double *delta_D;
	double err;
	int conv = 0;
	int iter = 0;
	double trace;
	double s;
	double c;
	double lambda;
	int i;
	int max_funcs;
	int max_buffer_dim;
	
	max_funcs =  2 * basis->max_momentum + 1;
	max_buffer_dim = max_funcs * max_funcs * max_funcs * max_funcs;
	
	int_buffer = (double *)malloc (max_buffer_dim * sizeof(double));
	tmp = (double *)malloc (n * n * sizeof(double));
	F_t = (double *)malloc (n * n * sizeof(double));
	D_t = (double *)malloc (n * n * sizeof(double));
	delta_D = (double *)malloc (n * n * sizeof(double));
	tmp2 = (double *)malloc (n * n * sizeof(double));
	F_tt = (double *)malloc (n * n * sizeof(double));
	memset (int_buffer, 0, max_buffer_dim * sizeof(double));
	memset (tmp, 0, n * n * sizeof(double));
	memset (F_t, 0, n * n * sizeof(double));
	memset (D_old, 0, n * n * sizeof(double));
	memset (D_new, 0, n * n * sizeof(double));
	memset (D_t, 0, n * n * sizeof(double));
	memset (delta_D, 0, n * n * sizeof(double));
	memset (tmp2, 0, n * n * sizeof(double));
	memset (F_tt, 0, n * n * sizeof(double));
	memcpy (F, H, n * n * sizeof(double));

	
	memcpy (F_t, H, n * n * sizeof(double));

	do {
		
#if ODA
		/*1. D <- Diagonalize(F_t) */
		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
			1.0, S_sinv, n, F_t, n, 0.0, tmp, n);

		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
			1.0, tmp, n, S_sinv, n, 0.0, F_tt, n);
	
		/*Compute D*/
		compute_D (n, n_ele, F_tt, D_new);
	
		/*Transform D*/
		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
			1.0, S_sinv, n, D_new, n, 0.0, tmp, n);

		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasTrans, n, n, n,
			1.0, tmp, n, S_sinv, n, 0.0, D_new, n);
		
		/*2. conv = Check (D-D') */

		/*3. F = Fock (D)*/
		
		memcpy (F, H, n * n * sizeof(double));
		build_fock (basis, erd_inp, int_buffer, D_new, F);

		/* delta_D = D - D_t*/
		
		memset (delta_D, 0, n * n * sizeof(double));
		cblas_daxpy (n * n, -1.0, D_t, 1, delta_D, 1);
		cblas_daxpy (n * n, 1.0, D_new, 1, delta_D, 1);

		/* s = trace(F_t * delta_D) */
		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
			1.0, F_t, n, delta_D, n, 0.0, tmp, n);

		
		s = compute_trace (tmp, n);
		
		/*tmp = F - F_t*/
		memset (tmp, 0, n * n * sizeof(double));
		cblas_daxpy (n * n, -1.0, F_t, 1, tmp, 1);
		cblas_daxpy (n * n, 1.0, F, 1, tmp, 1);

		/* c = trace (tmp * delta_D) */
		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
			1.0, tmp, n, delta_D, n, 0.0, tmp2, n);

		
		c = compute_trace (tmp2, n);
		/* set lambda */
		
		if (c < -s/2.0) {
			lambda = 1.0;
		} else {
			lambda = -s / (2.0 * c);
		}
		memcpy (D_old, D_t, n * n * sizeof (double));
		memcpy (F_tt, F_t, n * n * sizeof (double));


		/* D_t = (1-lambda) * D_t + lambda * D */
		memset (tmp, 0, n * n * sizeof(double));
		cblas_daxpy (n * n, (1.0 - lambda), D_t, 1, tmp, 1);
		cblas_daxpy (n * n, lambda, D_new, 1, tmp, 1);
		memset (D_t, 0, n * n * sizeof(double));
		cblas_daxpy (n * n, 1.0, tmp, 1, D_t, 1);
		
		/* F_t = (1-lambda) * F_t + lambda * F */
		memset (tmp, 0, n * n * sizeof(double));
		cblas_daxpy (n * n, (1.0 - lambda), F_t, 1, tmp, 1);
		cblas_daxpy (n * n, lambda, F, 1, tmp, 1);
		memset (F_t, 0, n * n * sizeof(double));
		cblas_daxpy (n * n, 1.0, tmp, 1, F_t, 1);
		
		/* print energy at each iteration */
		err = fabs (calc_hf_ene (D_new, F, H, n) - calc_hf_ene (D_old, F_tt, H, n));
		/* fprintf (stderr, "\n iteration ene %d: %lf", iter, calc_hf_ene(D_new, F, H, n)); */
		/* fprintf (stderr, "\n iteration %d: %10.6e", iter, err); */
		/* fprintf (stderr, "\n lambda %d: %lf",iter, lambda); */

		fprintf (stdout, "\n %d, %lf, %10.6e", iter, calc_hf_ene(D_new, F, H, n), err);


	
		iter++;

#endif

#if NORM
		memcpy (D_old, D_new, n * n * sizeof(double));

		/*Build F*/
		memcpy (F, H, n * n * sizeof(double));
		build_fock (basis, erd_inp, int_buffer, D_new, F);

		/*Transform F*/
		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
			1.0, S_sinv, n, F, n, 0.0, tmp, n);

		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
			1.0, tmp, n, S_sinv, n, 0.0, F_t, n);
	
		/*Compute D*/
		compute_D (n, n_ele, F_t, D_new);
	
		/*Transform D*/
		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
			1.0, S_sinv, n, D_new, n, 0.0, tmp, n);

		cblas_dgemm (CblasColMajor, CblasNoTrans, CblasTrans, n, n, n,
			1.0, tmp, n, S_sinv, n, 0.0, D_new, n);
		
		iter++;

		/*Check energy convergence*/
		err = fabs (calc_hf_ene (D_new, F, H, n) - calc_hf_ene (D_old, F, H, n));
		/* fprintf (stderr, "\n iteration ene %d: %lf", iter, calc_hf_ene(D_new, F, H, n)); */
		/* fprintf (stderr, "\n iteration %d: %10.6e", iter, err); */
		fprintf (stdout, "\n %d, %lf, %10.6e", iter, calc_hf_ene(D_new, F, H, n), err);
		

#endif


	} while ((iter < maxit));

	fprintf (stderr, "\n Final Energy: %lf \n", calc_hf_ene (D_new, F, H, n));

	/* printmatCM ("Final D", D_new, n, n); */
	/* printmatCM ("Final F", F, n, n); */
	free (D_t);
	free (delta_D);
	free (tmp2);
	free (tmp);
	free (F_t);
	free (F_tt);
	free (int_buffer);
	return 0;
}