//---------------------------------------------


        #region Protected Methods
        /// <summary>
        ///   Creates additional information about principal components.
        /// </summary>
        ///
        protected void CreateDiscriminants()
        {
            int numDiscriminants = eigenvalues.Length;

            discriminantProportions = new double[numDiscriminants];
            discriminantCumulative  = new double[numDiscriminants];


            // Calculate total scatter matrix
            int size = Sw.GetLength(0);

            St = new double[size, size];
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    St[i, j] = Sw[i, j] + Sb[i, j];
                }
            }


            // Calculate proportions
            double sum = 0.0;

            for (int i = 0; i < numDiscriminants; i++)
            {
                sum += System.Math.Abs(eigenvalues[i]);
            }
            sum = (sum == 0) ? 0 : (1.0 / sum);

            for (int i = 0; i < numDiscriminants; i++)
            {
                discriminantProportions[i] = System.Math.Abs(eigenvalues[i]) * sum;
            }


            // Calculate cumulative proportions
            if (numDiscriminants > 0)
            {
                this.discriminantCumulative[0] = this.discriminantProportions[0];
                for (int i = 1; i < this.discriminantCumulative.Length; i++)
                {
                    this.discriminantCumulative[i] = this.discriminantCumulative[i - 1] + this.discriminantProportions[i];
                }
            }


            // Creates the object-oriented structure to hold the linear discriminants
            Discriminant[] discriminants = new Discriminant[numDiscriminants];
            for (int i = 0; i < numDiscriminants; i++)
            {
                discriminants[i] = new Discriminant(this, i);
            }
            this.discriminantCollection = new DiscriminantCollection(discriminants);
        }
Пример #2
0
        /// <summary>
        ///   Creates additional information about principal components.
        /// </summary>
        ///
        protected void CreateDiscriminants()
        {
            if (classCollection == null)
            {
                // Creates simple structures to hold information later
                this.classCount     = new int[NumberOfOutputs];
                this.classMeans     = new double[NumberOfOutputs][];
                this.classStdDevs   = new double[NumberOfOutputs][];
                this.classScatter   = new double[NumberOfOutputs][][];
                this.projectedMeans = new double[NumberOfOutputs][];


                // Creates the object-oriented structure to hold information about the classes
                var collection = new DiscriminantAnalysisClass[NumberOfOutputs];
                for (int i = 0; i < collection.Length; i++)
                {
                    collection[i] = new DiscriminantAnalysisClass(this, i, i);
                }
                this.classCollection = new DiscriminantAnalysisClassCollection(collection);
            }

            int numDiscriminants = eigenvalues.Length;

            discriminantProportions = new double[numDiscriminants];
            discriminantCumulative  = new double[numDiscriminants];


            // Calculate total scatter matrix
            St = Sw.Add(Sb);

            // Calculate proportions
            double sum = 0.0;

            for (int i = 0; i < numDiscriminants; i++)
            {
                sum += System.Math.Abs(eigenvalues[i]);
            }
            sum = (sum == 0) ? 0 : (1.0 / sum);

            for (int i = 0; i < numDiscriminants; i++)
            {
                discriminantProportions[i] = System.Math.Abs(eigenvalues[i]) * sum;
            }


            // Calculate cumulative proportions
            if (numDiscriminants > 0)
            {
                this.discriminantCumulative[0] = this.discriminantProportions[0];
                for (int i = 1; i < this.discriminantCumulative.Length; i++)
                {
                    this.discriminantCumulative[i] = this.discriminantCumulative[i - 1] + this.discriminantProportions[i];
                }
            }


            // Creates the object-oriented structure to hold the linear discriminants
            var discriminants = new Discriminant[numDiscriminants];

            for (int i = 0; i < discriminants.Length; i++)
            {
                discriminants[i] = new Discriminant(this, i);
            }
            this.discriminantCollection = new DiscriminantCollection(discriminants);
        }