Exemplo n.º 1
0
        public void EstimatoCos_Estimate()
        {
            Estimator estimator = new EstimatorCos(pure, output);

            double result = estimator.Estimate();

            Assert.IsTrue(ExtraMath.EqualValue(result, 0.995));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Переключает режим работы между вводом данных и анализом
        /// </summary>
        /// <param name="parameters">Структура с параметрами запуск</param>
        /// <param name="distance">Расстояние</param>
        /// <param name="manhattan">Расстояние Манхеттена</param>
        /// <param name="euclid">Расстояние Евклида</param>
        /// <param name="correlation">Коэффициент корреляции<</param>
        /// <param name="cos">Косинусная мера</param>
        public void Switch(StrategiesParameters parameters, out double distance, out double manhattan, out double euclid, out double correlation, out double cos)
        {
            emulatorSettings = parameters.EmulatorSetting;

            IsEmulation = parameters.Source != SourceType.Network;

            correlation = 0.0;
            euclid = 0.0;
            distance = 0.0;
            manhattan = 0.0;
            cos = 0.0;

            if (!emulatorSettings.Fast)
            {
                if (IsWorking == false)
                {
                    time = 0.0;

                    IsWorking = true;

                    setStrategies(parameters);

                    refreshChart();

                    if ((source != null) && (filter != null) && (noiser != null))
                        source.Start();
                }
                else
                {
                    IsWorking = false;

                    unsetStrategies();

                    if (IsEmulation)
                    {
                        Estimator estimatorDistance = new EstimatorDistance(pure, output);
                        Estimator estimatorManhattan = new EstimatorMinkowski(pure, output, 1.0);
                        Estimator estimatorEuclid = new EstimatorMinkowski(pure, output, 2.0);
                        Estimator estimatorCorrelation = new EstimatorCorrelation(pure, output);
                        Estimator estimatorCos = new EstimatorCos(pure, output);

                        distance = estimatorDistance.Estimate();
                        manhattan = estimatorManhattan.Estimate();
                        euclid = estimatorEuclid.Estimate();
                        correlation = estimatorCorrelation.Estimate();
                        cos = estimatorCos.Estimate();
                    }
                }
            }
            else
            {
                double x = 0.0;

                setStrategies(parameters);

                time = 0.0;

                refreshChart();

                while (x <= emulatorSettings.Range)
                {
                    double currentInput, currentOutput, currentPure;

                    currentInput = ((SourceEmulator)source).GetNext();

                    filter.AddInput(currentInput);

                    currentOutput = filter.GetOutput();
                    currentPure = ((SourceEmulator)source).DataPure;

                    input.Add(currentInput);
                    pure.Add(currentPure);
                    output.Add(currentOutput);

                    mainChart.Series["input"].Points.AddXY(x, currentInput);
                    mainChart.Series["output"].Points.AddXY(x, currentOutput);
                    mainChart.Series["pure"].Points.AddXY(x, currentPure);

                    x += emulatorSettings.Interval / 1000.0;
                }

                Estimator estimatorDistance = new EstimatorDistance(pure, output);
                Estimator estimatorManhattan = new EstimatorMinkowski(pure, output, 1.0);
                Estimator estimatorEuclid = new EstimatorMinkowski(pure, output, 2.0);
                Estimator estimatorCorrelation = new EstimatorCorrelation(pure, output);
                Estimator estimatorCos = new EstimatorCos(pure, output);

                distance = estimatorDistance.Estimate();
                manhattan = estimatorManhattan.Estimate();
                euclid = estimatorEuclid.Estimate();
                correlation = estimatorCorrelation.Estimate();
                cos = estimatorCos.Estimate();
            }
        }