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


C++ DiagonalMatrix::inplacePseudoInverse方法代码示例

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


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

示例1: Solve

LP_InteriorPointSolver::Result LP_InteriorPointSolver::Solve()
{
  if (verbose>=1) cout << "Solving LP_InteriorPoint:" << endl;
  
  if (x0.n == 0) {
    if (! FindFeasiblePoint()) {
      if(verbose>=1) cout << "Couldn't find an initial feasible point in LP_InteriorPointSolver::solve()" << endl;
      return Infeasible;
    }
  }
	
  if (verbose>=2) { cout << "x0 = "<<VectorPrinter(x0)<<endl; }
	
  // Make sure starting xopt is always set to x0 when we begin to solve.
  xopt = x0;
    
  // Already checked that the initial point is feasible.
	
  //
  // Algorithm parameters
  //
  
  //	t	- indicates how far the search is along the "central path"; basically,
  //		  it just trades off how much we weight the goal vs. the inequality barriers.
  double t=0.01;
  //	mu	- multiple by which we increase t at each outer iteration.
  double mu=15;
  //	alpha	- ? - in backtracking line search, I think this indicates a goal decrement or something.
  //	beta	- in backtracking line search, how much we back off at each iteration
  double alpha=0.2;
  double beta=0.5;
	
  //
  // Outer Loop
  //

  DiagonalMatrix d;
  Matrix Hsub,H;
  Vector g;
  Vector dx;
  Vector xcur;
  //cout<<"A is "<<endl<<MatrixPrinter(A)<<endl;
  //cout<<"b is "<<VectorPrinter(b)<<endl;
  //getchar();
	
  double gap=1.0;
  int iter_outer=0;
  while (gap>tol_outer) {
    if(verbose >= 2) { cout << "Current xopt = "<<VectorPrinter(xopt)<<endl; }
		
    ++iter_outer;
    if (iter_outer > kMaxIters_Outer) {
      cout << "WARNING: LP_InteriorPoint outer loop did not converge within max iters" << endl;
      return MaxItersReached;
    }
		
    // Update position along the central path
    t *= mu;
		
    if (verbose>=2) cout << " Outer iter " << iter_outer << ", t=" << t << endl;
		
    //
    // Inner Loop
    //
		
    double dec=1.0;
    int iter_inner=0;
    while ((fabs(dec)>tol_inner) && (iter_inner <= kMaxIters_Inner)) {
      ++iter_inner;
      /*
	if (iter_inner > kMaxIters_Inner) {
	cout << "WARNING: LP_InteriorPoint inner loop did not converge within max iters" << endl;
	return MaxItersReached;
	}
      */
			
      if (verbose>=3) cout << "  Inner iter " << iter_inner << ", dec=" << dec << endl;
			
      // (1) Compute the direction to descend
      //		- Newton direction is dx = -(Hessian^-1)*(gradient)
      //		- H = (Aineq'*(diag(d.^2))*Aineq)
      //		- g = (t*f) + (Aineq'*d)
			
      //cout << "Size of Aineq is " << A.m << " x " << A.n << endl;

      //d = (bineq-Aineq*xopt)^-1 component-wise
      A.mul(xopt,d);  d.inplaceNegative();  d += p;
      d.inplacePseudoInverse();
      //Hsub = diag(d)*Aineq
      d.preMultiply(A,Hsub);
      //H = Hsub'*Hsub
      H.mulTransposeA(Hsub,Hsub);		

      //g = Aineq'*d+t*c	
      A.mulTranspose(d,g);
      g.madd(c,t);
      Matrix Htemp=H;
      Vector gtemp=g;
      // Solve the system to find Newton direction
      // Try using a better numerically conditioned matrix
//.........这里部分代码省略.........
开发者ID:camall3n,项目名称:KrisLibrary,代码行数:101,代码来源:LP_InteriorPoint.cpp


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