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 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++) { double[] xvals = GetColumn(mdata, colIndx[k]); double[] yvals = GetColumn(mdata, colIndy[k]); DensityEstimationType type = DensityEstimationType.JointDistribution; switch (typeInd) { case 1: type = DensityEstimationType.DivideByX; break; case 2: type = DensityEstimationType.DivideByY; break; case 3: type = DensityEstimationType.DivideByXY; break; } (double[] dvals, double[] pvals) = DensityEstimation.CalcDensitiesAtData(xvals, yvals, points, type); 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); } }