当前位置: 首页>>代码示例>>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;未经允许,请勿转载。