public static void AddRange <TKey, TBin>(
     this IHistogram <TKey, TBin> hist,
     IEnumerable <TKey> keys)
     where TBin : struct
 {
     AddRange(hist, keys, hist.DefaultIncrement);
 }
示例#2
0
        public static HistogramVisitor Collect(this IHistogram histogram)
        {
            var visitor = new HistogramVisitor();

            histogram.Visit(visitor);
            return(visitor);
        }
示例#3
0
 public ProceduralCardGenerator(IHistogram m, ImageGlossary i, CreatureModelIndex creatureModels, NameModel name)
 {
     model              = m;
     images             = i;
     creatureModelIndex = creatureModels;
     nameModel          = name;
 }
 public HistogramStopwatch(IHistogram histogram, bool useTicks = false)
 {
     Contract.Requires(histogram != null, nameof(histogram) + " is null.");
     this.histogram = histogram;
     this.useTicks  = useTicks;
     watch          = Stopwatch.StartNew();
 }
        public static async Task <T> Measure <T>(Func <Task <T> > action, IHistogram metric, ICounter errorCounter = null)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            T result;

            try
            {
                result = await action();
            }
            catch (Exception)
            {
                errorCounter?.Inc();
                throw;
            }
            finally
            {
                stopwatch.Stop();
                metric.Observe(stopwatch.ElapsedTicks / (double)Stopwatch.Frequency);
            }

            return(result);
        }
示例#6
0
    static private CardDescription GenerateTrapCard(System.Random random, IHistogram model, ImageGlossary images, CreatureModelIndex creatureModels, NameModel nameModel, CardGenerationFlags flags)
    {
        CardDescription card = ScriptableObject.CreateInstance(typeof(CardDescription)) as CardDescription;

        card.cardType = CardType.TRAP;
        card.manaCost = (int)ProceduralUtils.GetRandomValue <ManaCost>(random, model);

        double powerBudget = PowerBudget.ManaPowerBudgets[card.manaCost];
        double powerMargin = PowerBudget.ManaPowerMargin[card.manaCost];
        double powerLimit  = PowerBudget.ManaPowerLimit[card.manaCost];

        card.cardName = "A trap card";
        //card.name += "(" + powerBudget.ToString() + ")";

        GenerateCardEffects(random, model, creatureModels, card, powerBudget, powerMargin, powerLimit);

        // Revise the mana cost based on what effects we actually did generate
        int revisedMana = PowerBudget.PowerLevelToMana(card.PowerLevel());

        if (revisedMana != card.manaCost)
        {
            Debug.Log("Had to revise the mana cost from " + card.manaCost.ToString() + " to " + revisedMana.ToString());
            card.manaCost = revisedMana;
        }
        card.image = ProceduralUtils.GetRandomTexture(random, images.GetTrapImages());

        CardTags tags = CardTagging.GetCardTags(card);

        card.cardName = nameModel.GenerateName(random, tags);

        return(card);
    }
示例#7
0
        private void buttonLoadImage_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ResetForm();
                this.labelLoading.Text = "Loading image...";
                Cursor.Current         = Cursors.WaitCursor;
                this.Update();

                ImageManager.SelectImagePath(openFileDialog1.FileName);
                try
                {
                    OriginalImage = new Bitmap(ImageManager.CurrentImagePath);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("Not an image" + ex);
                    this.labelLoading.Text = "";
                    return;
                }
                pictureBoxOriginal.Image = OriginalImage;
                Histogram = new Histogram(OriginalImage);

                this.textBoxImageName.Text          = ImageManager.ImageName;
                this.buttonHistogramOrignal.Enabled = true;
                this.buttonStretch.Enabled          = true;
                this.labelLoading.Text = "";
                Cursor.Current         = Cursors.Default;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Histogram"/> class.
 /// </summary>
 /// <param name="histogram">A histogram.</param>
 /// <param name="name">A name.</param>
 /// <param name="help">Help text.</param>
 /// <param name="appInsightsMetric">The ApplicationInsights <see cref="Metric"/> object.</param>
 public Histogram(IHistogram histogram, string name, string help, Metric?appInsightsMetric)
 {
     this.histogram         = histogram;
     this.Name              = name;
     this.Help              = help;
     this.appInsightsMetric = appInsightsMetric;
 }
示例#9
0
 public void SetupParameters(System.Random r, IHistogram m, double minBudget, double maxBudget)
 {
     random = r;
     model  = m;
     Assert.IsTrue(maxBudget >= minBudget);
     minAllocatedBudget = minBudget;
     maxAllocatedBudget = maxBudget;
 }
示例#10
0
 internal RasterHistogram(IHistogram histogram)
 {
     if (histogram == null)
     {
         throw new ArgumentNullException("histogram");
     }
     _histogram = histogram;
 }
示例#11
0
 public Node(
     IStatistic statistic,
     IHistogram histogram
     )
 {
     _statistic    = statistic;
     _histogram    = histogram;
     Distributions = new List <IDistribution>();
 }
 /// Create an instance of the receiver with parameters estimated from
 /// the given histogram using best guesses. This method can be used to
 /// find the initial values for a fit.
 /// @param h DhbScientificCurves.Histogram
 /// @exception ArgumentOutOfRangeException
 ///							when no suitable parameter can be found.
 public StudentDistribution(IHistogram h)
 {
     double variance = h.Variance;
     if (variance <= 0)
         throw new ArgumentOutOfRangeException(
                 Resource.Student_distribution_is_only_defined_for_positive_variance);
     DefineParameters((int)System.Math.Max(1,
                                 System.Math.Round(2 / (1 - 1 / variance))));
 }
        public static List <KeyValuePair <TKey, TBin> > GetPeaks <TKey, TBin>(
            this IHistogram <TKey, TBin> hist)
            where TBin : struct
        {
            var peaks = new List <KeyValuePair <TKey, TBin> >();

            GetPeaks(hist, peaks);
            return(peaks);
        }
        /// Create an instance of the receiver with parameters estimated from
        /// the given histogram using best guesses. This method can be used to
        /// find the initial values for a fit.
        /// @param h DhbScientificCurves.Histogram
        /// @exception ArgumentOutOfRangeException
        ///							when no suitable parameter can be found.
        public ExponentialDistribution(IHistogram h)
        {
            if (h.Minimum < 0)
                throw new ArgumentOutOfRangeException(Resource.Exponential_distribution_is_only_defined_for_non_negative_values);

            if (h.Average < 0)
                throw new ArgumentOutOfRangeException(Resource.Exponential_distribution_is_only_defined_for_positive_scale);

            this.Scale = h.Average;
        }
示例#15
0
        public static HistogramValue GetCurrentValue(IHistogram metric)
        {
            var implementation = metric as IHistogramMetric;

            if (implementation != null)
            {
                return(implementation.Value);
            }
            return(EmptyHistogram);
        }
 public static void AddRange <TKey, TBin>(
     this IHistogram <TKey, TBin> hist,
     IEnumerable <KeyValuePair <TKey, TBin> > keysAndIncrements)
     where TBin : struct
 {
     foreach (var kvp in keysAndIncrements)
     {
         hist.Add(kvp);
     }
 }
示例#17
0
 public Portfolio(
     IStatistic statistics,
     IHistogram histogram,
     IPortfolioSimulator portfolioSimulator
     )
 {
     _statistics         = statistics;
     _histogram          = histogram;
     _portfolioSimulator = portfolioSimulator;
 }
 public static void CopyTo <TKey, TBin>(
     this IHistogram <TKey, TBin> hist,
     ICollection <KeyValuePair <TKey, TBin> > dest)
     where TBin : struct
 {
     foreach (var kvp in hist)
     {
         dest.Add(kvp);
     }
 }
示例#19
0
 public ContactMetrics(IMetrics metrics)
 {
     _writeDurations = metrics.Histogram()
                       .Name("myservice_contact_write_duration_seconds")
                       .Help("Average duration of persistence write operations for contacts")
                       .Register();
     _pokes = metrics.Counter()
              .Name("myservice_contact_pokes_total")
              .Help("Number of times contacts were poked")
              .Register();
 }
 public static void AddRange <TKey, TBin>(
     this IHistogram <TKey, TBin> hist,
     IEnumerable <TKey> keys,
     TBin increment)
     where TBin : struct
 {
     foreach (var key in keys)
     {
         hist.Add(key, increment);
     }
 }
示例#21
0
        public void Setup()
        {
            _histogramDefaultBuckets = OurMetricFactory.CreateHistogram("testhistogram1", HelpText);
            _histogramManyBuckets    = OurMetricFactory.CreateHistogram("testhistogram2", HelpText, false, _bucketsMany);

            _theirHistogramDefaultBuckets = TheirMetricFactory.CreateHistogram("testhistogram1", HelpText);
            _theirHistogramManyBuckets    = TheirMetricFactory.CreateHistogram("testhistogram2", HelpText, new Their.Prometheus.HistogramConfiguration()
            {
                Buckets = _bucketsMany
            });
        }
 /// Create an instance of the receiver with parameters estimated from
 /// the given histogram using best guesses. This method can be used to
 /// find the initial values for a fit.
 /// @param h Histogram
 /// @exception ArgumentOutOfRangeException
 ///							when no suitable parameter can be found.
 public ChiSquareDistribution(IHistogram h)
 {
     if (h.Minimum < 0)
         throw new ArgumentOutOfRangeException(
             Resource.Chi_square_distribution_is_only_defined_for_non_negative_values);
     int dof = (int)System.Math.Round(h.Average);
     if (dof <= 0)
         throw new ArgumentOutOfRangeException(
             Resource.Chi_square_distribution_is_only_defined_for_positive_degrees_of_freedom);
     DegreesOfFreedom = dof;
 }
示例#23
0
 public DummyMetrics(IMetrics metrics)
 {
     _runs = metrics.Counter()
             .Name("myservice_dummy_runs")
             .Help("Number of times the dummy worker ran")
             .Register();
     _runDurations = metrics.Histogram()
                     .Name("myservice_dummy_duration_seconds")
                     .Help("Average duration of a dummy worker run")
                     .Register();
 }
        public static Dictionary <TKey, TBin> ToDictionary <TKey, TBin>(
            this IHistogram <TKey, TBin> hist)
            where TBin : struct
        {
            var dict = new Dictionary <TKey, TBin>();

            foreach (var kvp in hist)
            {
                dict.Add(kvp.Key, kvp.Value);
            }
            return(dict);
        }
示例#25
0
 /// Create an instance of the receiver with parameters estimated from the
 /// given histogram using best guesses. This method can be used to
 /// find the initial values for a fit.
 /// @param h DhbScientificCurves.Histogram
 /// @exception ArgumentOutOfRangeException when no suitable parameter can be found.
 public GammaDistribution(IHistogram h)
 {
     if (h.Minimum < 0)
         throw new ArgumentOutOfRangeException("Gamma distribution is only defined for non-negative values");
     double shape = h.Average;
     if (shape <= 0)
         throw new ArgumentOutOfRangeException("Gamma distribution must have a non-negative shape parameter");
     double scale = h.Variance / shape;
     if (scale <= 0)
         throw new ArgumentOutOfRangeException("Gamma distribution must have a non-negative scale parameter");
     DefineParameters(shape / scale, scale);
 }
示例#26
0
        /// Create an instance of the receiver with parameters estimated from
        /// the given histogram using best guesses. This method can be used to
        /// find the initial values for a fit.
        /// @param h DhbScientificCurves.Histogram
        /// @exception ArgumentOutOfRangeException
        ///							when no suitable parameter can be found.
        public StudentDistribution(IHistogram h)
        {
            double variance = h.Variance;

            if (variance <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "Student distribution is only defined for positive variance");
            }
            DefineParameters((int)Math.Max(1,
                                           Math.Round(2 / (1 - 1 / variance))));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SerializerDecorator" /> class.
        /// </summary>
        /// <param name="metrics">The metrics factory.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="connectionInformation">The connection information.</param>
        public SerializerDecorator(IMetrics metrics,
                                   ISerializer handler,
                                   IConnectionInformation connectionInformation)
        {
            var name = handler.GetType().Name;

            _bytesToMessageTimer = metrics.Timer($"{connectionInformation.QueueName}.{name}.ConvertBytesToMessageTimer", Units.Calls);
            _messageToBytesTimer = metrics.Timer($"{connectionInformation.QueueName}.{name}.ConvertMessageToBytesTimer", Units.Calls);
            _resultSizeHistogram = metrics.Histogram($"{connectionInformation.QueueName}.{name}.ConvertMessageToBytesHistogram", Units.Bytes,
                                                     SamplingTypes.LongTerm);
            _handler = handler;
        }
示例#28
0
        private double[] fnClassification(IFeatureLayer pFLayer, decimal NClasses, string strClassifiedField, string ClassifiedMethod)
        {
            IFeatureClass pFClass = pFLayer.FeatureClass;

            //Create Rendering of Mean Value at Target Layer
            int intBreakeCount = Convert.ToInt32(NClasses);

            ITable       pTable = (ITable)pFClass;
            IClassifyGEN pClassifyGEN;

            switch (ClassifiedMethod)
            {
            case "Equal Interval":
                pClassifyGEN = new EqualIntervalClass();
                break;

            case "Geometrical Interval":
                pClassifyGEN = new GeometricalInterval();
                break;

            case "Natural Breaks":
                pClassifyGEN = new NaturalBreaksClass();
                break;

            case "Quantile":
                pClassifyGEN = new QuantileClass();
                break;

            case "StandardDeviation":
                pClassifyGEN = new StandardDeviationClass();
                break;

            default:
                pClassifyGEN = new NaturalBreaksClass();
                break;
            }

            //Need to be changed 1/29/15
            ITableHistogram pTableHistogram = new TableHistogramClass();

            pTableHistogram.Field = strClassifiedField;
            pTableHistogram.Table = pTable;
            IHistogram pHistogram = (IHistogram)pTableHistogram;

            object xVals, frqs;

            pHistogram.GetHistogram(out xVals, out frqs);
            pClassifyGEN.Classify(xVals, frqs, intBreakeCount);
            double[] cb = (double[])pClassifyGEN.ClassBreaks;

            return(cb);
        }
示例#29
0
        public HistogramTests()
        {
            noLabel = new DefaultHistogram("noLabel", new HistogramOptions
            {
                Help = "help noLabels",
            });

            labeled = new DefaultHistogram("labeled", new HistogramOptions
            {
                Help       = "help labeled",
                LabelNames = Labeled.SingleLabels
            });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExpressionSerializerDecorator" /> class.
        /// </summary>
        /// <param name="metrics">The metrics factory.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="connectionInformation">The connection information.</param>
        public ExpressionSerializerDecorator(IMetrics metrics,
                                             IExpressionSerializer handler,
                                             IConnectionInformation connectionInformation)
        {
            var name = "ExpressionSerializer";

            _methodToBytesTimer        = metrics.Timer($"{connectionInformation.QueueName}.{name}.ConvertMethodToBytesTimer", Units.Calls);
            _bytesToMethodTimer        = metrics.Timer($"{connectionInformation.QueueName}.{name}.ConvertBytesToMethodTimer", Units.Calls);
            _resultMethodSizeHistogram = metrics.Histogram($"{connectionInformation.QueueName}.{name}.ConvertMethodToBytesHistogram", Units.Bytes,
                                                           SamplingTypes.LongTerm);

            _handler = handler;
        }
        public static KeyValuePair <TKey, TBin>[] ToSortedArray <TKey, TBin>(
            this IHistogram <TKey, TBin> hist)
            where TBin : struct
        {
            var arr = ToArray(hist);

            int CompareFunc(KeyValuePair <TKey, TBin> first, KeyValuePair <TKey, TBin> second)
            {
                return(hist.HistArith.Compare(first.Value, second.Value));
            }

            Array.Sort(arr, CompareFunc);
            return(arr);
        }
示例#32
0
        public override IImage ApplyEqualizedHistogram(IHistogram histogram)
        {
            List<int> equalizedValues = new List<int>(histogram.EqualizedValues);
            GrayscalePixel[,] pixels = new GrayscalePixel[this.Height, this.Width];

            for (int row = 0; row < histogram.Image.Height; row++)
            {
                for (int column = 0; column < histogram.Image.Width; column++)
                {
                    int level = ((GrayscalePixel)this.pixels[row, column]).Level;
                    pixels[row, column] = new GrayscalePixel((byte)equalizedValues[level]);
                }
            }
            return new GrayscaleImage(pixels);
        }
示例#33
0
        /// <summary>
        /// Stretch Image Histogram
        /// </summary>
        private void Stretch()
        {
            this.labelLoading.Text = "Stretching Histogram from image...";
            this.Update();

            int lower = (int)this.numericUpDownLower.Value;
            int upper = (int)this.numericUpDownUpper.Value;

            this.pictureBoxStretched.Image = Histogram.Stretch(lower, upper);

            HistogramStretched = new Histogram((Bitmap)this.pictureBoxStretched.Image);

            this.isStretched       = true;
            this.labelLoading.Text = "";
        }
示例#34
0
        public IHistogram <byte> Merge(IHistogram <byte> other)
        {
            if (Normalized || other.Normalized)
            {
                throw new HistogramException("Normalized histogram can not be merged");
            }

            HueHisto h = new HueHisto();

            for (byte i = 0; i < Dimension; i++)
            {
                h[i] = hhisto[i] + other[i];
            }

            return(h);
        }
示例#35
0
        /// Create an instance of the receiver with parameters estimated from
        /// the given histogram using best guesses. This method can be used to
        /// find the initial values for a fit.
        /// @param h Histogram
        /// @exception ArgumentOutOfRangeException
        ///							when no suitable parameter can be found.
        public ChiSquareDistribution(IHistogram h)
        {
            if (h.Minimum < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "Chi square distribution is only defined for non-negative values");
            }
            int dof = (int)Math.Round(h.Average);

            if (dof <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "Chi square distribution is only defined for positive degrees of freedom");
            }
            DegreesOfFreedom = dof;
        }
示例#36
0
        public HistogramViewModel(MainWindowViewModel mainViewModel, IHistogram histogram)
        {
            this.mainViewModel = mainViewModel;
            this.histogram = histogram;
            this.image = histogram.Image;
            this.points = new PointCollection();

            this.points.Add(new Point(0, histogram.Max));
            int i = 0;
            foreach (int value in histogram.Values)
            {
                points.Add(new Point(i++, histogram.Max - value));
            }
            // last point (lower-right corner)
            points.Add(new Point(i, histogram.Max));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExpressionSerializerDecorator" /> class.
        /// </summary>
        /// <param name="metrics">The metrics factory.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="connectionInformation">The connection information.</param>
        public ExpressionSerializerDecorator(IMetrics metrics,
            IExpressionSerializer handler,
            IConnectionInformation connectionInformation)
        {
            var name = handler.GetType().Name;
            _methodToBytesTimer = metrics.Timer($"{connectionInformation.QueueName}.{name}.ConvertMethodToBytesTimer", Units.Calls);
            _bytesToMethodTimer = metrics.Timer($"{connectionInformation.QueueName}.{name}.ConvertBytesToMethodTimer", Units.Calls);
            _resultMethodSizeHistogram = metrics.Histogram($"{connectionInformation.QueueName}.{name}.ConvertMethodToBytesHistogram", Units.Bytes,
                SamplingTypes.LongTerm);

            _functionToBytesTimer = metrics.Timer($"{connectionInformation.QueueName}.{name}.ConvertFunctionToBytesTimer", Units.Calls);
            _bytesToFunctionTimer = metrics.Timer($"{connectionInformation.QueueName}.{name}.ConvertBytesToFunctionTimer", Units.Calls);
            _resultFunctionSizeHistogram = metrics.Histogram($"{connectionInformation.QueueName}.{name}.ConvertFunctionToBytesHistogram", Units.Bytes,
                SamplingTypes.LongTerm);

            _handler = handler;
        }
        /// Create an instance of the receiver with parameters estimated from
        /// the given histogram using best guesses. This method can be used to
        /// find the initial values for a fit.
        /// @param h Histogram
        /// @exception ArgumentOutOfRangeException
        ///							when no suitable parameter can be found.
        public FisherSnedecorDistribution(IHistogram h)
        {
            if (h.Minimum < 0)
                throw new ArgumentOutOfRangeException(Resource.Fisher_Snedecor_distribution_is_only_defined_for_non_negative_values);

            int n2 = (int)System.Math.Round(2 / (1 - 1 / h.Average));
            if (n2 <= 0)
                throw new ArgumentOutOfRangeException(Resource.Fisher_Snedecor_distribution_has_positive_degrees_of_freedom);

            var a = 1 - (n2 - 2) * (n2 - 4) * h.Variance / (2 * 2 * n2);
            var n1 = (int)System.Math.Round(0.7 * (n2 - 2) / a);

            if (n1 <= 0)
                throw new ArgumentOutOfRangeException(Resource.Fisher_Snedecor_distribution_has_positive_degrees_of_freedom);

            DefineParameters(n1, n2);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageInterceptorDecorator" /> class.
        /// </summary>
        /// <param name="metrics">The metrics factory.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="connectionInformation">The connection information.</param>
        public MessageInterceptorDecorator(IMetrics metrics,
            IMessageInterceptor handler,
            IConnectionInformation connectionInformation)
        {
            _handler = handler;
            var name = handler.GetType().Name;

            _metricTimerBytes =
                metrics.Timer($"{connectionInformation.QueueName}.{name}.BytesToMessageTimer", Units.Calls);

            _metricTimerMessage =
                metrics.Timer($"{connectionInformation.QueueName}.{name}.MessageToBytesTimer", Units.Calls);

            _metricHistogram = metrics.Histogram($"{connectionInformation.QueueName}.{name}.MessageToBytesHistogram", Units.Bytes,
                SamplingTypes.LongTerm);

            _metricHistogramDelta = metrics.Histogram($"{connectionInformation.QueueName}.{name}.MessageToBytesDeltaHistogram", Units.Bytes,
                SamplingTypes.LongTerm);

            _metricHistogramOptOut = metrics.Histogram($"{connectionInformation.QueueName}.{name}.OptOutOfGraphHistogram",
                Units.Bytes, SamplingTypes.LongTerm);
        }
示例#40
0
 public override IImage ApplyEqualizedHistogram(IHistogram histogram)
 {
     // TODO: Implement this method
     throw new NotImplementedException();
 }
 public FetchRequestAndResponseMetrics(ClientIdAndBroker metricId)
 {
     this.RequestTimer = new KafkaTimer(MetersFactory.NewTimer(metricId + "FetchRequestRateAndTimeMs", TimeSpan.FromMilliseconds(1), TimeSpan.FromSeconds(1)));
     this.RequestSizeHist = MetersFactory.NewHistogram(metricId + "FetchResponseSize");
 }
示例#42
0
 /// Create an instance of the receiver with parameters estimated from
 /// the given histogram using best guesses. This method can be used to
 /// find the initial values for a fit.
 /// @param h DhbScientificCurves.Histogram
 public NormalDistribution(IHistogram h)
     : this(h.Average, h.StandardDeviation)
 {
 }
 /// @param f statistics.ProbabilityDensity
 /// @param hist curves.Histogram
 public ScaledProbabilityDensityFunction(ProbabilityDensityFunction f, IHistogram hist)
     : this(f, hist.Count, hist.BinWidth)
 {
 }