Ejemplo n.º 1
0
  /**
   * Calculates new weight for a particle.
   *
   * @param p Particle whose weight will be calculated
   */
  private void calcWeight(Particle p) {

    double weight = 0;

    // list with new weights
    List<Double> weight_list = new ArrayList<Double>();
    List<Measure> mlist = p.getMeasure();

    // measures at this location
    for (int i = 0; i < current.size(); i++) {

      String ssid = current.get(i).getBSSID();

      // all measures from generated particle
      for (int j = 0; j < mlist.size(); j++) {

        String ssid_part = mlist.get(j).getBSSID();

        // same ssids --> I can calculate a new weight
        if (ssid.equals(ssid_part)) {

          // rssi from actual location
          int rssi_curr = current.get(i).getRssi();
          // rssi from particle
          int rssi_part = mlist.get(j).getRssi();

          // calc new weight; typecast is necessary
          weight = ((double) rssi_curr) / ((double) rssi_part);

          // get percentage
          if (weight > 1.0) weight = 1.0 / weight;

          // add to list
          weight_list.add(weight);
        }
      }
    }

    double sum = 0;
    int number_weights = weight_list.size();

    // calc sum of all weights
    for (int k = 0; k < number_weights; k++) sum = sum + weight_list.get(k);

    // double mean_weight = sum / number_weights;
    double mean_weight = sum / current.size();

    // set new weight
    p.setWeight(mean_weight);
  }
Ejemplo n.º 2
0
  /** Method creates and initializes all particles. */
  public void initFilter() {

    // calc initial weight
    double initial_weight = 1.0 / num_part;

    for (int i = 0; i < num_part; i++) {

      // create random point
      Point p = createRandomPoint();

      // new particle on point p
      Particle part = new Particle(p);

      // interpolate particle part by his neighbors from database
      InterpolateParticle ip = new InterpolateParticle(part, db_list);
      Particle clean = ip.interpolatedParticle();

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

      // add particle to list
      part_list.add(clean);
    }
  }
Ejemplo n.º 3
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;
  }