Ejemplo n.º 1
0
double CrossLinkMSRestraint::unprotected_evaluate(DerivativeAccumulator *accum)
    const {
    double score = 0;
    if (get_log_prob_) {
       score = -log(get_probability());
    } else { 
       score = get_probability();
    }
    // std::cout << "here" << std::endl;

    // double prob=get_probability();
    // if (prob==0.0){score = std::numeric_limits<double>::max( );}
    // else{score=-log(prob);};
    if (accum) {
    };
    
    return score;
}
Ejemplo n.º 2
0
void FretData::init_grids
     (const Floats& d_grid_int, Float R0, Float Rmin, Float Rmax, bool do_limit)
{
  // grid on distance between termini
  for(unsigned l=0; l<d_term_.size(); ++l){
   // grid on sigma
   for(unsigned i=0; i<s_grid_.size(); ++i){
    // grid on distance between center of GMM
    for(unsigned j=0; j<d_center_.size(); ++j){
     Float marg=0.;
     Float norm=0.;
     unsigned kmin=0;
     unsigned kmax=d_grid_int.size();
     // find boundaries for marginalization
     if(do_limit){
      kmin=get_closest(d_grid_int,std::max(Rmin,d_term_[l]-Rmax));
      kmax=get_closest(d_grid_int,d_term_[l]+Rmax);
     }
     // do the marginalization
     for(unsigned k=kmin+1; k<kmax; ++k){

      Float dx = d_grid_int[k] - d_grid_int[k-1];

      Float prob   = get_probability(d_grid_int[k],   d_center_[j], s_grid_[i]);
      Float probm1 = get_probability(d_grid_int[k-1], d_center_[j], s_grid_[i]);

      Float kernel   = get_kernel( d_grid_int[k],   R0 );
      Float kernelm1 = get_kernel( d_grid_int[k-1], R0 );

      marg += ( kernel * prob + kernelm1 * probm1 ) / 2.0 * dx;
      norm += ( prob + probm1 ) / 2.0 * dx;
     }
     // store in grid_ and norm_
     grid_.push_back(marg);
     norm_.push_back(norm);
    }
   }
  }
}
Ejemplo n.º 3
0
int main(void) {
	double field_numbers, field_picks, mega_numbers;
	field_numbers = field_picks = mega_numbers = 0;
	
	std::cout << "Enter the total number of field choices, the number of field picks, and the number of mega choices: " << std::endl;
	while ((std::cin >> field_numbers >> field_picks >> mega_numbers) && field_picks <= field_numbers) {
		std::cout << "You have one chance in ";
		std::cout << get_probability(field_numbers, mega_numbers, field_picks);
		std::cout << " of winning.\n";
		std::cout << "Next three numbers (q to quit): ";
	}
	
	return 0;
}
Ejemplo n.º 4
0
//Given the calculated feature values (after finding final ratios) calculate the probablility associated with each class
std::vector<float> frame::calc_probs(std::vector<float> model_vals, std::vector<float> feat_vals)
{
	float prob_a = log(model_vals[0]);
	float prob_b = log(model_vals[model_vals.size()/2]); // Get model B's value
	model_vals.erase(model_vals.begin()); // Erase the class probability of A from the vector
	model_vals.erase(model_vals.begin() + model_vals.size()/2); // Erase the class probability of B from the vector
	int itr_size = model_vals.size();
	int lin_count = 0; 
	std:vector<float> class_probs; // Vector of size two holding prob for class A and B

	// Iterate through each feature for class A and B and sum to get the probability
	for(int i = 0; i < itr_size/2 ; i+=3)
	{
			prob_a += log(get_probability(feat_vals[lin_count], model_vals[i], model_vals[i+1], model_vals[i+3]));
			prob_b += log(get_probability(feat_vals[lin_count], model_vals[i+itr_size/2], model_vals[i+itr_size/2 +1], model_vals[i+itr_size/2+2]));
			cout << feat_vals[lin_count] << endl;
			lin_count++;
	}
	//cout << "PROB A: " << prob_a << endl;
	//cout << "PROB B: " << prob_b << endl;
	class_probs.push_back(prob_a);
	class_probs.push_back(prob_b);
	return class_probs;
}
Ejemplo n.º 5
0
/* Apply the score if it's a scale decorator.
 */
double vonMisesKappaJeffreysRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const {
  double score;
  Scale kappascale(kappa_);
  double kappaval = kappascale.get_scale();
  // computes the bessel functions if necessary
  score = -std::log(get_probability());
  if (accum) {
    /* calculate derivative and add to 1st coordinate of kappascale */
    double ratio = I1_ / I0_;
    double deriv =
        0.5 *
        (-1.0 / ratio + 3 * ratio + 1 / kappaval +
         1 / (kappaval * (1 - kappaval / ratio) + ratio * kappaval * kappaval));
    kappascale.add_to_scale_derivative(deriv, *accum);
  }
  return score;
}
Ejemplo n.º 6
0
void kmeans_compressor::bicriteria_to_coreset(
    wplist& src,
    wplist& bicriteria,
    csize_t dstsize,
    wplist& dst) {
  if (bicriteria.size() == 0) {
    dst = src;
    return;
  }
  double weight_sum = 0;
  double squared_min_dist_sum = 0;
  for (wplist::iterator it = src.begin(); it != src.end(); ++it) {
    std::pair<int, double> m = min_dist(*it, bicriteria);
    (*it).free_long = m.first;
    (*it).free_double = m.second;
    bicriteria.at((*it).free_long).free_double += (*it).weight;
    squared_min_dist_sum += pow((*it).free_double, 2) * (*it).weight;
    weight_sum += (*it).weight;
  }
  std::vector<double> weights;
  double sumw = 0;
  double prob = 0;
  for (wplist::iterator it = src.begin(); it != src.end(); ++it) {
    weighted_point p = *it;
    weighted_point bp = bicriteria.at(p.free_long);
    prob = get_probability(p, bp, weight_sum, squared_min_dist_sum);
    (*it).free_double = prob;
    weights.push_back(prob);
    sumw += prob;
  }

  discrete_distribution d(weights.begin(), weights.end());

  std::vector<size_t> ind(dstsize);
  std::generate(ind.begin(), ind.end(), d);

  for (std::vector<size_t>::iterator it = ind.begin(); it != ind.end(); ++it) {
    weighted_point sample = src.at(*it);
    sample.weight = 1.0 / dstsize * sumw / sample.free_double * sample.weight;
    sample.free_double = 0;
    sample.free_long = 0;
    dst.push_back(sample);
  }
}
Ejemplo n.º 7
0
double UniformBoundedRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const {
  double score;

  double prob = get_probability();

  // check if probability is too low (e.g. equal to zero)
  // and assign its value to the smallest double
  if (prob <= std::numeric_limits<double>::epsilon()) {
    prob = std::numeric_limits<double>::epsilon();
  }

  score = -log(prob);

  if (accum) {
  }

  return score;
}
//TODO incluir a parte S_t-1que considera a geometria
double
get_particle_weight(moving_objects3_particle_t particle_t, carmen_velodyne_projected_on_ground_message velodyne_projected_on_ground)
{
	double probability = 1.0;
	double cost,sigma;
	rectangle_points r_a, r_b, r_c;

	carmen_vector_2D_t end_point;

	generate_rectangles_points(particle_t.pose, particle_t.geometry.width, particle_t.geometry.length, &r_c, &r_b, &r_a);

	for (int i = 0; i < velodyne_projected_on_ground.num_rays; i++)
	{
		transform_polar_coordinates_to_cartesian_coordinates(velodyne_projected_on_ground.ranges[i], velodyne_projected_on_ground.angles[i], &end_point.x, &end_point.y);
		cost = get_ray_cost(end_point, r_a, r_b, r_c);
		sigma = get_sigma_from_cost(cost);
		probability *= get_probability(cost, sigma);
	}
	return probability;
}