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

C# LinearAlgebra.DoubleVector类代码示例

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

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



DoubleVector类属于Altaxo.Calc.LinearAlgebra命名空间,在下文中一共展示了DoubleVector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: InternalCompute

		/// <summary>Performs the QR factorization.</summary>
		protected override void InternalCompute()
		{
			int m = matrix.Rows;
			int n = matrix.Columns;

#if MANAGED
			int minmn = m < n ? m : n;
			r_ = new DoubleMatrix(matrix); // create a copy
			DoubleVector[] u = new DoubleVector[minmn];
			for (int i = 0; i < minmn; i++)
			{
				u[i] = Householder.GenerateColumn(r_, i, m - 1, i);
				Householder.UA(u[i], r_, i, m - 1, i + 1, n - 1);
			}
			q_ = DoubleMatrix.CreateIdentity(m);
			for (int i = minmn - 1; i >= 0; i--)
			{
				Householder.UA(u[i], q_, i, m - 1, i, m - 1);
			}
#else
      qr = new double[matrix.data.Length];
      Array.Copy(matrix.data, qr, matrix.data.Length);
      jpvt = new int[n];
      jpvt[0] = 1;
      Lapack.Geqp3.Compute(m, n, qr, m, jpvt, out tau);
      r_ = new DoubleMatrix(m, n);
      // Populate R
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
          if (i <= j) {
            r_.data[j * m + i] = qr[(jpvt[j]-1) * m + i];
          }
          else {
            r_.data[j * m + i] = 0.0;
          }
        }
      }
      q_ = new DoubleMatrix(m, m);
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          if (j < n)
            q_.data[j * m + i] = qr[j * m + i];
          else
            q_.data[j * m + i] = 0.0;
        }
      }

      if( m < n ){
        Lapack.Orgqr.Compute(m, m, m, q_.data, m, tau);
      } else{
        Lapack.Orgqr.Compute(m, m, n, q_.data, m, tau);
      }
#endif
			for (int i = 0; i < m; i++)
			{
				if (q_[i, i] == 0)
					isFullRank = false;
			}
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:60,代码来源:DoubleQRDecomp.cs


示例2: CtorInitialValues

 public void CtorInitialValues()
 {
   DoubleVector test = new DoubleVector(2,1);
   
   Assert.AreEqual(test.Length, 2);
   Assert.AreEqual(test[0],1);
   Assert.AreEqual(test[1],1);
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:8,代码来源:DoubleVectorTest.cs


示例3: CtorDimensions

 public void CtorDimensions()
 {
   DoubleVector test = new DoubleVector(2);
   
   Assert.AreEqual(test.Length, 2);
   Assert.AreEqual(test[0],0);
   Assert.AreEqual(test[1],0);
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:8,代码来源:DoubleVectorTest.cs


示例4: Value

 public override double Value (DoubleVector x) 
 {
   double retvalue=0;
   for (int i=1; i<x.Length; i++) 
   {
     retvalue = retvalue + 100*System.Math.Pow((x[i] - System.Math.Pow(x[i-1],2)),2) + System.Math.Pow((1-x[i-1]),2);
   }
   return retvalue;
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:9,代码来源:Rosenbrock.cs


示例5: CurrentException2

		public void CurrentException2()
		{
			DoubleVector test = new DoubleVector(new double[2] { 1, 2 });
			IEnumerator enumerator = test.GetEnumerator();
			enumerator.MoveNext();
			enumerator.MoveNext();
			enumerator.MoveNext();
			object value = enumerator.Current;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:9,代码来源:DoubleVectorEnumeratorTest.cs


示例6: CtorArray

 public void CtorArray()
 {
   double[] testvector = new double[2]{0,1};
   
   DoubleVector test = new DoubleVector(testvector);
   Assert.AreEqual(test.Length,testvector.Length);
   Assert.AreEqual(test[0],testvector[0]);
   Assert.AreEqual(test[1],testvector[1]);
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:9,代码来源:DoubleVectorTest.cs


示例7: Gradient

 public override DoubleVector Gradient(DoubleVector x) 
 {
   DoubleVector retvalue = new DoubleVector(x.Length,0.0);
   retvalue[0] = -400*x[0]*(x[1]-System.Math.Pow(x[0],2))-2*(1-x[0]);
   retvalue[x.Length-1] = 200*(x[x.Length-1]-System.Math.Pow(x[x.Length-2],2));
   if (x.Length>2) 
   {
     for (int i=1; i<x.Length-1; i++)
       retvalue[i] = 200*(x[i]-System.Math.Pow(x[i-1],2))-400*x[i]*(x[i+1]-System.Math.Pow(x[i],2))-2*(1-x[i]);
   }
   return retvalue;
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:12,代码来源:Rosenbrock.cs


示例8: Update

		public double Update(DoubleVector solution, DoubleVector direction, double beta)
		{
			DoubleVector newSolution;
			double newbeta = beta;
			for (int i = 0; i < 200; i++)
			{
				newSolution = solution + newbeta * direction;
				if (Check(newSolution))
				{
					return newbeta;
				}
				newbeta *= 0.5;
			}
			throw new OptimizationException("Beta couldn't be found to satisfy constraint");
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:15,代码来源:ConstraintDefinition.cs


示例9: Hessian

 public override DoubleMatrix Hessian(DoubleVector x) 
 {
   DoubleMatrix ret = new DoubleMatrix(x.Length,x.Length,0.0);
   
   for (int i=0; i<x.Length-1; i++)
   {
     ret[i,i+1] = -400*x[i];
     ret[i+1,i] = -400*x[i];
   }
   ret[0,0] = System.Math.Pow(1200*x[0],2)-400*x[1]+2;
   ret[x.Length-1,x.Length-1] = 200;
   for (int i=1; i<x.Length-1; i++)
     ret[i,i] = 202 + System.Math.Pow(1200*x[i],2) - 400*x[i+1];
   return ret;
 } 
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:15,代码来源:Rosenbrock.cs


示例10: Search

		///<summary> Minimize the given cost function </summary>
		public override DoubleVector Search(DoubleVector x, DoubleVector d, double stp)
		{
			DoubleVector ret = new DoubleVector(x);
			double j = 0;
			double delta_d = d.GetDotProduct(d);
			double alpha;
			do
			{
				alpha = -GradientEvaluation(ret).GetDotProduct(d) /
					d.GetDotProduct(HessianEvaluation(ret) * d);
				ret = ret + alpha * d;
				j++;
			} while ((j < maxIteration) && (alpha * alpha * delta_d > tolerance * tolerance));
			return ret;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:16,代码来源:NewtonRaphsonLineSearch.cs


示例11: Current

		public void Current()
		{
			DoubleVector test = new DoubleVector(new double[2] { 1, 2 });
			IEnumerator enumerator = test.GetEnumerator();
			bool movenextresult;

			movenextresult = enumerator.MoveNext();
			Assert.IsTrue(movenextresult);
			Assert.AreEqual(enumerator.Current, test[0]);

			movenextresult = enumerator.MoveNext();
			Assert.IsTrue(movenextresult);
			Assert.AreEqual(enumerator.Current, test[1]);

			movenextresult = enumerator.MoveNext();
			Assert.IsFalse(movenextresult);
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:17,代码来源:DoubleVectorEnumeratorTest.cs


示例12: Gradient

 ///<summary>Method to override to calculate the grad_f, the first derivative of 
 /// the cost function with respect to x</summary>
 public virtual DoubleVector Gradient(DoubleVector x)
 {
   double eps = 1e-8;
   double fp, fm;
   DoubleVector grad = new DoubleVector(x.Length,0.0);
   
   DoubleVector xx = new DoubleVector(x);
   for (int i=0; i<x.Length; i++) 
   {
     xx[i] += eps;
     fp = this.Value(xx);
     xx[i] -= 2.0*eps;
     fm = this.Value(xx);
     grad[i] = 0.5*(fp - fm)/eps;
     xx[i] = x[i];
   }
   return grad;
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:20,代码来源:CostFunction.cs


示例13: TestRosenbrock

		public void TestRosenbrock()
		{
			Rosenbrock cf = new Rosenbrock();
			EndCriteria ec = new EndCriteria();
			ConjugateGradient optim = new ConjugateGradient(cf, ec);
			//  new SecantLineSearch(cf,ec));

			DoubleVector x0 = new DoubleVector(new double[5] { 1.3, 0.7, 0.8, 1.9, 1.2 });

			optim.Minimize(x0);

			Assert.AreEqual(optim.SolutionValue, 0.0, 0.1);
			Assert.AreEqual(optim.SolutionVector[0], 1.0, 0.1);
			Assert.AreEqual(optim.SolutionVector[1], 1.0, 0.1);
			Assert.AreEqual(optim.SolutionVector[2], 1.0, 0.1);
			Assert.AreEqual(optim.SolutionVector[3], 1.0, 0.2);
			Assert.AreEqual(optim.SolutionVector[4], 1.0, 0.4);
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:18,代码来源:ConjugateGradientTest.cs


示例14: Search

 ///<summary> Minimize the given cost function </summary>
 public override DoubleVector Search(DoubleVector x, DoubleVector d, double step) 
 {
   DoubleVector ret = new DoubleVector(x);
   double j=0;
   double eta;
 
   double delta_d = d.GetDotProduct(d);
   double alpha = -sigma_0;
   double eta_prev = d.GetDotProduct(GradientEvaluation(ret+sigma_0*d));
   do 
   {
     eta = d.GetDotProduct(GradientEvaluation(ret));
     alpha = alpha*(eta/(eta_prev-eta));
     ret = ret + alpha*d;
     eta_prev = eta;
     j++;
   } while ((j<maxIteration) && (alpha*alpha*delta_d > tolerance*tolerance));
   return ret;
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:20,代码来源:SecantLineSearch.cs


示例15: TestReflection

 public void TestReflection() 
 {
   Poly cf = new Poly();
   NelderMead optim = new NelderMead(cf);
   
   DoubleVector[] simplex = new DoubleVector[3];
   simplex[0] = new DoubleVector(new double[2]{1,1});
   simplex[1] = new DoubleVector(new double[2]{1,-1});
   simplex[2] = new DoubleVector(new double[2]{2,0});
   
   optim.Rho = 1.5;
   optim.InitializeMethod(simplex);
   optim.IterateMethod();
   
   DoubleVector xr = (1+optim.Rho)*(new DoubleVector(new double[2]{1,0})) - optim.Rho*simplex[2];
   
   Assert.IsTrue(optim.LastStep == NelderMead.Step.Reflection);
   Assert.AreEqual(optim.Simplex[0][0],xr[0]);
   Assert.AreEqual(optim.Simplex[0][1],xr[1]);
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:20,代码来源:NelderMeadTest.cs


示例16: Search

		public override LinearAlgebra.DoubleVector Search(LinearAlgebra.DoubleVector x, LinearAlgebra.DoubleVector direction, double step)
		{
			DoubleVector retx = new DoubleVector(x);
			double oldVal = FunctionEvaluation(retx);
			double newVal = oldVal;

			// First find the initial direction
			double valPos = FunctionEvaluation(retx + direction * step);
			double valNeg = FunctionEvaluation(retx - direction * step);
			if (valPos >= oldVal && valNeg < oldVal) // we reverse the direction only if the other direction really gives the smaller result
			{
				retx -= direction * step;
				oldVal = valNeg;
				step = -step;
			}
			else if (valPos < oldVal)
			{
				retx += direction * step;
				oldVal = valPos;
			}

			// now iterate
			for (; ; )
			{
				retx += direction * step;
				newVal = FunctionEvaluation(retx);

				if (newVal > oldVal)
				{
					step /= -2;
				}
				else if (!(newVal != oldVal))
				{
					break;
				}
				oldVal = newVal;
			}

			return retx;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:40,代码来源:StupidLineSearch.cs


示例17: TestInitializeMethod

 public void TestInitializeMethod()
 {
   Rosenbrock cf = new Rosenbrock();
   NelderMead optim = new NelderMead(cf);
   DoubleVector x0 = new DoubleVector(new double[4]{0,1,2,3});
   
   optim.SimplexDelta = 0.1;
   optim.SimplexZeroDelta = 0.0001;
   
   optim.InitializeMethod(x0);
   
   Assert.AreEqual(optim.Simplex.Length,5);
   for (int i=0; i<optim.Simplex.Length; i++) 
   {
     Assert.AreEqual(optim.Simplex[i][0],x0[0],optim.SimplexZeroDelta);
     Assert.AreEqual(optim.Simplex[i][1],x0[1],optim.SimplexDelta*x0[1]+0.001);
     Assert.AreEqual(optim.Simplex[i][2],x0[2],optim.SimplexDelta*x0[2]+0.001);
     Assert.AreEqual(optim.Simplex[i][3],x0[3],optim.SimplexDelta*x0[3]+0.001);
   }
   for (int i=1; i<optim.Simplex.Length; i++) 
   {
     Assert.IsTrue(cf.Value(optim.Simplex[i-1])<cf.Value(optim.Simplex[i]));
   }
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:24,代码来源:NelderMeadTest.cs


示例18: SetDiagonal

 public void SetDiagonal()
 {
   DoubleMatrix a = new DoubleMatrix(2,2);
   DoubleVector b = new DoubleVector(2);
   b[0] = 1;
   b[1] = 2;
   a.SetDiagonal(b);
   Assert.AreEqual(b[0], a[0,0]);
   Assert.AreEqual(b[1], a[1,1]);
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:10,代码来源:DoubleMatrixTest.cs


示例19: DoubleVectorEnumerator

 ///<summary> Constructor </summary>
 public DoubleVectorEnumerator (DoubleVector vector) 
 {
   v=vector;
   index=-1;
   length=v.Length;
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:7,代码来源:DoubleVectorEnumerator.cs


示例20: SetColumnOutOfRange

 public void SetColumnOutOfRange()
 {
   DoubleMatrix a = new DoubleMatrix(2,2);
   DoubleVector b = new DoubleVector(2);
   a.SetColumn(2,b);
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:6,代码来源:DoubleMatrixTest.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# LinearAlgebra.FloatSymmetricLevinson类代码示例发布时间:2022-05-24
下一篇:
C# LinearAlgebra.DoubleSymmetricLevinson类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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