Ignore:
Timestamp:
06/29/17 23:04:03 (3 months ago)
Author:
abeham
Message:

#2797:

  • Added SPSO 2007 and SPSO 2011 particle updaters
  • Unhide particle updater parameter
  • Changed default parameters of sample
  • Changed max velocity to very high value by default (no speed limit)
  • Adapted unit test
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs

    r15091 r15096  
    1919 */
    2020#endregion
    21 
    22 using System;
     21 
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    2524using HeuristicLab.Data;
    2625using HeuristicLab.Operators;
     26using HeuristicLab.Optimization;
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    6060      get { return (ILookupParameter<DoubleValue>)Parameters["CurrentMaxVelocity"]; }
    6161    }
    62     public ILookupParameter<DoubleValue> InertiaParameter {
     62    public ILookupParameter<DoubleValue> CurrentInertiaParameter {
    6363      get { return (ILookupParameter<DoubleValue>)Parameters["CurrentInertia"]; }
    6464    }
     65    ILookupParameter<DoubleValue> IParticleUpdater.InertiaParameter { get { return CurrentInertiaParameter; } }
     66
    6567    public ILookupParameter<DoubleValue> PersonalBestAttractionParameter {
    6668      get { return (ILookupParameter<DoubleValue>)Parameters["PersonalBestAttraction"]; }
     
    8991    }
    9092    #endregion
    91 
    92     protected void UpdateVelocity() {
    93       var velocity = VelocityParameter.ActualValue;
    94       var position = RealVectorParameter.ActualValue;
    95       var inertia = InertiaParameter.ActualValue.Value;
    96       var personalBest = PersonalBestParameter.ActualValue;
    97       var personalBestAttraction = PersonalBestAttractionParameter.ActualValue.Value;
    98       var neighborBest = NeighborBestParameter.ActualValue;
    99       var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value;
    100 
    101       var random = RandomParameter.ActualValue;
    102 
    103       for (int i = 0; i < velocity.Length; i++) {
    104         double r_p = random.NextDouble();
    105         double r_g = random.NextDouble();
    106         velocity[i] =
    107           velocity[i] * inertia +
    108           (personalBest[i] - position[i]) * personalBestAttraction * r_p +
    109           (neighborBest[i] - position[i]) * neighborBestAttraction * r_g;
    110       }
    111 
    112       var maxVelocity = CurrentMaxVelocityParameter.ActualValue.Value;
    113       var speed = Math.Sqrt(velocity.DotProduct(velocity));
    114       if (speed > maxVelocity) {
    115         for (var i = 0; i < velocity.Length; i++) {
    116           velocity[i] *= maxVelocity / speed;
    117         }
    118       }
    119     }
    120 
    121     protected void UpdatePosition() {
    122       var velocity = VelocityParameter.ActualValue;
    123       var position = RealVectorParameter.ActualValue;
    124 
    125       for (int i = 0; i < velocity.Length; i++) {
    126         position[i] += velocity[i];
    127       }
    128 
    129       var bounds = BoundsParameter.ActualValue;
    130       for (int i = 0; i < position.Length; i++) {
    131         double min = bounds[i % bounds.Rows, 0];
    132         double max = bounds[i % bounds.Rows, 1];
    133         if (position[i] < min) {
    134           position[i] = min;
    135           velocity[i] = -0.5 * velocity[i]; // SPSO 2011
    136         }
    137         if (position[i] > max) {
    138           position[i] = max;
    139           velocity[i] = -0.5 * velocity[i]; // SPSO 2011
    140         }
    141       }
    142     }
    14393  }
    14494}
Note: See TracChangeset for help on using the changeset viewer.