Esempio n. 1
0
 public static double[] CalcDensity(IMatrixData mdata, int colIndX, int colIndY, int points, bool logarithmicX,
                                    bool logaritmicY, DensityEstimationType type)
 {
     double[] dvals = new double[0];
     double[] xvals = new double[0];
     double[] yvals = new double[0];
     if (logarithmicX && !logaritmicY)
     {
         xvals = GetLog(GetColumn(mdata, colIndX));
         yvals = GetColumn(mdata, colIndY);
     }
     else if (!logarithmicX && logaritmicY)
     {
         xvals = GetColumn(mdata, colIndX);
         yvals = GetLog(GetColumn(mdata, colIndY));
     }
     else if (logarithmicX)
     {
         xvals = GetLog(GetColumn(mdata, colIndX));
         yvals = GetLog(GetColumn(mdata, colIndY));
     }
     else
     {
         xvals = GetColumn(mdata, colIndX);
         yvals = GetColumn(mdata, colIndY);
     }
     (double[,] values, double[] xmat, double[] ymat) = DensityEstimation.CalcDensityOnGrid(xvals, yvals,
                                                                                            points, type);
     DensityEstimation.DivideByMaximum(values);
     double[,] percvalues = CalcExcludedPercentage(values);
     dvals = new double[xvals.Length];
     double[] pvals = new double[xvals.Length];
     for (int i = 0; i < dvals.Length; i++)
     {
         double xx = xvals[i];
         double yy = yvals[i];
         if (!double.IsNaN(xx) && !double.IsNaN(yy))
         {
             int xind = ArrayUtils.ClosestIndex(xmat, xx);
             int yind = ArrayUtils.ClosestIndex(ymat, yy);
             dvals[i] = values[xind, yind];
             pvals[i] = percvalues[xind, yind];
         }
         else
         {
             dvals[i] = double.NaN;
             pvals[i] = double.NaN;
         }
     }
     return(pvals);
 }
        public static double[] CalcDensity(IMatrixData mdata, int colIndx, int colIndy,
                                           int points)
        {
            double[] dvals = new double[0];

            double[] xvals = GetColumn(mdata, colIndx);
            double[] yvals = GetColumn(mdata, colIndy);
            GetValidPairs(xvals, yvals, out double[] xvals1, out double[] yvals1);
            DensityEstimation.CalcRanges(xvals1, yvals1, out double xmin, out double xmax, out double ymin, out double ymax);
            double[,] values = DensityEstimation.GetValuesOnGrid(xvals1, xmin, (xmax - xmin) / points, points, yvals1, ymin,
                                                                 (ymax - ymin) / points, points);

            DensityEstimation.DivideByMaximum(values);
            double[] xmat = new double[points];
            for (int i = 0; i < points; i++)
            {
                xmat[i] = xmin + i * (xmax - xmin) / points;
            }
            double[] ymat = new double[points];
            for (int i = 0; i < points; i++)
            {
                ymat[i] = ymin + i * (ymax - ymin) / points;
            }
            double[,] percvalues = CalcExcludedPercentage(values);
            dvals = new double[xvals.Length];
            double[] pvals = new double[xvals.Length];
            for (int i = 0; i < dvals.Length; i++)
            {
                double xx = xvals[i];
                double yy = yvals[i];
                if (!double.IsNaN(xx) && !double.IsNaN(yy))
                {
                    int xind = ArrayUtils.ClosestIndex(xmat, xx);
                    int yind = ArrayUtils.ClosestIndex(ymat, yy);
                    dvals[i] = values[xind, yind];
                    pvals[i] = percvalues[xind, yind];
                }
                else
                {
                    dvals[i] = double.NaN;
                    pvals[i] = double.NaN;
                }
            }


            return(dvals);
        }
Esempio n. 3
0
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            int[] colIndx = param.GetParam <int[]>("x").Value;
            int[] colIndy = param.GetParam <int[]>("y").Value;
            if (colIndx.Length == 0)
            {
                processInfo.ErrString = "Please select some columns";
                return;
            }
            if (colIndx.Length != colIndy.Length)
            {
                processInfo.ErrString = "Please select the same number of columns in the boxes for the first and second columns.";
                return;
            }
            int typeInd = param.GetParam <int>("Distribution type").Value;
            int points  = param.GetParam <int>("Number of points").Value;

            for (int k = 0; k < colIndx.Length; k++)
            {
                float[] xvals = GetColumn(mdata, colIndx[k]);
                float[] yvals = GetColumn(mdata, colIndy[k]);
                float[] xvals1;
                float[] yvals1;
                NumUtils.GetValidPairs(xvals, yvals, out xvals1, out yvals1);
                double xmin;
                double xmax;
                double ymin;
                double ymax;
                DensityEstimation.CalcRanges(xvals1, yvals1, out xmin, out xmax, out ymin, out ymax);
                float[,] values = DensityEstimation.GetValuesOnGrid(xvals1, xmin, (xmax - xmin) / points, points, yvals1, ymin,
                                                                    (ymax - ymin) / points, points);
                if (typeInd == 1)
                {
                    MakeConditional1(values);
                }
                if (typeInd == 2)
                {
                    MakeConditional2(values);
                }
                if (typeInd == 3)
                {
                    MakeConditional3(values);
                }
                DensityEstimation.DivideByMaximum(values);
                double[] xmat = new double[points];
                for (int i = 0; i < points; i++)
                {
                    xmat[i] = xmin + i * (xmax - xmin) / points;
                }
                double[] ymat = new double[points];
                for (int i = 0; i < points; i++)
                {
                    ymat[i] = ymin + i * (ymax - ymin) / points;
                }
                float[,] percvalues = CalcExcludedPercentage(values);
                double[] dvals = new double[xvals.Length];
                double[] pvals = new double[xvals.Length];
                for (int i = 0; i < dvals.Length; i++)
                {
                    double xx = xvals[i];
                    double yy = yvals[i];
                    if (!double.IsNaN(xx) && !double.IsNaN(yy))
                    {
                        int xind = ArrayUtils.ClosestIndex(xmat, xx);
                        int yind = ArrayUtils.ClosestIndex(ymat, yy);
                        dvals[i] = values[xind, yind];
                        pvals[i] = percvalues[xind, yind];
                    }
                    else
                    {
                        dvals[i] = double.NaN;
                        pvals[i] = double.NaN;
                    }
                }
                string xname = GetColumnName(mdata, colIndx[k]);
                string yname = GetColumnName(mdata, colIndy[k]);
                mdata.AddNumericColumn("Density_" + xname + "_" + yname,
                                       "Density of data points in the plane spanned by the columns " + xname + " and " + yname + ".", dvals);
                mdata.AddNumericColumn("Excluded fraction_" + xname + "_" + yname,
                                       "Percentage of points with a point density smaller than at this point in the plane spanned by the columns " + xname +
                                       " and " + yname + ".", pvals);
            }
        }