 #include <boost/random/variate_generator.hpp>
 #include <boost/random/mersenne_twister.hpp>
 
+double factor = 1;
 
 struct likelihoodgetter
 {
+double factor;
+
 double __device__ likelihood(int count, int mask, cufftComplex val)
 {	
 	if (!mask) return 0;
 	double val2 = /*val.x * val.x + val.y * val.y*/ val.x;
 	double term = 0;
-	if (val2 <= 1e-10)
-	{
-		term = /*-val.x * val.x;val2 = 1e-9*/ -1e9 + val2 * 1e9;
-	}
-	else
-	{
-		term += log(val2) * count - val2;
-	}
+	/*if (val2 <= 1e-10)
+	{
+		term += val2 * factor;
+		val2 = 1e-10;
+	}
+	term += log(val2) * count - val2;*/
+	term -= (val2 - count) * (val2 - count);	
 	term -= fabs(val.y) * 1;
 
 	
 
 //	term -= val.y * val.y;
+//	term -= 34154;
 	return term;
 }
 

	int chosen = 0;
	int skips = 0;
	column_vector guess;
	guess.set_size(elem_count, 1);
	for (int y = 0; y < SHORT_SIDE / 2 + SHORT_SIDE % 2; y++)
	{
		for (int x = 0; x < SHORT_SIDE; x++)

		double val = thrust::transform_reduce(thrust::make_zip_iterator(thrust::make_tuple(t_truePattern, t_mask, t_pattern)),
                                         thrust::make_zip_iterator(thrust::make_tuple(&t_truePattern[SIDE * SIDE], &t_mask[SIDE * SIDE], &t_pattern[SIDE * SIDE])), likelihooder,
					 (double) 0, thrust::plus<double>()) /*+ 34154. * SIDE * SIDE*/;
		printf("VAL %le %le %le\n", sum, val, iorig[elem_count]);
		static int count = 0;
		count++;
		if (!(count & 255)) fflush(stdout);
