SEEUMiner.Library.DescriptiveStatistics.Median C# (CSharp) Method

Median() public method

public Median ( ) : double
return double
        public double Median()
        {
            int pozita;
            double median;
            if (array_items.Length % 2 == 1)
            {

                pozita = (int)Math.Ceiling((double)array_items.Length / 2) - 1;
                median = array_items[pozita];
            }
            else //rasti cift
            {
                pozita = array_items.Length / 2;
                median = (array_items[pozita - 1] + array_items[pozita]) / 2;
            }

            return median;
        }

Usage Example

コード例 #1
0
ファイル: Form1.cs プロジェクト: vshehu/SEEUMiner
        private void button1_Click(object sender, EventArgs e)
        {
            string[] array = txtItems.Text.Split(',');

            double[] dArray = Array.ConvertAll(array, Double.Parse);

            DescriptiveStatistics s = new DescriptiveStatistics(dArray);

            MessageBox.Show("Mesatarja: " + s.Average().ToString());

            MessageBox.Show("Median:" + s.Median().ToString());

            MessageBox.Show("STDEV_Population: " + s.StandardDeviationP().ToString());
            MessageBox.Show("STDEV_Sample: " + s.StandardDeviationS().ToString());

            //CategoricalStatistics s = new CategoricalStatistics(array);

            //foreach (KeyValuePair<object, int> kv in s.Frequency())
            //{
            //    MessageBox.Show(kv.Key.ToString() + " - " + kv.Value.ToString());

            //}

            // test test test
            CategoricalStatistics cs = new CategoricalStatistics(dArray);
               // MessageBox.Show(Convert.ToInt32( cs.CalculateMode()).ToString());

            foreach (KeyValuePair<object, int> kv in cs.CalculateMode())
            {
               // MessageBox.Show("Mode: " + kv.Key.ToString() + "=" + kv.Value.ToString());
                label1.Text = "Mode: " + kv.Key.ToString() + "=" + kv.Value.ToString();
            }
        }