Пример #1
0
    private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
    {
      using (StreamWriter sw = new StreamWriter(this.saveFileDialog.FileName))
      { // Write distribution info and properties to file.
        sw.WriteLine( AssemblyDescription);
        sw.WriteLine("Version " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
        // Get parameter names (null "" if no parameter).
        int i = distribution.SelectedIndex;
        distributionValueLabel.Text = boost_math.any_distribution.distribution_name(i).ToString();
        sw.WriteLine(distributionValueLabel.Text + " distribution");
        parameterLabel1.Text = boost_math.any_distribution.first_param_name(i).ToString();
        parameterLabel2.Text = boost_math.any_distribution.second_param_name(i).ToString();
        parameterLabel3.Text = boost_math.any_distribution.third_param_name(i).ToString();
        string separator = "\t "; // , or tab or space?
        // Write parameter name & value.
        sw.WriteLine(parameterLabel1.Text + separator + this.parameter1.Text);
        if (boost_math.any_distribution.second_param_name(i).Length.CompareTo(0) != 0)
        { // Is a 2nd parameter.
          sw.WriteLine(parameterLabel2.Text + separator +  this.parameter2.Text);
        }
        if (boost_math.any_distribution.third_param_name(i).Length.CompareTo(0) != 0)
        { // Is a 3rd parameter.
          sw.WriteLine(parameterLabel3.Text + separator + this.parameter3.Text);
        }
        sw.WriteLine();
        sw.WriteLine("Properties");
        // Show computed properties of distribution.
        double x = double.Parse(parameter1.Text);
        double y = double.Parse(parameter2.Text);
        double z = double.Parse(parameter3.Text);
        dist = new boost_math.any_distribution(i, x, y, z);
        // Note global dist might not have been calculated yet if no of the tabs clicked.
        try
        {
            mean.Text = dist.mean().ToString();
        }
        catch
        {
            mean.Text = "Undefined";
        }
        sw.WriteLine("Mean" + separator + mean.Text);
        try
        {
            mode.Text = dist.mode().ToString();
        }
        catch
        {
            mode.Text = "Undefined";
        }
        sw.WriteLine("mode" + separator + mode.Text);
        try
        {
            median.Text = dist.median().ToString();
        }
        catch
        {
            median.Text = "Undefined";
        }
        sw.WriteLine("Median" + separator + median.Text);
        try
        {
            variance.Text = dist.variance().ToString();
        }
        catch
        {
            variance.Text = "Undefined";
        }
        sw.WriteLine("Variance" + separator + variance.Text);
        try
        {
            standard_deviation.Text = dist.standard_deviation().ToString();
        }
        catch
        {
            standard_deviation.Text = "Undefined";
        }
        sw.WriteLine("Standard Deviation" + separator + standard_deviation.Text);
        try
        {
            skewness.Text = dist.skewness().ToString();
        }
        catch
        {
            skewness.Text = "Undefined";
        }
        sw.WriteLine("Skewness" + separator + skewness.Text);
        try
        {
            coefficient_of_variation.Text = dist.coefficient_of_variation().ToString();
        }
        catch
        {
            coefficient_of_variation.Text = "Undefined";
        }
        sw.WriteLine("Cofficient of variation" + separator + coefficient_of_variation.Text);
        try
        {
            kurtosis.Text = dist.kurtosis().ToString();
        }
        catch
        {
            kurtosis.Text = "Undefined";
        }
        sw.WriteLine("Kurtosis" + separator + kurtosis.Text);
        try
        {
            kurtosis_excess.Text = dist.kurtosis_excess().ToString();
        }
        catch
        {
            kurtosis_excess.Text = "Undefined";
        }
        sw.WriteLine("Kurtosis excess" + separator + kurtosis_excess.Text);
        sw.WriteLine();

        sw.WriteLine("Range from" + separator + dist.lowest().ToString() + separator +
        "to" + separator + dist.uppermost().ToString());
        sw.WriteLine("Support from " + separator + dist.lower().ToString() +separator+
        "to " + separator + dist.upper().ToString());
        sw.WriteLine();

        //
        sw.WriteLine("Quantiles");
        if (QuantileData.Rows.Count == 1)
        { // Add some defaults:
          QuantileData.Rows.Add(5); // 5 Risk levels.
          QuantileData.Rows[0].Cells[0].Value = "0.001"; // Risk values as text,
          QuantileData.Rows[0].Cells[1].Value = dist.quantile(0.001); // & as double.
          QuantileData.Rows[0].Cells[2].Value = dist.quantile_c(0.001);
          QuantileData.Rows[1].Cells[0].Value = "0.01";
          QuantileData.Rows[1].Cells[1].Value = dist.quantile(0.01); // 99% confidence.
          QuantileData.Rows[1].Cells[2].Value = dist.quantile_c(0.01);
          QuantileData.Rows[2].Cells[0].Value = "0.05";
          QuantileData.Rows[2].Cells[1].Value = dist.quantile(0.05);
          QuantileData.Rows[2].Cells[2].Value = dist.quantile_c(0.05);
          QuantileData.Rows[3].Cells[0].Value = "0.1";
          QuantileData.Rows[3].Cells[1].Value = dist.quantile(0.1);
          QuantileData.Rows[3].Cells[2].Value = dist.quantile_c(0.1);
          QuantileData.Rows[4].Cells[0].Value = "0.33333333333333333";
          QuantileData.Rows[4].Cells[1].Value = dist.quantile(0.33333333333333333);
          QuantileData.Rows[4].Cells[2].Value = dist.quantile_c(0.33333333333333333);
        }
        // else have already been calculated by entering the quantile tab.
        for (int r = 0; r < QuantileData.Rows.Count-1; r++)
        { // Show all the rows of quantiles, including any optional user values.
          sw.WriteLine(QuantileData.Rows[r].Cells[0].Value.ToString() + separator +
            QuantileData.Rows[r].Cells[1].Value.ToString() + separator +
            QuantileData.Rows[r].Cells[2].Value.ToString());
        }
        sw.WriteLine();
        sw.WriteLine("PDF, CDF & complement(s)");
        for (int r = 0; r < CDF_data.Rows.Count-1; r++)
        { // Show all the rows of pdf, cdf, including any optional user values.
          sw.WriteLine(CDF_data.Rows[r].Cells[0].Value.ToString() + separator + // x value.
            CDF_data.Rows[r].Cells[1].Value.ToString() + separator + // pdf
            CDF_data.Rows[r].Cells[2].Value.ToString() + separator + // cdf
            CDF_data.Rows[r].Cells[3].Value.ToString());// cdf complement.
        }
        sw.WriteLine();
    }

    } // saveFileDialog1_FileOk
Пример #2
0
        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            using (StreamWriter sw = new StreamWriter(this.saveFileDialog.FileName))
              { // Write distribution info and properties to file.
            sw.WriteLine( AssemblyDescription);
            sw.WriteLine("Version " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
            // Get parameter names (null "" if no parameter).
            int i = distribution.SelectedIndex;
            distributionValueLabel.Text = boost_math.any_distribution.distribution_name(i).ToString();
            sw.WriteLine(distributionValueLabel.Text + " distribution");
            parameterLabel1.Text = boost_math.any_distribution.first_param_name(i).ToString();
            parameterLabel2.Text = boost_math.any_distribution.second_param_name(i).ToString();
            parameterLabel3.Text = boost_math.any_distribution.third_param_name(i).ToString();
            string separator = "\t "; // , or tab or space?
            // Write parameter name & value.
            sw.WriteLine(parameterLabel1.Text + separator + this.parameter1.Text);
            if (boost_math.any_distribution.second_param_name(i).Length.CompareTo(0) != 0)
            { // Is a 2nd parameter.
              sw.WriteLine(parameterLabel2.Text + separator +  this.parameter2.Text);
            }
            if (boost_math.any_distribution.third_param_name(i).Length.CompareTo(0) != 0)
            { // Is a 3rd parameter.
              sw.WriteLine(parameterLabel3.Text + separator + this.parameter3.Text);
            }
            sw.WriteLine();
            sw.WriteLine("Properties");
            // Show computed properties of distribution.
            double x = double.Parse(parameter1.Text);
            double y = double.Parse(parameter2.Text);
            double z = double.Parse(parameter3.Text);
            dist = new boost_math.any_distribution(i, x, y, z);
            // Note global dist might not have been calculated yet if no of the tabs clicked.
            try
            {
            mean.Text = dist.mean().ToString();
            }
            catch
            {
            mean.Text = "Undefined";
            }
            sw.WriteLine("Mean" + separator + mean.Text);
            try
            {
            mode.Text = dist.mode().ToString();
            }
            catch
            {
            mode.Text = "Undefined";
            }
            sw.WriteLine("mode" + separator + mode.Text);
            try
            {
            median.Text = dist.median().ToString();
            }
            catch
            {
            median.Text = "Undefined";
            }
            sw.WriteLine("Median" + separator + median.Text);
            try
            {
            variance.Text = dist.variance().ToString();
            }
            catch
            {
            variance.Text = "Undefined";
            }
            sw.WriteLine("Variance" + separator + variance.Text);
            try
            {
            standard_deviation.Text = dist.standard_deviation().ToString();
            }
            catch
            {
            standard_deviation.Text = "Undefined";
            }
            sw.WriteLine("Standard Deviation" + separator + standard_deviation.Text);
            try
            {
            skewness.Text = dist.skewness().ToString();
            }
            catch
            {
            skewness.Text = "Undefined";
            }
            sw.WriteLine("Skewness" + separator + skewness.Text);
            try
            {
            coefficient_of_variation.Text = dist.coefficient_of_variation().ToString();
            }
            catch
            {
            coefficient_of_variation.Text = "Undefined";
            }
            sw.WriteLine("Cofficient of variation" + separator + coefficient_of_variation.Text);
            try
            {
            kurtosis.Text = dist.kurtosis().ToString();
            }
            catch
            {
            kurtosis.Text = "Undefined";
            }
            sw.WriteLine("Kurtosis" + separator + kurtosis.Text);
            try
            {
            kurtosis_excess.Text = dist.kurtosis_excess().ToString();
            }
            catch
            {
            kurtosis_excess.Text = "Undefined";
            }
            sw.WriteLine("Kurtosis excess" + separator + kurtosis_excess.Text);
            sw.WriteLine();

            sw.WriteLine("Range from" + separator + dist.lowest().ToString() + separator +
            "to" + separator + dist.uppermost().ToString());
            sw.WriteLine("Support from " + separator + dist.lower().ToString() +separator+
            "to " + separator + dist.upper().ToString());
            sw.WriteLine();

            //
            sw.WriteLine("Quantiles");
            if (QuantileData.Rows.Count == 1)
            { // Add some defaults:
              QuantileData.Rows.Add(5); // 5 Risk levels.
              QuantileData.Rows[0].Cells[0].Value = "0.001"; // Risk values as text,
              QuantileData.Rows[0].Cells[1].Value = dist.quantile(0.001); // & as double.
              QuantileData.Rows[0].Cells[2].Value = dist.quantile_c(0.001);
              QuantileData.Rows[1].Cells[0].Value = "0.01";
              QuantileData.Rows[1].Cells[1].Value = dist.quantile(0.01); // 99% confidence.
              QuantileData.Rows[1].Cells[2].Value = dist.quantile_c(0.01);
              QuantileData.Rows[2].Cells[0].Value = "0.05";
              QuantileData.Rows[2].Cells[1].Value = dist.quantile(0.05);
              QuantileData.Rows[2].Cells[2].Value = dist.quantile_c(0.05);
              QuantileData.Rows[3].Cells[0].Value = "0.1";
              QuantileData.Rows[3].Cells[1].Value = dist.quantile(0.1);
              QuantileData.Rows[3].Cells[2].Value = dist.quantile_c(0.1);
              QuantileData.Rows[4].Cells[0].Value = "0.33333333333333333";
              QuantileData.Rows[4].Cells[1].Value = dist.quantile(0.33333333333333333);
              QuantileData.Rows[4].Cells[2].Value = dist.quantile_c(0.33333333333333333);
            }
            // else have already been calculated by entering the quantile tab.
            for (int r = 0; r < QuantileData.Rows.Count-1; r++)
            { // Show all the rows of quantiles, including any optional user values.
              sw.WriteLine(QuantileData.Rows[r].Cells[0].Value.ToString() + separator +
            QuantileData.Rows[r].Cells[1].Value.ToString() + separator +
            QuantileData.Rows[r].Cells[2].Value.ToString());
            }
            sw.WriteLine();
            sw.WriteLine("PDF, CDF & complement(s)");
            for (int r = 0; r < CDF_data.Rows.Count-1; r++)
            { // Show all the rows of pdf, cdf, including any optional user values.
              sw.WriteLine(CDF_data.Rows[r].Cells[0].Value.ToString() + separator + // x value.
            CDF_data.Rows[r].Cells[1].Value.ToString() + separator + // pdf
            CDF_data.Rows[r].Cells[2].Value.ToString() + separator + // cdf
            CDF_data.Rows[r].Cells[3].Value.ToString());// cdf complement.
            }
            sw.WriteLine();
            }
        }
Пример #3
0
    private void tabPage2_Enter(object sender, EventArgs e)
    { // Properties tab shows distribution's mean, mode, median...
      try
      { // Show chosen distribution name, and parameter names & values.
        int i = distribution.SelectedIndex;
        distributionValueLabel.Text = boost_math.any_distribution.distribution_name(i).ToString();
        parameterLabel1.Text = boost_math.any_distribution.first_param_name(i).ToString();
        parameter1ValueLabel.Text = double.Parse(parameter1.Text).ToString();
        parameterLabel2.Text = boost_math.any_distribution.second_param_name(i).ToString();
        parameter2ValueLabel.Text = double.Parse(parameter2.Text).ToString();
        parameterLabel3.Text = boost_math.any_distribution.third_param_name(i).ToString();
        parameter3ValueLabel.Text = double.Parse(parameter3.Text).ToString();

        // Show computed properties of distribution.
        try
        {
            mean.Text = dist.mean().ToString();
        }
        catch
        {
            mean.Text = "Undefined.";
        }
        try
        {
            mode.Text = dist.mode().ToString();
        }
        catch
        {
            mode.Text = "Undefined.";
        }
        try
        {
            median.Text = dist.median().ToString();
        }
        catch
        {
            median.Text = "Undefined.";
        }
        try
        {
            variance.Text = dist.variance().ToString();
        }
        catch
        {
            variance.Text = "Undefined.";
        }
        try
        {
            standard_deviation.Text = dist.standard_deviation().ToString();
        }
        catch
        {
            standard_deviation.Text = "Undefined.";
        }
        try
        {
            skewness.Text = dist.skewness().ToString();
        }
        catch
        {
            skewness.Text = "Undefined.";
        }
        try
        {
            kurtosis.Text = dist.kurtosis().ToString();
        }
        catch
        {
            kurtosis.Text = "Undefined.";
        }
        try
        {
            kurtosis_excess.Text = dist.kurtosis_excess().ToString();
        }
        catch
        {
            kurtosis_excess.Text = "Undefined.";
        }
        try
        {
            coefficient_of_variation.Text = dist.coefficient_of_variation().ToString();
        }
        catch
        {
            coefficient_of_variation.Text = "Undefined.";
        }

        rangeLowestLabel.Text = dist.lowest().ToString();
        rangeGreatestLabel.Text = dist.uppermost().ToString();
        supportLowerLabel.Text = dist.lower().ToString();
        supportUpperLabel.Text = dist.upper().ToString();
        cdfTabPage.ToolTipText = "Random variate can range from " + rangeLowestLabel.Text
          + " to " + rangeGreatestLabel.Text
          + ",\nbut is said to be supported from " + supportLowerLabel.Text
          + " to " + supportUpperLabel.Text
          + "\nWithin this supported range the PDF and CDF have values between 0 and 1,\nbut below " + supportLowerLabel.Text + " both are zero, and above "
          +  supportUpperLabel.Text + " both are unity";
      }
      catch (SystemException se)
      {
        MessageBox.Show(se.Message, "Calculation Error!");
      }
    }