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


C# Discrete类代码示例

本文整理汇总了C#中Discrete的典型用法代码示例。如果您正苦于以下问题:C# Discrete类的具体用法?C# Discrete怎么用?C# Discrete使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: run

        public override Statistics run()
        {
            Environment env = new Environment();

            //dist
            List<double> valueList = new List<double>() { 1, 2, 3, 4, 5 };
            List<double> distribution = new List<double>() { 0.5, 0.6, 0.7, 0.8, 1.0 };
            Discrete d = new Discrete(valueList, distribution);
            //dist1
            Uniform n = new Uniform(1, 3);
            Distribution dist = new Distribution(d);
            Distribution dist1 = new Distribution(n);

            Create c = new Create(env, 0, 20, dist);

            Dispose di = new Dispose(env, 1);

            Queue q = new Queue(env, 3);
            q.Capacity = 1;
            Resource r = new Resource(env, 2, 1, dist1, q);

            c.Next_AID.Add("First", 2);
            r.Next_AID.Add("First", 1);

            env.System_Time = new DateTime(1970, 1, 1, 0, 0, 0);
            env.Start_Time = new DateTime(1970, 1, 1, 0, 0, 0);
            env.Setup_Simulation();
            return env.Simulate();
        }
开发者ID:aidint,项目名称:SimExpert,代码行数:29,代码来源:SimpleSimulation.cs

示例2: SelectorAverageConditional

		/// <summary>
		/// EP message to 'selector'.
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'.</param>
		/// <param name="probs">Constant value for 'probs'.</param>
		/// <param name="result">Modified to contain the outgoing message.</param>
		/// <returns><paramref name="result"/></returns>
		/// <remarks><para>
		/// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'selector'.
		/// The formula is <c>int f(selector,x) q(x) dx</c> where <c>x = (sample,probs)</c>.
		/// </para></remarks>
		public static Discrete SelectorAverageConditional(Discrete sample, Matrix probs, Discrete result)
		{
			Vector v = result.GetWorkspace();
			v.SetToProduct(probs, sample.GetProbs());
			result.SetProbs(v);
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:18,代码来源:DiscreteFromDiscrete.cs

示例3: LogEvidenceRatio

		/// <summary>
		/// Evidence message for EP.
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'.</param>
		/// <param name="selector">Incoming message from 'selector'.</param>
		/// <param name="probs">Constant value for 'probs'.</param>
		//[Skip]
		//public static double LogEvidenceRatio(Discrete sample, Discrete selector, Matrix probs) { return 0.0; }
		public static double LogEvidenceRatio(Discrete sample, Discrete selector, Matrix probs)
		{
			// use this if the rows are not normalized
			Discrete toSample = SampleAverageConditional(selector, probs, Discrete.Uniform(sample.Dimension, sample.Sparsity));
			return LogAverageFactor(sample, selector, probs)
				-toSample.GetLogAverageOf(sample);
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:15,代码来源:DiscreteFromDiscrete.cs

示例4: SampleAverageConditional

		/// <summary>
		/// EP message to 'sample'.
		/// </summary>
		/// <param name="selector">Incoming message from 'selector'.</param>
		/// <param name="probs">Constant value for 'probs'.</param>
		/// <param name="result">Modified to contain the outgoing message.</param>
		/// <returns><paramref name="result"/></returns>
		/// <remarks><para>
		/// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'sample'.
		/// The formula is <c>int f(sample,x) q(x) dx</c> where <c>x = (selector,probs)</c>.
		/// </para></remarks>
		public static Discrete SampleAverageConditional(Discrete selector, Matrix probs, Discrete result)
		{
			Vector v = result.GetWorkspace();
			v.SetToProduct(selector.GetProbs(), probs);
			result.SetProbs(v);
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:18,代码来源:DiscreteFromDiscrete.cs

示例5: Infer

        public InferenceResult<Cluster[]> Infer(Vector[] observedData, int clusters)
        {
            var dimensions = observedData.First().Count;
            var evidence = Variable.Bernoulli(0.5).Named("evidence");
            var evidenceBlock = Variable.If(evidence);
            var clustersRange = new Range(clusters).Named("clustersRange");
            var meansPrior = Variable.Array<Vector>(clustersRange).Named("meansPrior");
            meansPrior[clustersRange] = Variable
                .VectorGaussianFromMeanAndPrecision(
                    Vector.Zero(dimensions),
                    PositiveDefiniteMatrix.IdentityScaledBy(dimensions, 0.01))
                .ForEach(clustersRange);

            var precisionsPrior = Variable.Array<PositiveDefiniteMatrix>(clustersRange).Named("precisionsPrior");
            precisionsPrior[clustersRange] = Variable.WishartFromShapeAndRate(100, PositiveDefiniteMatrix.IdentityScaledBy(dimensions, 0.01))
                .ForEach(clustersRange);

            var initialWeights = Enumerable.Range(0, clusters).Select(_ => 1.0).ToArray();
            var mixtureWeightsPrior = Variable.Dirichlet(clustersRange, initialWeights).Named("mixtureWeightsPrior");

            var dataRange = new Range(observedData.Length).Named("dataRange");
            var data = Variable.Array<Vector>(dataRange).Named("data");

            var latentIndex = Variable.Array<int>(dataRange).Named("latentIndex");

            using (Variable.ForEach(dataRange))
            {
                latentIndex[dataRange] = Variable.Discrete(mixtureWeightsPrior);
                using (Variable.Switch(latentIndex[dataRange]))
                {
                    data[dataRange] = Variable.VectorGaussianFromMeanAndPrecision(meansPrior[latentIndex[dataRange]], precisionsPrior[latentIndex[dataRange]]);
                }
            }

            var zinit = new Discrete[dataRange.SizeAsInt];
            for (int i = 0; i < zinit.Length; i++)
                zinit[i] = Discrete.PointMass(Rand.Int(clustersRange.SizeAsInt), clustersRange.SizeAsInt);
            latentIndex.InitialiseTo(Distribution<int>.Array(zinit));

            evidenceBlock.CloseBlock();

            data.ObservedValue = observedData;

            var ie = new InferenceEngine(new VariationalMessagePassing());
            ie.ShowProgress = false;

            var mixtureWeightsPosterior = ie.Infer(mixtureWeightsPrior);
            var meansPosterior = ie.Infer<VectorGaussian[]>(meansPrior);
            var precisionsPosterior = ie.Infer<Wishart[]>(precisionsPrior);
            var bEvidence = ie.Infer<Bernoulli>(evidence);

            var result = new List<Cluster>();
            for (var i = 0; i < clusters; i++)
            {
                result.Add(new Cluster(meansPosterior[i].GetMean(), precisionsPosterior[i].GetMean().Inverse()));
            }

            return new InferenceResult<Cluster[]>(bEvidence, result.ToArray());
        }
开发者ID:adamgoral,项目名称:infernethol,代码行数:59,代码来源:MultinomialMixtureModel.cs

示例6: LogAverageFactor

		/// <summary>
		/// Evidence message for EP
		/// </summary>
		/// <param name="sample">Constant value for 'sample'.</param>
		/// <param name="size">Incoming message from 'size'.</param>
		/// <returns>Logarithm of the factor's average value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>log(sum_(size) p(size) factor(sample,size))</c>.
		/// </para></remarks>
		public static double LogAverageFactor(int sample, Discrete size)
		{
			double z = 0.0;
			for (int i = sample+1; i < size.Dimension; i++)
			{
				z += size[i]/i;
			}
			return Math.Log(z);
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:18,代码来源:DiscreteUniform.cs

示例7: LogAverageFactor

		/// <summary>
		/// Evidence message for EP
		/// </summary>
		/// <param name="sample">Constant value for 'sample'.</param>
		/// <param name="p">Incoming message from 'p'.</param>
		/// <param name="trialCount">Incoming message from 'trialCount'.</param>
		/// <returns>Logarithm of the factor's average value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>log(sum_(p,trialCount) p(p,trialCount) factor(sample,trialCount,p))</c>.
		/// </para></remarks>
		public static double LogAverageFactor(int sample, Beta p, Discrete trialCount)
		{
			double logZ = Double.NegativeInfinity;
			for (int n = 0; n < trialCount.Dimension; n++)
			{
				logZ = MMath.LogSumExp(logZ, trialCount.GetLogProb(n) + LogAverageFactor(sample, p, n));
			}
			return logZ;
		}
开发者ID:dtrckd,项目名称:Mixed-Membership-Stochastic-Blockmodel,代码行数:19,代码来源:BinomialOp.cs

示例8: Reset

 /// <summary>
 /// Configures constant values that will not change during the lifetime of the class.
 /// </summary>
 /// <remarks>
 /// This method should be called once only after the class is instantiated.  In future, it will likely become
 /// the class constructor.
 /// </remarks>
 public void Reset()
 {
     // Create array for 'vint0_uses' backwards messages.
     this.vint0_uses_B = new Discrete[0];
     this.vint0_F = ArrayHelper.MakeUniform<Discrete>(new Discrete(0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647, 0.0588235294117647));
     this.vDiscrete0 = new Discrete(0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
     // Message to 'vint0' from Random factor
     this.vint0_F = UnaryOp<int>.RandomAverageConditional<Discrete>(this.vDiscrete0);
 }
开发者ID:smokelore,项目名称:HeraAndZeus,代码行数:16,代码来源:Model0_EP.cs

示例9: LogAverageFactor

		/// <summary>
		/// Evidence message for EP.
		/// </summary>
		/// <param name="sample">Constant value for 'sample'.</param>
		/// <param name="index">Incoming message from 'index'.</param>
		/// <param name="probTrue">Constant value for 'probTrue'.</param>
		/// <returns><c>log(int f(x) qnotf(x) dx)</c></returns>
		/// <remarks><para>
		/// The formula for the result is <c>log(int f(x) qnotf(x) dx)</c>
		/// where <c>x = (sample,index,probTrue)</c>.
		/// </para></remarks>
		public static double LogAverageFactor(bool sample, Discrete index, double[] probTrue)
		{
			double p = 0;
			for (int i = 0; i < index.Dimension; i++)
			{
				p += probTrue[i] * index[i];
			}
			if (!sample) p = 1-p;
			return Math.Log(p);
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:21,代码来源:BernoulliFromDiscrete.cs

示例10: LogAverageFactor

		/// <summary>
		/// Evidence message for EP
		/// </summary>
		/// <param name="sum">Constant value for 'Sum'.</param>
		/// <param name="a">Incoming message from 'A'.</param>
		/// <param name="b">Incoming message from 'B'.</param>
		/// <returns>Logarithm of the factor's average value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>log(sum_(A,B) p(A,B) factor(Sum,A,B))</c>.
		/// </para></remarks>
		public static double LogAverageFactor(int sum, Discrete a, Discrete b)
		{
			if (a.IsPointMass) return LogAverageFactor(sum, a.Point, b);
			double z = 0.0;
			for (int i = 0; (i < a.Dimension) && (sum-i < b.Dimension); i++)
			{
				z += a[i] * b[sum-i];
			}
			return Math.Log(z);
		}
开发者ID:dtrckd,项目名称:Mixed-Membership-Stochastic-Blockmodel,代码行数:20,代码来源:PlusInt.cs

示例11: Run

		public void Run()
		{
			// Define a range for the number of mixture components
			Range k = new Range(2).Named("k");

			// Mixture component means
			VariableArray<Vector> means = Variable.Array<Vector>(k).Named("means");			
			means[k] = Variable.VectorGaussianFromMeanAndPrecision(
				Vector.FromArray(0.0,0.0),
				PositiveDefiniteMatrix.IdentityScaledBy(2,0.01)).ForEach(k);
	
			// Mixture component precisions
			VariableArray<PositiveDefiniteMatrix> precs = Variable.Array<PositiveDefiniteMatrix>(k).Named("precs");
			precs[k] = Variable.WishartFromShapeAndScale(100.0, PositiveDefiniteMatrix.IdentityScaledBy(2,0.01)).ForEach(k);
			
			// Mixture weights 
			Variable<Vector> weights = Variable.Dirichlet(k, new double[] { 1, 1 }).Named("weights");	

			// Create a variable array which will hold the data
			Range n = new Range(300).Named("n");
			VariableArray<Vector> data = Variable.Array<Vector>(n).Named("x");
			// Create latent indicator variable for each data point
			VariableArray<int> z = Variable.Array<int>(n).Named("z");

			// The mixture of Gaussians model
			using (Variable.ForEach(n)) {
				z[n] = Variable.Discrete(weights);
				using (Variable.Switch(z[n])) {
					data[n] = Variable.VectorGaussianFromMeanAndPrecision(means[z[n]], precs[z[n]]);
				}
			}

			// Attach some generated data
			data.ObservedValue = GenerateData(n.SizeAsInt);

			// Initialise messages randomly so as to break symmetry
			Discrete[] zinit = new Discrete[n.SizeAsInt];		
			for (int i = 0; i < zinit.Length; i++) 
			  zinit[i] = Discrete.PointMass(Rand.Int(k.SizeAsInt), k.SizeAsInt);
			z.InitialiseTo(Distribution<int>.Array(zinit)); 

			// The inference
			InferenceEngine ie = new InferenceEngine();
			if (!(ie.Algorithm is ExpectationPropagation))
			{
				Console.WriteLine("Dist over pi=" + ie.Infer(weights));
				Console.WriteLine("Dist over means=\n" + ie.Infer(means));
				Console.WriteLine("Dist over precs=\n" + ie.Infer(precs));
			}
			else
				Console.WriteLine("This example is not supported by Expectation Propagation");
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:52,代码来源:MixtureOfGaussians.cs

示例12: run

        public double run()
        {
            Environment env = new Environment();

            //dist for Create
            Constant Const = new Constant(1);
            Distribution CreateDist = new Distribution(Const);
            //distributions for Inventory
            List<double> States = new List<double>() { 1, 2, 3 }; //1 for good, 2 for fair, 3 for poor
            List<double> States_Prob = new List<double>() { 0.35, 0.80, 1.00 };
            Discrete StatesDisc = new Discrete(States, States_Prob);

            List<double> State1 = new List<double>() { 40, 50, 60, 70, 80, 90, 100 };
            List<double> State1_Prob = new List<double>() { 0.03, 0.08, 0.23, 0.43, 0.78, 0.93, 1.00 };
            Discrete State1Disc = new Discrete(State1, State1_Prob);

            List<double> State2 = new List<double>() { 40, 50, 60, 70, 80, 90, 100 };
            List<double> State2_Prob = new List<double>() { 0.10, 0.28, 0.68, 0.88, 0.96, 1.00, 1.00 };
            Discrete State2Disc = new Discrete(State2, State2_Prob);

            List<double> State3 = new List<double>() { 40, 50, 60, 70, 80, 90, 100 };
            List<double> State3_Prob = new List<double>() { 0.44, 0.66, 0.82, 0.94, 1.00, 1.00, 1.00 };
            Discrete State3Disc = new Discrete(State3, State3_Prob);

            Dictionary<double, Discrete> Demand = new Dictionary<double, Discrete>();
            Demand.Add(1, State1Disc);
            Demand.Add(2, State2Disc);
            Demand.Add(3, State3Disc);

            List<Int64> Amount = new List<Int64>();
            for (int i = 0; i < 20; i++) Amount.Add(70);

            Create create = new Create(env, 0, 20, CreateDist, Amount);

            Dispose dispose = new Dispose(env, 2);

            Inventory inv = new Inventory(env, 1, new TimeSpan(1), 70, StatesDisc, Demand, 0.33, 0.50, true, 0.05);

            create.Next_AID.Add("First", 1);
            inv.Next_AID.Add("First", 2);

            env.System_Time = new DateTime(1970, 1, 1, 0, 0, 0);
            env.Start_Time = new DateTime(1970, 1, 1, 0, 0, 0);

            env.Setup_Simulation();
            env.Simulate();

            double sumOfProfit = 0;
            for (int i = 1; i <= 20; i++)
                sumOfProfit += (double)inv.Statistics.OtherStatistics[i][5].StatisticValue;
            return sumOfProfit;
        }
开发者ID:aidint,项目名称:SimExpert,代码行数:52,代码来源:InventorySample.cs

示例13: run

        public void run()
        {
            Environment env = new Environment();

            //
            List<double> valueList = new List<double>() { 1, 2, 3, 4, 5 };
            List<double> distribution = new List<double>() { 0.5, 0.6, 0.7, 0.8, 1.0 };
            Discrete discrete = new Discrete(valueList, distribution, 0);
            //
            Uniform uniform = new Uniform(1, 3, 0);
            Distribution CreateDist = new Distribution(discrete);
            Distribution ResDist = new Distribution(uniform);

            Create c = new Create(env, 0, 4, CreateDist);

            Dispose dispose = new Dispose(env, 10);

            Queue q = new Queue(env, 5);
            q.Capacity = 10;
            Resource r = new Resource(env, 1, 1, ResDist, q);

            Queue q2 = new Queue(env, 6);
            q2.Capacity = 10;
            Resource r2 = new Resource(env, 2, 1, ResDist, q2);

            Queue q3 = new Queue(env, 7);
            q3.Capacity = 10;
            Resource r3 = new Resource(env, 3, 1, ResDist, q3);

            Queue q4 = new Queue(env, 8);
            q4.Capacity = 10;
            Resource r4 = new Resource(env, 4, 1, ResDist, q4);

            c.Next_AID.Add("First", 1);
            r.Next_AID.Add("First", 2);
            r2.Next_AID.Add("First", 3);
            r3.Next_AID.Add("First", 4);
            r4.Next_AID.Add("First", 2);

            env.System_Time = new DateTime(1970, 1, 1, 0, 0, 0);
            env.Start_Time = new DateTime(1970, 1, 1, 0, 0, 0);
            env.Setup_Simulation(TimeSpan.FromSeconds(300));
            env.Simulate();
        }
开发者ID:aidint,项目名称:SimExpert,代码行数:44,代码来源:Chain.cs

示例14: run

        public void run()
        {
            Environment env = new Environment();

            //dist
            List<double> valueList = new List<double>() { 1, 2, 3, 4, 5 };
            List<double> distribution = new List<double>() { 0.5, 0.6, 0.7, 0.8, 1.0 };
            Discrete d = new Discrete(valueList, distribution, 0);
            //dist1
            Uniform n = new Uniform(1, 3, 0);
            Distribution dist = new Distribution(d);
            Distribution dist1 = new Distribution(n);

            Create c = new Create(env, 0, 10000, dist,null,new List<double>(){0.3,0.8,1.0});

            Dispose di = new Dispose(env, 1);

            Queue q = new Queue(env, 3);
            q.Capacity = 1;
            Resource r = new Resource(env, 2, 1, dist1, q);

            Queue q2 = new Queue(env,5);
            q2.Capacity = 1;
            Resource r2 = new Resource(env, 6, 1, dist1, q2);

            Queue q3 = new Queue(env, 10);
            q3.Capacity = 1;
            Resource r3 = new Resource(env, 7, 1, dist1, q3);

            c.Next_AID.Add("First", 2);
            c.Next_AID.Add("Second", 6);
            c.Next_AID.Add("Third", 7);

            r.Next_AID.Add("First", 1);
            r2.Next_AID.Add("First", 1);
            r3.Next_AID.Add("First", 1);

            env.System_Time = new DateTime(1970, 1, 1, 0, 0, 0);
            env.Start_Time = new DateTime(1970, 1, 1, 0, 0, 0);
            env.Setup_Simulation();
            env.Simulate();
        }
开发者ID:aidint,项目名称:SimExpert,代码行数:42,代码来源:SimpleProbShare.cs

示例15: PaintLabelPosteriorProbabilityGraph

        } // End Constructor


        /// <summary>
        /// Paint the label Posterior Probability graph
        /// </summary>
        /// <param name="printableConfusionMatrix"></param>
        private void PaintLabelPosteriorProbabilityGraph(Discrete probabilityMatrix , bool isFirstTimeToAdd = false)
        {
            int labelCount = probabilityMatrix.Dimension;
            Series currentSeries; 

            //initial the graph at the first time
            if (isFirstTimeToAdd)
            {
                currentSeries = new Series();
                currentSeries.ChartArea = "Default";
                currentSeries.ChartType = SeriesChartType.Column;
                currentSeries.IsVisibleInLegend = false;
                currentSeries.IsXValueIndexed = true;

                this.workerConfusionMatrixGraph.ChartAreas[0].AxisX.Interval = 1;
                this.workerConfusionMatrixGraph.Series.Add(currentSeries);
            }
            else //obtain the current series
            {
                currentSeries = workerConfusionMatrixGraph.Series[0];
            }

            probabilityText = "";

            //for each label, add the corresponding datapoint
            for (int currentLabelPos = 0; currentLabelPos < labelCount; currentLabelPos++)
            {
               double pointValue = probabilitiesArray[currentLabelPos];
               DataPoint currentDataPoint = new DataPoint(currentLabelPos, pointValue);
               currentDataPoint.AxisLabel = "Label " + (currentLabelPos + 1) ;
               currentSeries.Points.Add(currentDataPoint);
               probabilityText += String.Format("{0:0.0000}       ", pointValue);

            }//end for goldLabel

            textBoxTaskValue.Text = labelHeader + Environment.NewLine + probabilityText;
            
        }
开发者ID:marknabil,项目名称:active-crowd-toolkit,代码行数:45,代码来源:FormTaskDetails.cs


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