@Override
  public Vector get(Particle particle) {
    Vector localGuide = (Vector) particle.getLocalGuide(); // personal best (yi)
    Vector globalGuide = (Vector) particle.getGlobalGuide(); // global best (y^i)

    Vector.Builder builder = Vector.newBuilder();
    for (int i = 0; i < particle.getDimension(); ++i) {
      // double tmp1 = cognitive.getParameter();
      // double tmp2 = social.getParameter();

      double sigma = Math.abs(localGuide.doubleValueOf(i) - globalGuide.doubleValueOf(i));
      if (sigma == 0) {
        sigma = 1;
      }
      // System.out.println("Sigma: "+sigma);
      // according to Kennedy
      double mean = (localGuide.doubleValueOf(i) + globalGuide.doubleValueOf(i)) / 2;
      // andries proposal: double mean = (tmp1*personalBestPosition.getReal(i) +
      // tmp2*nBestPosition.getReal(i)) / (tmp1+tmp2);
      if (Rand.nextDouble() < p) {
        builder.add(
            localGuide.doubleValueOf(i) + this.cauchyDistribution.getRandomNumber(mean, sigma));
      } else {
        builder.add(
            globalGuide.doubleValueOf(i) + this.gaussianDistribution.getRandomNumber(mean, sigma));
      }
    }
    return builder.build();
  }
Example #2
0
 /** {@inheritDoc} */
 @Override
 public void randomise() {
   double tmp =
       Rand.nextDouble() * (getBounds().getUpperBound() - getBounds().getLowerBound())
           + getBounds().getLowerBound();
   this.value = Double.valueOf(tmp).intValue();
 }
Example #3
0
  @Override
  public Vector get(Particle particle) {
    Vector velocity = (Vector) particle.getVelocity();
    Vector position = (Vector) particle.getPosition();
    PSO algorithm = (PSO) AbstractAlgorithm.get();
    int ns = (int) nSize.getParameter();
    fj.data.List<Particle> neighbours =
        algorithm
            .getTopology()
            .sort(
                Ord.ord(
                    VectorBasedFunctions.sortByDistance(particle, new EuclideanDistanceMeasure())))
            .take(ns);

    Vector.Builder builder = Vector.newBuilder();
    for (int i = 0; i < particle.getDimension(); ++i) {
      double informationSum = 0.0;
      double randomSum = 0;

      for (Particle currentTarget : neighbours) {
        Vector currentTargetPosition = (Vector) currentTarget.getBestPosition();
        double randomComponent = Rand.nextDouble() * (4.1 / ns);
        informationSum += randomComponent * currentTargetPosition.doubleValueOf(i);
        randomSum += randomComponent;
      }

      double value =
          inertiaWeight.getParameter()
              * (velocity.doubleValueOf(i)
                  + randomSum * ((informationSum / (ns * randomSum) - position.doubleValueOf(i))));
      builder.add(value);
    }

    return builder.build();
  }