Exemple #1
0
  /**
   * Creates particles on their probability-density-function. More probable particles are
   * propagated. Less probable particles will be rejected and replaced by new more probable
   * particles.
   */
  public void propagate() {

    // calcs sum of all weights
    double sum = sumWeight(part_list);

    // mean weight overall particles
    double mean_weight = sum / num_part;

    // List for particles
    List<Particle> tmp_list = new ArrayList<Particle>();

    double mean_x = 0;
    double mean_y = 0;

    for (int i = 0; i < part_list.size(); i++) {

      // get particle from list
      Particle p = part_list.get(i);
      // weight of particle
      double weight = p.getWeight();

      // if particle has more weight than average particle, write to list
      if (weight >= mean_weight) {

        tmp_list.add(p);

        // calc sum of coordinates
        mean_x = mean_x + p.getX();
        mean_y = mean_y + p.getY();
      }
    }

    // calc mean coordinate
    mean_x = Math.round(mean_x / tmp_list.size());
    mean_y = Math.round(mean_y / tmp_list.size());
    int x = (int) mean_x;
    int y = (int) mean_y;

    // difference between all particles and more probable particles
    int diff = num_part - tmp_list.size();

    // there must be a difference, except for completely degeneration
    if (diff > 0) {

      // initial weight
      double initial_weight = 1.0 / num_part;

      // create new particles according to difference
      for (int j = 0; j < diff; j++) {

        Point new_coord;
        Particle part;

        // only if there is a mean position of predicted particle
        if ((x != 0) && (y != 0)) {

          // new particle on pseudo-random point near predicted point
          new_coord = createPseudoRandomPoint(x, y);
          part = new Particle(new_coord);

        } else {

          // new particle on random point
          new_coord = createRandomPoint();
          part = new Particle(new_coord);
        }

        // new particle on random point
        // Point new_coord = createRandomPoint();
        // Particle part = new Particle(new_coord);

        // interpolate from neigborhood
        InterpolateParticle ip = new InterpolateParticle(part, db_list);
        Particle clean = ip.interpolatedParticle();

        // set new weight
        clean.setWeight(initial_weight);

        tmp_list.add(clean);
      }
    }

    // update particlelist
    part_list = tmp_list;
  }