Free cookie consent management tool by TermsFeed Policy Generator

Changeset 469 for trunk/sources


Ignore:
Timestamp:
08/08/08 19:56:19 (16 years ago)
Author:
gkronber
Message:

fixed #238 by using floor instead of round when we use a uniform-distribution in combination with integer variables

Location:
trunk/sources/HeuristicLab.Random
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Random/NormalRandomAdder.cs

    r426 r469  
    8888
    8989      public override void Visit(ConstrainedDoubleData data) {
    90 
    9190        for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    9291          double newValue = data.Data + normal.NextDouble();
    93 
    9492          if(IsIntegerConstrained(data)) {
    9593            newValue = Math.Round(newValue);
     
    9997          }
    10098        }
    101 
    10299        throw new InvalidProgramException("Coudn't find a valid value");
    103100      }
     
    112109            return;
    113110        }
    114 
    115111        throw new InvalidProgramException("Couldn't find a valid value.");
    116112      }
  • trunk/sources/HeuristicLab.Random/NormalRandomizer.cs

    r426 r469  
    7979        for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    8080          double r = normal.NextDouble();
    81 
    8281          if(IsIntegerConstrained(data)) {
    8382            r = Math.Round(r);
    8483          }
    85 
    8684          if(data.TrySetData(r)) {
    8785            return;
     
    9290
    9391      public override void Visit(ConstrainedIntData data) {
    94 
    9592        for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    9693          double r = normal.NextDouble();
    97           if(data.TrySetData((int)Math.Round(r)))
     94          if(data.TrySetData((int)Math.Round(r))) // since r is a continuous normally distributed random variable rounding should be OK
    9895            return;
    9996        }
    100 
    10197        throw new InvalidProgramException("Couldn't find a valid value");
    10298      }
  • trunk/sources/HeuristicLab.Random/UniformRandomAdder.cs

    r2 r469  
    4343    public UniformRandomAdder() {
    4444      AddVariableInfo(new VariableInfo("Value", "The value to manipulate (type is one of: IntData, ConstrainedIntData, DoubleData, ConstrainedDoubleData)", typeof(IObjectData), VariableKind.In));
    45       AddVariableInfo(new VariableInfo("ShakingFactor", "Determines the force of the shaking factor.", typeof(DoubleData), VariableKind.In));
     45      AddVariableInfo(new VariableInfo("ShakingFactor", "Determines the force of the shaking factor", typeof(DoubleData), VariableKind.In));
    4646      AddVariableInfo(new VariableInfo("Random", "The random generator to use", typeof(MersenneTwister), VariableKind.In));
    47       AddVariableInfo(new VariableInfo("Min", "Lower bound of the uniform distribution.", typeof(DoubleData), VariableKind.None));
     47      AddVariableInfo(new VariableInfo("Min", "Lower bound of the uniform distribution (inclusive)", typeof(DoubleData), VariableKind.None));
    4848      GetVariableInfo("Min").Local = true;
    4949      AddVariable(new Variable("Min", new DoubleData(-1.0)));
    5050
    51       AddVariableInfo(new VariableInfo("Max", "Upper bound of the uniform distribution", typeof(DoubleData), VariableKind.None));
     51      AddVariableInfo(new VariableInfo("Max", "Upper bound of the uniform distribution (exclusive)", typeof(DoubleData), VariableKind.None));
    5252      GetVariableInfo("Max").Local = true;
    5353      AddVariable(new Variable("Max", new DoubleData(1.0)));
     
    8484
    8585      public override void Visit(ConstrainedDoubleData data) {
    86 
    8786        for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    88 
    8987          double newValue = data.Data + mt.NextDouble() * (max - min) + min;
    90 
    9188          if(IsIntegerConstrained(data)) {
    92             newValue = Math.Round(newValue);
     89            newValue = Math.Floor(newValue);
    9390          }
    94 
    9591          if(data.TrySetData(newValue)) {
    9692            return;
    9793          }
    9894        }
    99 
    10095        throw new InvalidProgramException("Couldn't find a valid value");
    10196      }
     
    10398      public override void Visit(ConstrainedIntData data) {
    10499        for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    105           int newValue = (int)Math.Round(data.Data + mt.NextDouble() * (max - min) + min);
    106 
     100          int newValue = (int)Math.Floor(data.Data + mt.NextDouble() * (max - min) + min);
    107101          if(data.TrySetData(newValue)) {
    108102            return;
     
    117111
    118112      public override void Visit(IntData data) {
    119         data.Data = (int)Math.Round(data.Data + mt.NextDouble() * (max - min) + min);
     113        data.Data = (int)Math.Floor(data.Data + mt.NextDouble() * (max - min) + min);
    120114      }
    121115      private bool IsIntegerConstrained(ConstrainedDoubleData data) {
  • trunk/sources/HeuristicLab.Random/UniformRandomizer.cs

    r426 r469  
    4646      AddVariableInfo(new VariableInfo("Value", "The value to manipulate (type is one of: IntData, ConstrainedIntData, DoubleData, ConstrainedDoubleData)", typeof(IObjectData), VariableKind.In));
    4747      AddVariableInfo(new VariableInfo("Random", "The random generator to use", typeof(MersenneTwister), VariableKind.In));
    48       AddVariableInfo(new VariableInfo("Min", "Lower bound of the uniform distribution", typeof(DoubleData), VariableKind.None));
     48      AddVariableInfo(new VariableInfo("Min", "Lower bound of the uniform distribution (inclusive)", typeof(DoubleData), VariableKind.None));
    4949      GetVariableInfo("Min").Local = true;
    5050      AddVariable(new Variable("Min", new DoubleData(0.0)));
    5151
    52       AddVariableInfo(new VariableInfo("Max", "Upper bound of the uniform distribution", typeof(DoubleData), VariableKind.None));
     52      AddVariableInfo(new VariableInfo("Max", "Upper bound of the uniform distribution (exclusive)", typeof(DoubleData), VariableKind.None));
    5353      GetVariableInfo("Max").Local = true;
    5454      AddVariable(new Variable("Max", new DoubleData(1.0)));
     
    8282
    8383      public override void Visit(IntData data) {
    84         data.Data = (int)Math.Round(mt.NextDouble() * (max - min) + min);
     84        data.Data = (int)Math.Floor(mt.NextDouble() * (max - min) + min);
    8585      }
    8686
    8787      public override void Visit(ConstrainedDoubleData data) {
    88 
    8988        for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    9089          double r = mt.NextDouble() * (max - min) + min;
    91 
    9290          if(IsIntegerConstrained(data)) {
    93             r = Math.Round(r);
     91            r = Math.Floor(r);
    9492          }
    95 
    9693          if(data.TrySetData(r)) {
    9794            return;
    9895          }
    9996        }
    100 
    10197        throw new InvalidProgramException("Couldn't find a valid value");
    10298      }
    10399
    104100      public override void Visit(ConstrainedIntData data) {
    105 
    106101        for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {
    107           int r = (int)Math.Round(mt.NextDouble() * (max - min) + min);
    108 
     102          int r = (int)Math.Floor(mt.NextDouble() * (max - min) + min);
    109103          if(data.TrySetData(r)) {
    110104            return;
Note: See TracChangeset for help on using the changeset viewer.