コード例 #1
0
        public virtual void CreateTargets(int noObjects, PointF center)
        {
            SizeF centerSz = new SizeF(center); // Is Size because there is no overload for +(Point,Point)........

            // Pick random unique shapes from the available pool
            Resize(ref m_shapeIdcs, noObjects);
            int shapeCount = Enum.GetValues(typeof(Shape.Shapes)).Length; // noObjects must be at most shapeCount

            MyCombinationBase.GenerateCombinationUnique(new ArraySegment <float>(m_shapeIdcs), m_candidates, 0, shapeCount, m_rndGen);

            // Setup initial shape's positional parameters
            float step  = (float)(2 * Math.PI / noObjects); // rads
            float angle = TSHints[TSHintAttributes.IS_VARIABLE_POSITION] > 0
                ? (float)(m_rndGen.NextDouble() * step) : 0;
            float distance = Math.Min(WrappedWorld.Viewport.Width, WrappedWorld.Viewport.Height) / 3f;

            Resize(ref m_targets, noObjects);

            for (int i = 0; i < m_targets.Length; i++)
            {
                // Determine shape position
                if (TSHints[IS_VARIABLE_DISTANCE] > 0)
                {
                    distance *= 1 + 0.04f * LearningTaskHelpers.GetRandomGaussian(m_rndGen) * TSHints[RANDOMNESS_LEVEL];
                }

                PointF pos = new PointF((float)(Math.Cos(angle) * distance), (float)(Math.Sin(angle) * distance));

                // Determine shape size
                float scale = 1.4f;

                if (TSHints[TSHintAttributes.IS_VARIABLE_SIZE] > 0)
                {
                    scale = scale + 0.2f * LearningTaskHelpers.GetRandomGaussian(m_rndGen) * TSHints[RANDOMNESS_LEVEL];
                }

                SizeF size = new SizeF(16 * scale, 16 * scale);

                // Determine shape rotation
                float rotation = 0;

                if (TSHints[TSHintAttributes.IS_VARIABLE_ROTATION] > 0)
                {
                    rotation = (float)(m_rndGen.NextDouble() * 360);
                }

                // Determine shape color
                Color color = Color.White;

                if (TSHints[TSHintAttributes.IS_VARIABLE_COLOR] > 0)
                {
                    color = LearningTaskHelpers.RandomVisibleColor(m_rndGen);
                }

                // Create the correct shape
                m_targets[i] = WrappedWorld.CreateShape((Shape.Shapes)m_shapeIdcs[i], color, pos + centerSz, size, rotation);

                angle += step;
            }
        }
コード例 #2
0
        public override void Execute()
        {
            if ((!Owner.RandomPeriod && (SimulationStep % Owner.Period == 0)) || (Owner.RandomPeriod && (SimulationStep == Owner.NextPeriodChange)))
            {
                if (!Owner.Output.OnHost)
                {
                    Owner.Output.SafeCopyToHost();
                }

                if (Unique)
                {
                    MyCombinationBase.GenerateCombinationUnique(new ArraySegment <float>(Owner.Output.Host), combHS, Min, Max, Owner.m_rnd);
                }
                else
                {
                    MyCombinationBase.GenerateCombination(new ArraySegment <float>(Owner.Output.Host), Min, Max, Owner.m_rnd);
                }

                Owner.Output.SafeCopyToDevice();

                Owner.SetSingle();
            }

            Owner.UpdatePeriod(this);
        }
コード例 #3
0
        public override void Execute()
        {
            if ((!RandomPeriod && (SimulationStep % Period == 0)) || (RandomPeriod && (SimulationStep == m_nextPeriodChange)))
            {
                switch (Distribution)
                {
                case RandomDistribution.Constant:
                    m_kernel.SetupExecution(Owner.Output.Count);
                    m_kernel.Run(Owner.Output, Constant, Owner.Output.Count);
                    break;

                case RandomDistribution.Uniform:
                    MyKernelFactory.Instance.GetRandDevice(Owner).GenerateUniform(Owner.Output.GetDevice(Owner));
                    break;

                case RandomDistribution.Normal:
                    //Normal RNG uses Box-Muller transformation, so it can generate only even number of values
                    if (Owner.Output.Count % 2 == 0)
                    {
                        MyKernelFactory.Instance.GetRandDevice(Owner).GenerateNormal(Owner.Output.GetDevice(Owner), Mean, StdDev);
                    }
                    else
                    {
                        MyKernelFactory.Instance.GetRandDevice(Owner).GenerateNormal(Owner.RandomNumbers.GetDevice(Owner), Mean, StdDev);
                        Owner.RandomNumbers.CopyToMemoryBlock(Owner.Output, 0, 0, Owner.Output.Count);
                    }

                    break;

                case RandomDistribution.Combination:
                    if (!Owner.Output.OnHost)
                    {
                        Owner.Output.SafeCopyToHost();
                    }

                    if (Unique)
                    {
                        MyCombinationBase.GenerateCombinationUnique(new ArraySegment <float>(Owner.Output.Host), combHS, Min, Max, m_rnd);
                    }
                    else
                    {
                        MyCombinationBase.GenerateCombination(new ArraySegment <float>(Owner.Output.Host), Min, Max, m_rnd);
                    }

                    Owner.Output.SafeCopyToDevice();
                    break;
                }

                if (Distribution == RandomDistribution.Uniform)
                {
                    //scale from 0-1 to min-max
                    m_polynomialKernel.SetupExecution(Owner.Output.Count);
                    m_polynomialKernel.Run(0, 0, (MaxValue - MinValue), MinValue,
                                           Owner.Output,
                                           Owner.Output,
                                           Owner.Output.Count
                                           );
                }

                if (Owner.SingleOutput == true)
                {
                    //delete all values except one
                    int keep = m_rnd.Next(Owner.Output.Count);
                    m_setKernel.SetupExecution(Owner.Output.Count);
                    m_setKernel.Run(Owner.Output, 0, keep, Owner.Output.Count);
                }
            }
            if (RandomPeriod && (SimulationStep == m_nextPeriodChange))
            {
                //+1 for inclusive interval
                Period              = m_rnd.Next(RandomPeriodMin, RandomPeriodMax + 1);
                m_nextPeriodChange += Period;
            }
        }