private void properties_tab_Deselecting(object sender, TabControlCancelEventArgs e) { try { if (e.TabPageIndex == 0) { // Update selected distribution object: double x = double.Parse(parameter1.Text); double y = double.Parse(parameter2.Text); double z = double.Parse(parameter3.Text); int i = distribution.SelectedIndex; dist = new boost_math.any_distribution(i, x, y, z); // Clear existing CDF data (has to be a better way?): while (CDF_data.Rows.Count > 1) { CDF_data.Rows.Remove(CDF_data.Rows[0]); } // Clear existing quantile data (has to be a better way?): while (QuantileData.Rows.Count > 1) { QuantileData.Rows.Remove(QuantileData.Rows[0]); } } } catch (SystemException se) { MessageBox.Show(se.Message + " Please check the distribution's parameters and try again.", "Distribution Error"); this.propertiesTab.SelectedIndex = 0; e.Cancel = true; } }
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(); } }
private void properties_tab_Deselecting(object sender, TabControlCancelEventArgs e) { try { if (e.TabPageIndex == 0) { // Update selected distribution object: double x = double.Parse(parameter1.Text); double y = double.Parse(parameter2.Text); double z = double.Parse(parameter3.Text); int i = distribution.SelectedIndex; dist = new boost_math.any_distribution(i, x, y, z); // Clear existing CDF data (has to be a better way?): while (CDF_data.Rows.Count > 1) { CDF_data.Rows.Remove(CDF_data.Rows[0]); } // Clear existing quantile data (has to be a better way?): while (QuantileData.Rows.Count > 1) { QuantileData.Rows.Remove(QuantileData.Rows[0]); } } } catch (SystemException se) { MessageBox.Show(se.Message + " Please check the distribution's parameters and try again.", "Distribution Error"); this.propertiesTab.SelectedIndex = 0; e.Cancel = true; } }
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