@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();
  }
Пример #2
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();
  }
Пример #3
0
  /** {@inheritDoc} */
  @Override
  public StringType getValue(Algorithm algorithm) {
    final StringBuilder tmp = new StringBuilder();
    final PSO pso = (PSO) algorithm;
    for (Particle particle : pso.getTopology()) {
      tmp.append("\nParticle: ");
      tmp.append(" Current Fitness: ");
      tmp.append(particle.getFitness().getValue());
      tmp.append(" Best Fitness: ");
      tmp.append(particle.getBestFitness().getValue());
      tmp.append(" Position: ");

      Vector v = (Vector) particle.getPosition();
      for (int j = 0; j < particle.getDimension(); ++j) {
        tmp.append(v.doubleValueOf(j));
        tmp.append(" ");
      }
    }

    return new StringType(tmp.toString());
  }