Free cookie consent management tool by TermsFeed Policy Generator

# Changeset 12582

Ignore:
Timestamp:
07/03/15 14:54:28 (8 years ago)
Message:

#2306 made comparers and initializers consistent

Location:
branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK
Files:
1 deleted
18 edited

Unmodified
Removed
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/BinaryVectorComparers/AverageBitBinaryVectorComparer.cs

 r12566 namespace HeuristicLab.Problems.NK { [Item("Average Bit Binary Vector Comparer", "Compares two binary vectors by their average positive bit location")] [StorableClass] public sealed class AverageBitBinaryVectorComparer : BinaryVectorComparer { public sealed class AverageBitBinaryVectorComparer : Item, IBinaryVectorComparer { [StorableConstructor] private AverageBitBinaryVectorComparer(bool deserializing) : base(deserializing) { } private AverageBitBinaryVectorComparer(AverageBitBinaryVectorComparer original, Cloner cloner) : base(original, cloner) { } : base(original, cloner) { } public AverageBitBinaryVectorComparer() { } public override IDeepCloneable Clone(Cloner cloner) { } public static double AverageBit(BinaryVector x) { private static double AverageBit(BinaryVector x) { return x.Select((b, i) => new { b, i }).Where(v => v.b).Average(v => v.i); } public override int Compare(BinaryVector x, BinaryVector y) { public int Compare(BinaryVector x, BinaryVector y) { return (AverageBit(x) - AverageBit(y)).CompareTo(0); }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/BinaryVectorComparers/IBinaryVectorComparer.cs

 r12569 namespace HeuristicLab.Problems.NK { public interface IBinaryVectorComparer : INamedItem, IComparer { } public interface IBinaryVectorComparer : IItem, IComparer { } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/BinaryVectorComparers/LexicographicBinaryVectorComparer.cs

 r12566 namespace HeuristicLab.Problems.NK { [Item("Lexicographic Binary Vector Comparer", "Compares two binary vectors lexicographically")] [StorableClass] public sealed class LexicographicBinaryVectorComparer : BinaryVectorComparer { public sealed class LexicographicBinaryVectorComparer : Item, IBinaryVectorComparer { [StorableConstructor] private LexicographicBinaryVectorComparer(bool deserializing) : base(deserializing) { } private LexicographicBinaryVectorComparer(LexicographicBinaryVectorComparer original, Cloner cloner) : base(original, cloner) { } : base(original, cloner) { } public LexicographicBinaryVectorComparer() { } public override IDeepCloneable Clone(Cloner cloner) { } public override int Compare(BinaryVector x, BinaryVector y) { public int Compare(BinaryVector x, BinaryVector y) { for (int i = 0; i < Math.Min(x.Length, y.Length); i++) { if (!x[i] && y[i])
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/BinaryVectorComparers/MedianBitBinaryVectorComparer.cs

 r12566 namespace HeuristicLab.Problems.NK { [Item("Median Bit Binary Vector Comparer", "Compares two binary vectors by the median positive bit location")] [StorableClass] public sealed class MedianBitBinaryVectorComparer : BinaryVectorComparer { public sealed class MedianBitBinaryVectorComparer : Item, IBinaryVectorComparer { [StorableConstructor] private MedianBitBinaryVectorComparer(bool deserializing) : base(deserializing) { } private MedianBitBinaryVectorComparer(MedianBitBinaryVectorComparer original, Cloner cloner) : base(original, cloner) { } : base(original, cloner) { } public MedianBitBinaryVectorComparer() { } public override IDeepCloneable Clone(Cloner cloner) { } public static int MedianBit(BinaryVector x) { private static int MedianBit(BinaryVector x) { var activeIndices = x.Select((b, i) => new { b, i }).Where(v => v.b).ToList(); if (activeIndices.Count > 0) return 0; } public override int Compare(BinaryVector x, BinaryVector y) { public int Compare(BinaryVector x, BinaryVector y) { return MedianBit(x) - MedianBit(y); }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/HeuristicLab.Problems.NK.csproj

 r12569
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/IInteractionInitializer.cs

 r12566 namespace HeuristicLab.Problems.NK { public interface IInteractionInitializer : INamedItem { public interface IInteractionInitializer : IItem { BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random); }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/IncreasingBlockSizeInteractionsInitializer.cs

 r12566 namespace HeuristicLab.Problems.NK { [Item("IncreasingBlockSizeInteractionsInitializer", "Randomly assignes interactions across all bits but makes sure that different numbers of ineractions are applied to different bits.")] [StorableClass] public class IncreasingBlockSizeInteractionsInitializer : ParameterizedNamedItem, IInteractionInitializer { public sealed class IncreasingBlockSizeInteractionsInitializer : Item, IInteractionInitializer { [StorableConstructor] protected IncreasingBlockSizeInteractionsInitializer(bool serializing) : base(serializing) { } protected IncreasingBlockSizeInteractionsInitializer(IncreasingBlockSizeInteractionsInitializer original, Cloner cloner) : base(original, cloner) { } public IncreasingBlockSizeInteractionsInitializer() { } private IncreasingBlockSizeInteractionsInitializer(bool serializing) : base(serializing) { } private IncreasingBlockSizeInteractionsInitializer(IncreasingBlockSizeInteractionsInitializer original, Cloner cloner) : base(original, cloner) { } public IncreasingBlockSizeInteractionsInitializer() { } public override IDeepCloneable Clone(Cloner cloner) { return new IncreasingBlockSizeInteractionsInitializer(this, cloner); } #region IInteractionInitializer Members public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) { Dictionary bitInteractionCounts = new Dictionary(); return m; } #endregion } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/LimitedRandomInteractionsInitializer.cs

 r12569 namespace HeuristicLab.Problems.NK { [Item("LimitedRandomInteractionsInitializer", "Randomly assignes interactions across bits in the vicinity of each other respecting the maximum distances if possible.")] [StorableClass] public class LimitedRandomInteractionsInitializer : ParameterizedNamedItem, IInteractionInitializer { public sealed class LimitedRandomInteractionsInitializer : ParameterizedNamedItem, IInteractionInitializer { private class Bounds { public readonly int Min; } [StorableConstructor] private LimitedRandomInteractionsInitializer(bool serializing) : base(serializing) { } private LimitedRandomInteractionsInitializer(LimitedRandomInteractionsInitializer original, Cloner cloner) : base(original, cloner) { } public LimitedRandomInteractionsInitializer() { Parameters.Add(new ValueParameter("MaximumDistance", "Maximum distance of interactions in bits or 0 for unlimited")); Parameters.Add(new ValueParameter("MaximumDistanceRatio", "Maximum distance of interactions as ratio of the total length or 0 for unlimited")); } public override IDeepCloneable Clone(Cloner cloner) { return new LimitedRandomInteractionsInitializer(this, cloner); } private int MaximumDistance(int length, int nInteractions) { int maxBitDist = MaximumDistanceParameter.Value.Value; } [StorableConstructor] protected LimitedRandomInteractionsInitializer(bool serializing) : base(serializing) { } protected LimitedRandomInteractionsInitializer(LimitedRandomInteractionsInitializer original, Cloner cloner) : base(original, cloner) { } public LimitedRandomInteractionsInitializer() { Parameters.Add(new ValueParameter("MaximumDistance", "Maximum distance of interactions in bits or 0 for unlimited")); Parameters.Add(new ValueParameter("MaximumDistanceRatio", "Maximum distance of interactions as ratio of the total length or 0 for unlimited")); } public override IDeepCloneable Clone(Cloner cloner) { return new LimitedRandomInteractionsInitializer(this, cloner); } #region IInteractionInitializer Members public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) { BoolMatrix m = new BoolMatrix(length, nComponents); return m; } #endregion } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/RandomInteractionsInitializer.cs

 r12566 namespace HeuristicLab.Problems.NK { [Item("RandomInteractionsInitializer", "Randomly assignes interactions across all bits")] [StorableClass] public class RandomInteractionsInitializer : NamedItem, IInteractionInitializer { public override bool CanChangeName { get { return false; } } public override bool CanChangeDescription { get { return false; } } public sealed class RandomInteractionsInitializer : Item, IInteractionInitializer { [StorableConstructor] protected RandomInteractionsInitializer(bool serializing) : base(serializing) { } protected RandomInteractionsInitializer(RandomInteractionsInitializer original, Cloner cloner) : base(original, cloner) { } public RandomInteractionsInitializer() { name = ItemName; description = ItemDescription; } private RandomInteractionsInitializer(bool serializing) : base(serializing) { } private RandomInteractionsInitializer(RandomInteractionsInitializer original, Cloner cloner) : base(original, cloner) { } public RandomInteractionsInitializer() { } public override IDeepCloneable Clone(Cloner cloner) { return new RandomInteractionsInitializer(this, cloner); } #region IInteractionInitializer Members public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) { BoolMatrix m = new BoolMatrix(length, nComponents); return m; } #endregion } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/InteractionInitializers/SortedRandomInteractionsInitializer.cs

 r12569 namespace HeuristicLab.Problems.NK { [Item("SortedRandomInteractionsInitializer", "Randomly assigns interactions across all bits and sorts components according to bit affinity.")] [StorableClass] public class SortedRandomInteractionsInitializer : ParameterizedNamedItem, IInteractionInitializer { public sealed class SortedRandomInteractionsInitializer : ParameterizedNamedItem, IInteractionInitializer { public IConstrainedValueParameter ComparerParameter { get { return (IConstrainedValueParameter)Parameters["Comparer"]; } [StorableConstructor] protected SortedRandomInteractionsInitializer(bool serializing) : base(serializing) { } protected SortedRandomInteractionsInitializer(SortedRandomInteractionsInitializer original, Cloner cloner) : base(original, cloner) { } private SortedRandomInteractionsInitializer(bool serializing) : base(serializing) { } private SortedRandomInteractionsInitializer(SortedRandomInteractionsInitializer original, Cloner cloner) : base(original, cloner) { } public SortedRandomInteractionsInitializer() { Parameters.Add(new ConstrainedValueParameter("Comparer", "Comparison for sorting of component functions.")); } #region IInteractionInitializer Members public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) { BinaryVector[] components = Enumerable.Range(0, nComponents).Select(i => new BinaryVector(length)).ToArray(); return m; } #endregion } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/NKLandscape.cs

 r12576 using HeuristicLab.PluginInfrastructure; using HeuristicLab.Problems.Binary; using HeuristicLab.Problems.NK.WeightInitializers; using HeuristicLab.Random; #region Evaluation function public static long Hash(long x, HashAlgorithm hashAlg) { private static long Hash(long x, HashAlgorithm hashAlg) { return BitConverter.ToInt64(hashAlg.ComputeHash(BitConverter.GetBytes(x), 0, 8), 0); } public static double F_i(long x, long i, long g_i, long seed, int q, double p) { var hash = new Func(y => Hash(y, HashAlgorithm)); var hash = new Func(y => Hash(y, HashAlgorithm)); var fi = Math.Abs((double)hash((x & g_i) ^ hash(g_i ^ hash(i ^ seed)))) / long.MaxValue; if (q > 0) { fi = Math.Round(fi*q)/q; } if (q > 0) { fi = Math.Round(fi * q) / q; } if (p > 0) { hash = y => Hash(y, HashAlgorithmP); } public static double F(long x, long[] g, double[] w, long seed, ref double[] f_i, int q, double p) { private static double F(long x, long[] g, double[] w, long seed, ref double[] f_i, int q, double p) { double value = 0; for (int i = 0; i < g.Length; i++) { public override double Evaluate(BinaryVector vector, IRandom random) { double[] f_i;//not used atm double[] f_i; //useful for debugging double quality = Evaluate(vector, GeneInteractions, Weights, InteractionSeed.Value, out f_i, Q, P); return quality;
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/WeightInitializers/EqualWeightsInitializer.cs

 r12569 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.NK.WeightInitializers { namespace HeuristicLab.Problems.NK { [Item("EqualWeightsInitializer", "Initializes all weights to 1.0.")] [StorableClass] public class EqualWeightsInitializer : NamedItem, IWeightsInitializer { public override bool CanChangeName { get { return false; } } public override bool CanChangeDescription { get { return false; } } public sealed class EqualWeightsInitializer : Item, IWeightsInitializer { [StorableConstructor] protected EqualWeightsInitializer(bool deserializing) : base(deserializing) { } protected EqualWeightsInitializer(EqualWeightsInitializer original, Cloner cloner) : base(original, cloner) { } public EqualWeightsInitializer() { name = ItemName; description = ItemDescription; } private EqualWeightsInitializer(bool deserializing) : base(deserializing) { } private EqualWeightsInitializer(EqualWeightsInitializer original, Cloner cloner) : base(original, cloner) { } public EqualWeightsInitializer() { } public override IDeepCloneable Clone(Cloner cloner) { return new EqualWeightsInitializer(this, cloner); } #region IWeightsInitializer Members public IEnumerable GetWeights(int nComponents) { return new[] { 1.0 }; } #endregion } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/WeightInitializers/ExponentialDistributionWeightsInitializer.cs

 r12569 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.NK.WeightInitializers { namespace HeuristicLab.Problems.NK { [Item("ExponentialDistributionWeightsInitializer", "Assigns exponentially decreasing weights using the rate parameter lambda.")] [StorableClass] public class ExponentialDistributionWeightsInitializer : ParameterizedNamedItem, IWeightsInitializer { public override bool CanChangeName { get { return false; } } public override bool CanChangeDescription { get { return false; } } public sealed class ExponentialDistributionWeightsInitializer : ParameterizedNamedItem, IWeightsInitializer { public IValueParameter LambdaParameter { get { return (IValueParameter)Parameters["Lambda"]; } [StorableConstructor] protected ExponentialDistributionWeightsInitializer(bool deserializing) : base(deserializing) { } protected ExponentialDistributionWeightsInitializer(ExponentialDistributionWeightsInitializer original, Cloner cloner) private ExponentialDistributionWeightsInitializer(bool deserializing) : base(deserializing) { } private ExponentialDistributionWeightsInitializer(ExponentialDistributionWeightsInitializer original, Cloner cloner) : base(original, cloner) { } } public static double f(double x, double lambda) { private static double f(double x, double lambda) { if (x < 0.0) return 0.0; } #region IWeightsInitializer Members public IEnumerable GetWeights(int nComponents) { double lambda = LambdaParameter.Value.Value; yield return f(i, lambda); } #endregion } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/WeightInitializers/ExponentialWeightsInitializer.cs

 r12569 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.NK.WeightInitializers { namespace HeuristicLab.Problems.NK { [Item("ExponentialWeightsInitializer", "Assigns exponentially increasing weights.")] [StorableClass] public class ExponentialWeightsInitializer : NamedItem, IWeightsInitializer { public override bool CanChangeName { get { return false; } } public override bool CanChangeDescription { get { return false; } } public sealed class ExponentialWeightsInitializer : Item, IWeightsInitializer { [StorableConstructor] protected ExponentialWeightsInitializer(bool deserializing) : base(deserializing) { } protected ExponentialWeightsInitializer(ExponentialWeightsInitializer original, Cloner cloner) private ExponentialWeightsInitializer(bool deserializing) : base(deserializing) { } private ExponentialWeightsInitializer(ExponentialWeightsInitializer original, Cloner cloner) : base(original, cloner) { } public ExponentialWeightsInitializer() { name = ItemName; description = ItemDescription; } public ExponentialWeightsInitializer() { } public override IDeepCloneable Clone(Cloner cloner) { return new ExponentialWeightsInitializer(this, cloner); } #region IWeightsInitializer Members public IEnumerable GetWeights(int nComponents) { yield return Math.Pow(2, i); } #endregion } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/WeightInitializers/IWeightsInitializer.cs

 r12569 namespace HeuristicLab.Problems.NK { public interface IWeightsInitializer : INamedItem { public interface IWeightsInitializer : IItem { IEnumerable GetWeights(int nComponents); }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/WeightInitializers/LinearWeightsInitializer.cs

 r12569 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.NK.WeightInitializers { namespace HeuristicLab.Problems.NK { [Item("LinearWeightsInitializer", "Assigns linear increasing weights.")] [StorableClass] public class LinearWeightsInitializer : NamedItem, IWeightsInitializer { public override bool CanChangeName { get { return false; } } public override bool CanChangeDescription { get { return false; } } public sealed class LinearWeightsInitializer : Item, IWeightsInitializer { [StorableConstructor] protected LinearWeightsInitializer(bool deserializing) : base(deserializing) { } protected LinearWeightsInitializer(LinearWeightsInitializer original, Cloner cloner) private LinearWeightsInitializer(bool deserializing) : base(deserializing) { } private LinearWeightsInitializer(LinearWeightsInitializer original, Cloner cloner) : base(original, cloner) { } public LinearWeightsInitializer() { name = ItemName; description = ItemDescription; } public LinearWeightsInitializer() { } public override IDeepCloneable Clone(Cloner cloner) { return new LinearWeightsInitializer(this, cloner); } #region IWeightsInitializer Members public IEnumerable GetWeights(int nComponents) { yield return i; } #endregion } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/WeightInitializers/ReverseExponentialWeightsInitializer.cs

 r12569 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.NK.WeightInitializers { namespace HeuristicLab.Problems.NK { [Item("ReverseExponentialWeightsInitializer", "Assigns exponentially decreasing weights.")] [StorableClass] public class ReverseExponentialWeightsInitializer : NamedItem, IWeightsInitializer { public override bool CanChangeName { get { return false; } } public override bool CanChangeDescription { get { return false; } } public sealed class ReverseExponentialWeightsInitializer : Item, IWeightsInitializer { [StorableConstructor] protected ReverseExponentialWeightsInitializer(bool deserializing) : base(deserializing) { } protected ReverseExponentialWeightsInitializer(ReverseExponentialWeightsInitializer original, Cloner cloner) private ReverseExponentialWeightsInitializer(bool deserializing) : base(deserializing) { } private ReverseExponentialWeightsInitializer(ReverseExponentialWeightsInitializer original, Cloner cloner) : base(original, cloner) { } public ReverseExponentialWeightsInitializer() { name = ItemName; description = ItemDescription; } public ReverseExponentialWeightsInitializer() { } public override IDeepCloneable Clone(Cloner cloner) { return new ReverseExponentialWeightsInitializer(this, cloner); } #region IWeightsInitializer Members public IEnumerable GetWeights(int nComponents) { yield return Math.Pow(2, i); } #endregion } }
• ## branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK/WeightInitializers/ReverseLinearWeightsInitializer.cs

 r12569 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.NK.WeightInitializers { namespace HeuristicLab.Problems.NK { [Item("ReverseLinearWeightsInitializer", "Assigns exponentially decreasing weights.")] [StorableClass] public class ReverseLinearWeightsInitializer : NamedItem, IWeightsInitializer { public override bool CanChangeName { get { return false; } } public override bool CanChangeDescription { get { return false; } } public sealed class ReverseLinearWeightsInitializer : Item, IWeightsInitializer { [StorableConstructor] protected ReverseLinearWeightsInitializer(bool deserializing) : base(deserializing) { } protected ReverseLinearWeightsInitializer(ReverseLinearWeightsInitializer original, Cloner cloner) private ReverseLinearWeightsInitializer(bool deserializing) : base(deserializing) { } private ReverseLinearWeightsInitializer(ReverseLinearWeightsInitializer original, Cloner cloner) : base(original, cloner) { } public ReverseLinearWeightsInitializer() { name = ItemName; description = ItemDescription; } public ReverseLinearWeightsInitializer() { } public override IDeepCloneable Clone(Cloner cloner) { return new ReverseLinearWeightsInitializer(this, cloner); } #region IWeightsInitializer Members public IEnumerable GetWeights(int nComponents) { yield return i; } #endregion } }
Note: See TracChangeset for help on using the changeset viewer.