// produces the Cholesky decomposition of A - x.t() * x where A = chol.t() * chol
void downdate_Cholesky(UpperTriangularMatrix &chol, RowVector x)
{
   int nRC = chol.Nrows();
	
   // solve R^T a = x
   LowerTriangularMatrix L = chol.t();
   ColumnVector a(nRC); a = 0.0;
   int i, j;
	
   for (i = 1; i <= nRC; ++i)
   {
      // accumulate subtr sum
      Real subtrsum = 0.0;
      for(int k = 1; k < i; ++k) subtrsum += a(k) * L(i,k);

      a(i) = (x(i) - subtrsum) / L(i,i);
   }

   // test that l2 norm of a is < 1
   Real squareNormA = a.SumSquare();
   if (squareNormA >= 1.0)
      Throw(ProgramException("downdate_Cholesky() fails", chol));

   Real alpha = sqrt(1.0 - squareNormA);

   // compute and apply Givens rotations to the vector a
   ColumnVector cGivens(nRC);  cGivens = 0.0;
   ColumnVector sGivens(nRC);  sGivens = 0.0;
   for(i = nRC; i >= 1; i--)
      alpha = pythag(alpha, a(i), cGivens(i), sGivens(i));

   // apply Givens rotations to the jth column of chol
   ColumnVector xtilde(nRC); xtilde = 0.0;
   for(j = nRC; j >= 1; j--)
   {
      // only the first j rotations have an affect on chol,0
      for(int k = j; k >= 1; k--)
         GivensRotation(cGivens(k), -sGivens(k), chol(k,j), xtilde(j));
   }
}
Exemplo n.º 2
0
void SetImage::pave(const IntervalVector& x, double epsilon) {

	Linside.clear();
	Lboundary.clear();

	PdcImageSubset p_fin(f,x,p_in);

	assert(x.size()==n);

	stack<IntervalVector> Ldomain;
	IntervalVector xtilde(n);
	IntervalVector ytilde(n);
	LargestFirst lf(epsilon);

	Ldomain.push(x);
	while (! Ldomain.empty()) {
		xtilde = Ldomain.top();
		Ldomain.pop();

		c_out.contract(xtilde);

		if (xtilde.is_empty()) {
			continue;
		}

		// use natural extension
		ytilde=f.eval_vector(xtilde);
		// improve with centered form
		ytilde&=f.eval_vector(xtilde.mid())+f.jacobian(xtilde)*(xtilde-xtilde.mid());
		if (p_in.test(xtilde)==YES && p_fin.test(cart_prod(xtilde,ytilde))==YES)
			Linside.push_back(ytilde);
		else if (xtilde.max_diam()<=epsilon)
			Lboundary.push_back(ytilde);
		else  {
			pair<IntervalVector,IntervalVector> boxes=lf.bisect(xtilde);
			Ldomain.push(boxes.first);
			Ldomain.push(boxes.second);
		}
	}
}
Exemplo n.º 3
0
QString expando(const QString cmd)
{
    QString rv;
    QString word, c, endc;
    QProcessEnvironment env=QProcessEnvironment::systemEnvironment();
    rv.reserve(cmd.length()+1024);
    int state=0;
    int escape=0;
    for (int i=0;i<cmd.length();i++)
    {
        c=cmd.mid(i,1);
        if (escape!=0)
        {
            if (escape==1) rv+=c; else word+=c;
            escape=0;
            continue;
        }
        switch (state)
        {
        case 2:   // looking for word sep
            if (c=="\\")
            {
                escape=2;
                continue;
            }
            if (c[0].isLetterOrNumber()||c[0]=='-'||c[0]=='_')   // is this list complete?
            {
                word+=c;
                continue;
            }
            rv+=env.value(word,"");
            state=0;
// fall through
        case 0:   // no env
            if (c=="\\")
            {
                escape=1;
                continue;
            }
            if (c!="$")
            {
                rv+=c;
                continue;
            }
            word="";
            state=1;
            continue;

        case 1:   // found $
            if (c=="("||c=="{"||c=="[")
            {
                endc=")";
                if (c=="{") endc="}";
                if (c=="[") endc="]";
                state=3;
                continue;
            }
            if (c!="\\") word+=c;
            state=2;
            continue;


        case 3:   // looking for )
            if (c=="\\")
            {
                escape=2;
                continue;
            }
            if (c==endc)
            {
                if (word.mid(0,9)=="QLPROMPT:")
                {
                    bool ok;
                    QString title="qlaunch prompt", prompt="", deftext="";

                    int n;
                    prompt=word.mid(9);  // put $QLPROMPT:prompt:default:title (all but prompt optional)
                    n=prompt.indexOf(':');
                    if (n!=-1)
                    {
                        deftext=prompt.mid(n+1);
                        prompt=prompt.mid(0,n);
                        n=deftext.indexOf(':');
                        if (n!=-1)
                        {
                            title=deftext.mid(n+1);
                            deftext=deftext.mid(0,n);
                        }

                    }
                    QString itext=QInputDialog::getText(NULL,title,prompt,QLineEdit::Normal,deftext,&ok);
                    if (ok) rv+=itext;
                }
                else rv+=env.value(word,"");
                state=0;
                continue;
            }
            word+=c;
            continue;

        }
    }
    if (state==2||state==3) rv+=env.value(word,""); // pick up any left over word at the end
    return xtilde(rv);

}