• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java UnivariateIntegrator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: cumulativeProbabilityIsOneWithRealData

import org.apache.commons.math3.analysis.integration.UnivariateIntegrator; //导入依赖的package包/类
private void cumulativeProbabilityIsOneWithRealData(final double mu, double min, double max, boolean test)
{
	double p = 0;

	UnivariateIntegrator in = new SimpsonIntegrator();

	p = in.integrate(20000, new UnivariateFunction()
	{
		public double value(double x)
		{
			double v;
			v = PoissonCalculator.likelihood(mu, x);
			//v = pgf.probability(x, mu);
			//System.out.printf("x=%f, v=%f\n", x, v);
			return v;
		}
	}, min, max);

	System.out.printf("mu=%f, p=%f\n", mu, p);
	if (test)
	{
		Assert.assertEquals(String.format("mu=%f", mu), P_LIMIT, p, 0.02);
	}
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:25,代码来源:PoissonCalculatorTest.java


示例2: getVelocity

import org.apache.commons.math3.analysis.integration.UnivariateIntegrator; //导入依赖的package包/类
public double getVelocity(double startSpeed, double startTime, double endTime){
    UnivariateIntegrator integrator = new SimpsonIntegrator();
    double integralAddition = 0;
    if (!dEqual(startTime,endTime)) {
        try {
            integralAddition = startTime * integrator.integrate(10, v -> getAccel(v), startTime, endTime);
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }
    return startSpeed + integralAddition;
}
 
开发者ID:ValisStigma,项目名称:LazyDrivers,代码行数:13,代码来源:Accel.java


示例3: cumulativeProbabilityIsOneWithRealData

import org.apache.commons.math3.analysis.integration.UnivariateIntegrator; //导入依赖的package包/类
private void cumulativeProbabilityIsOneWithRealData(final double mu, double min, double max, boolean test)
{
	double p = 0;

	// Test using a standard Poisson-Gaussian convolution
	//min = -max;
	//final PoissonGaussianFunction pgf = PoissonGaussianFunction.createWithVariance(1, 1, VAR);

	UnivariateIntegrator in = new SimpsonIntegrator();

	p = in.integrate(20000, new UnivariateFunction()
	{
		public double value(double x)
		{
			double v;
			v = SCMOSLikelihoodWrapper.likelihood(mu, VAR, G, O, x);
			//v = pgf.probability(x, mu);
			//System.out.printf("x=%f, v=%f\n", x, v);
			return v;
		}
	}, min, max);

	//System.out.printf("mu=%f, p=%f\n", mu, p);
	if (test)
	{
		Assert.assertEquals(String.format("mu=%f", mu), P_LIMIT, p, 0.02);
	}
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:29,代码来源:SCMOSLikelihoodWrapperTest.java


示例4: createAiryDistribution

import org.apache.commons.math3.analysis.integration.UnivariateIntegrator; //导入依赖的package包/类
private static synchronized void createAiryDistribution()
{
	if (spline != null)
		return;
	
	final double relativeAccuracy = 1e-4;
	final double absoluteAccuracy = 1e-8;
	final int minimalIterationCount = 3;
	final int maximalIterationCount = 32;

	UnivariateIntegrator integrator = new SimpsonIntegrator(relativeAccuracy, absoluteAccuracy,
			minimalIterationCount, maximalIterationCount);
	UnivariateFunction f = new UnivariateFunction()
	{
		public double value(double x)
		{
			// The pattern profile is in one dimension. 
			// Multiply by the perimeter of a circle to convert to 2D volume then normalise by 4 pi
			//return AiryPattern.intensity(x) * 2 * Math.PI * x / (4 * Math.PI);
			return AiryPattern.intensity(x) * 0.5 * x;
		}
	};

	// Integrate up to a set number of dark rings
	int samples = 1000;
	final double step = RINGS[SAMPLE_RINGS] / samples;
	double to = 0, from = 0;
	r = new double[samples + 1];
	sum = new double[samples + 1];
	for (int i = 1; i < sum.length; i++)
	{
		from = to;
		r[i] = to = step * i;
		sum[i] = integrator.integrate(2000, f, from, to) + sum[i - 1];
	}

	if (DoubleEquality.relativeError(sum[samples], POWER[SAMPLE_RINGS]) > 1e-3)
		throw new RuntimeException("Failed to create the Airy distribution");

	SplineInterpolator si = new SplineInterpolator();
	spline = si.interpolate(sum, r);
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:43,代码来源:AiryPSFModel.java


示例5: computeI1

import org.apache.commons.math3.analysis.integration.UnivariateIntegrator; //导入依赖的package包/类
/**
 * Compute the function I1 using numerical integration. See Mortensen, et al (2010) Nature Methods 7, 377-383), SI
 * equation 43.
 * 
 * <pre>
 * I1 = 1 + sum [ ln(t) / (1 + t/rho) ] dt
 *    = - sum [ t * ln(t) / (t + rho) ] dt
 * </pre>
 * 
 * Where sum is the integral between 0 and 1. In the case of rho=0 the function returns 1;
 * 
 * @param rho
 * @param integrationPoints
 *            the number of integration points for the LegendreGaussIntegrator
 * @return the I1 value
 */
private static double computeI1(final double rho, int integrationPoints)
{
	if (rho == 0)
		return 1;

	final double relativeAccuracy = 1e-4;
	final double absoluteAccuracy = 1e-8;
	final int minimalIterationCount = 3;
	final int maximalIterationCount = 32;

	// Use an integrator that does not use the boundary since log(0) is undefined.
	UnivariateIntegrator i = new IterativeLegendreGaussIntegrator(integrationPoints, relativeAccuracy,
			absoluteAccuracy, minimalIterationCount, maximalIterationCount);

	// Specify the function to integrate
	UnivariateFunction f = new UnivariateFunction()
	{
		public double value(double x)
		{
			return x * Math.log(x) / (x + rho);
		}
	};
	final double i1 = -i.integrate(2000, f, 0, 1);
	//System.out.printf("I1 = %f (%d)\n", i1, i.getEvaluations());

	// The function requires more evaluations and sometimes does not converge,
	// presumably because log(x) significantly changes as x -> 0 where as x log(x) in the function above 
	// is more stable

	//		UnivariateFunction f2 = new UnivariateFunction()
	//		{
	//			@Override
	//			public double value(double x)
	//			{
	//				return Math.log(x) / ( 1 + x / rho);
	//			}
	//		};
	//		double i2 = 1 + i.integrate(2000, f2, 0, 1);
	//		System.out.printf("I1 (B) = %f (%d)\n", i2, i.getEvaluations());

	return i1;
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:59,代码来源:Gaussian2DPeakResultHelper.java


示例6: testPdf

import org.apache.commons.math3.analysis.integration.UnivariateIntegrator; //导入依赖的package包/类
@Test
public void testPdf() {

       final int numberOfTests = 100;
       double totErr = 0;
       double ptotErr = 0; int np = 0;
       double qtotErr = 0;

       Random random = new Random(37);

       for(int i = 0; i < numberOfTests; i++){
           final double mean = .01 + (3-0.01) * random.nextDouble();
           final double var = .01 + (3-0.01) * random.nextDouble();

           final double scale = var / mean;
           final double shape = mean / scale;

           final GammaDistribution gamma = new GammaDistribution(shape,scale);

           final double value = gamma.nextGamma();

           final double mypdf = mypdf(value, shape, scale);
           final double pdf = gamma.pdf(value);
           if ( Double.isInfinite(mypdf) && Double.isInfinite(pdf)) {
               continue;
           }

           assertFalse(Double.isNaN(mypdf));
           assertFalse(Double.isNaN(pdf));

           totErr +=  mypdf != 0 ? Math.abs((pdf - mypdf)/mypdf) : pdf;

           assertFalse("nan", Double.isNaN(totErr));
           //assertEquals("" + shape + "," + scale + "," + value, mypdf,gamma.pdf(value),1e-10);

           final double cdf = gamma.cdf(value);
           UnivariateFunction f = new UnivariateFunction() {
               public double value(double v) {
                   return mypdf(v, shape, scale);
               }
           };
           final UnivariateIntegrator integrator = new RombergIntegrator(MachineAccuracy.SQRT_EPSILON, 1e-14, 1, 16);

           double x;
           try {
               x = integrator.integrate(16, f, 0.0, value);
               ptotErr += cdf != 0.0 ? Math.abs(x-cdf)/cdf : x;
               np += 1;
               //assertTrue("" + shape + "," + scale + "," + value + " " + Math.abs(x-cdf)/x + "> 1e-6", Math.abs(1-cdf/x) < 1e-6);

               //System.out.println(shape + ","  + scale + " " + value);
           } catch(MaxCountExceededException e ) {
                // can't integrate , skip test
             //  System.out.println(shape + ","  + scale + " skipped");
           }

           final double q = gamma.quantile(cdf);
           qtotErr += q != 0 ? Math.abs(q-value)/q : value;
          // assertEquals("" + shape + "," + scale + "," + value + " " + Math.abs(q-value)/value, q, value, 1e-6);
       }
       //System.out.println( !Double.isNaN(totErr) );
      // System.out.println(totErr);
       // bad test, but I can't find a good threshold that works for all individual cases 
       assertTrue("failed " + totErr/numberOfTests, totErr/numberOfTests < 1e-7);
       assertTrue("failed " + ptotErr/np, np > 0 ? (ptotErr/np < 1e-5) : true);
       assertTrue("failed " + qtotErr/numberOfTests , qtotErr/numberOfTests < 1e-7);
}
 
开发者ID:armanbilge,项目名称:B3,代码行数:68,代码来源:GammaDistributionTest.java



注:本文中的org.apache.commons.math3.analysis.integration.UnivariateIntegrator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MvcFeature类代码示例发布时间:2022-05-23
下一篇:
Java IncludedGrammar类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap