public void CreateColumnsUnivariateDistributions()
        {
            dataGridUnivariateDistributions.AutoGenerateColumns = false;

            var argumentColumn = new DataGridViewTextBoxColumn();

            argumentColumn.Width            = 50;
            argumentColumn.HeaderText       = Languages.GetText("Argument");
            argumentColumn.DataPropertyName = nameof(DistributionFunctionArgument.Argument);
            dataGridUnivariateDistributions.Columns.Add(argumentColumn);

            var distributionTypeColumn = new DataGridViewComboBoxColumn();

            distributionTypeColumn.HeaderText       = Languages.GetText("DistributionType");
            distributionTypeColumn.DataPropertyName = nameof(DistributionFunctionArgument.SettingsType);
            distributionTypeColumn.DataSource       = DisplayNameAndSettingType.DisplayNames;
            distributionTypeColumn.DisplayMember    = nameof(DisplayNameAndSettingType.Name);
            distributionTypeColumn.ValueMember      = nameof(DisplayNameAndSettingType.SettingsType);
            dataGridUnivariateDistributions.Columns.Add(distributionTypeColumn);

            var distributionSettingsColumn = new DataGridViewTextBoxColumn();

            distributionSettingsColumn.ReadOnly         = true;
            distributionSettingsColumn.HeaderText       = Languages.GetText("DistributionSettings");
            distributionSettingsColumn.DataPropertyName = nameof(DistributionFunctionArgument.DistributionSettings);
            dataGridUnivariateDistributions.Columns.Add(distributionSettingsColumn);
        }
Beispiel #2
0
 private void Datagrid_DataError(object sender, DataGridViewDataErrorEventArgs e)
 {
     if (e.Context.HasFlag(DataGridViewDataErrorContexts.Parsing))
     {
         bool parsed = false;
         if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
         {
             var cell = DataGrid[e.ColumnIndex, e.RowIndex];
             if (cell.EditedFormattedValue is string edited && IsFractional(cell.ValueType))
             {
                 edited = edited.Replace(",", ".");
                 try
                 {
                     cell.Value = Convert.ChangeType(edited, cell.ValueType, _nfi);
                     parsed     = true;
                 }
                 catch
                 {
                 }
             }
         }
         if (!parsed)
         {
             MessageBox.Show(e.Exception.Message, Languages.GetText("Exception"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         e.Cancel = false;
     }
     else
     {
         MessageBox.Show(e.Exception.Message, Languages.GetText("Exception"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
        private void SetLanguage()
        {
            Text = Languages.GetText("Distributions");

            btnEvaluate.Text      = Languages.GetText("ButtonEvaluate");
            btnOptimizations.Text = Languages.GetText("Optimizations");
            btnExport.Text        = Languages.GetText("Export");

            checkEvaluateRandomsAlgebra.Text = Languages.GetText("RandomsAlgebra");
            checkEvaluateMonteCarlo.Text     = Languages.GetText("MonteCarlo");
            groupCommonParameters.Text       = Languages.GetText("GroupCommonParameters");

            groupDistributions.Text = Languages.GetText("GroupDistributions");
            groupMultivariate.Text  = Languages.GetText("GroupMultivariate");
            groupResults.Text       = Languages.GetText("GroupResults");
            groupWarnings.Text      = Languages.GetText("GroupWarnings");

            lbModel.Text            = Languages.GetText("LabelModel");
            lbSamplesCount.Text     = Languages.GetText("LabelSamplesCount");
            lbExperimentsCount.Text = Languages.GetText("LabelExperimentsCount");
            lbPocketsCount.Text     = Languages.GetText("LabelPocketsCount");
            lbProbabilityP.Text     = Languages.GetText("LabelProbablility");
            lbChartPoints.Text      = Languages.GetText("LabelChartPoints");


            btnAddUnivariateDistribution.Text     = Languages.GetText("ButtonAdd");
            btnRemoveUnivariateDistribution.Text  = Languages.GetText("ButtonRemove");
            btnAddMultivariateDistribution.Text   = Languages.GetText("ButtonAdd");
            btnRemoveMultivariateDistibution.Text = Languages.GetText("ButtonRemove");
        }
Beispiel #4
0
        public MultivariateDistributionSettingsForm(bool showCoeff, bool showDistributionParameters)
        {
            InitializeComponent();

            Text           = Languages.GetText("MultivariateDistribution");
            btnOk.Text     = Languages.GetText("ButtonOk");
            btnCancel.Text = Languages.GetText("ButtonCancel");

            groupMatrixParameters.Text       = Languages.GetText("GroupMatrixParameters");
            groupDistributionParameters.Text = Languages.GetText("GroupDistributionParameters");
            btnBuildTables.Text     = Languages.GetText("ButtonBuildTables");
            lbDimensions.Text       = Languages.GetText("Dimensions");
            lbDistributionType.Text = Languages.GetText("DistributionType");
            lbDegreesOfFreedom.Text = Languages.GetText(nameof(StudentGeneralizedDistributionSettings.DegreesOfFreedom));

            groupArguments.Text    = Languages.GetText("Arguments");
            groupCoefficients.Text = Languages.GetText("TableCoeffitients");
            groupMatrix.Text       = Languages.GetText("TableMatrix");
            groupMeans.Text        = Languages.GetText("TableMeans");

            _matrixSource.DataSource    = _matrix;
            _argumentsSource.DataSource = _arguments;
            _meansSource.DataSource     = _means;
            _coeffSource.DataSource     = _coeff;

            comboDistributionType.DataSource = new string[] { Languages.GetText(nameof(MultivariateNormalDistributionSettings)), Languages.GetText(nameof(MultivariateTDistributionSettings)) };

            DataGridManager.StartManage(dataGridArguments);
            DataGridManager.StartManage(dataGridCoefficients);
            DataGridManager.StartManage(dataGridMatrix);
            DataGridManager.StartManage(dataGridMeans);

            groupDistributionParameters.Visible = showDistributionParameters;
            ChangeRowVisibility(1, showCoeff);
        }
Beispiel #5
0
        public static void AddCharts(ZedGraphControl pdf, ZedGraphControl cdf, DistributionsPair distributions, int length)
        {
            AddChart(pdf, cdf, distributions.RandomsAlgebra, Languages.GetText("RandomsAlgebra"), Color.Blue, length);
            AddChart(pdf, cdf, distributions.MonteCarlo, Languages.GetText("MonteCarlo"), Color.Red, length);

            InvalidateChart(pdf);
            InvalidateChart(cdf);
        }
Beispiel #6
0
        public OptimizationsForm()
        {
            InitializeComponent();

            Text = Languages.GetText("Optimizations");
            checkContinuousConvolution.Text = Languages.GetText("CheckContinuous");
            checkFFTConvolution.Text = Languages.GetText("CheckFFT");
            btnOk.Text = Languages.GetText("ButtonOk");
            btnCancel.Text = Languages.GetText("ButtonCancel");
        }
 private void btnOk_Click(object sender, EventArgs e)
 {
     try
     {
         OnOK();
         DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, Languages.GetText("Exception"), MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public CommonDistributionSettingsForm(DistributionSettings settings)
        {
            InitializeComponent();

            Text           = Languages.GetText("DistributionSettings");
            btnOk.Text     = Languages.GetText("ButtonOk");
            btnCancel.Text = Languages.GetText("ButtonCancel");

            _labels    = new Label[] { lbParameter0, lbParameter1, lbParameter2, lbParameter3, lbParameter4 };
            _textBoxes = new TextBox[] { txtParameter0, txtParameter1, txtParameter2, txtParameter3, txtParameter4 };

            _settings = settings;
            OnSettingsSet(settings);
        }
            public SettingsMembers(Label nameHolder, TextBox valueHolder, DistributionSettings owner, PropertyInfo info)
            {
                var name = Languages.GetText(info.Name);

                nameHolder.Text  = name;
                valueHolder.Text = info.GetValue(owner, null)?.ToString();

                nameHolder.Visible  = true;
                valueHolder.Visible = true;

                NameHolder  = nameHolder;
                ValueHolder = valueHolder;
                Owner       = owner;
                Info        = info;
            }
Beispiel #10
0
        public MultivariateDistributionFunctionArgument GetFunctionArgument()
        {
            if (_arguments.Rows.Count > 0)
            {
                string[] args = _arguments.Rows[0].ItemArray.Cast <string>().ToArray();

                var settings = GetSettings();

                return(new MultivariateDistributionFunctionArgument(args, settings));
            }
            else
            {
                throw new Exception(Languages.GetText("ExceptionArgumentsMissing"));
            }
        }
        public static string ExportToText(DistributionsPair pair)
        {
            StringBuilder sb = new StringBuilder();

            if (pair.RandomsAlgebra != null)
            {
                sb.AppendLine(Languages.GetText("RandomsAlgebra"));
                AppendDistribution(sb, pair.RandomsAlgebra);
            }

            if (pair.MonteCarlo != null)
            {
                sb.AppendLine(Languages.GetText("MonteCarlo"));
                AppendDistribution(sb, pair.MonteCarlo);
            }

            return(sb.ToString());
        }
        public void CreateColumnsMuiltivriateDistributions()
        {
            dataGridMultivariateDistributions.AutoGenerateColumns = false;

            var joinedArgumentsColumn = new DataGridViewTextBoxColumn();

            joinedArgumentsColumn.Width            = 100;
            joinedArgumentsColumn.ReadOnly         = true;
            joinedArgumentsColumn.HeaderText       = Languages.GetText("Arguments");
            joinedArgumentsColumn.DataPropertyName = nameof(MultivariateDistributionFunctionArgument.JoinedArguments);
            dataGridMultivariateDistributions.Columns.Add(joinedArgumentsColumn);

            var multivariateDistributionTypeColumn = new DataGridViewTextBoxColumn();

            multivariateDistributionTypeColumn.Width            = 100;
            multivariateDistributionTypeColumn.ReadOnly         = true;
            multivariateDistributionTypeColumn.HeaderText       = Languages.GetText("DistributionType");
            multivariateDistributionTypeColumn.DataPropertyName = nameof(MultivariateDistributionFunctionArgument.DistributionName);
            dataGridMultivariateDistributions.Columns.Add(multivariateDistributionTypeColumn);
        }
Beispiel #13
0
        public MultivariateBasedNormalDistributionSettings GetDistributionSettings()
        {
            if (_coeff.Rows.Count > 0)
            {
                double[] coeff = _coeff.Rows[0].ItemArray.Cast <double>().ToArray();

                var settings = GetSettings();

                if (!(settings is MultivariateNormalDistributionSettings))
                {
                    settings = new MultivariateNormalDistributionSettings(settings.Means, settings.CovarianceMatrix);
                }

                return(new MultivariateBasedNormalDistributionSettings(coeff, (MultivariateNormalDistributionSettings)settings));
            }
            else
            {
                throw new Exception(Languages.GetText("ExceptionCoeffitientsMissing"));
            }
        }
        private static void AppendDistribution(StringBuilder sb, RandomAlgebra.Distributions.BaseDistribution distribution)
        {
            double step = distribution.Step;
            var    inv  = System.Globalization.CultureInfo.CurrentCulture;


            AppendTableLine(sb, Languages.GetText("Argument"), Languages.GetText("PDFTitle"), Languages.GetText("CDFTitle"));

            for (int i = 0; i < distribution.Samples; i++)
            {
                double x = i * distribution.Step + distribution.MinX;

                if (i == distribution.Samples - 1)
                {
                    x = distribution.MaxX;
                }

                AppendTableLine(sb, x.ToString(inv), distribution.ProbabilityDensityFunction(x).ToString(inv), distribution.DistributionFunction(x).ToString(inv));
            }
        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.Filter = "Text|*.txt";

            if (saveFile.ShowDialog(this) == DialogResult.OK)
            {
                try
                {
                    string path   = saveFile.FileName;
                    string toSave = ImportExport.ExportToText(_distributionsPair);
                    System.IO.File.WriteAllText(path, toSave);
                    System.Diagnostics.Process.Start(path);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Languages.GetText("Exception"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public void CreateColumnsResults()
        {
            dataGridResults.AutoGenerateColumns = false;

            var parameterName = new DataGridViewTextBoxColumn();

            parameterName.Width            = 50;
            parameterName.ReadOnly         = true;
            parameterName.HeaderText       = Languages.GetText("ColumnParameterName");
            parameterName.DataPropertyName = nameof(DistributionParameters.Name);
            dataGridResults.Columns.Add(parameterName);

            var randomsAlgebra = new DataGridViewTextBoxColumn();

            randomsAlgebra.Width            = 70;
            randomsAlgebra.ReadOnly         = true;
            randomsAlgebra.HeaderText       = Languages.GetText("RandomsAlgebra");
            randomsAlgebra.DataPropertyName = nameof(DistributionParameters.RandomsAlgebra);
            dataGridResults.Columns.Add(randomsAlgebra);

            var monteCarlo = new DataGridViewTextBoxColumn();

            monteCarlo.Width            = 70;
            monteCarlo.ReadOnly         = true;
            monteCarlo.HeaderText       = Languages.GetText("MonteCarlo");
            monteCarlo.DataPropertyName = nameof(DistributionParameters.MonteCarlo);
            dataGridResults.Columns.Add(monteCarlo);

            var persentRation = new DataGridViewTextBoxColumn();

            persentRation.Width            = 70;
            persentRation.ReadOnly         = true;
            persentRation.HeaderText       = Languages.GetText("ColumnPersentRatio");
            persentRation.DataPropertyName = nameof(DistributionParameters.PersentRatio);
            dataGridResults.Columns.Add(persentRation);
        }
Beispiel #17
0
        public MultivariateDistributionSettings GetSettings()
        {
            if (_matrix.Rows.Count > 0)
            {
                double degrees = (double)numericDegreesOfFreedom.Value;

                double[,] input = new double[_matrix.Columns.Count, _matrix.Rows.Count];

                for (int i = 0; i < _matrix.Columns.Count; i++)
                {
                    for (int j = 0; j < _matrix.Rows.Count; j++)
                    {
                        input[i, j] = (double)_matrix.Rows[j][i];
                    }
                }

                double[] means = _means.Rows[0].ItemArray.Cast <double>().ToArray();

                if (comboDistributionType.SelectedIndex == 0)
                {
                    return(new MultivariateNormalDistributionSettings(means, input));
                }
                else if (comboDistributionType.SelectedIndex == 1)
                {
                    return(new MultivariateTDistributionSettings(means, input, degrees));
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            else
            {
                throw new Exception(Languages.GetText("ExceptionMaxtrixMissing"));
            }
        }
        private void Process()
        {
#if !DEBUG
            try
#endif
            {
                _warningsSource.Clear();

                string expression             = txtFunction.Text;
                bool   evaluateRandomsAlgebra = checkEvaluateRandomsAlgebra.Checked;
                bool   evaluateMonteCarlo     = checkEvaluateMonteCarlo.Checked;

                int samples     = (int)numericSamplesCount.Value;
                int experiments = (int)numericExperimentsCount.Value;
                int pockets     = (int)numericPocketsCount.Value;

                var univariate = DistributionFunctionArgument.CreateDictionary(_argumentsUnivariate);


                var multivariate = MultivariateDistributionFunctionArgument.CreateDictionary(_argumentsMultivariate);
                if (multivariate.Count == 0)
                {
                    multivariate = null;
                }

                Stopwatch sw = Stopwatch.StartNew();

                if (evaluateRandomsAlgebra)
                {
                    sw.Restart();
                    _distributionsPair.RandomsAlgebra = DistributionManager.RandomsAlgebraDistribution(expression, univariate, multivariate, samples);

                    if (_distributionsPair.RandomsAlgebra is ContinuousDistribution continuous)
                    {
                        //_distributionsPair.RandomsAlgebra = continuous.Discretize();
                    }


                    sw.Stop();

                    _distributionsPair.RandomsAlgebraTime = sw.Elapsed;
                }
                else
                {
                    _distributionsPair.RandomsAlgebra     = null;
                    _distributionsPair.RandomsAlgebraTime = null;
                }

                if (evaluateMonteCarlo)
                {
                    sw.Restart();
                    _distributionsPair.MonteCarlo = DistributionManager.MonteCarloDistribution(expression, univariate, multivariate, experiments, pockets);
                    sw.Stop();

                    _distributionsPair.MonteCarloTime = sw.Elapsed;
                }
                else
                {
                    _distributionsPair.MonteCarlo     = null;
                    _distributionsPair.MonteCarloTime = null;
                }

                FillResults();
                FillCharts();
            }
#if !DEBUG
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Languages.GetText("Exception"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
#endif
        }
Beispiel #19
0
 public DisplayNameAndSettingType(Type settingType)
 {
     SettingsType = settingType;
     Name         = Languages.GetText(settingType.Name);
 }
Beispiel #20
0
 public static void PrepareGraph(ZedGraphControl pdf, ZedGraphControl cdf)
 {
     PrepareGraph(pdf, Languages.GetText("PDFTitle"));
     PrepareGraph(cdf, Languages.GetText("CDFTitle"));
 }