Exemplo n.º 1
0
        /// <summary>
        /// Transfer a number of instances from the unlabelled to the labelled set for the given resident.
        /// </summary>
        /// <param name="resident">The index of the resident.</param>
        /// <param name="num">The number to transfer.</param>
        public void Transfer(int resident, int num)
        {
            if (num == 0)
            {
                return;
            }

            var rng = new Random();

            for (int tt = 0; tt < 2; ++tt)
            {
                for (int nn = 0; nn < num; ++nn)
                {
                    var uinds = Unlabelled.OrderBy(x => rng.Next());

                    foreach (var ind in uinds)
                    {
                        if (dataSet.Labels[0][ind] == (tt == 0 ? false : true))
                        {
                            Unlabelled.Remove(ind);
                            Labelled.Add(ind);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void VOITest(int numActivelySelected, Marginals priors)
        {
            var onlineEstimates = new List <Bernoulli>();
            var onlineTargets   = new List <bool>();

            Metrics metrics = null;

            for (int jj = 0; jj < numActivelySelected; ++jj)
            {
                CalculateProbabilities(priors);

                //Console.WriteLine( "\nJL: {0}", JL() );
                //Console.WriteLine( "JU: {0}", JU() );

                int    argMax;
                double maxVal;
                GetArgMaxVOI(hypothesisActivityPosteriors, priors, out argMax, out maxVal);

                Unlabelled.Remove(argMax);
                Labelled.Add(argMax);

                UpdateModel(argMax);


                onlineEstimates.Add(GetProbabilityOf(argMax, priors));
                onlineTargets.Add(DataSet.Labels[0][argMax]);

                metrics = new Metrics
                {
                    Name       = "active",
                    Estimates  = onlineEstimates.Select(ia => new Bernoulli(ia)).ToArray(),
                    TrueLabels = onlineTargets.ToArray()
                };

                // metrics.PrintSummary();
            }

            if (Unlabelled.Any())
            {
                CalculateProbabilities(priors);
                foreach (var index in Unlabelled)
                {
                    onlineEstimates.Add(hypothesisActivityPosteriors[index]);
                    onlineTargets.Add(DataSet.Labels[0][index]);
                }

                metrics = new Metrics
                {
                    Name       = "active",
                    Estimates  = onlineEstimates.Select(ia => new Bernoulli(ia)).ToArray(),
                    TrueLabels = onlineTargets.ToArray()
                };
            }

            if (metrics != null)
            {
                metrics.PrintSummary();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the model.
        /// </summary>
        /// <param name="index">Index.</param>
        public void UpdateModel(int index)
        {
            if (Labelled.Contains(index))
            {
                throw new Exception("The selected index is already in the labelled set.");
            }

            Unlabelled.Remove(index);
            Labelled.Add(index);
        }