Click here to Skip to main content
15,893,594 members
Articles / Desktop Programming / WPF

The Time Machine

Rate me:
Please Sign up or sign in to vote.
4.91/5 (13 votes)
9 May 2012CPOL6 min read 34.2K   1.2K   32  
Long time strategy of software design and development
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using DiagramUI;
using Regression;
using MathStatistics;

namespace DataPerformerUI.UserControls
{
    /// <summary>
    /// User control for comparation by Fisher criterion
    /// </summary>
    public partial class UserControlFisherComparator : UserControl
    {

        #region Fields

        /// <summary>
        /// Collection of objects
        /// </summary>
        protected ObjectsCollection collection;

        Dictionary<string, AliasRegression> items = new Dictionary<string, AliasRegression>();
        #endregion

        #region Ctor

        /// <summary>
        /// Default constructor
        /// </summary>
        public UserControlFisherComparator()
        {
            InitializeComponent();
            this.LoadResources();
        }

        #endregion

        #region Members

        internal ObjectsCollection Collection
        {
            set
            {
                Type t = value.Type;
                if (!t.Equals(typeof(AliasRegression)))
                {
                    throw new Exception("Illegal type");
                }
                collection = value;
                collection.Object = this;
            }
        }

        /// <summary>
        /// Updetes itself
        /// </summary>
        new protected void Update()
        {
            checkedListBox.Items.Clear();
            items.Clear();
            int n = collection.Count;
            for (int i = 0; i < n; i++)
            {
                AliasRegression ar = collection[i] as AliasRegression;
                string name = collection.GetRelativeName(ar) 
                    + "("  + ar.Dimension + ")";
                checkedListBox.Items.Add(name);
                items[name] = ar;
            }
        }

        private void Compare()
        {
           CheckedListBox.CheckedItemCollection ch = checkedListBox.CheckedItems;
            if (ch.Count != 2)
            {
                return;
            }
            List<AliasRegression> arl = new List<AliasRegression>();
            foreach (string s in ch)
            {
                arl.Add(items[s]);
            }
            int n1 = arl[0].Dimension;
            int n2 = arl[1].Dimension;
            int k1 = n1;
            int k2 = n2;
            AliasRegression[] arr = null;
            if (n1 > n2)
            {
                arr = new AliasRegression[] { arl[0], arl[1] };
            }
            else
            {
                arr = new AliasRegression[] { arl[1], arl[0] };
                k1 = n2;
                k2 = n1;
            }
            double[] ss = new double[2];
            int[] kk = new int[2];
            for (int i = 0; i < ss.Length; i++)
            {
                AliasRegression aa = arr[i];
                int dim = aa.DataDimension - aa.Dimension;
                ss[i] = aa.StandardDeviation / ((double)dim);
                kk[i] = dim;
            }
            double x = StatisticsFunctions.Fisher(kk[0], kk[1], ss[0] / ss[1], 1E-8);
            labelLevel.Text = x + "";
        }

        #endregion

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            Update();
        }

        private void buttonCompare_Click(object sender, EventArgs e)
        {
            Compare();
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions