コード例 #1
0
ファイル: Histogram.cs プロジェクト: vchistov/prometheus-net
        internal Histogram(string name, string help, string[] labelNames, double[] buckets = null) : base(name, help, labelNames)
        {
            if (labelNames.Any(l => l == "le"))
            {
                throw new ArgumentException("'le' is a reserved label name");
            }
            _buckets = buckets ?? DefaultBuckets;

            if (_buckets.Length == 0)
            {
                throw new ArgumentException("Histogram must have at least one bucket");
            }

            if (!double.IsPositiveInfinity(_buckets[_buckets.Length - 1]))
            {
                _buckets = _buckets.Concat(new[] { double.PositiveInfinity }).ToArray();
            }

            for (int i = 1; i < _buckets.Length; i++)
            {
                if (_buckets[i] <= _buckets[i - 1])
                {
                    throw new ArgumentException("Bucket values must be increasing");
                }
            }

            Unlabelled.Init(this, LabelValues.Empty);
        }
コード例 #2
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;
                        }
                    }
                }
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
0
 public void Reset()
 {
     Unlabelled.ResetValue();
     foreach (var labelledMetric in LabelledMetrics)
     {
         labelledMetric.Value.ResetValue();
     }
 }
コード例 #5
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);
        }
コード例 #6
0
        //		/// <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() );
        }
コード例 #7
0
        public override void GetArgMaxVOI(MicrosoftResearch.Infer.Distributions.Bernoulli[] activityPosteriors, Marginals priors, out int argMax, out double maxVal)
        {
            CalculateProbabilities(priors);

            var evidences = new Dictionary <int, double>();

            var sortedUnlabelled = Unlabelled
                                   .OrderBy(_ => rng.NextDouble())
                                   .OrderBy(uu => Math.Abs(hypothesisActivityPosteriors[uu].GetMean() - 0.5))
                                   .Take(10)
            ;

            foreach (var index in sortedUnlabelled)
            {
                var evidence = ExpectedEvidence(index, priors);

                evidences.Add(index, evidence);
            }

            var ordered = evidences.OrderBy(ee => ee.Value);

            argMax = ordered.First().Key;
            maxVal = ordered.First().Value;
        }
コード例 #8
0
ファイル: Gauge.cs プロジェクト: tpodolak/prometheus-net
 public void Unpublish() => Unlabelled.Unpublish();
コード例 #9
0
 public void Observe(double val)
 {
     Unlabelled.Observe(val);
 }
コード例 #10
0
ファイル: Gauge.cs プロジェクト: wardensky/prometheus-net
 public void Dec(double decrement = 1) => Unlabelled.Dec(decrement);
コード例 #11
0
 public void Inc(double increment, long?timestamp)
 {
     Unlabelled.Inc(increment, timestamp);
 }
コード例 #12
0
ファイル: Untyped.cs プロジェクト: oholsen/Prometheus.Client
 public void Set(double val, long?timestamp)
 {
     Unlabelled.Set(val, timestamp);
 }
コード例 #13
0
 public void Inc(long increment)
 {
     Unlabelled.Inc(increment);
 }
コード例 #14
0
ファイル: Gauge.cs プロジェクト: oholsen/Prometheus.Client
 public void Dec(double decrement, long?timestamp)
 {
     Unlabelled.Dec(decrement, timestamp);
 }
コード例 #15
0
ファイル: Gauge.cs プロジェクト: oholsen/Prometheus.Client
 public void Dec()
 {
     Unlabelled.Dec();
 }
コード例 #16
0
 /// <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)
 {
     argMax = Unlabelled.ToArray()[random.Next(Unlabelled.Count)];
     maxVal = 0.0;
 }
コード例 #17
0
 public void Inc()
 {
     Unlabelled.Inc();
 }
コード例 #18
0
ファイル: Gauge.cs プロジェクト: valmac/Prometheus.Client
 public void Dec(double decrement)
 {
     Unlabelled.Dec(decrement);
 }
コード例 #19
0
ファイル: Gauge.cs プロジェクト: wardensky/prometheus-net
 public void Set(double val) => Unlabelled.Set(val);
コード例 #20
0
ファイル: Histogram.cs プロジェクト: wardensky/prometheus-net
 public void Observe(double val) => Unlabelled.Observe(val, 1);
コード例 #21
0
 public void Observe(double val, long?timestamp)
 {
     Unlabelled.Observe(val, timestamp);
 }
コード例 #22
0
ファイル: Histogram.cs プロジェクト: wardensky/prometheus-net
 public void Observe(double val, long count) => Unlabelled.Observe(val, count);
コード例 #23
0
 public void Inc(double increment = 1)
 {
     Unlabelled.Inc(increment);
 }
コード例 #24
0
ファイル: Gauge.cs プロジェクト: tpodolak/prometheus-net
 public void IncTo(double targetValue) => Unlabelled.IncTo(targetValue);
コード例 #25
0
 public void Publish() => Unlabelled.Publish();
コード例 #26
0
ファイル: Gauge.cs プロジェクト: tpodolak/prometheus-net
 public void DecTo(double targetValue) => Unlabelled.DecTo(targetValue);