public SparseBoolFeatures(BoolMatrix dense) : this(modshogunPINVOKE.new_SparseBoolFeatures__SWIG_5(BoolMatrix.getCPtr(dense)), true)
 {
     if (modshogunPINVOKE.SWIGPendingException.Pending)
     {
         throw modshogunPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #2
0
        public GEArtificialAntProblem()
            : base(new GEArtificialAntEvaluator(), new UniformRandomIntegerVectorCreator())
        {
            BoolMatrix world = new BoolMatrix(santaFeAntTrail);

            Parameters.Add(new ValueParameter <IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant (genotype length).", new IntValue(30)));
            Parameters.Add(new ValueParameter <ISymbolicExpressionGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", new ArtificialAntExpressionGrammar()));
            Parameters.Add(new ValueParameter <BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
            Parameters.Add(new ValueParameter <IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
            IntMatrix m = new IntMatrix(new int[, ] {
                { 0, 100 }
            });

            Parameters.Add(new ValueParameter <IntMatrix>("Bounds", "The integer number range in which the single genomes of a genotype are created.", m));
            Parameters.Add(new ValueParameter <IGenotypeToPhenotypeMapper>("GenotypeToPhenotypeMapper", "Maps the genotype (an integer vector) to the phenotype (a symbolic expression tree).", new DepthFirstMapper()));

            Maximization.Value           = true;
            MaximizationParameter.Hidden = true;
            BestKnownQuality             = new DoubleValue(89);

            SolutionCreator.IntegerVectorParameter.ActualName           = "AntTrailSolutionIntegerVector";
            Evaluator.SymbolicExpressionTreeParameter.ActualName        = "AntTrailSolutionTree";
            Evaluator.SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar";
            Evaluator.QualityParameter.ActualName = "FoodEaten";

            InitializeOperators();
            RegisterEventHandlers();
        }
        public ArtificialAntProblem()
            : base(new Evaluator(), new ProbabilisticTreeCreator())
        {
            BoolMatrix world = new BoolMatrix(santaFeAntTrail);

            Parameters.Add(new ValueParameter <IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100)));
            Parameters.Add(new ValueParameter <IntValue>("MaximumExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10)));
            Parameters.Add(new ValueParameter <IntValue>("MaximumFunctionDefinitions", "Maximal number of automatically defined functions in the expression to control the artificial ant.", new IntValue(3)));
            Parameters.Add(new ValueParameter <IntValue>("MaximumFunctionArguments", "Maximal number of arguments of automatically defined functions in the expression to control the artificial ant.", new IntValue(3)));
            Parameters.Add(new ValueParameter <ISymbolicExpressionGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", new ArtificialAntExpressionGrammar()));
            Parameters.Add(new ValueParameter <BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
            Parameters.Add(new ValueParameter <IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));

            Maximization.Value           = true;
            MaximizationParameter.Hidden = true;
            BestKnownQuality             = new DoubleValue(89);
            SolutionCreator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution";
            ((ProbabilisticTreeCreator)SolutionCreator).SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar";
            Evaluator.QualityParameter.ActualName = "FoodEaten";
            InitializeOperators();
            RegisterEventHandlers();

            ArtificialAntExpressionGrammar.MaximumFunctionDefinitions = MaxFunctionDefinitions.Value;
            ArtificialAntExpressionGrammar.MaximumFunctionArguments   = MaxFunctionArguments.Value;
        }
Beispiel #4
0
 public BoolFeatures(BoolMatrix matrix) : this(modshogunPINVOKE.new_BoolFeatures__SWIG_3(BoolMatrix.getCPtr(matrix)), true)
 {
     if (modshogunPINVOKE.SWIGPendingException.Pending)
     {
         throw modshogunPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) {
   Dictionary<int, int> bitInteractionCounts = new Dictionary<int, int>();
   for (int i = 0; i < length; i++) {
     int count = nInteractions * 2 * i / length;
     if (count > 0)
       bitInteractionCounts[i] = count;
   }
   List<BinaryVector> components = new List<BinaryVector>();
   while (bitInteractionCounts.Count > 0) {
     BinaryVector component = new BinaryVector(length);
     for (int i = 0; i < nInteractions; i++) {
       while (bitInteractionCounts.Count > 0) {
         int bit = bitInteractionCounts.ElementAt(random.Next(bitInteractionCounts.Count)).Key;
         if (bitInteractionCounts[bit]-- <= 0)
           bitInteractionCounts.Remove(bit);
         if (!component[bit]) {
           component[bit] = true;
           break;
         }
       }
     }
     components.Add(component);
   }
   BoolMatrix m = new BoolMatrix(length, components.Count);
   foreach (var c in components.Select((v, j) => new { v, j })) {
     for (int i = 0; i < c.v.Length; i++) {
       m[i, c.j] = c.v[i];
     }
   }
   return m;
 }
Beispiel #6
0
 public BoolMatrix(BoolMatrix orig) : this(modshogunPINVOKE.new_BoolMatrix__SWIG_5(BoolMatrix.getCPtr(orig)), true)
 {
     if (modshogunPINVOKE.SWIGPendingException.Pending)
     {
         throw modshogunPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #7
0
 public AntTrail(BoolMatrix world, SymbolicExpressionTree expression, IntValue maxTimeSteps)
   : this() {
   this.world = world;
   this.expression = expression;
   this.maxTimeSteps = maxTimeSteps;
   Initialize();
 }
Beispiel #8
0
 public Solution(BoolMatrix world, ISymbolicExpressionTree expression, int maxTimeSteps, double quality)
 {
     this.World = world;
     this.SymbolicExpressionTree = expression;
     this.MaxTimeSteps           = maxTimeSteps;
     this.Quality = quality;
 }
Beispiel #9
0
 public Interpreter(ISymbolicExpressionTree tree, BoolMatrix world, int maxTimeSteps) {
   this.Expression = tree;
   this.MaxTimeSteps = maxTimeSteps;
   // create a clone of the world because the ant will remove the food items it can find.
   World = (BoolMatrix)world.Clone();
   CountFoodItems();
 }
Beispiel #10
0
        public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random)
        {
            BoolMatrix m = new BoolMatrix(length, nComponents);
            int        maxBitDistance = MaximumDistance(length, nInteractions);
            var        minBounds      = new Bounds(0, length - nInteractions);
            var        maxBounds      = new Bounds(nInteractions, length - 1);

            for (int c = 0; c < m.Columns; c++)
            {
                int min     = minBounds.Bounded(c - maxBitDistance);
                int max     = maxBounds.Bounded(c + maxBitDistance);
                var indices = Enumerable.Range(min, max - min).ToList();
                indices.Remove(c);
                m[c, c] = true;
                while (indices.Count > nInteractions)
                {
                    indices.RemoveAt(random.Next(indices.Count));
                }
                foreach (var i in indices)
                {
                    m[i, c] = true;
                }
            }
            return(m);
        }
Beispiel #11
0
    public void initFieldsVal()
    {
        Cartesian Cell;
        this.PlayerField = new int[10, 10];

        //Initialize visible and collision matrix
        this.Vision = new BoolMatrix ();
        Vision.initMatrix (10, 10);

        BoolMatrix OccupPositions = new BoolMatrix ();
        OccupPositions.initMatrix (10, 10);

        for (int size=4; size>0; size--) {
            int num = 5 - size;
            for (int i=0; i<num; i++) {
                bool isPlaced = true;
                do {
                Cell = new Cartesian(Random.Range(0,10),Random.Range(0,10));
                if (OccupPositions.isFreeCell (Cell, size)) {
                        isPlaced = false;
                    }
                }while(isPlaced);
            }
        }
    }
Beispiel #12
0
        public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random)
        {
            BinaryVector[] components = Enumerable.Range(0, nComponents).Select(i => new BinaryVector(length)).ToArray();
            for (int c = 0; c < components.Length; c++)
            {
                var indices = Enumerable.Range(0, length).ToList();
                if (indices.Count > c)
                {
                    indices.RemoveAt(c);
                    components[c][c] = true;
                }
                while (indices.Count > nInteractions)
                {
                    indices.RemoveAt(random.Next(indices.Count));
                }
                foreach (var i in indices)
                {
                    components[c][i] = true;
                }
            }
            BoolMatrix m = new BoolMatrix(length, nComponents);

            foreach (var c in components.OrderBy(v => v, Comparer).Select((v, j) => new { v, j }))
            {
                for (int i = 0; i < c.v.Length; i++)
                {
                    m[i, c.j] = c.v[i];
                }
            }
            return(m);
        }
        public override IOperation Apply()
        {
            ItemArray <SymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
            ItemArray <DoubleValue>            qualities   = QualityParameter.ActualValue;
            BoolMatrix       world        = WorldParameter.ActualValue;
            IntValue         maxTimeSteps = MaxTimeStepsParameter.ActualValue;
            ResultCollection results      = ResultsParameter.ActualValue;

            int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => - x.Value).First().index;

            AntTrail antTrail = BestSolutionParameter.ActualValue;

            if (antTrail == null)
            {
                var bestAntTrail = new AntTrail(world, expressions[i], maxTimeSteps);
                BestSolutionParameter.ActualValue = bestAntTrail;
                results.Add(new Result("Best Artificial Ant Solution", bestAntTrail));
            }
            else
            {
                antTrail.World = world;
                antTrail.SymbolicExpressionTree = expressions[i];
                antTrail.MaxTimeSteps           = maxTimeSteps;
                results["Best Artificial Ant Solution"].Value = antTrail;
            }
            return(base.Apply());
        }
Beispiel #14
0
        public void Render(BoolMatrix boolMatrix, PixelFetcher pf, 
		       Drawable drawable)
        {
            var dimensions = drawable.Dimensions;
              RenderDrop(boolMatrix, pf, dimensions);
              RenderShadow(pf, drawable, dimensions);
        }
 public Interpreter(ISymbolicExpressionTree tree, BoolMatrix world, int maxTimeSteps)
 {
     this.Expression   = tree;
     this.MaxTimeSteps = maxTimeSteps;
     // create a clone of the world because the ant will remove the food items it can find.
     World = (BoolMatrix)world.Clone();
     CountFoodItems();
 }
Beispiel #16
0
 public virtual void copy_feature_matrix(BoolMatrix src)
 {
     modshogunPINVOKE.BoolFeatures_copy_feature_matrix(swigCPtr, BoolMatrix.getCPtr(src));
     if (modshogunPINVOKE.SWIGPendingException.Pending)
     {
         throw modshogunPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #17
0
 public void set_feature_matrix(BoolMatrix matrix)
 {
     modshogunPINVOKE.BoolFeatures_set_feature_matrix(swigCPtr, BoolMatrix.getCPtr(matrix));
     if (modshogunPINVOKE.SWIGPendingException.Pending)
     {
         throw modshogunPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #18
0
        public void Render(BoolMatrix boolMatrix, PixelFetcher pf,
                           Drawable drawable)
        {
            var dimensions = drawable.Dimensions;

            RenderDrop(boolMatrix, pf, dimensions);
            RenderShadow(pf, drawable, dimensions);
        }
Beispiel #19
0
 private AntTrail(AntTrail original, Cloner cloner)
     : base(original, cloner)
 {
     expression   = cloner.Clone(original.expression);
     world        = cloner.Clone(original.world);
     maxTimeSteps = cloner.Clone(original.maxTimeSteps);
     Initialize();
 }
Beispiel #20
0
 public AntTrail(BoolMatrix world, SymbolicExpressionTree expression, IntValue maxTimeSteps)
     : this()
 {
     this.world        = world;
     this.expression   = expression;
     this.maxTimeSteps = maxTimeSteps;
     Initialize();
 }
Beispiel #21
0
        public void Render(Image image, Drawable drawable, bool preview)
        {
            int size = GetValue <int>("size");

            image.UndoGroupStart();

            var procedure = new Procedure("plug_in_pixelize");

            procedure.Run(image, drawable, size);

            var palette = new MinisteckPalette();

            image.ConvertIndexed(ConvertDitherType.No, ConvertPaletteType.Custom,
                                 0, false, false, "Ministeck");
            palette.Delete();

            image.ConvertRgb();
            image.UndoGroupEnd();

            // And finally calculate the Ministeck pieces

            using (var painter = new Painter(drawable, size, GetValue <RGB>("color")))
            {
                Shape.Painter = painter;

                int width  = drawable.Width / size;
                int height = drawable.Height / size;

                var A = new BoolMatrix(width, height);

                // Fill in shapes
                bool limit  = GetValue <bool>("limit");
                var  shapes = new ShapeSet();
                shapes.Add((limit) ? 2 : 1, new TwoByTwoShape());
                shapes.Add((limit) ? 8 : 1, new ThreeByOneShape());
                shapes.Add((limit) ? 3 : 1, new TwoByOneShape());
                shapes.Add((limit) ? 2 : 1, new CornerShape());
                shapes.Add((limit) ? 1 : 1, new OneByOneShape());

                Action <int> update = null;
                if (!preview)
                {
                    var progress = new Progress(_("Ministeck..."));
                    update = y => progress.Update((double)y / height);
                }

                var generator =
                    new CoordinateGenerator(new Rectangle(0, 0, width, height), update);
                generator.ForEach(c => { if (!A.Get(c))
                                         {
                                             shapes.Fits(A, c);
                                         }
                                  });
            }

            drawable.Flush();
            drawable.Update();
        }
Beispiel #22
0
        public static double Evaluate(BinaryVector vector, BoolMatrix interactions, DoubleArray weights, int seed, out double[] f_i, int q, double p)
        {
            long x = Encode(vector);

            long[]   g = Encode(interactions);
            double[] w = Normalize(weights);
            f_i = new double[interactions.Columns];
            return(F(x, g, w, (long)seed, ref f_i, q, p));
        }
    public virtual bool set_full_feature_matrix(BoolMatrix full)
    {
        bool ret = modshogunPINVOKE.SparseBoolFeatures_set_full_feature_matrix(swigCPtr, BoolMatrix.getCPtr(full));

        if (modshogunPINVOKE.SWIGPendingException.Pending)
        {
            throw modshogunPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
        public void RoundTrip_3_3_Identity()
        {
            var stringMatrix = @"1 0 0
0 1 0
0 0 1";

            var roundTrip = BoolMatrix.Parse(stringMatrix).ToString();

            Assert.AreEqual(stringMatrix, roundTrip);
        }
Beispiel #25
0
 public void Fits(BoolMatrix A, IntCoordinate c)
 {
     foreach (var shape in this)
     {
         if (shape.Fits(A, c))
         {
             break;
         }
     }
 }
Beispiel #26
0
 public void Fits(BoolMatrix A, IntCoordinate c)
 {
     foreach (var shape in this)
     {
       if (shape.Fits(A, c))
     {
       break;
     }
     }
 }
Beispiel #27
0
        private BoolMatrix CreateTable(int width, int heigh)
        {
            var result = new BoolMatrix();

            for (var i = 0; i < heigh; i++)
            {
                result.Add(new BoolVector(width));
            }
            return(new BoolMatrix(result));
        }
Beispiel #28
0
    public BoolMatrix steal_feature_matrix()
    {
        BoolMatrix ret = new BoolMatrix(modshogunPINVOKE.BoolFeatures_steal_feature_matrix(swigCPtr), true);

        if (modshogunPINVOKE.SWIGPendingException.Pending)
        {
            throw modshogunPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
Beispiel #29
0
        public bool Fits(Painter painter, BoolMatrix A, IntCoordinate p)
        {
            var color = painter.GetPixel(p);

            return(TrueForAll(offset =>
            {
                var c = new IntCoordinate(p.X + offset.X, p.Y + offset.Y);
                return A.IsInside(c) && !A.Get(c) && painter.IsSameColor(c, color);
            }));
        }
Beispiel #30
0
        public void Size2Square_BottomRight_3_3()
        {
            var stringMatrix = @"
0 0 0
0 1 1
0 1 1".Trim();
            var result       = GetResult(BoolMatrix.Parse(stringMatrix));

            Assert.AreEqual(2, result.Size);
            Assert.AreEqual(1, result.StartX);
            Assert.AreEqual(1, result.StartY);
        }
Beispiel #31
0
 public bool Fits(BoolMatrix A, IntCoordinate c)
 {
     foreach (var shape in _set[_random.Next(0, _set.Count)])
     {
         if (shape.Fits(Painter, A, c))
         {
             shape.Fill(A, c);
             return(true);
         }
     }
     return(false);
 }
Beispiel #32
0
        public void Size2Square_TopLeft_3_3()
        {
            var stringMatrix = @"
1 1 0
1 1 0
0 0 0".Trim();
            var result       = GetResult(BoolMatrix.Parse(stringMatrix));

            Assert.AreEqual(2, result.Size);
            Assert.AreEqual(0, result.StartX);
            Assert.AreEqual(0, result.StartY);
        }
Beispiel #33
0
 public bool Fits(BoolMatrix A, IntCoordinate c)
 {
     foreach (var shape in _set[_random.Next(0, _set.Count)])
     {
       if (shape.Fits(Painter, A, c))
     {
       shape.Fill(A, c);
       return true;
     }
     }
       return false;
 }
Beispiel #34
0
        public void Size1Square_3_3()
        {
            var stringMatrix = @"
0 0 0
0 1 0
0 0 0".Trim();
            var result       = GetResult(BoolMatrix.Parse(stringMatrix));

            Assert.AreEqual(1, result.Size);
            Assert.AreEqual(1, result.StartX);
            Assert.AreEqual(1, result.StartY);
        }
Beispiel #35
0
        public void Render(Image image, Drawable drawable, bool preview)
        {
            int size = GetValue<int>("size");

              image.UndoGroupStart();

              var procedure = new Procedure("plug_in_pixelize");
              procedure.Run(image, drawable, size);

              var palette = new MinisteckPalette();
              image.ConvertIndexed(ConvertDitherType.No, ConvertPaletteType.Custom,
               0, false, false, "Ministeck");
              palette.Delete();

              image.ConvertRgb();
              image.UndoGroupEnd();

              // And finally calculate the Ministeck pieces

              using (var painter = new Painter(drawable, size, GetValue<RGB>("color")))
            {
              Shape.Painter = painter;

              int width = drawable.Width / size;
              int height = drawable.Height / size;

              var A = new BoolMatrix(width, height);

              // Fill in shapes
              bool limit = GetValue<bool>("limit");
              var shapes = new ShapeSet();
              shapes.Add((limit) ? 2 : 1, new TwoByTwoShape());
              shapes.Add((limit) ? 8 : 1, new ThreeByOneShape());
              shapes.Add((limit) ? 3 : 1, new TwoByOneShape());
              shapes.Add((limit) ? 2 : 1, new CornerShape());
              shapes.Add((limit) ? 1 : 1, new OneByOneShape());

              Action<int> update = null;
              if (!preview)
            {
              var progress = new Progress(_("Ministeck..."));
              update = y => progress.Update((double) y / height);
            }

              var generator =
            new CoordinateGenerator(new Rectangle(0, 0, width, height), update);
              generator.ForEach(c => {if (!A.Get(c)) shapes.Fits(A, c);});
            }

              drawable.Flush();
              drawable.Update();
        }
        public override IOperation Apply()
        {
            BinaryVector   binaryVector = BinaryVectorParameter.ActualValue;
            OneBitflipMove move         = OneBitflipMoveParameter.ActualValue;
            BoolMatrix     interactions = GeneInteractionsParameter.ActualValue;
            DoubleArray    weights      = WeightsParameter.ActualValue;
            int            seed         = InteractionSeedParameter.ActualValue.Value;
            double         moveQuality  = QualityParameter.ActualValue.Value;
            int            q            = QParameter.ActualValue.Value;
            double         p            = PParameter.ActualValue.Value;

            List <int> affectedFitnessComponents = new List <int>();

            for (int c = 0; c < interactions.Columns; c++)
            {
                if (interactions[move.Index, c])
                {
                    affectedFitnessComponents.Add(c);
                }
            }
            BinaryVector moved = new BinaryVector(binaryVector);

            MovedBinaryVectorParameter.ActualValue = moved;
            moved[move.Index] = !moved[move.Index];
            if (affectedFitnessComponents.Count * 2 > interactions.Columns)
            {
                double[] f_i;
                moveQuality = NKLandscape.Evaluate(moved, interactions, weights, seed, out f_i, q, p);
            }
            else
            {
                long     x = NKLandscape.Encode(binaryVector);
                long     y = NKLandscape.Encode(moved);
                long[]   g = NKLandscape.Encode(interactions);
                double[] w = NKLandscape.Normalize(weights);
                foreach (var c in affectedFitnessComponents)
                {
                    moveQuality -= w[c % w.Length] * NKLandscape.F_i(x, c, g[c], seed, q, p);
                    moveQuality += w[c % w.Length] * NKLandscape.F_i(y, c, g[c], seed, q, p);
                }
            }

            if (MoveQualityParameter.ActualValue == null)
            {
                MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
            }
            else
            {
                MoveQualityParameter.ActualValue.Value = moveQuality;
            }
            return(base.Apply());
        }
Beispiel #37
0
 public static long[] Encode(BoolMatrix m)
 {
     long[] x = new long[m.Columns];
     for (int c = 0; c < m.Columns; c++)
     {
         x[c] = 0;
         for (int r = 0; r < 64 && r < m.Rows; r++)
         {
             x[c] |= (m[r, c] ? (long)1 : (long)0) << r;
         }
     }
     return(x);
 }
Beispiel #38
0
        private static void run()
        {
            bool[,] Matrix = ReadBoolMatrix();
            BoolMatrix boolMatrix = new BoolMatrix(Matrix);

            if (boolMatrix.SearchMaxRectangle(out int Row, out int Column, out int height, out int width))
            {
                WriteString("(" + Row + "," + Column + "," + height + "," + width + ")");
            }
            else
            {
                WriteString("прямоугольник не найден");
            }
        }
 public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) {
   BoolMatrix m = new BoolMatrix(length, nComponents);
   for (int c = 0; c < m.Columns; c++) {
     var indices = Enumerable.Range(0, length).ToList();
     if (indices.Count > c) {
       indices.RemoveAt(c);
       m[c, c] = true;
     }
     while (indices.Count > nInteractions) {
       indices.RemoveAt(random.Next(indices.Count));
     }
     foreach (var i in indices) {
       m[i, c] = true;
     }
   }
   return m;
 }
 public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) {
   BoolMatrix m = new BoolMatrix(length, nComponents);
   int maxBitDistance = MaximumDistance(length, nInteractions);
   var minBounds = new Bounds(0, length - nInteractions);
   var maxBounds = new Bounds(nInteractions, length - 1);
   for (int c = 0; c < m.Columns; c++) {
     int min = minBounds.Bounded(c - maxBitDistance);
     int max = maxBounds.Bounded(c + maxBitDistance);
     var indices = Enumerable.Range(min, max - min).ToList();
     indices.Remove(c);
     m[c, c] = true;
     while (indices.Count > nInteractions) {
       indices.RemoveAt(random.Next(indices.Count));
     }
     foreach (var i in indices) {
       m[i, c] = true;
     }
   }
   return m;
 }
 public BoolMatrix InitializeInterations(int length, int nComponents, int nInteractions, IRandom random) {
   BinaryVector[] components = Enumerable.Range(0, nComponents).Select(i => new BinaryVector(length)).ToArray();
   for (int c = 0; c < components.Length; c++) {
     var indices = Enumerable.Range(0, length).ToList();
     if (indices.Count > c) {
       indices.RemoveAt(c);
       components[c][c] = true;
     }
     while (indices.Count > nInteractions) {
       indices.RemoveAt(random.Next(indices.Count));
     }
     foreach (var i in indices) {
       components[c][i] = true;
     }
   }
   BoolMatrix m = new BoolMatrix(length, nComponents);
   foreach (var c in components.OrderBy(v => v, Comparer).Select((v, j) => new { v, j })) {
     for (int i = 0; i < c.v.Length; i++) {
       m[i, c.j] = c.v[i];
     }
   }
   return m;
 }
Beispiel #42
0
 public RaindropFactory(int dropSize, int fishEye, Dimensions dimensions)
 {
     _dropSize = dropSize;
       _newCoeff = Clamp(fishEye, 1, 100) * 0.01;
       BoolMatrix = new BoolMatrix(dimensions.Width, dimensions.Height);
 }
Beispiel #43
0
    public Problem()
      : base() {
      BoolMatrix world = new BoolMatrix(ToBoolMatrix(santaFeAntTrail));
      Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
      Parameters.Add(new ValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));

      base.BestKnownQuality = 89;
      var g = new SimpleSymbolicExpressionGrammar();
      g.AddSymbols(new string[] { "IfFoodAhead", "Prog2" }, 2, 2);
      g.AddSymbols(new string[] { "Prog3" }, 3, 3);
      g.AddTerminalSymbols(new string[] { "Move", "Left", "Right" });
      base.Encoding = new SymbolicExpressionTreeEncoding(g, 20, 10);
    }
Beispiel #44
0
 public BoolMatrix(BoolMatrix orig) : this(modshogunPINVOKE.new_BoolMatrix__SWIG_5(BoolMatrix.getCPtr(orig)), true) {
   if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve();
 }
Beispiel #45
0
 internal static HandleRef getCPtr(BoolMatrix obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Beispiel #46
0
 public virtual void copy_feature_matrix(BoolMatrix src) {
   modshogunPINVOKE.BoolFeatures_copy_feature_matrix(swigCPtr, BoolMatrix.getCPtr(src));
   if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve();
 }
Beispiel #47
0
 private AntTrail(AntTrail original, Cloner cloner)
   : base(original, cloner) {
   expression = cloner.Clone(original.expression);
   world = cloner.Clone(original.world);
   maxTimeSteps = cloner.Clone(original.maxTimeSteps);
   Initialize();
 }
Beispiel #48
0
 public static long[] Encode(BoolMatrix m) {
   long[] x = new long[m.Columns];
   for (int c = 0; c < m.Columns; c++) {
     x[c] = 0;
     for (int r = 0; r < 64 && r < m.Rows; r++) {
       x[c] |= (m[r, c] ? (long)1 : (long)0) << r;
     }
   }
   return x;
 }
Beispiel #49
0
 public BoolFeatures(BoolMatrix matrix) : this(modshogunPINVOKE.new_BoolFeatures__SWIG_3(BoolMatrix.getCPtr(matrix)), true) {
   if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve();
 }
Beispiel #50
0
 public static double Evaluate(BinaryVector vector, BoolMatrix interactions, DoubleArray weights, int seed, out double[] f_i, int q, double p) {
   long x = Encode(vector);
   long[] g = Encode(interactions);
   double[] w = Normalize(weights);
   f_i = new double[interactions.Columns];
   return F(x, g, w, (long)seed, ref f_i, q, p);
 }
 public BoolMatrix get_full_feature_matrix() {
   BoolMatrix ret = new BoolMatrix(modshogunPINVOKE.SparseBoolFeatures_get_full_feature_matrix(swigCPtr), true);
   if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public SparseBoolFeatures(BoolMatrix dense) : this(modshogunPINVOKE.new_SparseBoolFeatures__SWIG_5(BoolMatrix.getCPtr(dense)), true) {
   if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve();
 }
 public virtual bool set_full_feature_matrix(BoolMatrix full) {
   bool ret = modshogunPINVOKE.SparseBoolFeatures_set_full_feature_matrix(swigCPtr, BoolMatrix.getCPtr(full));
   if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Beispiel #54
0
		public ParticleEnsemble(int nparticles, double MinRad, double MaxRad, List<string> FFtype, int Height, int Width, double scaleFactor)
		{
			int i;
			maxNumberOfParticles = 1000;	// set the maximum number of particles to 1000

			kb = 8.314;									// value of the boltzmann constant - we dont really care about units now...
			BerendsenCoupling = 1.0;		// value of the berendsen coupling constant - set this to be controlled by the artist...
			Tequilibrium = 20000;
			BerendsenThermostat = true;
			//  BerendsenThermostat=false;
			EnsembleReinitializationFlag = false;
			NumberOfParticlesChangedFlag = false;
			NumberOfParticlesIsGreaterFlag = false;

			radiiScaleFactor = 1.0;
			InitialKE = 0.0;
			gradientScaleFactor = scaleFactor;

			step = 0;
			NumberOfParticles = nparticles;
			BoxHeight = Height;
			BoxWidth = Width;

			MaxForceThreshold = 1.0e6;
			initialMaxForceThreshold = MaxForceThreshold;

			AverageVelocityAutoCorrelationFunction = new List<double>(new double[1024]);

			InitialMinVel = 100.0;
			InitialMaxVel = 200.0;

			for (int ii = 0; ii < maxNumberOfParticles; ++ii)
			{
				initializeOneNewParticle();
			}

			if (!EliminateParticleOverlap(Height, Width))
			{
				// adjust particle positions to eliminate overlap 
				do
				{
					//cout << "Can't fit " << NumberOfParticles << " particles into the simulation box " << endl;
					NumberOfParticles -= 1;                       // if there's too many particles to fit in the simulation box
					//cout << "Decrementing the number of particles to " << NumberOfParticles << endl;
					EliminateParticleOverlap(Height, Width);				// decrement the particles till it's ok
				}
				while (!EliminateParticleOverlap(Height, Width));
			}

			//DPMatrix tmp1 = new DPMatrix(0.0, maxNumberOfParticles, maxNumberOfParticles);			// assign tmp1 matrix to distanceMatrix & distanceMatrixLastTime
			distanceMatrix = new DPMatrix(0.0, maxNumberOfParticles, maxNumberOfParticles);
			distanceMatrixLastTime = new DPMatrix(0.0, maxNumberOfParticles, maxNumberOfParticles);
			distanceMatrixLastLastTime = new DPMatrix(0.0, maxNumberOfParticles, maxNumberOfParticles);

			particlesWithinRange = new BoolMatrix(false, maxNumberOfParticles, maxNumberOfParticles); // update the particlesWithinRange matrix

			UpdateInterParticleSeparations();						// update the interparticle separation matrix

			PotentialEnergy = 0.0;

			//initialize forcefield Object
			//	cout << FFtype[0] << endl;
			//if(FFtype[0]=="HardSpheres"){ 
			//	pForceFieldVector.push_back(new HardSpheres(this));
			//}  
			//else{

			// push back forceField objects onto pForceFieldVector - at present, we only have LJ forces, but this can be
			// easily expanded
			for (i = 0; i < FFtype.Count; ++i)
			{
				if (FFtype[i] == "SoftSpheres") { pForceFieldVector.Add(new SoftSpheres(this)); }
				//		if(FFtype[i]=="ExternalField"){ pForceFieldVector.push_back(new ExternalField(this));}
			}
			//}

			// test of the matrix class implementation 
			/*
			Mat_DP AA(1.0,3,3), BB(2.0,3,3), CC(0.0,3,3);
	
			NR::matadd(AA, BB, CC); // matrix addition

			for(int i=0; i<3; ++i){ // print out
				for(int j=0; j<3; ++j){
					cout << CC[i][j] << endl;
				}
			}
			*/


		}
Beispiel #55
0
        void RenderDrop(BoolMatrix boolMatrix, PixelFetcher pf, 
		    Dimensions dimensions)
        {
            int x0 = -_radius;
              int y0 = -_radius;
              int x1 = _newSize - _radius;
              int y1 = _newSize - _radius;
              var rectangle = new Rectangle(x0, y0, x1, y1);

              foreach (var c in new CoordinateGenerator(rectangle))
            {
              double r = c.Radius;
              double a = c.Angle;

              if (r <= _radius)
            {
              double oldRadius = r;
              r = (Math.Exp (r / _s) - 1) / _newCoeff;

              int k = X + (int) (r * Math.Sin(a));
              int l = Y + (int) (r * Math.Cos(a));

              int m = X + c.X;
              int n = Y + c.Y;

              if (dimensions.IsInside(k, l) && dimensions.IsInside(m, n))
            {
              boolMatrix[n, m] = true;

              var newColor = pf[l, k] + GetBright(oldRadius, a);
              newColor.Clamp0255();
              pf[l, k] = newColor;
            }
            }
            }
        }
Beispiel #56
0
 public Solution(BoolMatrix world, ISymbolicExpressionTree expression, int maxTimeSteps, double quality) {
   this.World = world;
   this.SymbolicExpressionTree = expression;
   this.MaxTimeSteps = maxTimeSteps;
   this.Quality = quality;
 }
Beispiel #57
0
		public ParticleEnsemble(int nparticles, double MinRad, double MaxRad, List<string> FFtype, int Height, int Width, double scaleFactor)
		{
			int i;
			
			// set the maximum number of particles to 1000
			m_MaxNumberOfParticles = 1000;

			Particles = new ParticleCollection(this, m_MaxNumberOfParticles); 

			// value of the boltzmann constant - we dont really care about units now...
			kb = 8.314;									
			// value of the berendsen coupling constant - set this to be controlled by the artist...
			m_BerendsenThermostatCoupling = 1.0;		
			
			m_EquilibriumTemperature = 20000;
			BerendsenThermostat = true;

			//  BerendsenThermostat=false;
			EnsembleReinitializationFlag = false;
			NumberOfParticlesChangedFlag = false;
			NumberOfParticlesIsGreaterFlag = false;

			m_RadiiScaleFactor = 1.0;
			InitialKE = 0.0;
			m_GradientScaleFactor = scaleFactor;

			step = 0;
			//NumberOfParticles = nparticles;
			m_BoxHeight = Height;
			m_BoxWidth = Width;

			m_MaxForceThreshold = 1.0e6;
			m_InitialMaxForceThreshold = m_MaxForceThreshold;

            // allocate maximum space for and initialize the velocity autocorrelation & FFT vectors
            m_FFTenabled = true;
            m_FFTofCorrelationFunction = new List<double>(new double[MAX_CORR_FTN_SIZE]);
            m_VelocityAutoCorrelationFunction = new double[MAX_CORR_FTN_SIZE];
            for (int ii = 0; ii < MAX_CORR_FTN_SIZE; ++ii)
            {
                m_VelocityAutoCorrelationFunction[ii] = 0.0;
                m_FFTofCorrelationFunction[ii] = 0.0;
            }

            for (int ii = 0; ii < FFTmatrixForMovingAverage.Count(); ++ii)
            {
                FFTmatrixForMovingAverage[ii]= new List<double>(new double[m_NumberOfFFTAverages]);
                for(int kk=0; kk < m_NumberOfFFTAverages; ++kk){
                    FFTmatrixForMovingAverage[ii][kk] = 0.0;
                }

            }

			InitialMinVel = 100.0;
			InitialMaxVel = 200.0;

			for (int ii = 0; ii < m_MaxNumberOfParticles; ++ii)
			{
				InitializeOneNewParticle();
			}

			for (int ii = nparticles; ii < m_MaxNumberOfParticles; ++ii)
			{
				Particles.Pop();
			}

			if (!EliminateParticleOverlap(Height, Width))
			{
				// adjust particle positions to eliminate overlap 
				do
				{
					// if there's too many particles to fit in the simulation box
					//NumberOfParticles -= 1;
					Particles.Pop();

					// decrement the particles till it's ok
					EliminateParticleOverlap(Height, Width);				
				}
				while (!EliminateParticleOverlap(Height, Width));
			}
			
			// create matrix to distanceMatrix & distanceMatrixLastTime
			distanceMatrix = new DPMatrix(0.0, MaxNumberOfParticles, MaxNumberOfParticles);
			distanceMatrixLastTime = new DPMatrix(0.0, MaxNumberOfParticles, MaxNumberOfParticles);
			distanceMatrixLastLastTime = new DPMatrix(0.0, MaxNumberOfParticles, MaxNumberOfParticles);
 
			// update the particlesWithinRange matrix
			particlesWithinRange = new BoolMatrix(false, MaxNumberOfParticles, MaxNumberOfParticles); 

			// update the interparticle separation matrix
			UpdateInterParticleSeparations();						

			m_PotentialEnergy = 0.0;

			// push back forceField objects onto pForceFieldVector - at present, we only have LJ forces, but this can be
			// easily expanded
			for (i = 0; i < FFtype.Count; ++i)
			{
				if (FFtype[i] == "SoftSpheres") { ForceFields.Add(new SoftSpheres(this)); }
			}
		}
Beispiel #58
0
		public ParticleEnsemble(int nparticles, double MinRad, double MaxRad, List<string> FFtype, int Height, int Width, double scaleFactor)
		{
			int i;
			// set the maximum number of particles to 1000
			m_MaxNumberOfParticles = 1000;

			// value of the boltzmann constant - we dont really care about units now...
			m_KB = 8.314;
			// value of the berendsen coupling constant - set this to be controlled by the artist...	
			m_BerendsenCoupling = 1.0;		
			m_Tequilibrium = 20000;
			m_BerendsenThermostat = true;
			//  BerendsenThermostat=false;
			m_EnsembleReinitializationFlag = false;
			m_NumberOfParticlesChangedFlag = false;
			m_NumberOfParticlesIsGreaterFlag = false;

			m_RadiiScaleFactor = 1.0;
			m_InitialKE = 0.0;
			m_GradientScaleFactor = scaleFactor;

			m_Step = 0;
			m_NumberOfParticles = nparticles;
			m_BoxHeight = Height;
			m_BoxWidth = Width;

			m_MaxForceThreshold = 1.0e6;
			m_InitialMaxForceThreshold = m_MaxForceThreshold;

			m_AverageVelocityAutoCorrelationFunction = new List<double>(new double[1024]);

			m_InitialMinVel = 100.0;
			m_InitialMaxVel = 200.0;

			for (int ii = 0; ii < m_MaxNumberOfParticles; ++ii)
			{
				InitializeOneNewParticle();
			}

			if (!EliminateParticleOverlap(Height, Width))
			{
				// adjust particle positions to eliminate overlap 
				do
				{
					//cout << "Can't fit " << NumberOfParticles << " particles into the simulation box " << endl;
					
					// if there's too many particles to fit in the simulation box
					m_NumberOfParticles -= 1;                       
					
					//cout << "Decrementing the number of particles to " << NumberOfParticles << endl;
					
					// decrement the particles till it's ok
					EliminateParticleOverlap(Height, Width);				
				}
				while (!EliminateParticleOverlap(Height, Width));
			}
			
			// assign tmp1 matrix to distanceMatrix & distanceMatrixLastTime
			m_DistanceMatrix = new DPMatrix(0.0, m_MaxNumberOfParticles, m_MaxNumberOfParticles);
			m_DistanceMatrixLastTime = new DPMatrix(0.0, m_MaxNumberOfParticles, m_MaxNumberOfParticles);
			m_DistanceMatrixLastLastTime = new DPMatrix(0.0, m_MaxNumberOfParticles, m_MaxNumberOfParticles);

			// update the particlesWithinRange matrix
			m_ParticlesWithinRange = new BoolMatrix(false, m_MaxNumberOfParticles, m_MaxNumberOfParticles); 

			// update the interparticle separation matrix
			UpdateInterParticleSeparations();						

			m_PotentialEnergy = 0.0;

			// push back forceField objects onto pForceFieldVector - at present, we only have LJ forces, but this can be easily expanded
			for (i = 0; i < FFtype.Count; ++i)
			{
				if (FFtype[i] == "SoftSpheres") 
				{ 
					m_ForceFields.Add(new SoftSpheres(this)); 
				}
			}
		}
Beispiel #59
0
 public void set_feature_matrix(BoolMatrix matrix) {
   modshogunPINVOKE.BoolFeatures_set_feature_matrix(swigCPtr, BoolMatrix.getCPtr(matrix));
   if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve();
 }