Takes a probability distribution and reduces higher-order terms by contributions arising from combinations of lower order terms. - Java java.lang

Java examples for java.lang:Math Statistics

Description

Takes a probability distribution and reduces higher-order terms by contributions arising from combinations of lower order terms.

Demo Code

/*/*from   www .  j a va  2  s .  c om*/
 * Copyright (c) 2014. Real Time Genomics Limited.
 *
 * Use of this source code is bound by the Real Time Genomics Limited Software Licence Agreement
 * for Academic Non-commercial Research Purposes only.
 *
 * If you did not receive a license accompanying this file, a copy must first be obtained by email
 * from support@realtimegenomics.com.  On downloading, using and/or continuing to use this source
 * code you accept the terms of that license agreement and any amendments to those terms that may
 * be made from time to time by Real Time Genomics Limited.
 */
//package com.java2s;
import java.util.Arrays;

public class Main {
    /**
     * Takes a probability distribution and reduces higher-order terms by
     * contributions arising from combinations of lower order terms. It
     * assumes the input distribution is suitable for this operation.
     *
     * @param p original distribution
     * @param rate decay rate
     * @return modified distribution
     */
    public static double[] deconvolve(final double[] p, final double rate) {
        final double[] r = Arrays.copyOf(p, p.length);
        for (int k = 0; k < p.length; k++) {
            for (int j = 0; j < p.length; j++) {
                if (k + j < p.length) {
                    r[k + j] -= rate * p[k] * p[j];
                }
            }
        }
        // renormalize
        double sum = 0;
        for (final double q : r) {
            sum += q;
        }
        sum = 1 / sum;
        for (int k = 0; k < r.length; k++) {
            r[k] *= sum;
        }
        return r;
    }
}

Related Tutorials