Ejemplo n.º 1
0
        //Get the example pair for the matrix
        public MatrixData GetExemplar(int col, int numClasses, int startAt = 0, string colName = "")
        {
            int        cols         = NumberOfColumns + numClasses - 1;
            MatrixData exemplarData = new MatrixData(NumberOfRows, cols);

            for (int r = 0; r < NumberOfRows; r++)
            {
                double[] rr = new double[cols];
                int      cc = 0;
                for (int c = 0; c < NumberOfColumns; c++)
                {
                    double d = _data[r, c];
                    if (c == col)
                    {
                        for (int j = 0; j < numClasses; j++)
                        {
                            rr[cc] = 0;
                            if ((j) == ((int)d) - startAt)
                            {
                                rr[cc] = 1;
                            }
                            cc++;
                        }
                    }
                    else
                    {
                        rr[cc] = d;
                        cc++;
                    }
                }
                exemplarData.ChangeRow(r, Array.ConvertAll <double, dynamic>(rr, x => (dynamic)x));
                //exemplarData.ReSetColTypes();
            }
            exemplarData.CopyMetaData(this);
            string headerName = (string.IsNullOrWhiteSpace(colName))? "Exemplar " : colName;

            for (int i = 1; i <= numClasses; i++)
            {
                exemplarData.DetermineColType(cols - i);
                exemplarData.ChangeHeader(cols - i, headerName + (numClasses - i + 1));
            }

            return(exemplarData);
        }