Example #1
0
        //-------------------------------------------------

        public double [] Consensus()
        {
            List <int> aDimVector = MyInputVectors[0].Dims;

            double[] consensus = new double[aDimVector.Count];
            foreach (sparseMatrixRow smr in MyInputVectors)
            {
                //We should make a clone
                sparseMatrixRow cv = new sparseMatrixRow(0);

                foreach (double v in smr.Values)
                {
                    cv.Values.Add(v);
                }

                cv.ConvertToUnitVector();

                for (int i = 0; i < cv.Values.Count; i++)
                {
                    consensus[i] += cv.Values[i];
                }
            }

            for (int i = 0; i < consensus.Length; i++)
            {
                consensus[i] /= (double)MyInputVectors.Count;
            }

            return(consensus);
        }
        /// <summary>
        /// Returns the sum of the euclidian stress
        /// </summary>
        /// <param name="sn"></param>
        /// <returns></returns>
        public double EStress(SpectralNode sn)
        {
            double eSumm = 0;

            List <double> consensus = sn.Consensus().ToList();

            foreach (sparseMatrixRow r in sn.MyInputVectors)
            {
                sparseMatrixRow cv = new sparseMatrixRow(0);

                foreach (double v in r.Values)
                {
                    cv.Values.Add(v);
                }

                cv.ConvertToUnitVector();

                eSumm += PatternTools.pTools.EuclidianDistance(consensus, cv.Values);
            }

            return(eSumm);
        }
        private void buttonPlotCluster_Click(object sender, EventArgs e)
        {
            List <int> aDimVector = resultsClusterAnalysis[(int)dataGridViewCluster.Rows[0].Cells[1].Value].MyInputVectors[0].Dims;

            double[] consensus  = new double[aDimVector.Count];
            double   conCounter = 0;


            plotDataTable = new DataTable();
            plotDataTable.Columns.Add("ID");
            plotDataTable.Columns.Add("Description");

            DataColumn dc = new DataColumn("Euclidian");

            //dc.DataType = System.Type.GetType("System.Double");

            plotDataTable.Columns.Add(dc);

            for (int i = 0; i < aDimVector.Count; i++)
            {
                DataColumn column = new DataColumn();
                column.DataType = typeof(double);
                plotDataTable.Columns.Add(aDimVector[i].ToString());
            }

            dataGridViewPlotData.AutoGenerateColumns = true;
            dataGridViewPlotData.DataSource          = plotDataTable;

            for (int r = 0; r < dataGridViewCluster.Rows.Count; r++)
            {
                if ((bool)dataGridViewCluster.Rows[r].Cells[0].Value)
                {
                    //Lets Construct a line for each element in the node

                    foreach (sparseMatrixRow inputVector in resultsClusterAnalysis[(int)dataGridViewCluster.Rows[r].Cells[1].Value].MyInputVectors)
                    {
                        conCounter++;

                        //We should make a clone
                        sparseMatrixRow cv = new sparseMatrixRow(0);

                        foreach (double v in inputVector.Values)
                        {
                            cv.Values.Add(v);
                        }

                        cv.ConvertToUnitVector();

                        for (int i = 0; i < cv.Values.Count; i++)
                        {
                            consensus[i] += cv.Values[i];
                        }


                        DataRow row = plotDataTable.NewRow();
                        row["ID"]          = plp.MyIndex.GetName(inputVector.Lable);
                        row["Description"] = plp.MyIndex.GetDescription(inputVector.Lable);

                        for (int i = 0; i < inputVector.Dims.Count; i++)
                        {
                            row[inputVector.Dims[i].ToString()] = cv.Values[i];
                        }

                        plotDataTable.Rows.Add(row);
                    }
                }
            }

            UpdateEuclidian();

            Plot();
        }