Exemplo n.º 1
0
void adjust_sigma(Simulator *sim, int steps, double step_size,
				  double factor)
{
	double original_sigma = sim->sigma;
	double best_sigma = sim->sigma;
	double best_error = barcode_error(sim);
	for (int step = -steps; step <= steps; step++) {
		if (step == 0)
			continue;
		sim->sigma = original_sigma + step * step_size;
		if (sim->sigma < 1.0)
			continue;
		compute_kernel(sim);
		convolve_1d(sim->kernel_width, sim->kernel,
					sim->width, sim->guess, sim->blur, 0, sim->width);
		double error = barcode_error(sim);
		// printf("sigma=%.2f error=%.2f\n", sim->sigma, error);
		if (error < best_error) {
			best_error = error;
			best_sigma = sim->sigma;
		}
	}
	sim->sigma = best_sigma * factor + original_sigma * (1.0 - factor);
	compute_kernel(sim);
	convolve_1d(sim->kernel_width, sim->kernel,
				sim->width, sim->guess, sim->blur, 0, sim->width);
}
Exemplo n.º 2
0
    void check_and_compute() {
        compute_kernel();

        // calculate error
        // not being done right now since we are doing a fixed no. of iterations

        double *tmp;
        tmp = temperature;
        temperature = new_temperature;
        new_temperature = tmp;

        constrainBC();

        if (iterations % CKP_FREQ == 0 || iterations > MAX_ITER) {
#ifdef CMK_MEM_CHECKPOINT
            contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy));
#elif CMK_MESSAGE_LOGGING
            if(iterations > MAX_ITER)
                contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy));
            else
                AtSync();
#else
            contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy));
#endif
        } else {
            doStep();
        }
    }
Exemplo n.º 3
0
TEST(Kernel, Diagonal)
{
  AbelianGroup X(0, 2);
  X(0) = 1;
  X(1) = 2;

  AbelianGroup Y(0, 1);
  Y(0) = 2;

  MatrixQ f = {{5, 2}};

  MatrixQList to_K;
  MatrixQList from_K;

  MatrixQList from_X;
  MatrixQ id = {{1, 0}, {0, 1}};
  from_X.emplace_back(id);

  GroupWithMorphisms K =
      compute_kernel(5, f, X, Y, MatrixQRefList(), ref(from_X));

  EXPECT_EQ(0, K.group.free_rank());
  ASSERT_EQ(1, K.group.tor_rank());
  EXPECT_EQ(1, K.group(0));
}
Exemplo n.º 4
0
static int compute_gainshift_kernel (Isis_Kernel_t *k, double *result, Isis_Hist_t *g, double *par, unsigned int num, /*{{{*/
                                     int (*fun)(Isis_Hist_t *))
{
   Isis_Rmf_t *rmf = k->rsp.rmf;
   double *ylo=NULL, *yhi=NULL;
   double *tmp, *shift_lo, *shift_hi;
   double r0 = par[0]/KEV_ANGSTROM, slope = par[1];
   unsigned int i, len, n;
   int status = -1;

   if (-1 == compute_kernel (k, result, g, par, num, fun))
     return -1;

   if ((par[0] < 0) || (par[1] == 0.0))
     {
        isis_vmesg(FAIL, I_ERROR, __FILE__, __LINE__,
                   "gainshift kernel:  parameters (%g, %g) define an invalid grid",
                   par[0], par[1]);
        return -1;
     }

   if (-1 == rmf->get_data_grid (rmf, &ylo, &yhi, &n, NULL))
     return -1;

   len = 3 * n * sizeof(double);
   if (NULL == (tmp = (double *) ISIS_MALLOC (len)))
     goto return_error;
   shift_lo  = tmp + n;
   shift_hi  = tmp + 2*n;

#define NEW_LAMBDA(y)    (1.0/(1.0/y/slope - r0))

   shift_lo[0] = NEW_LAMBDA(ylo[0]);
   for (i = 1; i < n; i++)
     {
        shift_lo[i] = NEW_LAMBDA(ylo[i]);
        shift_hi[i-1] = shift_lo[i];
     }
   shift_hi[n-1] = NEW_LAMBDA(yhi[n-1]);

   if (-1 == rebin_histogram (result, ylo, yhi, n,
                              tmp, shift_lo, shift_hi, n))
     {
        ISIS_FREE(tmp);
        isis_vmesg(FAIL, I_ERROR, __FILE__, __LINE__,
                   "gainshift kernel failed while rebinning histogram");
        goto return_error;
     }

   memcpy ((char *)result, (char *)tmp, n * sizeof(double));
   ISIS_FREE(tmp);

   status = 0;
   return_error:
   ISIS_FREE(ylo);
   ISIS_FREE(yhi);

   return status;
}
Exemplo n.º 5
0
GroupWithMorphisms compute_image(const std::size_t p, const MatrixQ& f,
                                 const AbelianGroup& X, const AbelianGroup& Y)
{
  MatrixQRefList to_X;
  MatrixQList from_X = {MatrixQ::identity(f.width())};
  GroupWithMorphisms K = compute_kernel(p, f, X, Y, to_X, ref(from_X));

  MatrixQList to_X_2 = {MatrixQ::identity(f.width())};
  MatrixQList from_X_2 = {f};
  GroupWithMorphisms img =
      compute_cokernel(p, f, Y, ref(to_X_2), ref(from_X_2));

  return img;
}
Exemplo n.º 6
0
GroupWithMorphisms compute_image(const mod_t p, const MatrixQ& f,
                                 const AbelianGroup& X, const AbelianGroup& Y)
{
  MatrixQRefList to_X_dummy;
  MatrixQList from_X = {MatrixQ::identity(f.width())};
  GroupWithMorphisms K = compute_kernel(p, f, X, Y, to_X_dummy, ref(from_X));

  MatrixQList to_X_2 =  {MatrixQ::identity(X.rank())};
  MatrixQList from_X_2 = {f,MatrixQ::identity(X.rank())};//hacky, since id:X->X doesn't vanish on K.
                                                         //but due to the implementation, the columns of this will contain
                                                         //representatives in X for the generators of img.
  GroupWithMorphisms img =
      compute_cokernel(p, K.maps_from[0], X, ref(to_X_2), ref(from_X_2));

  return img;
}
Exemplo n.º 7
0
/** processes the actual fourier transformation
 * does a fourier transformation. This part of the program is rather
 * expensive to compute, so make sure you call this a minimum number of
 * times.
 *
 * @param amp A handler for the LV2 plugin instance.
 */
void fftprocess(Amp * amp)
{

    int i;
    float *fourier_buffer = amp->fourier_buffer;
    float output[FOURIER_SIZE];

    bcopy(amp->fourier_buffer, amp->previous_buffer,
          sizeof(float) * FOURIER_SIZE);
    peek_buffer(fourier_buffer, amp->in_buffer, FOURIER_SIZE);
    compute_kernel(amp);
#ifdef __OPENMP__
#pragma omp parallel for
#endif
    for (i = 0; i < FOURIER_SIZE; i++) {
        float inbuf[FOURIER_SIZE];
        float kernel[FOURIER_SIZE];
        //float* inbufp = (float*)inbuf; // pointer type

        prefetch_buffer(inbuf, amp->in_buffer, FOURIER_SIZE, i);

#ifdef __SSE__
		if (has_sse()){
	        average_kernels_sse(kernel, amp);
		} else {
        	average_kernels(kernel, amp);
			exit(EXIT_FAILURE);
		}
#else
        average_kernels(kernel, amp);
#endif
        //bcopy(kernel, amp->fourier_buffer, sizeof(float) * FOURIER_SIZE);

        output[i] = (amp->convolve_func) (inbuf, kernel);
		assert( output[i] >= -1.0 && output[i] <= 1.0);
    }

    write_buffer(amp->out_buffer, output, FOURIER_SIZE);
    read_buffer(NULL, amp->in_buffer, FOURIER_SIZE);
}
Exemplo n.º 8
0
static int compute_yshift_kernel (Isis_Kernel_t *k, double *result, Isis_Hist_t *g, double *par, unsigned int num, /*{{{*/
                                 int (*fun)(Isis_Hist_t *))
{
   Isis_Rmf_t *rmf = k->rsp.rmf;
   double *ylo=NULL, *yhi=NULL;
   double dy = par[0];
   unsigned int n;
   int status = -1;

   if (-1 == compute_kernel (k, result, g, par, num, fun))
     return -1;

   if (dy == 0.0)
     return 0;

   if (-1 == rmf->get_data_grid (rmf, &ylo, &yhi, &n, NULL))
     return -1;

   if (ylo[0] + dy > 0.0)
     {
        double *tmp, *shift_lo, *shift_hi;
        unsigned int i, len;

        len = 3 * n * sizeof(double);
        if (NULL == (tmp = (double *) ISIS_MALLOC (len)))
          goto return_error;
        shift_lo  = tmp + n;
        shift_hi  = tmp + 2*n;

        /* dy > 0 moves features to longer wavelengths */

        shift_lo[0] = ylo[0] - dy;
        for (i = 1; i < n; i++)
          {
             shift_lo[i] = ylo[i] - dy;
             shift_hi[i-1] = shift_lo[i];
          }
        shift_hi[n-1] = yhi[n-1] - dy;

        if (-1 == rebin_histogram (result, ylo, yhi, n,
                                   tmp, shift_lo, shift_hi, n))
          {
             ISIS_FREE(tmp);
             isis_vmesg(FAIL, I_ERROR, __FILE__, __LINE__,
                        "shift kernel failed while rebinning histogram");
             goto return_error;
          }

        memcpy ((char *)result, (char *)tmp, n * sizeof(double));
        ISIS_FREE(tmp);
     }
   else
     {
        isis_vmesg(FAIL, I_ERROR, __FILE__, __LINE__, "offset=%g yields invalid grid", dy);
        goto return_error;
     }

   status = 0;
   return_error:
   ISIS_FREE(ylo);
   ISIS_FREE(yhi);

   return status;
}