當前位置: 首頁>>代碼示例>>C#>>正文


C# Bernoulli.Select方法代碼示例

本文整理匯總了C#中Bernoulli.Select方法的典型用法代碼示例。如果您正苦於以下問題:C# Bernoulli.Select方法的具體用法?C# Bernoulli.Select怎麽用?C# Bernoulli.Select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bernoulli的用法示例。


在下文中一共展示了Bernoulli.Select方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: JAll_j

        private double JAll_j(int index, Bernoulli[] activityPosteriors, Marginals priors)
        {
            // var prevProbs = activityPosteriors.Select(ia => new Bernoulli(ia)).ToArray();
            hypothesisActivityPosteriors = activityPosteriors.Select(ia => new Bernoulli(ia)).ToArray();

            // Get datum
            // var datum = DataSet.GetSubSet(0, index);
            bool trueLabel = DataSet.Labels[0][index];

            // Create copies of the Labelled an Unlabelled sets
            var labelled = new HashSet<int>(Labelled);
            var unlabelled = new HashSet<int>(Unlabelled);

            labelled.Add(index);
            unlabelled.Remove(index);

            // datum.Labels[0][0] = true;
            DataSet.Labels[0][index] = true;

            // Learn as if positive
            // var positivePosteriors = TrainModel.Train(datum, priors, 1);
            Marginals positivePosteriors = priors;

            try
            {
                positivePosteriors = TrainModel.Train(DataSet.GetSubSet(0, index), priors, 1);
            }
            catch (ImproperMessageException)
            {
                // As fallback use priors
            }

            // recompute probabilities
            CalculateProbabilities(positivePosteriors);

            //var jjposl = JL(labelled);
            //var jjposu = JU(unlabelled);
            var Jjpos = (JAll()) * (1.0 - hypothesisActivityPosteriors[index].GetMean());

            // Restore posteriors

            labelled.Add(index);
            unlabelled.Remove(index);

            // datum.Labels[0][0] = false;
            DataSet.Labels[0][index] = false;

            // Learn as if negative
            // var negativePosteriors = TrainModel.Train(datum, priors, 1);
            Marginals negativePosteriors = priors;
            try
            {
                negativePosteriors = TrainModel.Train(DataSet.GetSubSet(0, index), priors, 1);
            }
            catch (ImproperMessageException)
            {
                // As fallback use priors
            }

            // recompute probabilities
            CalculateProbabilities(negativePosteriors);

            //var jjnegl = JL(labelled);
            //var jjnegu = JU(unlabelled);
            var Jjneg = (JAll()) * (hypothesisActivityPosteriors[index].GetMean());

            // restore posteriors
            // activityPosteriors = prevProbs;
            DataSet.Labels[0][index] = trueLabel;

            var voi = Jjpos + Jjneg;

            return voi;
        }
開發者ID:IRC-SPHERE,項目名稱:ActiveTransfer,代碼行數:74,代碼來源:ActiveLearner.cs

示例2: GetArgMaxVOI

        //        /// <summary>
        //        /// Gets the value of information.
        //        /// </summary>
        //        /// <value>The value of information.</value>
        //        public double[] GetValueOfInformation()
        //        {
        //            double jall = JAll();
        //            return Unlabelled.Select(index => VOI(jall, index)).ToArray();
        //        }
        /// <summary>
        /// Gets the argument maxising the Value of information.
        /// </summary>
        /// <param name="activityPosteriors">Activity posteriors.</param>
        /// <param name="priors">Priors.</param>
        /// <param name="argMax">Argument max.</param>
        /// <param name="maxVal">Max value.</param>
        public override void GetArgMaxVOI(Bernoulli[] activityPosteriors, Marginals priors, out int argMax, out double maxVal)
        {
            hypothesisActivityPosteriors = activityPosteriors.Select(ia => new Bernoulli(ia)).ToArray();
            double jall = JAll();

            var unlabelled = Unlabelled.ToArray();
            argMax = -1;
            maxVal = Reversed ? double.PositiveInfinity : double.NegativeInfinity;

            var signs = new double[unlabelled.Length];
            var vois = new double[unlabelled.Length];

            for (int i = 0; i < unlabelled.Length; i++)
            {
                var index = unlabelled[i];
                vois[i] = VOI(jall, index, activityPosteriors, priors);
                signs[i] = Math.Sign(vois[i]) / 2.0 + 0.5;
                //Console.Write( "." );
                //Console.WriteLine( "y_true: {0}", labels[0][ind] );
                //Console.WriteLine( "y_hat: {0}", probs[ind] );
                //Console.WriteLine( "VOJ_{0}: {1}", ind, voi );
                //Console.WriteLine();
                if (Reversed)
                {
                    if (vois[i] < maxVal || argMax < 0)
                    {
                        maxVal = vois[i];
                        argMax = index;
                    }
                }
                else
                {
                    if (vois[i] > maxVal || argMax < 0)
                    {
                        maxVal = vois[i];
                        argMax = index;
                    }
                }
            }

            //Console.WriteLine();
            //Console.WriteLine( "\n+ivity: {0}", signs.Average() );
        }
開發者ID:IRC-SPHERE,項目名稱:ActiveTransfer,代碼行數:59,代碼來源:ActiveLearner.cs


注:本文中的Bernoulli.Select方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。