• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MixtureMultivariateNormalDistribution类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution的典型用法代码示例。如果您正苦于以下问题:Java MixtureMultivariateNormalDistribution类的具体用法?Java MixtureMultivariateNormalDistribution怎么用?Java MixtureMultivariateNormalDistribution使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

MixtureMultivariateNormalDistribution类属于org.apache.commons.math3.distribution包,在下文中一共展示了MixtureMultivariateNormalDistribution类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testMaxIterationsPositive

点赞 2

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
@Test(expected = NotStrictlyPositiveException.class)
public void testMaxIterationsPositive() {
    // Maximum iterations for fit must be positive integer
    double[][] data = getTestSamples();
    MultivariateNormalMixtureExpectationMaximization fitter =
            new MultivariateNormalMixtureExpectationMaximization(data);

    MixtureMultivariateNormalDistribution
        initialMix = MultivariateNormalMixtureExpectationMaximization.estimate(data, 2);

    fitter.fit(initialMix, 0, 1E-5);
}
 

开发者ID:Quanticol,
项目名称:CARMA,
代码行数:13,
代码来源:MultivariateNormalMixtureExpectationMaximizationTest.java

示例2: testThresholdPositive

点赞 2

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
@Test(expected = NotStrictlyPositiveException.class)
public void testThresholdPositive() {
    // Maximum iterations for fit must be positive
    double[][] data = getTestSamples();
    MultivariateNormalMixtureExpectationMaximization fitter =
            new MultivariateNormalMixtureExpectationMaximization(
                data);

    MixtureMultivariateNormalDistribution
        initialMix = MultivariateNormalMixtureExpectationMaximization.estimate(data, 2);

    fitter.fit(initialMix, 1000, 0);
}
 

开发者ID:Quanticol,
项目名称:CARMA,
代码行数:14,
代码来源:MultivariateNormalMixtureExpectationMaximizationTest.java

示例3: testConvergenceException

点赞 2

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
@Test(expected = ConvergenceException.class)
public void testConvergenceException() {
    // ConvergenceException thrown if fit terminates before threshold met
    double[][] data = getTestSamples();
    MultivariateNormalMixtureExpectationMaximization fitter
        = new MultivariateNormalMixtureExpectationMaximization(data);

    MixtureMultivariateNormalDistribution
        initialMix = MultivariateNormalMixtureExpectationMaximization.estimate(data, 2);

    // 5 iterations not enough to meet convergence threshold
    fitter.fit(initialMix, 5, 1E-5);
}
 

开发者ID:Quanticol,
项目名称:CARMA,
代码行数:14,
代码来源:MultivariateNormalMixtureExpectationMaximizationTest.java

示例4: testIncompatibleIntialMixture

点赞 2

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
@Test(expected = DimensionMismatchException.class)
public void testIncompatibleIntialMixture() {
    // Data has 3 columns
    double[][] data = new double[][] {
            { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }
    };
    double[] weights = new double[] { 0.5, 0.5 };

    // These distributions are compatible with 2-column data, not 3-column
    // data
    MultivariateNormalDistribution[] mvns = new MultivariateNormalDistribution[2];

    mvns[0] = new MultivariateNormalDistribution(new double[] {
                    -0.0021722935000328823, 3.5432892936887908 },
                    new double[][] {
                            { 4.537422569229048, 3.5266152281729304 },
                            { 3.5266152281729304, 6.175448814169779 } });
    mvns[1] = new MultivariateNormalDistribution(new double[] {
                    5.090902706507635, 8.68540656355283 }, new double[][] {
                    { 2.886778573963039, 1.5257474543463154 },
                    { 1.5257474543463154, 3.3794567673616918 } });

    // Create components and mixture
    List<Pair<Double, MultivariateNormalDistribution>> components =
            new ArrayList<Pair<Double, MultivariateNormalDistribution>>();
    components.add(new Pair<Double, MultivariateNormalDistribution>(
            weights[0], mvns[0]));
    components.add(new Pair<Double, MultivariateNormalDistribution>(
            weights[1], mvns[1]));

    MixtureMultivariateNormalDistribution badInitialMix
        = new MixtureMultivariateNormalDistribution(components);

    MultivariateNormalMixtureExpectationMaximization fitter
        = new MultivariateNormalMixtureExpectationMaximization(data);

    fitter.fit(badInitialMix);
}
 

开发者ID:Quanticol,
项目名称:CARMA,
代码行数:39,
代码来源:MultivariateNormalMixtureExpectationMaximizationTest.java

示例5: retrieveGaussianMixtureModelForFilteredTargets

点赞 2

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
/** <p>Produces a Gaussian mixture model based on the difference between targets and segment means.</p>
 * <p>Filters targets to populations where more than the minProportion lie in a single segment.</p>
 * <p>Returns null if no pass filtering.  Please note that in these cases,
 * in the rest of this class, we use this to assume that a GMM is not a good model.</p>
 *
 * @param segments  -- segments with segment mean in log2 copy ratio space
 * @param targets -- targets with a log2 copy ratio estimate
 * @param minProportion -- minimum proportion of all targets that a given segment must have in order to be used
 *                      in the evaluation
 * @param numComponents -- number of components to use in the GMM.  Usually, this is 2.
 * @return  never {@code null}.  Fitting result with indications whether it converged or was even attempted.
 */
private MixtureMultivariateNormalFitResult retrieveGaussianMixtureModelForFilteredTargets(final List<ModeledSegment> segments,
                                                                                          final TargetCollection<ReadCountRecord.SingleSampleRecord> targets, double minProportion, int numComponents){

    // For each target in a segment that contains enough targets, normalize the difference against the segment mean
    //  and collapse the filtered targets into the copy ratio estimates.
    final List<Double> filteredTargetsSegDiff = getNumProbeFilteredTargetList(segments, targets, minProportion);

    if (filteredTargetsSegDiff.size() < numComponents) {
        return new MixtureMultivariateNormalFitResult(null, false, false);
    }

    // Assume that Apache Commons wants data points in the first dimension.
    // Note that second dimension of length 2 (instead of 1) is to wrok around funny Apache commons API.
    final double[][] filteredTargetsSegDiff2d = new double[filteredTargetsSegDiff.size()][2];

    // Convert the filtered targets into 2d array (even if second dimension is length 1).  The second dimension is
    //  uncorrelated Gaussian.  This is only to get around funny API in Apache Commons, which will throw an
    //  exception if the length of the second dimension is < 2
    final RandomGenerator rng = RandomGeneratorFactory.createRandomGenerator(new Random(RANDOM_SEED));
    final NormalDistribution nd = new NormalDistribution(rng, 0, .1);
    for (int i = 0; i < filteredTargetsSegDiff.size(); i++) {
        filteredTargetsSegDiff2d[i][0] = filteredTargetsSegDiff.get(i);
        filteredTargetsSegDiff2d[i][1] = nd.sample();
    }

    final MixtureMultivariateNormalDistribution estimateEM0 = MultivariateNormalMixtureExpectationMaximization.estimate(filteredTargetsSegDiff2d, numComponents);
    final MultivariateNormalMixtureExpectationMaximization multivariateNormalMixtureExpectationMaximization = new MultivariateNormalMixtureExpectationMaximization(filteredTargetsSegDiff2d);

    try {
        multivariateNormalMixtureExpectationMaximization.fit(estimateEM0);
    } catch (final MaxCountExceededException | ConvergenceException | SingularMatrixException e) {
        // We are done, we cannot make a fitting.  We should return a result that we attempted a fitting, but it
        //  did not converge.  Include the model as it was when the exception was thrown.
        return new MixtureMultivariateNormalFitResult(multivariateNormalMixtureExpectationMaximization.getFittedModel(), false, true);
    }
    return new MixtureMultivariateNormalFitResult(multivariateNormalMixtureExpectationMaximization.getFittedModel(), true, true);
}
 

开发者ID:broadinstitute,
项目名称:gatk-protected,
代码行数:50,
代码来源:CoverageDropoutDetector.java

示例6: testInitialMixture

点赞 2

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
@Test
public void testInitialMixture() {
    // Testing initial mixture estimated from data
    final double[] correctWeights = new double[] { 0.5, 0.5 };

    final double[][] correctMeans = new double[][] {
        {-0.0021722935000328823, 3.5432892936887908},
        {5.090902706507635, 8.68540656355283},
    };

    final RealMatrix[] correctCovMats = new Array2DRowRealMatrix[2];

    correctCovMats[0] = new Array2DRowRealMatrix(new double[][] {
            { 4.537422569229048, 3.5266152281729304 },
            { 3.5266152281729304, 6.175448814169779 } });

    correctCovMats[1] = new Array2DRowRealMatrix( new double[][] {
            { 2.886778573963039, 1.5257474543463154 },
            { 1.5257474543463154, 3.3794567673616918 } });

    final MultivariateNormalDistribution[] correctMVNs = new
            MultivariateNormalDistribution[2];

    correctMVNs[0] = new MultivariateNormalDistribution(correctMeans[0],
            correctCovMats[0].getData());

    correctMVNs[1] = new MultivariateNormalDistribution(correctMeans[1],
            correctCovMats[1].getData());

    final MixtureMultivariateNormalDistribution initialMix
        = MultivariateNormalMixtureExpectationMaximization.estimate(getTestSamples(), 2);

    int i = 0;
    for (Pair<Double, MultivariateNormalDistribution> component : initialMix
            .getComponents()) {
        Assert.assertEquals(correctWeights[i], component.getFirst(),
                Math.ulp(1d));
        
        final double[] means = component.getValue().getMeans();
        Assert.assertTrue(Arrays.equals(correctMeans[i], means));
        
        final RealMatrix covMat = component.getValue().getCovariances();
        Assert.assertEquals(correctCovMats[i], covMat);
        i++;
    }
}
 

开发者ID:Quanticol,
项目名称:CARMA,
代码行数:47,
代码来源:MultivariateNormalMixtureExpectationMaximizationTest.java

示例7: testFit

点赞 2

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
@Test
public void testFit() {
    // Test that the loglikelihood, weights, and models are determined and
    // fitted correctly
    final double[][] data = getTestSamples();
    final double correctLogLikelihood = -4.292431006791994;
    final double[] correctWeights = new double[] { 0.2962324189652912, 0.7037675810347089 };
    
    final double[][] correctMeans = new double[][]{
        {-1.4213112715121132, 1.6924690505757753},
        {4.213612224374709, 7.975621325853645}
    };
    
    final RealMatrix[] correctCovMats = new Array2DRowRealMatrix[2];
    correctCovMats[0] = new Array2DRowRealMatrix(new double[][] {
        { 1.739356907285747, -0.5867644251487614 },
        { -0.5867644251487614, 1.0232932029324642 } }
            );
    correctCovMats[1] = new Array2DRowRealMatrix(new double[][] {
        { 4.245384898007161, 2.5797798966382155 },
        { 2.5797798966382155, 3.9200272522448367 } });
    
    final MultivariateNormalDistribution[] correctMVNs = new MultivariateNormalDistribution[2];
    correctMVNs[0] = new MultivariateNormalDistribution(correctMeans[0], correctCovMats[0].getData());
    correctMVNs[1] = new MultivariateNormalDistribution(correctMeans[1], correctCovMats[1].getData());

    MultivariateNormalMixtureExpectationMaximization fitter
        = new MultivariateNormalMixtureExpectationMaximization(data);

    MixtureMultivariateNormalDistribution initialMix
        = MultivariateNormalMixtureExpectationMaximization.estimate(data, 2);
    fitter.fit(initialMix);
    MixtureMultivariateNormalDistribution fittedMix = fitter.getFittedModel();
    List<Pair<Double, MultivariateNormalDistribution>> components = fittedMix.getComponents();

    Assert.assertEquals(correctLogLikelihood,
                        fitter.getLogLikelihood(),
                        Math.ulp(1d));

    int i = 0;
    for (Pair<Double, MultivariateNormalDistribution> component : components) {
        final double weight = component.getFirst();
        final MultivariateNormalDistribution mvn = component.getSecond();
        final double[] mean = mvn.getMeans();
        final RealMatrix covMat = mvn.getCovariances();
        Assert.assertEquals(correctWeights[i], weight, Math.ulp(1d));
        Assert.assertTrue(Arrays.equals(correctMeans[i], mean));
        Assert.assertEquals(correctCovMats[i], covMat);
        i++;
    }
}
 

开发者ID:Quanticol,
项目名称:CARMA,
代码行数:52,
代码来源:MultivariateNormalMixtureExpectationMaximizationTest.java

示例8: MixtureMultivariateNormalFitResult

点赞 2

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
public MixtureMultivariateNormalFitResult(final MixtureMultivariateNormalDistribution mixtureMultivariateNormalDistribution, final boolean isConverged, final boolean wasFitAttempted) {
    this.isConverged = isConverged;
    this.mixtureMultivariateNormalDistribution = mixtureMultivariateNormalDistribution;
    this.wasFitAttempted = wasFitAttempted;
}
 

开发者ID:broadinstitute,
项目名称:gatk-protected,
代码行数:6,
代码来源:CoverageDropoutDetector.java

示例9: getMixtureMultivariateNormalDistribution

点赞 2

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
public MixtureMultivariateNormalDistribution getMixtureMultivariateNormalDistribution() {
    return mixtureMultivariateNormalDistribution;
}
 

开发者ID:broadinstitute,
项目名称:gatk-protected,
代码行数:4,
代码来源:CoverageDropoutDetector.java

示例10: fit

点赞 1

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
/**
 * Fit a mixture model to the data supplied to the constructor.
 *
 * The quality of the fit depends on the concavity of the data provided to
 * the constructor and the initial mixture provided to this function. If the
 * data has many local optima, multiple runs of the fitting function with
 * different initial mixtures may be required to find the optimal solution.
 * If a SingularMatrixException is encountered, it is possible that another
 * initialization would work.
 *
 * @param initialMixture Model containing initial values of weights and
 *            multivariate normals
 * @throws SingularMatrixException if any component's covariance matrix is
 *             singular during fitting
 * @throws NotStrictlyPositiveException if numComponents is less than one or
 *             threshold is less than Double.MIN_VALUE
 */
public void fit(MixtureMultivariateNormalDistribution initialMixture)
    throws SingularMatrixException,
           NotStrictlyPositiveException {
    fit(initialMixture, DEFAULT_MAX_ITERATIONS, DEFAULT_THRESHOLD);
}
 

开发者ID:biocompibens,
项目名称:SME,
代码行数:23,
代码来源:MultivariateNormalMixtureExpectationMaximization.java

示例11: getFittedModel

点赞 1

import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; //导入依赖的package包/类
/**
 * Gets the fitted model.
 *
 * @return fitted model or {@code null} if no fit has been performed yet.
 */
public MixtureMultivariateNormalDistribution getFittedModel() {
    return new MixtureMultivariateNormalDistribution(fittedModel.getComponents());
}
 

开发者ID:biocompibens,
项目名称:SME,
代码行数:9,
代码来源:MultivariateNormalMixtureExpectationMaximization.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)