Esempio n. 1
0
 private void QuantileData_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 { // aka Risk & critical values tab.
   try
   {
     if (e.ColumnIndex == 0)
     {
       int i = e.RowIndex;
       string s = QuantileData.Rows[i].Cells[0].Value.ToString();
       double x = double.Parse(s);
       // Remember x is alpha: 1 - the probability:
       double lcv = dist.quantile(x);
       double ucv = dist.quantile_c(x);
       QuantileData.Rows[i].Cells[1].Value = lcv;
       QuantileData.Rows[i].Cells[2].Value = ucv;
     }
   }
   catch (SystemException se)
   {
     // TODO add some proper handling here!
     MessageBox.Show("Error in probability value: " + se.Message, "Calculation Error");
   }
 }
Esempio n. 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();
            }
        }
Esempio n. 3
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