public void ComputeCovarianceMatrix3DWithEmptyList()
        {
            var result = StatisticsHelper.ComputeCovarianceMatrix(new List <Vector3D>());

            foreach (var element in result.ToList(MatrixOrder.RowMajor))
            {
                Assert.IsNaN(element);
            }
        }
예제 #2
0
        public void CalculateZScoresWho2007()
        {
            var    who2007      = new AnthStat.Statistics.WHO2007();
            double ageMonths    = double.Parse(TxtEdadMeses.Text);
            double Weight       = double.Parse(TxtPeso.Text);
            double Lenght       = double.Parse(TxtTalla.Text);
            double LenghtMeters = Lenght / 100;
            double imc          = Weight / (LenghtMeters * LenghtMeters);
            double z            = 0.0;
            double x            = 0.0;
            double y            = 0.0;

            TxtIMCCalculado.Text = Math.Round(imc, 2).ToString();
            if (txtSexo.Text == "Masculino" || txtSexo.Text == "Masculino\t")
            {
                if (who2007.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement: imc, age: ageMonths, sex: Sex.Male, z: ref z))
                {
                    double p = StatisticsHelper.CalculatePercentile(z);
                    TxtIMCEdadWho2007Z.Text = Math.Round(z, 2).ToString();
                    TxtIMCEdadWho2007P.Text = Math.Round(p, 2).ToString();
                }
                if (who2007.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement: Weight, age: ageMonths, sex: Sex.Male, z: ref x))
                {
                    double p = StatisticsHelper.CalculatePercentile(x);
                    TxtPesoEdadWho2007Z.Text = Math.Round(x, 2).ToString();
                    TxtPesoEdadWho2007P.Text = Math.Round(p, 2).ToString();
                }
                if (who2007.TryCalculateZScore(indicator: Indicator.HeightForAge, measurement: Lenght, age: ageMonths, sex: Sex.Male, z: ref y))
                {
                    double p = StatisticsHelper.CalculatePercentile(y);
                    TxtTallaEdadWho2007Z.Text = Math.Round(y, 2).ToString();
                    TxtTallaEdadWho2007P.Text = Math.Round(p, 2).ToString();
                }
            }
            else if (txtSexo.Text == "Femenino" || txtSexo.Text == "Femenino\t")
            {
                if (who2007.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement: imc, age: ageMonths, sex: Sex.Female, z: ref z))
                {
                    double p = StatisticsHelper.CalculatePercentile(z);
                    TxtIMCEdadWho2007Z.Text = Math.Round(z, 2).ToString();
                    TxtIMCEdadWho2007P.Text = Math.Round(p, 2).ToString();
                }
                if (who2007.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement: Weight, age: ageMonths, sex: Sex.Female, z: ref x))
                {
                    double p = StatisticsHelper.CalculatePercentile(x);
                    TxtPesoEdadWho2007Z.Text = Math.Round(x, 2).ToString();
                    TxtPesoEdadWho2007P.Text = Math.Round(p, 2).ToString();
                }
                if (who2007.TryCalculateZScore(indicator: Indicator.HeightForAge, measurement: Lenght, age: ageMonths, sex: Sex.Female, z: ref y))
                {
                    double p = StatisticsHelper.CalculatePercentile(y);
                    TxtTallaEdadWho2007Z.Text = Math.Round(y, 2).ToString();
                    TxtTallaEdadWho2007P.Text = Math.Round(p, 2).ToString();
                }
            }
        }
예제 #3
0
 public void ComputeCovarianceMatrixFWithVectorsOfDifferentLength()
 {
     List <VectorF> points = new List <VectorF>(new[]
     {
         new VectorF(new float[] { -1, -2, 1 }),
         new VectorF(new float[] { 2, -1, 3 }),
         new VectorF(new float[] { 2, -1, 2, 3 }),
     });
     var result = StatisticsHelper.ComputeCovarianceMatrix(points);
 }
예제 #4
0
 public void ComputeCovarianceMatrixDWithVectorsOfDifferentLength()
 {
     List <VectorD> points = new List <VectorD>(new[]
     {
         new VectorD(new double[] { -1, -2, 1 }),
         new VectorD(new double[] { 2, -1, 3, 1 }),
         new VectorD(new double[] { 2, -1, 2 }),
     });
     var result = StatisticsHelper.ComputeCovarianceMatrix(points);
 }
예제 #5
0
        //数据库操作成功
        private void OperatorSuccess(User user, JObject responseData)
        {
            responseData.Add(MyCommon.CODE, (int)Consts.Code.Code_OK);
            responseData.Add(MyCommon.UID, user.Uid);

            MySqlUtil.UpdateUserTask(user.Uid);
            ProgressTaskHandler.ProgressTaskSql(208, user.Uid);

            StatisticsHelper.StatisticsRegister(user.Uid);
        }
        public void IsApproximatelyEqual_Test_Fractions()
        {
            // Positive Tests
            Assert.IsTrue(StatisticsHelper.IsApproximatelyEqual(0.10D, 0.12D, decimals: 1));
            Assert.IsTrue(StatisticsHelper.IsApproximatelyEqual(0.01D, 0.00D, decimals: 1));
            Assert.IsTrue(StatisticsHelper.IsApproximatelyEqual(0.01D, 0.009D, decimals: 2));
            Assert.IsTrue(StatisticsHelper.IsApproximatelyEqual(0.01D, 0.009D, decimals: 1));

            // Negative Tests
            Assert.IsFalse(StatisticsHelper.IsApproximatelyEqual(0.01D, 0.00D, decimals: 2));
        }
예제 #7
0
            internal PerformanceMetrics()
            {
                //
                _triangleCount = new StatisticsHelper();
                _batchCount    = new StatisticsHelper();
                _drawCount     = new StatisticsHelper();
                _frameRate     = new StatisticsHelper();

                //
                _timer = new Interval(1F);
            }
        private void OperatorSuccess(User user, string channelName, string ip, string versionName, JObject responseData)
        {
            responseData.Add(MyCommon.CODE, (int)Consts.Code.Code_OK);
            responseData.Add(MyCommon.UID, user.Uid);

            //更新下用户的任务
            MySqlUtil.UpdateUserTask(user.Uid);

            StatisticsHelper.StatisticsLogin(user.Uid);

            StatictisLogUtil.Login(user.Uid, user.Username, ip, channelName, versionName, MyCommon.OpType.Login);
        }
        public JsonResult Statistics(StatistiscViewModel model)
        {
            int userId            = UserHelper.GetUserByIdentityName(User.Identity.Name).Id;
            List <SiteCount> data = StatisticsHelper.GetSitesStatistics(
                model.CurrentAttribute, userId, model.StartDate, model.EndDate);

            model.Labels      = GetLabels(data);
            model.CountedData = GetData(data);
            model.Attributes  = GetAttributes();
            model.ChartTypes  = GetChartTypes();
            return(Json(new { labels = model.Labels, countedData = model.CountedData, chartType = model.CurrentChartType }));
        }
예제 #10
0
        static void Main(string[] args)
        {
            BCT.Execute(c => { });
            while (true)
            {
                #region DEBUG
                //var caches = BulletinCollector.GetBulletinsByQuery(@"http://avito.ru", "iPhone");
                //caches = BulletinCollector.GetBulletinsBySheets(caches);
                #endregion
                Console.Write("BC> ");
                var text = Console.ReadLine();
                BCT.Execute(c =>
                {
                    var enterArgs = text.Split(new[] { " -" }, StringSplitOptions.None);
                    var command   = enterArgs[0];
                    switch (command)
                    {
                    case "TaskGeneration":
                        GenerationHelpers.GenerationFull();
                        break;

                    case "TaskGenerationClear":
                        GenerationHelpers.GenerationClearData();
                        break;

                    case "NextTask":
                        var r2 = BackTaskHelper.Next();
                        r2     = r2;
                        break;

                    case "RunStatisticsTasks":
                        StatisticsHelper.RunUserStatisticsTask(new Guid("43461B22-1BC4-4584-8DB8-FA930CB331C5"));
                        break;

                    case "ComputeStatisticsTasks":
                        StatisticsHelper.ComputeUserStatistics(new Guid("43461B22-1BC4-4584-8DB8-FA930CB331C5"));
                        break;

                    case "GetCalls":
                        StatisticsHelper.GetCallsStatistics(new Guid("43461B22-1BC4-4584-8DB8-FA930CB331C5"));
                        break;

                    case "help":
                        Console.WriteLine(Help);
                        break;

                    default:
                        Console.WriteLine("Command not found");
                        break;
                    }
                });
            }
        }
        public void IsApproximatelyEqual_Test_NonFractions()
        {
            // Positive Tests
            Assert.IsTrue(StatisticsHelper.IsApproximatelyEqual(0, 0, decimals: 10));
            Assert.IsTrue(StatisticsHelper.IsApproximatelyEqual(0D, 0D, decimals: 10));

            // Negative Tests
            Assert.IsFalse(StatisticsHelper.IsApproximatelyEqual(0D, 1D, decimals: 1));
            Assert.IsFalse(StatisticsHelper.IsApproximatelyEqual(0, 1, decimals: 10));
            Assert.IsFalse(StatisticsHelper.IsApproximatelyEqual(0D, 1D, decimals: 10));
            Assert.IsFalse(StatisticsHelper.IsApproximatelyEqual(500D, 2D, decimals: 15));
        }
예제 #12
0
        /// <summary>
        ///     Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        ///     A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString( )
        {
            IXmlLineInfo lineInfo = Source;

            return(string.Format(@"  Entity Id: {0}
  Field Id: {1}
  Mode: {2}
  Reason: {3}
  Value: {4}
  Node: {5}
  Line: {6}
  Position: {7}", EntityUpgradeId.ToString("B"), FieldUpgradeId.ToString("B"), StatisticsHelper.Capitalize(Mode.ToString( )), StatisticsHelper.Capitalize(Reason.ToString( )), Value, Source, lineInfo.HasLineInfo( ) ? lineInfo.LineNumber.ToString( ) : "N/A", lineInfo.HasLineInfo( ) ? lineInfo.LinePosition.ToString( ) : "N/A"));
        }
예제 #13
0
        public PartnerMonthlyStatistics GetPartnerMonthlyStatistics(Partner partner)
        {
            var paymentStatistics = new UserRepository(Db).GetPaymentStatistics(partner.User.Id);

            var x = new PartnerMonthlyStatistics
            {
                MonthlyIncome =
                    paymentStatistics.Single(ps => ps.Month == StatisticsHelper.GetLastMonthNumber()).Value,
                Balance = partner.User.GetTotalCash()
            };

            return(x);
        }
        public ActionResult ProductsWithDateEnd()
        {
            Statistics stat = new Statistics();

            stat.DateEnd120 = null;
            List <Product> productList120 = new List <Product>();
            List <Product> productList90  = new List <Product>();
            List <Product> productList60  = new List <Product>();

            foreach (var item in db.Products)
            {
                TimeSpan ts   = item.DateEnd - DateTime.Now;
                int      time = ts.Days;

                Product prod = null;
                if (time <= 120 && time > 90)
                {
                    prod = item;
                    //productList.Add(item);
                    //stat.DateEnd120.Add(prod);
                    productList120.Add(item);
                }
                else if (time <= 90 && time > 60)
                {
                    StatisticsHelper statHelper = new StatisticsHelper();
                    statHelper.Name    = item.ProductName;
                    statHelper.Price   = item.ProductPrice;
                    statHelper.DateEnd = item.DateEnd;
                    //productList.Add(item);
                    //stat.DateEnd90.Add(statHelper);
                    productList90.Add(item);
                }
                else if (time <= 60)
                {
                    StatisticsHelper statHelper = new StatisticsHelper();
                    statHelper.Name    = item.ProductName;
                    statHelper.Price   = item.ProductPrice;
                    statHelper.DateEnd = item.DateEnd;
                    //productList.Add(item);
                    //stat.DateEnd60.Add(statHelper);
                    productList60.Add(item);
                }
                stat.DateEnd120 = productList120;
                stat.DateEnd90  = productList90;
                stat.DateEnd60  = productList60;
            }


            return(View(stat));
        }
예제 #15
0
        // Computes the covariance matrix for a list of points.
        private static MatrixF ComputeCovarianceMatrixFromPoints(IList <Vector3> points)
        {
            // Convert IList<Vector3> to IList<VectorF> which is required for PCA.
            int            numberOfPoints = points.Count;
            List <VectorF> pointsCopy     = new List <VectorF>(numberOfPoints);

            for (int i = 0; i < numberOfPoints; i++)
            {
                var point = points[i];
                pointsCopy.Add(point.ToVectorF());
            }

            return(StatisticsHelper.ComputeCovarianceMatrix(pointsCopy));
        }
예제 #16
0
        // Methods

        public override bool ExecuteCommand()
        {
            // Initialize the text-to-Id mappers:
            int gold_i = 0;

            featureToFeatureId = new TextIdMapper();
            classToClassId     = new TextIdMapper();
            TextIdMapper[] headerToHeaderIds = new TextIdMapper[] { classToClassId };

            // Workaround: Read everything from STDIN to a file. (Files are used as the text source throughout this application.)
            var svmLight_data = Console.In.ReadToEnd();

            Console.Error.WriteLine("{0} characters of input received.", svmLight_data.Length);
            string tempFile = Path.GetTempFileName();

            int[] goldClasses;
            List <FeatureVector> vectors;

            try
            {
                File.WriteAllText(tempFile, svmLight_data);
                FeatureVectorFile vectorFile = new FeatureVectorFile(path: tempFile, noOfHeaderColumns: 1, featureDelimiter: ' ', isSortRequired: false);

                vectors     = vectorFile.LoadFromSVMLight(featureToFeatureId, headerToHeaderIds, FeatureType.Binary);
                goldClasses = vectorFile.Headers[gold_i];
            }
            finally
            {
                File.Delete(tempFile);
            }
            Debug.Assert(vectors.Count > 0);

            IdValuePair <double>[] chiSquare = new IdValuePair <double> [featureToFeatureId.Count];
            //TODO: Make the implementation less binary dependent (i.e. the hardcoded 2 below).
            double[][,] contingencyTable_f = new double[featureToFeatureId.Count][, ];
            for (int f_i = 0; f_i < featureToFeatureId.Count; f_i++)
            {
                // Create a contingency table for this vector.
                contingencyTable_f[f_i] = new double[classToClassId.Count, 2];
                for (int v_i = 0; v_i < vectors.Count; v_i++)
                {
                    FeatureVector v = vectors[v_i];
                    contingencyTable_f[f_i][v.Headers[gold_i], (int)v.Features[f_i]]++;
                }
                chiSquare[f_i] = new IdValuePair <double>(f_i, StatisticsHelper.CalculateChiSquare(contingencyTable_f[f_i]));
            }
            ReportChiSquareResults(contingencyTable_f, chiSquare);
            return(true);
        }
 public override void Calculate(MainWindow mainWindow, MainViewModel mainViewModel)
 {
     if (InputFieldsIsValid(mainWindow))
     {
         mainWindow.GetValues(out var a, out var r0, out var m, out var max);
         var randomValues = GenerateValues(a, r0, m, max);
         mainWindow.GetExpValues(out double lambda);
         var expValues = ExponentialDistribution(randomValues, lambda).ToList();
         StatisticsHelper.CalculateStatistics(expValues, out double expectedValue,
                                              out double dispersion, out double squareDeviation);
         mainWindow.UpdateStatistics(expectedValue, dispersion, squareDeviation);
         var model = PlotModelGenerator.GenerateModel(expValues);
         mainViewModel.UpdatePlotModel(model);
     }
 }
예제 #18
0
        private async Task ViewLoaded()
        {
            if (!_viewModelLoaded)
            {
                IsBusy = true;
                var athlete = await _stravaService.GetAthleteAsync();

                var statistics = await _stravaService.GetStatsAsync(athlete.Id.ToString());

                RunStatistics    = StatisticsHelper.GetRunStatistics(statistics);
                RideStatistics   = StatisticsHelper.GetRideStatistics(statistics);
                _viewModelLoaded = true;
                IsBusy           = false;
            }
        }
예제 #19
0
        public void Softmax_Create_Test()
        {
            var output = NormalizationHelper.CreateSoftmaxNormalization(givenInput);

            Assert.IsTrue(!object.ReferenceEquals(output, givenInput));
            double sum = 0;

            for (int i = 0; i < givenInput.Count; i++)
            {
                double diff = Math.Abs(expectedOutput[i] - output[i]);
                Assert.IsTrue(diff < Math.Pow(10, -6));
                sum += output[i];
            }
            Assert.IsTrue(StatisticsHelper.IsApproximatelyEqual(sum, 1D));
        }
        public void IsWholeNumber_Success()
        {
            double [] wholes    = { 0.0, 9.0, 5.0, -5.0, 100.0, 932.0, 454.0, 7983.0 };
            double [] notWholes = { 9.7, 7.65, 4.3, -0.1, 0.00000000001, 0.03, 834.56, 99.99 };

            foreach (var whole in wholes)
            {
                Assert.True(StatisticsHelper.IsWholeNumber(whole));
            }

            foreach (var notWhole in notWholes)
            {
                Assert.False(StatisticsHelper.IsWholeNumber(notWhole));
            }
        }
 public override void Calculate(MainWindow mainWindow, MainViewModel mainViewModel)
 {
     if (InputFieldsIsValid(mainWindow))
     {
         mainWindow.GetValues(out var a, out var r0, out var m, out var max);
         mainWindow.GetSimpsValues(out double A, out double B);
         var randomValues = GenerateValues(a, r0, m, max, A / 2, B / 2);
         var simpsonValue = SimpsonDistribution(randomValues).ToList();
         StatisticsHelper.CalculateStatistics(simpsonValue, out double expectedValue,
                                              out double dispersion, out double squareDeviation);
         mainWindow.UpdateStatistics(expectedValue, dispersion, squareDeviation);
         var model = PlotModelGenerator.GenerateModel(simpsonValue);
         mainViewModel.UpdatePlotModel(model);
     }
 }
예제 #22
0
 public override void Calculate(MainWindow mainWindow, MainViewModel mainViewModel)
 {
     if (InputFieldsIsValid(mainWindow))
     {
         mainWindow.GetValues(out var a, out var r0, out var m, out var max);
         var randomValues = GenerateValues(a, r0, m, max);
         mainWindow.GetTriangleValue(out bool isMin, out double A, out double B);
         var triangleValues = TriangleDistribution(randomValues, isMin, A, B).ToList();
         StatisticsHelper.CalculateStatistics(triangleValues, out double expectedValue,
                                              out double dispersion, out double squareDeviation);
         mainWindow.UpdateStatistics(expectedValue, dispersion, squareDeviation);
         var model = PlotModelGenerator.GenerateModel(triangleValues);
         mainViewModel.UpdatePlotModel(model);
     }
 }
예제 #23
0
        public void Softmax_InPlace_Test()
        {
            var values = givenInput.ToArray();

            Assert.IsTrue(!object.ReferenceEquals(values, givenInput));
            NormalizationHelper.Softmax(values);
            double sum = 0;

            for (int i = 0; i < values.Length; i++)
            {
                double diff = Math.Abs(expectedOutput[i] - values[i]);
                Assert.IsTrue(diff < Math.Pow(10, -6));
                sum += values[i];
            }
            Assert.IsTrue(StatisticsHelper.IsApproximatelyEqual(sum, 1D));
        }
        public override void Calculate(MainWindow mainWindow, MainViewModel mainViewModel)
        {
            if (InputFieldsIsValid(mainWindow))
            {
                mainWindow.GetValues(out var a, out var r0, out var m, out var max);
                var randomValues = GenerateValues(a, r0, m, max);
                mainWindow.GetGaussValues(out double matWait, out double gaussDispersion);
                var gaussValues = GaussianDistribution(randomValues, matWait, gaussDispersion);

                StatisticsHelper.CalculateStatistics(gaussValues, out double expectedValue,
                                                     out double dispersion, out double squareDeviation);
                mainWindow.UpdateStatistics(expectedValue, dispersion, squareDeviation);
                var model = PlotModelGenerator.GenerateModel(gaussValues);
                mainViewModel.UpdatePlotModel(model);
            }
        }
예제 #25
0
        internal ParsedEvtcLog(int evtcVersion, FightData fightData, AgentData agentData, SkillData skillData,
                               List <CombatItem> combatItems, List <Player> playerList, IReadOnlyDictionary <uint, AbstractExtensionHandler> extensions, long evtcLogDuration, EvtcParserSettings parserSettings, ParserController operation)
        {
            FightData      = fightData;
            AgentData      = agentData;
            SkillData      = skillData;
            PlayerList     = playerList;
            ParserSettings = parserSettings;
            _operation     = operation;
            var friendlies = new List <AbstractSingleActor>();

            friendlies.AddRange(playerList);
            friendlies.AddRange(fightData.Logic.NonPlayerFriendlies);
            Friendlies = friendlies;
            //
            FriendliesListBySpec = friendlies.GroupBy(x => x.Spec).ToDictionary(x => x.Key, x => x.ToList());
            PlayerAgents         = new HashSet <AgentItem>(playerList.Select(x => x.AgentItem));
            FriendlyAgents       = new HashSet <AgentItem>(friendlies.Select(x => x.AgentItem));
            _operation.UpdateProgressWithCancellationCheck("Creating GW2EI Combat Events");
            CombatData = new CombatData(combatItems, FightData, AgentData, SkillData, playerList, operation, extensions, evtcVersion);
            operation.UpdateProgressWithCancellationCheck("Checking CM");
            FightData.SetCM(CombatData, AgentData);
            operation.UpdateProgressWithCancellationCheck("Setting Fight Name");
            FightData.SetFightName(CombatData, AgentData);
            //
            _operation.UpdateProgressWithCancellationCheck("Checking Success");
            FightData.Logic.CheckSuccess(CombatData, AgentData, FightData, PlayerAgents);
            if (FightData.FightDuration <= ParserSettings.TooShortLimit)
            {
                throw new TooShortException(FightData.FightDuration, ParserSettings.TooShortLimit);
            }
            if (ParserSettings.SkipFailedTries && !FightData.Success)
            {
                throw new SkipException();
            }
            _operation.UpdateProgressWithCancellationCheck("Creating GW2EI Log Meta Data");
            LogData = new LogData(evtcVersion, CombatData, evtcLogDuration, playerList, extensions, operation);
            //
            _operation.UpdateProgressWithCancellationCheck("Creating Buff Container");
            Buffs = new BuffsContainer(LogData.GW2Build, CombatData, operation);
            _operation.UpdateProgressWithCancellationCheck("Creating Damage Modifier Container");
            DamageModifiers = new DamageModifiersContainer(LogData.GW2Build, fightData.Logic.Mode, parserSettings);
            _operation.UpdateProgressWithCancellationCheck("Creating Mechanic Data");
            MechanicData = FightData.Logic.GetMechanicData();
            _operation.UpdateProgressWithCancellationCheck("Creating General Statistics Container");
            StatisticsHelper = new StatisticsHelper(CombatData, PlayerList, Buffs);
        }
예제 #26
0
        /// <summary>
        /// Calculates both the Zscore and Percentile.
        /// </summary>
        /// <param name="indicator">The growth indicator</param>
        /// <param name="measurement">The specified measured value</param>
        /// <param name="ageInDays">The age in total days</param>
        /// <param name="sex">Human sex designation per ISO/IEC 5218 code</param>
        /// <returns>Returns the z-score and percentile for a growth measure using a specified value.</returns>
        public static async Task <Tuple <double, double> > GetScore(Indicator indicator, double measurement, double ageInDays, Sex sex)
        {
            WHO2006 who2006 = new();

            double z = 0.0;
            double p = 0.0;

            if (who2006.TryCalculateZScore(indicator, measurement, ageInDays, sex, z: ref z))
            {
                p = await Task.FromResult(StatisticsHelper.CalculatePercentile(z));
            }

            z = Math.Round(z, 2);
            p = Math.Round(p, 1);

            return(Tuple.Create(z, p));
        }
예제 #27
0
        private void Init()
        {
            var task = Task.Run(async() => { await PopulateRecordings(); });

            task.Wait();

            task = Task.Run(async() => { await PopulatePlaces(); });
            task.Wait();

            CreateFoldersStructure();
            if (RecordingsList.Count > 0)
            {
                GuessingHelper.PickNewRecord();
            }
            statistics = StatisticsHelper.LoadStatistics();
            StatisticsListView.ItemsSource = statistics.StatisticsObservableList;
        }
예제 #28
0
        public void TestInitialise()
        {
            _ClassFactorySnapshot = Factory.TakeSnapshot();

            _Statistics       = StatisticsHelper.CreateLockableStatistics();
            _HeartbeatService = TestUtilities.CreateMockSingleton <IHeartbeatService>();

            _Clock = new ClockMock();
            Factory.Singleton.RegisterInstance <IClock>(_Clock.Object);

            _Presenter = Factory.Singleton.Resolve <IStatisticsPresenter>();
            _View      = TestUtilities.CreateMockInstance <IStatisticsView>();

            _View.Setup(r => r.Statistics).Returns(_Statistics.Object);
            _View.Setup(r => r.AdsbMessageTypeCount).Returns(new long[256]);
            _View.Setup(r => r.ModeSDFStatistics).Returns(new ModeSDFStatistics[32]);
            _View.Setup(r => r.AdsbMessageFormatCount).Returns(new long[Enum.GetValues(typeof(MessageFormat)).OfType <MessageFormat>().Select(r => (int)r).Max() + 1]);
        }
        public void ExecuteCommand_MaxEnt_Classify_Test()
        {
            // Set up the parameters:
            using (var vectors_inFile = new TempFile(Resources.SVMLight_TestVectors))
                using (var model_inFile = new TempFile(Resources.Model_MaxEnt_Mallet))
                    using (var sys_outFile = new TempFile())
                    {
                        // Initialize the commmand parameters:
                        string   command = $"maxent_classify {vectors_inFile.Location} {model_inFile.Location} {sys_outFile.Location}";
                        string[] args    = TextHelper.SplitOnWhitespace(command);

                        // Execute the command:
                        double accuracy = (double)CommandPlatform.Execute(args);

                        // Confirm the result:
                        Assert.IsTrue(StatisticsHelper.IsApproximatelyEqual(accuracy, 0.82667D, 5));
                    }
        }
예제 #30
0
 /// <summary>
 /// Logs the trip between this waypoint (the 'origin') and the other waypoint (the 'destination').
 /// </summary>
 /// <param name="destinationWP">The destination waypoint of the trip to log.</param>
 /// <param name="bot">The bot that did the trip.</param>
 protected void StatPropagateDestination(Waypoint destinationWP, Bot bot)
 {
     // Init logging if not already done
     if (_statForwardStar == null)
     {
         _statForwardStar = new Dictionary <Waypoint, ConnectionStatisticsDataPoint>();
     }
     if (destinationWP._statBackwardStar == null)
     {
         destinationWP._statBackwardStar = new Dictionary <Waypoint, ConnectionStatisticsDataPoint>();
     }
     // --> Log forward stars of this origin waypoint
     if (!_statForwardStar.ContainsKey(destinationWP))
     {
         _statForwardStar[destinationWP] = StatInitTripDataPoint(this, destinationWP, Instance.Controller.CurrentTime - bot.StatLastTripStartTime);
     }
     else
     {
         StatisticsHelper.UpdateAvgVarData(
             ref _statForwardStar[destinationWP].Count,
             ref _statForwardStar[destinationWP].TravelTimeAvg,
             ref _statForwardStar[destinationWP].TravelTimeVar,
             ref _statForwardStar[destinationWP].TravelTimeMin,
             ref _statForwardStar[destinationWP].TravelTimeMax,
             ref _statForwardStar[destinationWP].TravelTimeSum,
             Instance.Controller.CurrentTime - bot.StatLastTripStartTime);
     }
     // --> Log backward stars of destination waypoint
     if (!destinationWP._statBackwardStar.ContainsKey(this))
     {
         destinationWP._statBackwardStar[this] = StatInitTripDataPoint(destinationWP, this, Instance.Controller.CurrentTime - bot.StatLastTripStartTime);
     }
     else
     {
         StatisticsHelper.UpdateAvgVarData(
             ref destinationWP._statBackwardStar[this].Count,
             ref destinationWP._statBackwardStar[this].TravelTimeAvg,
             ref destinationWP._statBackwardStar[this].TravelTimeVar,
             ref destinationWP._statBackwardStar[this].TravelTimeMin,
             ref destinationWP._statBackwardStar[this].TravelTimeMax,
             ref destinationWP._statBackwardStar[this].TravelTimeSum,
             Instance.Controller.CurrentTime - bot.StatLastTripStartTime);
     }
 }