コード例 #1
0
        /// <summary>
        /// Bias variance analysis calculator for constructing learning curves.
        /// Learning curves can be used to determine if a model has high bias or high variance.
        /// </summary>
        /// <param name="trainingValidationIndexSplitter"></param>
        /// <param name="shuffler">Type of shuffler to use when splitting data</param>
        /// <param name="metric">The error metric used</param>
        /// <param name="samplePercentages">A list of sample percentages determining the
        /// training data used in each point of the learning curve</param>
        /// <param name="numberOfShufflesPrSample">How many times should the data be shuffled pr. calculated point</param>
        public LearningCurvesCalculator(ITrainingTestIndexSplitter <double> trainingValidationIndexSplitter,
                                        IIndexSampler <double> shuffler, IMetric <double, TPrediction> metric, double[] samplePercentages, int numberOfShufflesPrSample = 5)
        {
            if (trainingValidationIndexSplitter == null)
            {
                throw new ArgumentException("trainingValidationIndexSplitter");
            }
            if (shuffler == null)
            {
                throw new ArgumentException("shuffler");
            }
            if (samplePercentages == null)
            {
                throw new ArgumentNullException("samplePercentages");
            }
            if (samplePercentages.Length < 1)
            {
                throw new ArgumentException("SamplePercentages length must be at least 1");
            }
            if (metric == null)
            {
                throw new ArgumentNullException("metric");
            }
            if (numberOfShufflesPrSample < 1)
            {
                throw new ArgumentNullException("numberOfShufflesPrSample must be at least 1");
            }

            m_trainingValidationIndexSplitter = trainingValidationIndexSplitter;
            m_indexedSampler           = shuffler;
            m_samplePercentages        = samplePercentages;
            m_metric                   = metric;
            m_numberOfShufflesPrSample = numberOfShufflesPrSample;
            m_random                   = new Random(42);
        }
コード例 #2
0
ファイル: IMetricParser.cs プロジェクト: Mirandatz/minotaur
        public static IMetric[] ParseMetrics(
            Dataset dataset,
            Array <string> metricsNames,
            ClassificationType classificationType
            )
        {
            if (metricsNames.IsEmpty)
            {
                throw new ArgumentException(nameof(metricsNames) + " can't be empty.");
            }

            var metrics = new IMetric[metricsNames.Length];

            for (int i = 0; i < metricsNames.Length; i++)
            {
                var currentMetricName = metricsNames[i];
                metrics[i] = (metricsNames[i], classificationType) switch
                {
                    ("fscore", ClassificationType.SingleLabel) => new SingleLabelFScore(dataset),
                    ("fscore", ClassificationType.MultiLabel) => new MultiLabelFScore(dataset),
                    ("average-rule-volume", _) => new AverageRuleVolume(dataset),
                    ("rule-count", _) => new RuleCount(),
                    ("model-size", _) => new ModelSize(),

                    _ => throw new ArgumentException($"Unsupported (Metric, ClassificationType): ({currentMetricName}, {classificationType})."),
                };
            }
コード例 #3
0
        public IDictionary <BKTreeNode <T>, int> Query(IMetric <T> metric, int radius)
        {
            IDictionary <BKTreeNode <T>, int> results = new Dictionary <BKTreeNode <T>, int>();

            QueryHelper(metric, radius, results);
            return(results);
        }
コード例 #4
0
        public IMetric GetOrAdd(MetricName name, IMetric metric)
        {
            var m = _metrics.GetOrAdd(name.CacheKey, metric);

            UpdateManifest(name);
            return(m);
        }
コード例 #5
0
 /// <summary>
 /// Remove a metric to the definition metric cache.  Used by the MetricCollection base class to flatten the hierarchy.
 /// </summary>
 /// <param name="victimMetric">The metric object to remove from the cache.</param>
 internal void RemoveMetric(IMetric victimMetric)
 {
     lock (m_Lock)
     {
         m_MetricById.Remove(victimMetric.Id);
     }
 }
コード例 #6
0
 public AStarSolver(State _initialState, IMetric metric, State _solved)
 {
     MaxDepth     = int.MinValue;
     this._metric = metric;
     InitialState = _initialState;
     Solved       = _solved;
 }
コード例 #7
0
        public void MetricCollectionFindByIndex()
        {
            MetricDefinition testMetricDefinition = GetTestMetricDefinition();
            IMetric          testMetric           = testMetricDefinition.Metrics[0];

            Assert.IsNotNull(testMetric);
        }
コード例 #8
0
 /// <summary>
 /// Add a metric to the definition metric cache.  Used by the MetricCollection base class to flatten the hierarchy.
 /// </summary>
 /// <param name="newMetric">The metric object to add to the cache.</param>
 internal void AddMetric(IMetric newMetric)
 {
     lock (m_Lock)
     {
         m_MetricById.Add(newMetric.Id, newMetric);
     }
 }
コード例 #9
0
ファイル: MetricExtensions.cs プロジェクト: signalfx/NanoTube
        //https://github.com/kiip/statsite
        //key:value|type[|@flag]

        /*
         * Key / Value pair - mysql.queries:1381|kv|@1313107325
         * Reporting how many queries we've seen in the last second on MySQL:
         *
         * Counting - rewards:1|c
         * Increments the "rewards" counter by 1 (use -1 to decrement by 1)
         *
         * Timing - api.session_created:114|ms
         * timing the response speed of an API call:
         *
         * Sampling - api.session_created:114|ms|@0.1
         * Saying we sample this data in 1/10th of the API requests.
         */
        private static string ToStatSiteString(this IMetric metric)
        {
            Type t = metric.GetType();

            if (t == typeof(KeyValue))
            {
                KeyValue keyValue = (KeyValue)metric;
                if (keyValue.Timestamp.HasValue)
                {
                    return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|kv|@{2}", keyValue.Key, keyValue.Value, keyValue.Timestamp.Value.AsUnixTime()));
                }
                return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|kv", keyValue.Key, keyValue.Value));
            }
            else if (t == typeof(Counter))
            {
                Counter counter = (Counter)metric;
                return(string.Format(CultureInfo.InvariantCulture, "{0}:{1}|c", counter.Key, counter.Adjustment));
            }
            else if (t == typeof(Timing))
            {
                Timing timing = (Timing)metric;
                return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|ms", timing.Key, timing.Duration));
            }

            Sample sample = (Sample)metric;             //last option

            return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|c|@{2:f}", sample.Key, sample.Value, sample.Frequency));
        }
コード例 #10
0
 public NearestKNeighboursAlgorithm(ClassifiedSample <double[]> classifiedSample,
                                    IMetric metric,
                                    int k)
     : base(classifiedSample, metric)
 {
     K = k;
 }
コード例 #11
0
        /// <summary>
        /// Calculates the distance.
        /// </summary>
        /// <param name="metric">The metric.</param>
        /// <param name="bmu">The bmu.</param>
        /// <param name="gridNeuron">The grid neuron.</param>
        /// <returns>System.Double.</returns>
        public double CalculateDistance(IMetric metric, IBestMatchingUnit bmu, IGridNeuron gridNeuron)
        {
            var distanceToBmu = metric.CalculateDistance(bmu.GridCoordinates, gridNeuron.GridCoordinates);

            if (!IsToroidal)
            {
                return(distanceToBmu);
            }

            // on spherical grids, check the wrap-around distances
            //
            //
            //   X 1 2 2 1
            //   1 2 3 3 2
            //   2 3 4 4 3
            //   1 2 3 3 2

            var coordinates   = gridNeuron.GridCoordinates;
            var coordinatesX  = new[] { coordinates[0] - Width + 2, coordinates[1] };
            var coordinatesY  = new[] { coordinates[0], coordinates[1] - Height + 2 };
            var coordinatesXy = new[] { coordinatesX[0], coordinatesY[1] };

            distanceToBmu = Math.Min(distanceToBmu, metric.CalculateDistance(bmu.GridCoordinates, coordinatesX));
            distanceToBmu = Math.Min(distanceToBmu, metric.CalculateDistance(bmu.GridCoordinates, coordinatesY));
            distanceToBmu = Math.Min(distanceToBmu, metric.CalculateDistance(bmu.GridCoordinates, coordinatesXy));
            return(distanceToBmu);
        }
コード例 #12
0
        /// <summary>
        /// Получает значение метрики для текущего файла.
        /// </summary>
        /// <param name="metric">Метрика текста.</param>
        /// <returns>Текствое представление метрики.</returns>
        private async Task <string> GetMetric(IMetric metric)
        {
            string result = String.Empty;

            long blockSize = 0x20000;
            long offset = 0, length = file.fileSize < blockSize ? file.fileSize : blockSize;
            var  fileSize = file.fileSize;

            await Task.Run(() =>
            {
                while ((offset + length) <= fileSize)
                {
                    if (!isActive)
                    {
                        break;
                    }

                    metric.DoMetric(file.ReadTextBlock(offset, length));
                    offset += length;
                }
            });

            result = metric.GetStringMetric();

            return(result);
        }
コード例 #13
0
 /// <summary>
 /// Greedy forward selection of ensemble models.
 /// </summary>
 /// <param name="metric">Metric to minimize</param>
 /// <param name="ensembleStrategy">Strategy for ensembling models</param>
 /// <param name="numberOfModelsToSelect">Number of models to select</param>
 /// <param name="numberOfModelsFromStart">Number of models from start of the search.
 /// The top n models will be selected based in their solo performance</param>
 /// <param name="selectWithReplacement">If true the same model can be selected multiple times.
 /// This will correspond to weighting the models. If false each model can only be selected once</param>
 public ForwardSearchClassificationEnsembleSelection(IMetric <double, ProbabilityPrediction> metric, IClassificationEnsembleStrategy ensembleStrategy,
                                                     int numberOfModelsToSelect, int numberOfModelsFromStart, bool selectWithReplacement)
 {
     if (metric == null)
     {
         throw new ArgumentNullException("metric");
     }
     if (ensembleStrategy == null)
     {
         throw new ArgumentNullException("ensembleStrategy");
     }
     if (numberOfModelsToSelect < 1)
     {
         throw new ArgumentException("numberOfModelsToSelect must be at least 1");
     }
     if (numberOfModelsFromStart < 1)
     {
         throw new ArgumentException("numberOfModelsFromStart must be at least 1");
     }
     if (numberOfModelsFromStart > numberOfModelsToSelect)
     {
         throw new ArgumentException("numberOfModelsFromStart must be smaller than numberOfModelsToSelect");
     }
     m_metric                  = metric;
     m_ensembleStrategy        = ensembleStrategy;
     m_numberOfModelsToSelect  = numberOfModelsToSelect;
     m_numberOfModelsFromStart = numberOfModelsFromStart;
     m_selectWithReplacement   = selectWithReplacement;
 }
コード例 #14
0
ファイル: MetricExtensions.cs プロジェクト: signalfx/NanoTube
        /// <summary>
        /// An IMetric extension method that converts a given metric value into a string representation based on the given MetricFormat.
        /// </summary>
        /// <exception cref="ArgumentNullException">	Thrown when the metric is null. </exception>
        /// <exception cref="ArgumentException">		Thrown when the key is invalid. </exception>
        /// <param name="metric">	The metric to act on. </param>
        /// <param name="key">      The optional key to prefix metrics with. </param>
        /// <param name="format">	Describes the format to use. </param>
        /// <returns>	A string representation of this object. </returns>
        public static string ToString(this IMetric metric, string key, MetricFormat format)
        {
            if (null == metric)
            {
                throw new ArgumentNullException("metric");
            }
            if (!key.IsValidKey())
            {
                throw new ArgumentException("contains invalid characters", "key");
            }

            string converted = null;

            switch (format)
            {
            case MetricFormat.StatSite:
                converted = metric.ToStatSiteString();
                break;

            case MetricFormat.StatsD:
            default:
                converted = metric.ToStatsDString();
                break;
            }

            return(string.IsNullOrEmpty(key) ? converted : string.Format(CultureInfo.InvariantCulture, "{0}.{1}", key, converted));
        }
コード例 #15
0
ファイル: MetricExtensions.cs プロジェクト: signalfx/NanoTube
        //https://github.com/etsy/statsd

        /*
         * Key / value pair - gorets 12345 timestamp
         * it doesn't appear statsd has native support for kv pairs and its not documented
         * Etsys parsing code lives here found other code to suggest it works like this - it appears from the code that a key
         * https://raw.github.com/etsy/statsd/master/stats.js
         *
         * Timing - glork:320|ms
         * The glork took 320ms to complete this time. StatsD figures out 90th percentile, average (mean), lower and upper bounds for the flush interval. The percentile threshold can be tweaked with config.percentThreshold.
         *
         * Counting - gorets:1|c
         * This is a simple counter. Add 1 to the "gorets" bucket. It stays in memory until the flush interval config.flushInterval.
         *
         * Sampling - gorets:1|c|@0.1
         * Tells StatsD that this counter is being sent sampled every 1/10th of the time.
         */
        private static string ToStatsDString(this IMetric metric)
        {
            Type t = metric.GetType();

            if (t == typeof(KeyValue))
            {
                //TODO: 1-19-2012 - this may be entirely wrong - we need to find a statsd to test against - eat timestamp
                KeyValue keyValue = (KeyValue)metric;
                return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|g", keyValue.Key, keyValue.Value));
            }
            else if (t == typeof(Timing))
            {
                Timing timing = (Timing)metric;
                return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|ms", timing.Key, timing.Duration));
            }
            else if (t == typeof(Counter))
            {
                Counter counter = (Counter)metric;
                return(string.Format(CultureInfo.InvariantCulture, "{0}:{1}|c", counter.Key, counter.Adjustment));
            }

            Sample sample = (Sample)metric;             //last option

            return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|c|@{2:f}", sample.Key, sample.Value, sample.Frequency));
        }
コード例 #16
0
ファイル: Metrics.cs プロジェクト: jango2015/EnyimMemcached2
        protected virtual void Visit(IMetric metric)
        {
            var im = metric as IMeter;

            if (im != null)
            {
                Visit(im);
            }
            else
            {
                var ic = metric as ICounter;
                if (ic != null)
                {
                    Visit(ic);
                }
                else
                {
                    var g = metric as IGauge;
                    if (g != null)
                    {
                        Visit(g);
                    }
                }
            }
        }
コード例 #17
0
 private void CreateVolume(IMetric metric)
 {
     if (!History.ContainsKey(metric.Key))
     {
         History.CreateVolume(metric.Key, new DataVolume(metric.Key, metric.Name, metric.Unit, metric.Domain, latLong));
     }
 }
コード例 #18
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        internal virtual IMetric CreateIMetric()
        {
            // TODO: Instantiate an appropriate concrete class.
            IMetric target = null;

            return(target);
        }
コード例 #19
0
        public void T001_SavingShouldNotInvalidateOtherCachedSingleObjects()
        {
            m_objMockRepository.BackToRecord(m_objIApplication);
            m_objMockRepository.BackToRecord(m_objIMetricBroker);
            long    lOtherID         = 200;
            DataSet objDSOtherMetric = new DataSet();

            using (m_objMockRepository.Ordered())
            {
                Rhino.Mocks.Expect.Call(m_objIApplication.IMetricBroker).Return(m_objIMetricBroker);
                Rhino.Mocks.Expect.Call(m_objIMetricBroker.FetchMetric(lOtherID)).Return(objDSOtherMetric);
            }
            m_objMockRepository.ReplayAll();

            IMetric objOtherMetric = Metric.GetByID(m_objIApplication, lOtherID);

            m_objMockRepository.VerifyAll();

            m_objMockRepository.BackToRecord(m_objIApplication);
            m_objMockRepository.BackToRecord(m_objIMetricBroker);

            m_objMockRepository.ReplayAll();
            //missing expectations here.

            //cause a stack overflow error

            Assert.Throws <ExpectationViolationException>("IApplicationSession.get_IMetricBroker(); Expected #0, Actual #1.",
                                                          () =>
            {
                IMetric objMetric = m_objIMetric.Numerator;
            });
        }
コード例 #20
0
        private FilterMetric(BoolSelectorDelegate <T> selector, MetricsTemplate <T> template)
        {
            _selector = selector ?? throw new ArgumentNullException(nameof(selector));
            _template = template ?? throw new ArgumentNullException(nameof(template));

            _metric = _template.Create();
        }
コード例 #21
0
 public TrainerSettings()
 {
     EpochsCount  = 1;
     Optimizer    = new CpuAdam(1e-3f);
     LossFunction = new CrossEntropy();
     Metric       = new CpuClassificationAccuracy();
 }
コード例 #22
0
        public MetricResult Calculate(IEnumerable <AssemblyDefinition> assemblies, IMetric metric)
        {
            List <AssemblyResult> assemblyResults = new List <AssemblyResult>();

            foreach (AssemblyDefinition assembly in assemblies)
            {
                List <ModuleResult> moduleResults = new List <ModuleResult>();
                foreach (ModuleDefinition module in assembly.Modules)
                {
                    List <TypeResult> typeResults = new List <TypeResult>();
                    foreach (TypeDefinition type in module.Types)
                    {
                        List <MethodResult> methodResults = new List <MethodResult>();
                        foreach (MethodDefinition method in type.Methods)
                        {
                            MethodResult methodResult = metric.ProcessMethod(method);
                            methodResults.Add(methodResult);
                        }
                        TypeResult typeResult = metric.ProcessType(type, methodResults.ToArray());
                        typeResults.Add(typeResult);
                    }
                    ModuleResult moduleResult = metric.ProcessModule(module, typeResults.ToArray());
                    moduleResults.Add(moduleResult);
                }
                AssemblyResult assemblyResult = metric.ProcessAssembly(assembly, moduleResults.ToArray());
                assemblyResults.Add(assemblyResult);
            }
            MetricResult result = metric.Process(assemblyResults.ToArray());

            return(result);
        }
コード例 #23
0
        private IMetric ActivateMetrics(string metric, Dictionary <string, string> args)
        {
            ObjectHandle handle;

            try
            {
                handle = Activator.CreateInstance(typeof(IMetric).Assembly.FullName, "WebAnalytics.Model.Metrics." + metric);
            }
            catch (Exception)
            {
                return(null);
            }

            //return the wrapped object
            IMetric m = (IMetric)handle.Unwrap();

            try
            {
                //Send the arguments that was appended to the URI and let each metric strip the arguments of what it may need to compute its metric value.
                m.SetParameters(args);
            }
            catch (KeyNotFoundException)
            {
                throw new Exception("Metric cannot be computed without arguments");
            }
            catch (NotImplementedException)
            {
                //no op
            }

            return(m);
        }
        /// <summary>
        /// Iterative random selection of ensemble models.
        /// </summary>
        /// <param name="metric">Metric to minimize</param>
        /// <param name="ensembleStrategy">Strategy for ensembling models</param>
        /// <param name="numberOfModelsToSelect">Number of models to select</param>
        /// <param name="iterations">Number of iterations to try random selection</param>
        /// <param name="selectWithReplacement">If true the same model can be selected multiple times.
        /// This will correspond to weighting the models. If false each model can only be selected once</param>
        /// <param name="seed"></param>
        public RandomClassificationEnsembleSelection(IMetric <double, ProbabilityPrediction> metric, IClassificationEnsembleStrategy ensembleStrategy,
                                                     int numberOfModelsToSelect, int iterations, bool selectWithReplacement, int seed = 42)
        {
            if (metric == null)
            {
                throw new ArgumentNullException("metric");
            }
            if (ensembleStrategy == null)
            {
                throw new ArgumentNullException("ensembleStrategy");
            }
            if (numberOfModelsToSelect < 1)
            {
                throw new ArgumentException("numberOfModelsToSelect must be at least 1");
            }
            if (iterations < 1)
            {
                throw new ArgumentException("Number of iterations");
            }

            m_metric                 = metric;
            m_ensembleStrategy       = ensembleStrategy;
            m_numberOfModelsToSelect = numberOfModelsToSelect;
            m_selectWithReplacement  = selectWithReplacement;
            m_iterations             = iterations;
            m_random                 = new Random(seed);
        }
コード例 #25
0
ファイル: MetricsData.cs プロジェクト: wonook/reef
 public void RegisterMetric(IMetric metric)
 {
     if (!_metricsMap.TryAdd(metric.Name, new MetricTracker(metric)))
     {
         throw new ArgumentException("The metric [{0}] already exists.", metric.Name);
     }
 }
コード例 #26
0
        internal Match(string first, string second, IMetric metric)
        {
            First  = first;
            Second = second;

            Score = metric.Compare(First, Second);
        }
コード例 #27
0
 /// <summary>
 /// Returns the zero-based index of the specified metric within the dictionary.
 /// </summary>
 /// <param name="item">A metric object to find the index of</param>
 /// <returns>The zero-based index of an item if found, a negative number if not found.</returns>
 public int IndexOf(IMetric item)
 {
     lock (m_Lock)
     {
         return(m_List.IndexOf(item));
     }
 }
コード例 #28
0
 public MetricSimilarity(MelodySequence seq, IMetric metric, SimilarityType type = SimilarityType.Cosine)
 {
     this.metrics = new IMetric[]{metric};
     this.target = seq.ToArray();
     this.type = type;
     this.target_metrics = new Dictionary<Pair, float>[] { this.metrics[0].Generate(this.target) };
 }
コード例 #29
0
 public MetricResult Calculate(IEnumerable<AssemblyDefinition> assemblies, IMetric metric)
 {
     List<AssemblyResult> assemblyResults = new List<AssemblyResult>();
     foreach(AssemblyDefinition assembly in assemblies)
     {
         List<ModuleResult> moduleResults = new List<ModuleResult>();
         foreach (ModuleDefinition module in assembly.Modules)
         {
             List<TypeResult> typeResults = new List<TypeResult>();
             foreach (TypeDefinition type in module.Types)
             {
                 List<MethodResult> methodResults = new List<MethodResult>();
                 foreach (MethodDefinition method in type.Methods)
                 {
                     MethodResult methodResult = metric.ProcessMethod(method);
                     methodResults.Add(methodResult);
                 }
                 TypeResult typeResult = metric.ProcessType(type, methodResults.ToArray());
                 typeResults.Add(typeResult);
             }
             ModuleResult moduleResult = metric.ProcessModule(module, typeResults.ToArray());
             moduleResults.Add(moduleResult);
         }
         AssemblyResult assemblyResult = metric.ProcessAssembly(assembly, moduleResults.ToArray());
         assemblyResults.Add(assemblyResult);
     }
     MetricResult result = metric.Process(assemblyResults.ToArray());
     return result;
 }
コード例 #30
0
ファイル: KDTree.cs プロジェクト: zadiran/framework
        /// <summary>
        ///   Creates a new k-dimensional tree from the given points.
        /// </summary>
        ///
        /// <param name="points">The points to be added to the tree.</param>
        /// <param name="distance">The distance function to use.</param>
        /// <param name="inPlace">Whether the given <paramref name="points"/> vector
        ///   can be ordered in place. Passing true will change the original order of
        ///   the vector. If set to false, all operations will be performed on an extra
        ///   copy of the vector.</param>
        ///
        /// <returns>A <see cref="KDTree{T}"/> populated with the given data points.</returns>
        ///
        public static KDTree FromData(double[][] points, IMetric <double[]> distance,
                                      bool inPlace = false)
        {
            if (points == null)
            {
                throw new ArgumentNullException("points");
            }

            if (distance == null)
            {
                throw new ArgumentNullException("distance");
            }

            if (points.Length == 0)
            {
                throw new ArgumentException("Insufficient points for creating a tree.");
            }

            int leaves;

            var root = CreateRoot(points, inPlace, out leaves);

            return(new KDTree(points[0].Length, root, points.Length, leaves)
            {
                Distance = distance,
            });
        }
コード例 #31
0
 /// <summary>
 /// Adds a <see cref="MetricRegistryListener"/> to a collection of listeners that will be notified on
 /// metric creation.Listeners will be notified in the order in which they are added.
 /// <para />
 /// The listener will be notified of all existing metrics when it first registers.
 /// </summary>
 /// <param name="listener"></param>
 public void AddListener(MetricRegistryListener listener)
 {
     handler.RegisterListener(listener);
     // TODO: Figure out how to notify listener of existing metrics efficiently
     foreach (KeyValuePair <MetricName, IMetric> entry in this._metrics)
     {
         MetricName name       = entry.Key;
         IMetric    metric     = entry.Value;
         Type       metricType = metric.GetType();
         if (metricType.IsSubclassOf(typeof(Gauge)))
         {
             handler.onGaugeAdded(name, (Gauge)metric);
         }
         else if (metric is Counter)
         {
             handler.onCounterAdded(name, (Counter)metric);
         }
         else if (metric is Histogram)
         {
             handler.onHistogramAdded(name, (Histogram)metric);
         }
         else if (metric is Meter)
         {
             handler.onMeterAdded(name, (Meter)metric);
         }
         else if (metric is Timer)
         {
             handler.onTimerAdded(name, (Timer)metric);
         }
         else
         {
             continue;
         }
     }
 }
コード例 #32
0
        private void OnMetricRemoved(MetricName name, IMetric metric)
        {
            Type metricType = metric.GetType();

            if (metricType.IsSubclassOf(typeof(Gauge)))
            {
                handler.onGaugeRemoved(name);
            }
            else if (metric is Counter)
            {
                handler.onCounterRemoved(name);
            }
            else if (metric is Histogram)
            {
                handler.onHistogramRemoved(name);
            }
            else if (metric is Meter)
            {
                handler.onMeterRemoved(name);
            }
            else if (metric is Timer)
            {
                handler.onTimerRemoved(name);
            }
            else
            {
                throw new ArgumentException("Unknown metric type: " + metricType);
            }
        }
コード例 #33
0
ファイル: Particle.cs プロジェクト: trojkac/effective_pso
        protected Particle(double restartEpsilon = 0.0, int iterationsToRestart = int.MaxValue)
        {
            _id = ++_idCounter;
            Metric = PsoServiceLocator.Instance.GetService<IMetric<double[]>>();
            Optimization = PsoServiceLocator.Instance.GetService<IOptimization<double[]>>();

            _iterationsToRestart = iterationsToRestart;
        }
コード例 #34
0
 public MetricSimilarity(MelodySequence seq, IMetric[] metrics, SimilarityType type = SimilarityType.Cosine)
 {
     this.metrics = metrics;
     this.target = seq.ToArray();
     target_metrics = new Dictionary<Pair, float>[metrics.Length];
     this.type = type;
     for (int i = 0; i < metrics.Length; i++)
         target_metrics[i] = this.metrics[i].Generate(this.target);
 }
コード例 #35
0
        /// <inheritdoc/>
        public IBenchmarkBuilderInSyntax<IBenchmarkBuilderContinutation> WithCustom(IMetric metric)
        {
            Ensure.ArgumentNotNull(metric, "metric");

            metric.Samples = samples;
            metrics.Add(metric);

            return new BenchmarkBuilderInSyntax<IBenchmarkBuilderContinutation>(metric, this);
        }
コード例 #36
0
		public static IMetric[] GetAll()
		{
			lock (CacheLock)
			{
				var retval = new IMetric[Cache.Count];
				Cache.Values.CopyTo(retval, 0);

				return retval;
			}
		}
コード例 #37
0
        /// <summary>
        /// Create a CSV for a metric that contains multiple instances
        /// </summary>
        public static StreamWriter CreateMetricInstanceStream(IRepositoryContext context, ExportAddInConfiguration config, ISession session, IMetric metric, ref int metricFileCount)
        {
            var info = session.Summary;
            var subFolder = Path.Combine(info.Product, info.Application);
            var metricName = metric.CategoryName + "." + metric.CounterName + "." + metric.InstanceName;
            subFolder = Path.Combine(subFolder, metricName);
            var fileName = info.EndDateTime.ToString("yyyy-MM-dd HH-mm-ss") + " on " + info.HostName;
            fileName += " (" + ++metricFileCount + ")"; // Uniquify filename for convenience with Excel
            if (config.UseUniqueFilenames)
                fileName += " " + info.Id;

            return CreateStream(context, config.SessionExportPath, subFolder, fileName, ".csv");
        }
コード例 #38
0
        public static MetricSimilarity GenerateMetricSimilarityMulti(IEnumerable<Composition> comps, IMetric[] metrics, SimilarityType type = SimilarityType.Cosine)
        {
            List<Note> notes = new List<Note>();
            foreach(var comp in comps)
            {
                if (comp.Tracks.Count < 1)
                    continue;
                var seq = comp.Tracks[0].GetMainSequence() as MelodySequence;
                foreach (var n in seq.Notes)
                    notes.Add(n);
            }

            return new MetricSimilarity(new MelodySequence(notes), metrics, type);
        }
コード例 #39
0
ファイル: DrivenMetric.cs プロジェクト: sprosin/DrivenMetrics
 public DrivenMetrics(IAssemblySearcher methodFinder, IReport report, IMetric[] metrics)
 {
     _assemblySearcher = methodFinder;
     Report = report;
     _metrics = metrics;
 }
コード例 #40
0
 void OnStep(IMetric metric) {
   var step = metric as IStepMetric;
   if (step != null) {
     step.OnStep();
   }
 }
コード例 #41
0
        /// <summary>
        /// Register metric (aka Y value)
        /// </summary>
        /// <returns>Current HistogramAggregator instance</returns>
        public HistogramAggregator Add(IMetric metricTemplate)
        {
            _metricTemplates.Add(metricTemplate);

            return this;
        }
コード例 #42
0
ファイル: MetricsManager.cs プロジェクト: airdye/libratoSharp
		public void CreateMetric(IMetric metric)
		{
			if (metric == null)
			{
				throw new ArgumentException("metric is null");
			}
			string json = this.CreateJsonObject(metric);
			string url = string.Format("/{0}", metric.Name);
			this.MakeJsonPost(json, url, "PUT");
		}
コード例 #43
0
        /// <summary>
        /// Writes the specified IMetric as tab separated values to a line of the file.
        /// </summary>
        /// <param name="metric">IMetric to write.</param>
        public void Write(IMetric metric)
        {
            if (metric == null)
            {
                throw new ArgumentNullException("metric");
            }

            if (this.streamWriter == null)
            {
                throw new InvalidOperationException(Properties.Resources.FILE_NOT_OPENED);
            }

            this.streamWriter.WriteLine(metric.ToString());

            if (this.AutoFlush)
            {
                this.streamWriter.Flush();
            }
        }
コード例 #44
0
			public SharedCounter(IMetric parent, string instance)
				: base(parent, instance)
			{
				Initialize();
			}
コード例 #45
0
        public void TFsetup()
        {
            #region Mock Objects
            m_objMockRepository = new MockRepository();
            m_objIApplication = (IApplicationSession)m_objMockRepository.StrictMock(typeof(IApplicationSession));
            m_objIMetricBroker = (IMetricBroker)m_objMockRepository.StrictMock(typeof(IMetricBroker));
            #endregion

            #region DataSets

            m_objDSRatioMetric = new DataSet();

            using (m_objMockRepository.Ordered())
            {
                Rhino.Mocks.Expect.Call(m_objIApplication.IMetricBroker).Return(m_objIMetricBroker);
                Rhino.Mocks.Expect.Call(m_objIMetricBroker.FetchMetric("Risk")).Return(m_objDSRatioMetric);
            }
            m_objMockRepository.ReplayAll();

            #endregion

            m_objIMetric = Metric.GetByName(m_objIApplication, "Risk");
            m_objMockRepository.VerifyAll();
        }
コード例 #46
0
 /// <inheritdoc/>
 public void Unregister(IMetric metric) {
   registry_.Unregister(metric);
 }
コード例 #47
0
			protected DefaultMetric(IMetric parent, string instance)
			{
				this.parent = parent;
				Instance = instance;
			}
コード例 #48
0
        /// <summary>
        /// ExportSamples is the shared logic for all sampled metric exports
        /// </summary>
        private void ExportSamples(StreamWriter writer, IMetric metric)
        {
            writer.Write("\"Sequence\",\"Timestamp\",\"{0}\"\r\n",
                string.IsNullOrEmpty(metric.InstanceName) ? "Value" : metric.InstanceName);

            foreach (var sample in metric.Samples)
            {
                writer.Write("{0},{1},{2}\r\n", sample.Sequence,sample.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"), sample.Value);
            }
        }
コード例 #49
0
ファイル: MetricsManager.cs プロジェクト: airdye/libratoSharp
		private string CreateJsonObject(IMetric metric)
		{
			StringBuilder sb = new StringBuilder();
			StringWriter sw = new StringWriter(sb);
			JsonWriter writer = new JsonTextWriter(sw);
			using (writer)
			{
				writer.Formatting = Formatting.Indented;
				writer.WriteStartObject();
				writer.WritePropertyName("type");
				writer.WriteValue(metric.Type);
				this.JsonAddMetricInfo(writer, metric, false);
				writer.WriteEndObject();
			}
			return sb.ToString();
		}
コード例 #50
0
ファイル: MetricsManager.cs プロジェクト: airdye/libratoSharp
		public void DeleteMetric(IMetric metric)
		{
			if (metric == null)
			{
				throw new ArgumentException("metric is null");
			}
			string url = string.Format("/{0}", metric.Name);
			this.MakeJsonPost(string.Empty, url, "DELETE");
		}
コード例 #51
0
ファイル: DrivenMetric.cs プロジェクト: sprosin/DrivenMetrics
            public DrivenMetrics Create(string[] assemblyNames, IMetric[] metrics, string reportFilePath, IReport htmlReport)
            {
                var assemblies = new List<AssemblyDefinition>();

                foreach (var assemblyName in assemblyNames)
                {
                    var assemblyLoader = new AssemblyLoader(assemblyName);
                    var assembly = assemblyLoader.Load();
                    assemblies.Add(assembly);
                }

                var methodFinder = new AssemblySearcher(assemblies.ToArray());
                var drivenMetric = new DrivenMetrics(methodFinder, htmlReport, metrics);

                return drivenMetric;
            }
コード例 #52
0
ファイル: MetricsManager.cs プロジェクト: mparsin/Elements
 /// <summary>
 /// The create metrics.
 /// </summary>
 /// <param name="metric">
 /// The metric.
 /// </param>
 /// <returns>
 /// The <see cref="Metric"/>.
 /// </returns>
 public Metric CreateMetrics(IMetric metric)
 {
     if (metric != null)
     {
         return new Metric(
             metric.Id,
             metric.Name,
             metric.Guid,
             metric.SummaryType,
             metric.MetricField,
             metric.MetricFieldSystemName,
             metric.GroupFieldOneSystemName,
             metric.GroupFieldTwoSystemName,
             metric.GroupFieldThreeSystemName,
             metric.GroupFieldFourSystemName,
             metric.FilterGuid,
             metric.FilterDefinition,
             metric.LockFilter);
     }
     return null;
 }
コード例 #53
0
			public DefaultMeter(IMetric parent, string instance, Interval interval)
				: base(parent, instance)
			{
				this.interval = interval;
				this.stopwatch = Stopwatch.StartNew();
			}
コード例 #54
0
        public FieldProblem_Owen()
        {
            m_objIApplication = (IApplicationSession)MockRepository.GenerateStrictMock(typeof(IApplicationSession), null, null);
            m_objIMetricBroker = (IMetricBroker)MockRepository.GenerateStrictMock(typeof(IMetricBroker), null, null);

            m_objDSRatioMetric = new DataSet();

            m_objIApplication.Expect(x => x.IMetricBroker).Return(m_objIMetricBroker);
            m_objIMetricBroker.Expect(x => x.FetchMetric("Risk")).Return(m_objDSRatioMetric);

            m_objIMetric = Metric.GetByName(m_objIApplication, "Risk");

            m_objIMetricBroker.AssertWasCalled(x => x.FetchMetric("Risk")).After(m_objIApplication.AssertWasCalled(x => x.IMetricBroker));

            m_objIApplication.VerifyAllExpectations();
            m_objIMetricBroker.VerifyAllExpectations();
        }
コード例 #55
0
			public DefaultGauge(IMetric parent, string instance) : base(parent, instance) { }
コード例 #56
0
ファイル: MetricClient.cs プロジェクト: jlawhon/NanoTube
        /// <summary>	Will send the given metric in the specified format. </summary>
        /// <exception cref="ArgumentNullException">	Thrown when the metric is null. </exception>
        /// <param name="metric">	The metric. </param>
        public void Send(IMetric metric)
        {
            if (null == metric) { throw new ArgumentNullException("metric"); }

            _messenger.SendMetrics(new[] { metric.ToString(_key, _format) });
        }
コード例 #57
0
		protected virtual void Visit(IMetric metric)
		{
			var im = metric as IMeter;
			if (im != null) Visit(im);
			else
			{
				var ic = metric as ICounter;
				if (ic != null) Visit(ic);
				else
				{
					var g = metric as IGauge;
					if (g != null) Visit(g);
				}
			}
		}
コード例 #58
0
ファイル: MetricsManager.cs プロジェクト: airdye/libratoSharp
		private void JsonAddMetricInfo(JsonWriter writer, IMetric metric, bool includeName)
		{
			if (includeName)
			{
				writer.WritePropertyName("name");
				writer.WriteValue(metric.Name);
			}
			if (metric.DisplayName != null)
			{
				writer.WritePropertyName("display_name");
				writer.WriteValue(metric.DisplayName);
			}
			if (metric.Description != null)
			{
				writer.WritePropertyName("description");
				writer.WriteValue(metric.Description);
			}
			if (metric.Period != -1)
			{
				writer.WritePropertyName("period");
				writer.WriteValue(metric.Period);
			}
		}
コード例 #59
0
ファイル: Program.cs プロジェクト: stefan-j/GeneticMIDI
        static void MetricTimingTest()
        {
            Databank db = new Databank("lib");
            var cat = db.Load("Classical");

            var fmets = new IMetric[]{new ChromaticTone(), new ChromaticToneDistance(), new ChromaticToneDuration(), new MelodicBigram(), new MelodicInterval()
            , new Pitch(), new Rhythm(), new RhythmicBigram(), new RhythmicInterval()};

            MusicPlayer player = new MusicPlayer();
            foreach (var m in fmets)
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();
                var metric = MetricSimilarity.GenerateMetricSimilarityMulti(cat.Compositions, new IMetric[] { m });

                GeneticGenerator gen = new GeneticGenerator(metric);
                gen.PrintProgress = false;
                gen.MaxGenerations = 1000;
                var mel = gen.Generate();
                mel.Trim(20);
                watch.Stop();
                var className = ((object)m).GetType().Name;
                Console.WriteLine("{0} - MF: {1}, AF {2}, T {3}", className, gen.MaxFitness, gen.AvgFitness, watch.ElapsedMilliseconds);
                Console.ReadLine();
                player.Play(mel);

            }

            Console.ReadLine();
        }
コード例 #60
0
 /// <inheritdoc/>
 public void Register(IMetric metric) {
   registry_.Register(metric);
 }