예제 #1
0
        public static double[][] GetIsotopeDistribution(int n, double[] masses, double[] composition)
        {
            int len = masses.Length;

            int[][]  partitions = NumUtil.GetPartitions(n, len);
            double[] ms         = new double[partitions.Length];
            double[] weights    = new double[partitions.Length];
            for (int i = 0; i < partitions.Length; i++)
            {
                weights[i] = 1;
                int[] partition = partitions[i];
                for (int j = 0; j < len; j++)
                {
                    ms[i] += partition[j] * masses[j];
                    for (int k = 0; k < partition[j]; k++)
                    {
                        weights[i] *= composition[j];
                    }
                }
                weights[i] *= NumUtil.Multinomial(n, partition);
            }
            int[] o = ArrayUtil.Order(ms);
            ms      = ArrayUtil.SubArray(ms, o);
            weights = ArrayUtil.SubArray(weights, o);
            double[][] x = FilterWeights(ms, weights, null, 1e-6);
            ms      = x[0];
            weights = x[1];
            x       = FilterMasses(ms, weights, null, 0.2);
            ms      = x[0];
            weights = x[1];
            return(new double[][] { ms, weights });
        }
예제 #2
0
        private static int[][] GetPartitions(int maxNum, int nLabels)
        {
            int[][] p = NumUtil.GetPartitions(maxNum, nLabels + 1);
            for (int i = 0; i < p.Length; i++)
            {
                p[i] = ArrayUtil.SubArray(p[i], nLabels);
            }
            List <int[]> result = new List <int[]>();

            for (int i = 0; i < p.Length; i++)
            {
                if (ArrayUtil.Sum(p[i]) > 0)
                {
                    result.Add(p[i]);
                }
            }
            return(result.ToArray());
        }