当前位置: 首页>>代码示例>>C#>>正文


C# ContinuousUniform.Sample方法代码示例

本文整理汇总了C#中MathNet.Numerics.Distributions.ContinuousUniform.Sample方法的典型用法代码示例。如果您正苦于以下问题:C# ContinuousUniform.Sample方法的具体用法?C# ContinuousUniform.Sample怎么用?C# ContinuousUniform.Sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MathNet.Numerics.Distributions.ContinuousUniform的用法示例。


在下文中一共展示了ContinuousUniform.Sample方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Build

        /// <summary>
        /// Build linear samples.
        /// </summary>
        /// <param name="x">X sample values.</param>
        /// <param name="y">Y samples values.</param>
        /// <param name="xtest">X test values.</param>
        /// <param name="ytest">Y test values.</param>
        /// <param name="samples">Sample values.</param>
        /// <param name="sampleOffset">Sample offset.</param>
        /// <param name="slope">Slope number.</param>
        /// <param name="intercept">Intercept criteria.</param>
        public static void Build(out double[] x, out double[] y, out double[] xtest, out double[] ytest, int samples = 3, double sampleOffset = -0.5, double slope = 2.0, double intercept = -1.0)
        {
            // Fixed-seed "random" distribution to ensure we always test with the same data
            var uniform = new ContinuousUniform(0.0, 1.0, new SystemRandomSource(42));

            // build linear samples
            x = new double[samples];
            y = new double[samples];
            for (int i = 0; i < x.Length; i++)
            {
                x[i] = i + sampleOffset;
                y[i] = (x[i]*slope) + intercept;
            }

            // build linear test vectors randomly between the sample points
            xtest = new double[samples + 1];
            ytest = new double[samples + 1];
            if (samples == 1)
            {
                // y = const
                xtest[0] = sampleOffset - uniform.Sample();
                xtest[1] = sampleOffset + uniform.Sample();
                ytest[0] = ytest[1] = (sampleOffset*slope) + intercept;
            }
            else
            {
                for (int i = 0; i < xtest.Length; i++)
                {
                    xtest[i] = (i - 1) + sampleOffset + uniform.Sample();
                    ytest[i] = (xtest[i]*slope) + intercept;
                }
            }
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:44,代码来源:LinearInterpolationCase.cs

示例2: ZergCharacter

        static ZergCharacter()
        {
            GOAL_PRIORITIES = new Dictionary<State, byte>(){
                {State.AttackGoal, 16},
                {State.FeedGoal, 8},
                {State.RetreatGoal, 1},
                {State.ServeGoal, 2}
            };

            var goals = new Stack<State>();

            var goalEnums = (State[])Enum.GetValues(typeof(State));
            foreach (var enumValue in goalEnums)
            {
                for (int i = 0; i < GOAL_PRIORITIES[enumValue]; i++)
                {
                    goals.Push(enumValue);
                }
            }

            int count = goals.Count;
            RND = new DiscreteUniform(0, count - 1);
            GOALS_LOOKUP_TABLE = new State[count];

            var rnd = new ContinuousUniform(0.0, 1.0);

            while (goals.Any())
            {
                int idx = (int)Math.Round(rnd.Sample() * (--count), 0);
                GOALS_LOOKUP_TABLE[idx] = goals.Pop();
            }
        }
开发者ID:homoluden,项目名称:GenAI,代码行数:32,代码来源:ZergCharacter.cs

示例3: CanSample

 public void CanSample()
 {
     var n = new ContinuousUniform();
     n.Sample();
 }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:5,代码来源:ContinuousUniformTests.cs

示例4: Run

        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29">ContinuousUniform distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the ContinuousUniform distribution class with default parameters.
            var continuousUniform = new ContinuousUniform();
            Console.WriteLine(@"1. Initialize the new instance of the ContinuousUniform distribution class with parameters Lower = {0}, Upper = {1}", continuousUniform.Lower, continuousUniform.Upper);
            Console.WriteLine();

            // 2. Distributuion properties:
            Console.WriteLine(@"2. {0} distributuion properties:", continuousUniform);

            // Cumulative distribution function
            Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", continuousUniform.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000"));

            // Probability density
            Console.WriteLine(@"{0} - Probability density at location '0.3'", continuousUniform.Density(0.3).ToString(" #0.00000;-#0.00000"));

            // Log probability density
            Console.WriteLine(@"{0} - Log probability density at location '0.3'", continuousUniform.DensityLn(0.3).ToString(" #0.00000;-#0.00000"));

            // Entropy
            Console.WriteLine(@"{0} - Entropy", continuousUniform.Entropy.ToString(" #0.00000;-#0.00000"));

            // Largest element in the domain
            Console.WriteLine(@"{0} - Largest element in the domain", continuousUniform.Maximum.ToString(" #0.00000;-#0.00000"));

            // Smallest element in the domain
            Console.WriteLine(@"{0} - Smallest element in the domain", continuousUniform.Minimum.ToString(" #0.00000;-#0.00000"));

            // Mean
            Console.WriteLine(@"{0} - Mean", continuousUniform.Mean.ToString(" #0.00000;-#0.00000"));

            // Median
            Console.WriteLine(@"{0} - Median", continuousUniform.Median.ToString(" #0.00000;-#0.00000"));

            // Mode
            Console.WriteLine(@"{0} - Mode", continuousUniform.Mode.ToString(" #0.00000;-#0.00000"));

            // Variance
            Console.WriteLine(@"{0} - Variance", continuousUniform.Variance.ToString(" #0.00000;-#0.00000"));

            // Standard deviation
            Console.WriteLine(@"{0} - Standard deviation", continuousUniform.StdDev.ToString(" #0.00000;-#0.00000"));

            // Skewness
            Console.WriteLine(@"{0} - Skewness", continuousUniform.Skewness.ToString(" #0.00000;-#0.00000"));
            Console.WriteLine();

            // 3. Generate 10 samples of the ContinuousUniform distribution
            Console.WriteLine(@"3. Generate 10 samples of the ContinuousUniform distribution");
            for (var i = 0; i < 10; i++)
            {
                Console.Write(continuousUniform.Sample().ToString("N05") + @" ");
            }

            Console.WriteLine();
            Console.WriteLine();

            // 4. Generate 100000 samples of the ContinuousUniform(0, 1) distribution and display histogram
            Console.WriteLine(@"4. Generate 100000 samples of the ContinuousUniform(0, 1) distribution and display histogram");
            var data = new double[100000];
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = continuousUniform.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 5. Generate 100000 samples of the ContinuousUniform(2, 10) distribution and display histogram
            Console.WriteLine(@"5. Generate 100000 samples of the ContinuousUniform(2, 10) distribution and display histogram");
            continuousUniform.Upper = 10;
            continuousUniform.Lower = 2;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = continuousUniform.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
        }
开发者ID:Mistrall,项目名称:Solvation,代码行数:83,代码来源:ContinuousUniformDistribution.cs

示例5: Cudnn_UseCase_ForwardConvolution_Float

        public void Cudnn_UseCase_ForwardConvolution_Float()
        {
            CudnnContext.DefaultType = CudnnType.Float;
            CudnnContext.DefaultTensorFormat = CudnnTensorFormat.MajorRow;

            using (var context = CudnnContext.Create())
            {
                // Set some options and tensor dimensions
                int nInput = 100;
                int filtersIn = 10;
                int filtersOut = 8;
                int heightIn = 20;
                int widthIn = 20;
                int heightFilter = 5;
                int widthFilter = 5;
                int paddingHeight = 4;
                int paddingWeight = 4;
                int verticalStride = 1;
                int horizontalStride = 1;
                int upscalex = 1;
                int upscaley = 1;

                var distribution = new ContinuousUniform(0, 1);

                // Input Tensor Data
                Vector<float> xDataVector = Vector<float>.Build.Dense(nInput * filtersIn * heightIn * widthIn);
                xDataVector.MapInplace(x => (float)distribution.Sample(), Zeros.Include);

                // Filter Tensor Data
                Vector<float> filterData = Vector<float>.Build.Dense(filtersOut * filtersIn * heightFilter * widthFilter);
                filterData.MapInplace(x => (float)distribution.Sample(), Zeros.Include);

                // Descriptor for input
                var xTensor = CudnnContext.CreateTensor(new CudnnTensorDescriptorParameters(nInput, filtersIn, heightFilter, widthFilter));

                // Filter descriptor
                var filter = CudnnContext.CreateFilter(new CudnnFilterDescriptorParameters(filtersOut, filtersIn, heightFilter, widthFilter));

                // Convolution descriptor
                var convolution = CudnnContext.CreateConvolution(new CudnnConvolutionDescriptorParameters(CudnnConvolutionMode.CrossCorrelation, xTensor, filter, paddingHeight, paddingWeight, verticalStride, horizontalStride, upscalex, upscaley));
                var output = convolution.GetOutputTensor(CudnnConvolutionPath.Forward);

                // Output tensor
                var yTensor = CudnnContext.CreateTensor(new CudnnTensorDescriptorParameters(nInput, filtersOut, output.Height, output.Width));
                float[] yData = new float[nInput * filtersOut * output.Height * output.Width];

                // Perform convolution
                context.Forward(xTensor, xDataVector.ToArray(), filter, filterData.ToArray(), convolution, yTensor, yData, CudnnAccumulateResult.DoNotAccumulate);

                // Clean up
                xTensor.Dispose();
                yTensor.Dispose();
                filter.Dispose();
                convolution.Dispose();
            }
        }
开发者ID:redknightlois,项目名称:cudalearn,代码行数:56,代码来源:CudnnUseCase.cs


注:本文中的MathNet.Numerics.Distributions.ContinuousUniform.Sample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。