public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables, ref IDocumentData[] documents, ProcessInfo processInfo) { int nrows = param.GetParam<int>("Number of rows").Value; nrows = Math.Min(nrows, mdata.RowCount); Random2 rand = new Random2(7); int[] rows = ArrayUtils.SubArray(rand.NextPermutation(mdata.RowCount), nrows); PerseusPluginUtils.FilterRows(mdata, param, rows); }
private static void RandomizeConstantRegion(int[] o, int startInd, int endInd) { int len = endInd - startInd; Random2 r = new Random2(7); int[] p = r.NextPermutation(len); int[] permuted = new int[len]; for (int i = 0; i < len; i++) { permuted[i] = o[startInd + p[i]]; } Array.Copy(permuted, 0, o, startInd, len); }
public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables, ref IDocumentData[] documents, ProcessInfo processInfo) { int nrows = param.GetParam <int>("Number of rows").Value; if (nrows >= mdata.RowCount) { return; } Random2 rand = new Random2(7); int[] inds = rand.NextPermutation(mdata.RowCount).SubArray(nrows); mdata.ExtractRows(inds); }
/// <summary> /// Creates permutations of group memberships of data points while preserving subgroup structures. /// </summary> public static void BalancedPermutationsSubgroups(int[][][] inds, out int[][] indsOut, Random2 r2) { //Permute indices within groups int[][][] inds1 = new int[inds.Length][][]; for (int i = 0; i < inds.Length; i++) { inds1[i] = ArrayUtils.SubArray(inds[i], r2.NextPermutation(inds[i].Length)); } //Permute order of groups inds1 = ArrayUtils.SubArray(inds1, r2.NextPermutation(inds1.Length)); List <int[]>[] newInds = new List <int[]> [inds1.Length]; for (int i = 0; i < inds1.Length; i++) { newInds[i] = new List <int[]>(); } int index = 0; for (int i = inds1.Length - 1; i >= 0; i--) { int[][] ig = inds1[i]; foreach (int[] ind in ig) { //It has to be inds[index] here since otherwise for sided two-sample tests the group size will be swapped while (newInds[index].Count >= inds[index].Length) { index = (index + 1) % inds1.Length; } newInds[index].Add(ind); index = (index + 1) % inds1.Length; } } indsOut = new int[inds1.Length][]; for (int i = 0; i < inds1.Length; i++) { indsOut[i] = ArrayUtils.Concat(newInds[i]); } }
private static double[,] SelectCenter(double[][] xy, int npoints, int nvars, double[,] centers, bool[] busycenters, int k) { int[] perm = randy.NextPermutation(npoints); for (int cc = 0; cc < k; cc++) { var row = xy[perm[cc]]; if (!busycenters[cc]) { for (int i = 0; i < nvars; i++) { centers[cc, i] = row[i]; } } } return(centers); }
private static string[][] CalcPermutationBasedFdr(IList <double> pvalsS0, int nperm, IMatrixData data, TwoSampleTest test, OneSampleTest test1, TestSide side, int[] colInd1, int[] colInd2, double s0, double threshold, List <int[]> colIndsPreserve1, List <int[]> colIndsPreserve2, List <int> validRows, out double[] fdrs, bool paired) { List <double> pq = new List <double>(); List <int> indices = new List <int>(); for (int i = 0; i < pvalsS0.Count; i++) { pq.Add(pvalsS0[i]); indices.Add(i); } Random2 r2 = new Random2(7); for (int p = 0; p < nperm; p++) { int[] colInd1P = null; int[] colInd2P = null; bool[] pairedPerm = null; if (!paired) { if (colIndsPreserve1 != null) { BalancedPermutationsSubgroups(colIndsPreserve1, colIndsPreserve2, out colInd1P, out colInd2P, r2); } else { BalancedPermutations(colInd1, colInd2, out colInd1P, out colInd2P, r2); } } else { pairedPerm = new bool[colInd1.Length]; for (int i = 0; i < colInd1.Length / 2; i++) { pairedPerm[i] = true; } pairedPerm = ArrayUtils.SubArray(pairedPerm, r2.NextPermutation(pairedPerm.Length)); } foreach (int row in validRows) { double[] vals1; double[] vals2; if (!paired) { vals1 = GetValues(row, colInd1P, data, true); vals2 = GetValues(row, colInd2P, data, true); } else { vals1 = GetValues(row, colInd1, data, false); vals2 = GetValues(row, colInd2, data, false); for (int i = 0; i < pairedPerm.Length; i++) { if (pairedPerm[i]) { double tmp = vals2[i]; vals2[i] = vals1[i]; vals1[i] = tmp; } } } CalcTest(test, test1, paired, vals1, vals2, s0, side, out double _, out double _, out double p1, out double _); pq.Add(p1); indices.Add(-1); } } double[] pv = pq.ToArray(); int[] inds = indices.ToArray(); int[] o = ArrayUtils.Order(pv); double forw = 0; double rev = 0; int lastind = -1; fdrs = new double[pvalsS0.Count]; foreach (int ind in o) { if (inds[ind] == -1) { rev++; } else { forw++; double fdr = Math.Min(1, rev / forw / nperm); fdrs[inds[ind]] = fdr; if (fdr <= threshold) { lastind = (int)Math.Round(forw - 1); } } } string[][] result = new string[pvalsS0.Count][]; for (int i = 0; i < result.Length; i++) { result[i] = new string[0]; } int[] o1 = ArrayUtils.Order(pvalsS0); for (int i = 0; i <= lastind; i++) { result[o1[i]] = new[] { "+" }; } return(result); }
private static void RandomizeConstantRegion(int[] o, int startInd, int endInd) { int len = endInd - startInd; Random2 r = new Random2(); int[] p = r.NextPermutation(len); int[] permuted = new int[len]; for (int i = 0; i < len; i++){ permuted[i] = o[startInd + p[i]]; } Array.Copy(permuted, 0, o, startInd, len); }