Example #1
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();
            }
        }
        /// <summary>
        /// Установка стратегий (настроек)
        /// </summary>
        /// <param name="emulatorSettings"></param>
        /// <returns></returns>
        private StrategiesParameters setParameters(EmulatorSettings emulatorSettings)
        {
            StrategiesParameters parameters = new StrategiesParameters();

            parameters.FilterLength = int.Parse(textFilterLength.Text);

            if (radioFilterMovingAverage.Checked)
                parameters.Filter = FilterType.MovingAverage;
            else if (radioFilterSinglePole.Checked)
            {
                parameters.Filter = FilterType.SignlePole;
                parameters.SinglePoleK = double.Parse(textFilterSinglePoleK.Text, CultureInfo.InvariantCulture);
            }
            else
            {
                parameters.Filter = FilterType.Gaussian;
                parameters.GaussianA = double.Parse(textFilterGaussianA.Text, CultureInfo.InvariantCulture);
            }

            if (radioNoiserIdle.Checked)
            {
                parameters.Noiser = NoiserType.Idle;
            }
            else if (radioNoiserUniform.Checked)
            {
                parameters.Noiser = NoiserType.Uniform;
                parameters.UniformMin = double.Parse(textNoiseUniformMin.Text, CultureInfo.InvariantCulture);
                parameters.UniformMax = double.Parse(textNoiseUniformMax.Text, CultureInfo.InvariantCulture);
            }
            else if (radioNoiserNormal.Checked)
            {
                parameters.Noiser = NoiserType.Normal;
                parameters.NormalMean = double.Parse(textNoiseNormalMean.Text, CultureInfo.InvariantCulture);
                parameters.NormalDeviation = double.Parse(textNoiseNormalDeviation.Text, CultureInfo.InvariantCulture);
            }
            else
                parameters.Noiser = NoiserType.Function;

            if (radioSourceNetwork.Checked)
            {
                parameters.Source = SourceType.Network;
                parameters.IP = IPAddress.Parse(comboIp.Text);

                if (radioSourcePitch.Checked)
                    parameters.Axis = RotationAxis.Pitch;
                else if (radioSourceRoll.Checked)
                    parameters.Axis = RotationAxis.Roll;
                else
                    parameters.Axis = RotationAxis.Yaw;
            }
            else if (radioSourceEmulatorSin.Checked)
            {
                parameters.Source = SourceType.Sin;
                parameters.SinAmplitude = double.Parse(textSourceSinAmplitude.Text, CultureInfo.InvariantCulture);
                parameters.SinAverage = double.Parse(textSourceSinAverage.Text, CultureInfo.InvariantCulture);
                parameters.SinPeriod = double.Parse(textSourceSinPeriod.Text, CultureInfo.InvariantCulture);
            }
            else if (radioSourceEmulatorLinear.Checked)
            {
                parameters.Source = SourceType.Linear;
                parameters.LinearMin = double.Parse(textSourceLinearMin.Text, CultureInfo.InvariantCulture);
                parameters.LinearMax = double.Parse(textSourceLinearMax.Text, CultureInfo.InvariantCulture);
            }
            else
            {
                parameters.Source = SourceType.Fourier;
                parameters.HalfOffset = double.Parse(textSourceFourierHalfOffset.Text, CultureInfo.InvariantCulture);
                parameters.aList = aList;
                parameters.bList = bList;
            }

            parameters.EmulatorSetting = emulatorSettings;

            return parameters;
        }
Example #3
0
        /// <summary>
        /// Устанавилвает стратегии
        /// </summary>
        /// <param name="parameters"></param>
        private void setStrategies(StrategiesParameters parameters)
        {
            input = new List<double>();
            output = new List<double>();
            pure = new List<double>();
            noise = new List<double>();

            switch (parameters.Filter)
            {
                case FilterType.MovingAverage:
                    filter = new FilterMovingAverage(parameters.FilterLength);                       break;
                case FilterType.SignlePole:
                    filter = new FilterSinglePole(parameters.FilterLength, parameters.SinglePoleK);  break;
                case FilterType.Gaussian:
                    filter = new FilterGaussian(parameters.FilterLength, parameters.GaussianA);      break;
            }
               
            switch (parameters.Noiser)
            {
                case NoiserType.Idle:
                    noiser = new NoiserIdle();                                                    break;
                case NoiserType.Uniform:
                    noiser = new NoiserUniform(parameters.UniformMin, parameters.UniformMax);     break;
                case NoiserType.Normal:
                    noiser = new NoiserNormal(parameters.NormalMean, parameters.NormalDeviation); break;
                case NoiserType.Function:
                    noiser = new NoiserFunction(ExtraMath.PieceWiseExample1);                     break;
            }

            if (parameters.Source == SourceType.Network)
            {
                udpThread = new UdpThread();
                udpThread.Start();

                IsEmulation = false;

                source = new SourceNetwork(parameters.Axis, parameters.IP);
            }
            else
            {
                IsEmulation = true;

                switch (parameters.Source)
                {
                    case SourceType.Sin:
                        source = new SourceEmulatorSin(emulatorSettings, noiser, parameters.SinAmplitude, parameters.SinAverage, parameters.SinPeriod);
                        break;
                    case SourceType.Linear:
                        source = new SourceEmulatorLinear(emulatorSettings, noiser, parameters.LinearMin, parameters.LinearMax);
                        break;
                    case SourceType.Fourier:
                        source = new SourceEmulatorFourier(emulatorSettings, noiser, parameters.HalfOffset, parameters.aList, parameters.bList);
                        break;
                }
            }
        }