当前位置: 首页>>代码示例>>C#>>正文


C# DoubleVector.Apply方法代码示例

本文整理汇总了C#中Altaxo.Calc.LinearAlgebra.DoubleVector.Apply方法的典型用法代码示例。如果您正苦于以下问题:C# DoubleVector.Apply方法的具体用法?C# DoubleVector.Apply怎么用?C# DoubleVector.Apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Altaxo.Calc.LinearAlgebra.DoubleVector的用法示例。


在下文中一共展示了DoubleVector.Apply方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProbabilityDensity


//.........这里部分代码省略.........

					case "bcv":
						//bcv = bw.bcv(x),
						break;

					case "sj":
						//sj = , "sj-ste" = bw.SJ(x, method="ste"),
						break;

					case "sj-dpi":
						//"sj-dpi" = bw.SJ(x, method="dpi"),
						break;

					default:
						throw new ArgumentException("Unknown bandwith selection rule: " + bwSel.ToString());
				}
			}

			if (!RMath.IsFinite(bw))
				throw new ArithmeticException("Bandwidth is not finite");

			bw = adjust * bw;

			if (!(bw > 0))
				throw new ArithmeticException("Bandwith is not positive");

			if (from.IsNaN())
				from = x.GetMinimum() - cut * bw;
			if (to.IsNaN())
				to = x.GetMaximum() + cut * bw;

			if (!RMath.IsFinite(from))
				throw new ArithmeticException("non-finite 'from'");
			if (!to.IsFinite())
				throw new ArithmeticException("non-finite 'to'");
			double lo = from - 4 * bw;
			double up = to + 4 * bw;

			var y = new DoubleVector(2 * n);
			MassDistribution(x, weights, lo, up, y, n);
			y.Multiply(totMass);

			var kords = new DoubleVector(2 * n);
			kords.FillWithLinearSequenceGivenByStartEnd(0, 2 * (up - lo));

			for (int i = n + 1, j = n - 1; j >= 0; i++, j--)
				kords[i] = -kords[j];

			switch (kernel)
			{
				case ConvolutionKernel.Gaussian:
					kords.Apply(new Probability.NormalDistribution(0, bw).PDF);
					break;

				case ConvolutionKernel.Rectangular:
					double a = bw * Math.Sqrt(3);
					kords.Apply(delegate(double xx) { return Math.Abs(xx) < a ? 0.5 / a : 0; });
					break;

				case ConvolutionKernel.Triangular:
					a = bw * Math.Sqrt(6);
					kords.Apply(delegate(double xx) { return Math.Abs(xx) < a ? (1 - Math.Abs(xx) / a) / a : 0; });
					break;

				case ConvolutionKernel.Epanechnikov:
					a = bw * Math.Sqrt(5);
					kords.Apply(delegate(double xx) { return Math.Abs(xx) < a ? 0.75 * (1 - RMath.Pow2(Math.Abs(xx) / a)) / a : 0; });
					break;

				case ConvolutionKernel.Biweight:
					a = bw * Math.Sqrt(7);
					kords.Apply(delegate(double xx) { return Math.Abs(xx) < a ? 15.0 / 16.0 * RMath.Pow2(1 - RMath.Pow2(Math.Abs(xx) / a)) / a : 0; });
					break;

				case ConvolutionKernel.Cosine:
					a = bw / Math.Sqrt(1.0 / 3 - 2 / RMath.Pow2(Math.PI));
					kords.Apply(delegate(double xx) { return Math.Abs(xx) < a ? (1 + Math.Cos(Math.PI * xx / a)) / (2 * a) : 0; });
					break;

				case ConvolutionKernel.Optcosine:
					a = bw / Math.Sqrt(1 - 8 / RMath.Pow2(Math.PI));
					kords.Apply(delegate(double xx) { return Math.Abs(xx) < a ? Math.PI / 4 * Math.Cos(Math.PI * xx / (2 * a)) / a : 0; });
					break;

				default:
					throw new ArgumentException("Unknown convolution kernel");
			}

			var result = new DoubleVector(2 * n);
			Fourier.FastHartleyTransform.CyclicRealConvolution(y.GetInternalData(), kords.GetInternalData(), result.GetInternalData(), 2 * n, null);
			y.Multiply(1.0 / (2 * n));
			VectorMath.Max(y, 0, y);
			var xords = VectorMath.CreateEquidistantSequenceByStartEndLength(lo, up, n);
			var xu = VectorMath.CreateEquidistantSequenceByStartEndLength(from, to, n_user);

			double[] res2 = new double[xu.Length];
			Interpolation.LinearInterpolation.Interpolate(xords, result, n, xu, xu.Length, 0, out res2);

			return new ProbabilityDensityResult() { X = xu, Y = VectorMath.ToROVector(res2), Bandwidth = bw };
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:101,代码来源:Statistics.cs


注:本文中的Altaxo.Calc.LinearAlgebra.DoubleVector.Apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。