Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/29/11 15:19:20 (14 years ago)
Author:
epitzer
Message:
  • Remove superfluous placeholders
  • Hide ParticleUpdater
  • Add CurrentVelocityBounds parameter analogous to CurrentInertia
  • Add (Current)VelocityBounds to results
  • Merge VelocityBoundsModifier directly into SwarmUpdater (#852)
Location:
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators
Files:
4 edited

Legend:

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

    r5592 r5866  
    5757      }
    5858
    59       BoundsChecker.Apply(velocity, VelocityBounds);
     59      BoundsChecker.Apply(velocity, CurrentVelocityBounds);
    6060      for (int i = 0; i < velocity.Length; i++) {
    6161        position[i] = RealVector[i] + velocity[i];
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs

    r5645 r5866  
    5959      get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    6060    }
    61     public ILookupParameter<DoubleMatrix> VelocityBoundsParameter {
    62       get { return (ILookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
     61    public ILookupParameter<DoubleMatrix> CurrentVelocityBoundsParameter {
     62      get { return (ILookupParameter<DoubleMatrix>)Parameters["CurrentVelocityBounds"]; }
    6363    }
    6464    public ILookupParameter<DoubleValue> InertiaParameter {
     
    9797      get { return BoundsParameter.ActualValue; }
    9898    }
    99     protected DoubleMatrix VelocityBounds {
    100       get { return VelocityBoundsParameter.ActualValue; }
     99    protected DoubleMatrix CurrentVelocityBounds {
     100      get { return CurrentVelocityBoundsParameter.ActualValue; }
    101101    }
    102102    protected DoubleValue Inertia {
     
    124124      Parameters.Add(new LookupParameter<RealVector>("NeighborBest", "Best neighboring solution."));
    125125      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem."));
    126       Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector."));
     126      Parameters.Add(new LookupParameter<DoubleMatrix>("CurrentVelocityBounds", "Upper and lower bounds for the particle's velocity vector."));
    127127      Parameters.Add(new LookupParameter<DoubleValue>("CurrentInertia", "The weight for the particle's velocity vector."));
    128128      Parameters.Add(new LookupParameter<DoubleValue>("PersonalBestAttraction", "The weight for the particle's personal best position."));
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorSwarmUpdater.cs

    r5643 r5866  
    2626using HeuristicLab.Operators;
    2727using HeuristicLab.Optimization;
     28using HeuristicLab.Optimization.Operators;
    2829using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.PluginInfrastructure;
    3032
    3133namespace HeuristicLab.Encodings.RealVectorEncoding {
     
    3436  public sealed class RealVectorSwarmUpdater : SingleSuccessorOperator, IRealVectorSwarmUpdater {
    3537
     38    [Storable]
     39    private ResultsCollector ResultsCollector;
     40
    3641    public override bool CanChangeName {
    3742      get { return false; }
     
    6974      get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; }
    7075    }
    71     public ValueLookupParameter<IDiscreteDoubleMatrixModifier> VelocityBoundsUpdaterParameter {
    72       get { return (ValueLookupParameter<IDiscreteDoubleMatrixModifier>)Parameters["VelocityBoundsUpdater"]; }
    73     }
    74     public LookupParameter<DoubleMatrix> VelocityBoundsParameter {
    75       get { return (LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
    76     }
     76    public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {
     77      get { return (ValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
     78    }
     79    public ILookupParameter<DoubleMatrix> CurrentVelocityBoundsParameter {
     80      get { return (ILookupParameter<DoubleMatrix>)Parameters["CurrentVelocityBounds"]; }
     81    }
     82    public LookupParameter<ResultCollection> ResultsParameter {
     83      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
     84    }
     85
     86    #region Velocity Bounds Updating
     87    public ILookupParameter<DoubleValue> VelocityBoundsScaleParameter {
     88      get { return (ILookupParameter<DoubleValue>)Parameters["VelocityBoundsScale"]; }
     89    }
     90    public OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> VelocityBoundsScalingOperatorParameter {
     91      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["VelocityBoundsScalingOperator"]; }
     92    }
     93    public IValueLookupParameter<DoubleValue> VelocityBoundsStartValueParameter {
     94      get { return (IValueLookupParameter<DoubleValue>)Parameters["VelocityBoundsStartValue"]; }
     95    }
     96    public IValueLookupParameter<DoubleValue> VelocityBoundsEndValueParameter {
     97      get { return (IValueLookupParameter<DoubleValue>)Parameters["VelocityBoundsEndValue"]; }
     98    }
     99    public ILookupParameter<IntValue> VelocityBoundsIndexParameter {
     100      get { return (ILookupParameter<IntValue>)Parameters["VelocityBoundsIndex"]; }
     101    }
     102    public IValueLookupParameter<IntValue> VelocityBoundsStartIndexParameter {
     103      get { return (IValueLookupParameter<IntValue>)Parameters["VelocityBoundsStartIndex"]; }
     104    }
     105    public IValueLookupParameter<IntValue> VelocityBoundsEndIndexParameter {
     106      get { return (IValueLookupParameter<IntValue>)Parameters["VelocityBoundsEndIndex"]; }
     107    }
     108    #endregion
     109
    77110    #endregion
    78111
     
    114147      get { return NeighborsParameter.ActualValue; }
    115148    }
    116     private IDiscreteDoubleMatrixModifier VelocityBoundsUpdater {
    117       get { return VelocityBoundsUpdaterParameter.ActualValue; }
    118     }
    119149    private DoubleMatrix VelocityBounds {
    120150      get { return VelocityBoundsParameter.ActualValue; }
    121       set { VelocityBoundsParameter.ActualValue = value; }
     151    }
     152    private DoubleMatrix CurrentVelocityBounds {
     153      get { return CurrentVelocityBoundsParameter.ActualValue; }
     154      set { CurrentVelocityBoundsParameter.ActualValue = value; }
     155    }
     156    private DoubleValue VelocityBoundsScale {
     157      get { return VelocityBoundsScaleParameter.ActualValue; }
     158      set { VelocityBoundsScaleParameter.ActualValue = value; }
     159    }
     160    private DoubleValue VelocityBoundsStartValue {
     161      get { return VelocityBoundsStartValueParameter.ActualValue; }
     162    }
     163    private IDiscreteDoubleValueModifier VelocityBoundsScalingOperator {
     164      get { return VelocityBoundsScalingOperatorParameter.Value; }
     165    }
     166    private ResultCollection Results {
     167      get { return ResultsParameter.ActualValue; }
    122168    }
    123169    #endregion
     
    127173    [StorableConstructor]
    128174    private RealVectorSwarmUpdater(bool deserializing) : base(deserializing) { }
    129     private RealVectorSwarmUpdater(RealVectorSwarmUpdater original, Cloner cloner) : base(original, cloner) { }
     175    private RealVectorSwarmUpdater(RealVectorSwarmUpdater original, Cloner cloner)
     176      : base(original, cloner) {
     177      ResultsCollector = cloner.Clone(original.ResultsCollector);
     178    }
    130179    public RealVectorSwarmUpdater()
    131180      : base() {
     
    140189      Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle."));
    141190      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    142       Parameters.Add(new ValueLookupParameter<IDiscreteDoubleMatrixModifier>("VelocityBoundsUpdater", "Modifies the velocity bounds in the course of optimization."));
    143       Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Maximum velocity for each dimension."));
     191      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("VelocityBounds", "Maximum velocity for each dimension.", new DoubleMatrix(new double[,] { { -1, 1 } })));
     192      Parameters.Add(new LookupParameter<DoubleMatrix>("CurrentVelocityBounds", "Current value of velocity bounds."));
     193      Parameters.Add(new LookupParameter<ResultCollection>("Results", "Results"));
     194
     195      #region Velocity Bounds Updating
     196      Parameters.Add(new LookupParameter<DoubleValue>("VelocityBoundsScale", "Scale parameter."));
     197      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("VelocityBoundsScalingOperator", "Modifies the value"));
     198      Parameters.Add(new ValueLookupParameter<DoubleValue>("VelocityBoundsStartValue", "The start value of 'Value'.", new DoubleValue(1)));
     199      Parameters.Add(new ValueLookupParameter<DoubleValue>("VelocityBoundsEndValue", "The end value of 'Value'.", new DoubleValue(1E-10)));
     200      Parameters.Add(new LookupParameter<IntValue>("VelocityBoundsIndex", "The current index.", "CurrentIteration"));
     201      Parameters.Add(new ValueLookupParameter<IntValue>("VelocityBoundsStartIndex", "The start index at which to start modifying 'Value'.", new IntValue(0)));
     202      Parameters.Add(new ValueLookupParameter<IntValue>("VelocityBoundsEndIndex", "The end index by which 'Value' should have reached 'EndValue'.", "MaxIterations"));
     203      VelocityBoundsStartIndexParameter.Hidden = true;
     204      VelocityBoundsEndIndexParameter.Hidden = true;
     205      #endregion
     206
     207      Initialize();
    144208    }
    145209
     
    149213
    150214    #endregion
     215
     216    private void Initialize() {
     217      ResultsCollector = new ResultsCollector();
     218      ResultsCollector.CollectedValues.Add(CurrentVelocityBoundsParameter);
     219      ResultsCollector.CollectedValues.Add(VelocityBoundsParameter);
     220
     221      foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>()) {
     222        VelocityBoundsScalingOperatorParameter.ValidValues.Add(op);
     223        op.ValueParameter.ActualName = VelocityBoundsScaleParameter.Name;
     224        op.StartValueParameter.ActualName = VelocityBoundsStartValueParameter.Name;
     225        op.EndValueParameter.ActualName = VelocityBoundsEndValueParameter.Name;
     226        op.IndexParameter.ActualName = VelocityBoundsIndexParameter.Name;
     227        op.StartIndexParameter.ActualName = VelocityBoundsStartIndexParameter.Name;
     228        op.EndIndexParameter.ActualName = VelocityBoundsEndIndexParameter.Name;
     229      }
     230      VelocityBoundsScalingOperatorParameter.Value = null;
     231    }
    151232
    152233    public override IOperation Apply() {
     
    194275    }
    195276
     277
     278
    196279    private IOperation UpdateVelocityBounds() {
    197       if (VelocityBounds == null)
    198         VelocityBounds = new DoubleMatrix(new double[,] { { -1, 1 } });
    199       return VelocityBoundsUpdater == null ?
    200         base.Apply() :
    201         new OperationCollection() {
    202           ExecutionContext.CreateChildOperation(VelocityBoundsUpdater),
    203           ExecutionContext.CreateOperation(Successor)
     280      if (CurrentVelocityBounds == null)
     281        CurrentVelocityBounds = (DoubleMatrix)VelocityBounds.Clone();
     282
     283      if (VelocityBoundsScalingOperator == null)
     284        return new OperationCollection() {
     285          ExecutionContext.CreateChildOperation(ResultsCollector),       
     286          base.Apply()
    204287        };
     288
     289
     290      DoubleMatrix matrix = CurrentVelocityBounds;
     291      if (VelocityBoundsScale == null && VelocityBoundsStartValue != null) {
     292        VelocityBoundsScale = new DoubleValue(VelocityBoundsStartValue.Value);
     293      }
     294      for (int i = 0; i < matrix.Rows; i++) {
     295        for (int j = 0; j < matrix.Columns; j++) {
     296          if (matrix[i, j] >= 0) {
     297            matrix[i, j] = VelocityBoundsScale.Value;
     298          } else {
     299            matrix[i, j] = (-1) * VelocityBoundsScale.Value;
     300          }
     301        }
     302      }
     303
     304      return new OperationCollection() {
     305        ExecutionContext.CreateChildOperation(ResultsCollector),
     306        ExecutionContext.CreateChildOperation(VelocityBoundsScalingOperator),       
     307        base.Apply()
     308      };
    205309    }
    206310  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorTotallyConnectedParticleUpdater.cs

    r5592 r5866  
    5757      }
    5858
    59       BoundsChecker.Apply(velocity, VelocityBounds);
     59      BoundsChecker.Apply(velocity, CurrentVelocityBounds);
    6060      for (int i = 0; i < velocity.Length; i++) {
    6161        position[i] = RealVector[i] + velocity[i];
Note: See TracChangeset for help on using the changeset viewer.