Exemple #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);
        }
Exemple #2
0
        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})."),
                };
            }
Exemple #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);
        }
Exemple #4
0
        public IMetric GetOrAdd(MetricName name, IMetric metric)
        {
            var m = _metrics.GetOrAdd(name.CacheKey, metric);

            UpdateManifest(name);
            return(m);
        }
Exemple #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);
     }
 }
Exemple #6
0
 public AStarSolver(State _initialState, IMetric metric, State _solved)
 {
     MaxDepth     = int.MinValue;
     this._metric = metric;
     InitialState = _initialState;
     Solved       = _solved;
 }
        public void MetricCollectionFindByIndex()
        {
            MetricDefinition testMetricDefinition = GetTestMetricDefinition();
            IMetric          testMetric           = testMetricDefinition.Metrics[0];

            Assert.IsNotNull(testMetric);
        }
Exemple #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);
     }
 }
        //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));
        }
 public NearestKNeighboursAlgorithm(ClassifiedSample <double[]> classifiedSample,
                                    IMetric metric,
                                    int k)
     : base(classifiedSample, metric)
 {
     K = k;
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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;
 }
Exemple #14
0
        /// <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));
        }
Exemple #15
0
        //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));
        }
Exemple #16
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);
                    }
                }
            }
        }
 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));
     }
 }
Exemple #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);
        }
        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;
            });
        }
Exemple #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();
        }
 public TrainerSettings()
 {
     EpochsCount  = 1;
     Optimizer    = new CpuAdam(1e-3f);
     LossFunction = new CrossEntropy();
     Metric       = new CpuClassificationAccuracy();
 }
        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);
        }
Exemple #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);
        }
Exemple #25
0
 public void RegisterMetric(IMetric metric)
 {
     if (!_metricsMap.TryAdd(metric.Name, new MetricTracker(metric)))
     {
         throw new ArgumentException("The metric [{0}] already exists.", metric.Name);
     }
 }
Exemple #26
0
        internal Match(string first, string second, IMetric metric)
        {
            First  = first;
            Second = second;

            Score = metric.Compare(First, Second);
        }
 /// <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));
     }
 }
 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) };
 }
 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;
 }
Exemple #30
0
        /// <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,
            });
        }
Exemple #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;
         }
     }
 }
Exemple #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);
            }
        }
Exemple #33
0
        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;
        }
 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);
 }
        /// <inheritdoc/>
        public IBenchmarkBuilderInSyntax<IBenchmarkBuilderContinutation> WithCustom(IMetric metric)
        {
            Ensure.ArgumentNotNull(metric, "metric");

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

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

				return retval;
			}
		}
        /// <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");
        }
        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);
        }
Exemple #39
0
 public DrivenMetrics(IAssemblySearcher methodFinder, IReport report, IMetric[] metrics)
 {
     _assemblySearcher = methodFinder;
     Report = report;
     _metrics = metrics;
 }
 void OnStep(IMetric metric) {
   var step = metric as IStepMetric;
   if (step != null) {
     step.OnStep();
   }
 }
        /// <summary>
        /// Register metric (aka Y value)
        /// </summary>
        /// <returns>Current HistogramAggregator instance</returns>
        public HistogramAggregator Add(IMetric metricTemplate)
        {
            _metricTemplates.Add(metricTemplate);

            return this;
        }
Exemple #42
0
		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");
		}
        /// <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();
            }
        }
			public SharedCounter(IMetric parent, string instance)
				: base(parent, instance)
			{
				Initialize();
			}
        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();
        }
 /// <inheritdoc/>
 public void Unregister(IMetric metric) {
   registry_.Unregister(metric);
 }
			protected DefaultMetric(IMetric parent, string instance)
			{
				this.parent = parent;
				Instance = instance;
			}
        /// <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);
            }
        }
Exemple #49
0
		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();
		}
Exemple #50
0
		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");
		}
Exemple #51
0
            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;
            }
Exemple #52
0
 /// <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;
 }
			public DefaultMeter(IMetric parent, string instance, Interval interval)
				: base(parent, instance)
			{
				this.interval = interval;
				this.stopwatch = Stopwatch.StartNew();
			}
        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();
        }
			public DefaultGauge(IMetric parent, string instance) : base(parent, instance) { }
Exemple #56
0
        /// <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) });
        }
		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);
				}
			}
		}
Exemple #58
0
		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);
			}
		}
Exemple #59
0
        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();
        }
 /// <inheritdoc/>
 public void Register(IMetric metric) {
   registry_.Register(metric);
 }