<commit_before>package dr.inference.distribution.shrinkage;

import dr.inference.model.Parameter;
import dr.inference.model.PriorPreconditioningProvider;
import dr.math.distributions.NormalDistribution;

/**
 * @author <NAME>
 * @author <NAME>
 */

public class JointBayesianBridgeDistributionModel extends BayesianBridgeDistributionModel
        implements PriorPreconditioningProvider {

    public JointBayesianBridgeDistributionModel(Parameter globalScale,
                                                Parameter localScale,
                                                Parameter exponent,
                                                Parameter slabWidth,
                                                int dim,
                                                boolean includeNormalizingConstant) {
        super(globalScale, exponent, dim, includeNormalizingConstant);
        this.localScale = localScale;
        this.slabWidth = slabWidth;

        if (dim != localScale.getDimension()) {
            throw new IllegalArgumentException("Invalid dimensions");
        }

        addVariable(localScale);
    }

    @Override
    public Parameter getLocalScale() { return localScale; }

    @Override
    public Parameter getSlabWidth() { return slabWidth; }

    @Override
    double[] gradientLogPdf(double[] x) {

        double[] gradient = new double[dim];
        for (int i = 0; i < dim; ++i) {
            gradient[i] = NormalDistribution.gradLogPdf(x[i], 0, getStandardDeviation(i));
        }
        return gradient;
    }

    @Override
    public double logPdf(double[] x) {

        double pdf = 0.0;
        for (int i = 0; i < dim; ++i) {
            pdf += NormalDistribution.logPdf(x[i], 0, getStandardDeviation(i));
        }

        if (includeNormalizingConstant) {
            // TODO Add density of localScale variables
            throw new RuntimeException("Not yet implemented");
        }

        return pdf;
    }

    @Override
    public double getStandardDeviation(int index) {
        double globalLocalProduct = globalScale.getParameterValue(0) * localScale.getParameterValue(index);
        if (slabWidth != null) {
            double ratio = globalLocalProduct / slabWidth.getParameterValue(0);
            globalLocalProduct /= Math.sqrt(1.0 + ratio * ratio);
        }
        return globalLocalProduct;
    }
<commit_msg>fix a major bug (feature?)<commit_after>package dr.inference.distribution.shrinkage;

import dr.inference.model.Parameter;
import dr.inference.model.PriorPreconditioningProvider;
import dr.math.distributions.NormalDistribution;

/**
 * @author <NAME>
 * @author <NAME>
 */

public class JointBayesianBridgeDistributionModel extends BayesianBridgeDistributionModel
        implements PriorPreconditioningProvider {

    public JointBayesianBridgeDistributionModel(Parameter globalScale,
                                                Parameter localScale,
                                                Parameter exponent,
                                                Parameter slabWidth,
                                                int dim,
                                                boolean includeNormalizingConstant) {
        super(globalScale, exponent, dim, includeNormalizingConstant);
        this.localScale = localScale;
        this.slabWidth = slabWidth;

        if (dim != localScale.getDimension()) {
            throw new IllegalArgumentException("Invalid dimensions");
        }

        addVariable(localScale);
    }

    @Override
    public Parameter getLocalScale() { return localScale; }

    @Override
    public Parameter getSlabWidth() { return slabWidth; }

    @Override
    double[] gradientLogPdf(double[] x) {

        double[] gradient = new double[dim];
        for (int i = 0; i < dim; ++i) {
            gradient[i] = NormalDistribution.gradLogPdf(x[i], 0, getStandardDeviation(i));
        }
        return gradient;
    }

    @Override
    public double logPdf(double[] x) {

        double pdf = 0.0;
        for (int i = 0; i < dim; ++i) {
            pdf += NormalDistribution.logPdf(x[i], 0, getStandardDeviation(i));
        }

        if (includeNormalizingConstant) {
            // TODO Add density of localScale variables
            throw new RuntimeException("Not yet implemented");
        }

        return pdf;
    }

    @Override
    public double getStandardDeviation(int index) {
        double globalLocalProduct = globalScale.getParameterValue(0) * localScale.getParameterValue(index);
        if (slabWidth != null) {
            double ratio = globalLocalProduct / slabWidth.getParameterValue(0);
            globalLocalProduct /= Math.sqrt(1.0 + ratio * ratio);
            globalLocalProduct = globalLocalProduct * slabWidth.getParameterValue(0);
        }
        return globalLocalProduct;
    }

{'fraction_non_alphanumeric': 0.08517220045370179, 'fraction_numerical': 0.004330789853578057, 'mean_word_length': 2.052234109502832, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4267573', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1135, 'n_words': 281}