Example #1
0
int main(int argc, char **argv)
{
  try {
    const int d = 7;
    Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > bases(1); 
    bases[0] = Teuchos::rcp(new Stokhos::HermiteBasis<int,double>(d));
    Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > basis = 
      Teuchos::rcp(new Stokhos::CompletePolynomialBasis<int,double>(bases));
    Teuchos::RCP<Teuchos::SerialDenseMatrix<int,double> > Bij =
      basis->computeDerivDoubleProductTensor();
    Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk =
      basis->computeTripleProductTensor(basis->size());
    Teuchos::RCP<Stokhos::Dense3Tensor<int,double> > Dijk =
      basis->computeDerivTripleProductTensor(Bij, Cijk);
    Stokhos::DerivOrthogPolyExpansion<int,double> expn(basis, Bij, Cijk, Dijk);
    Stokhos::OrthogPolyApprox<int,double> u(basis),v(basis),w(basis);
    u[0] = 1.0;
    u[1] = 0.4;
    u[2] = 0.06;
    u[3] = 0.002;

    expn.log(v,u);
    expn.times(w,v,v);
    expn.plusEqual(w,1.0);
    expn.divide(v,1.0,w);
    expn.sinh(w,v);

    std::cout << "u (orthogonal basis) = " << u << std::endl;
    std::cout.precision(12);
    std::cout << "w (orthogonal basis) = " << w << std::endl;
  }
  catch (std::exception& e) {
    std::cout << e.what() << std::endl;
  }
}
Example #2
0
int decstat()
{
 if(T[nt++].t==13)
 {
  stmtflag[no]=1;
  if(T[nt++].t==20)
  {
   if(expn())
   {
	if(T[nt++].t==21)
	{
	 if(stmt())
	 {
	  if(dprime())
	   return 1;
	  else
	   return 0;
	 }
	 else
	  return 0;
	}
	else
	{
	 strcpy(miss,")");
	 return 0;
	}
   }
   else
	return 0;
  }
  else
  {
   strcpy(miss,"(");
   return 0;
  }
 }
 else
 {
  nt--;
  return 0;
 }
}
Example #3
0
int assstat()
{
 if(T[nt++].t==50)
 {
  stmtflag[no]=1;
  if(T[nt++].t==28)
  {
   if(expn())
	return 1;
   else
	return 0;
  }
  else
  {
   strcpy(miss,"=");
   return 0;
  }
 }
 else
 {
  nt--;
  return 0;
 }
}
Example #4
0
int main(int argc, char **argv)
{
  try {

    // Basis of dimension 3, order 5
    const int d = 3;
    const int p = 5;
    Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > bases(d); 
    for (int i=0; i<d; i++) {
      bases[i] = Teuchos::rcp(new Stokhos::HermiteBasis<int,double>(p));
    }
    Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > basis = 
      Teuchos::rcp(new Stokhos::CompletePolynomialBasis<int,double>(bases));

    // Quadrature method
    Teuchos::RCP<const Stokhos::Quadrature<int,double> > quad = 
        Teuchos::rcp(new Stokhos::TensorProductQuadrature<int,double>(basis));

    // Triple product tensor
    Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk =
      basis->computeTripleProductTensor(basis->size());

    // Expansion method
    Stokhos::QuadOrthogPolyExpansion<int,double> expn(basis, Cijk, quad);

    // Polynomial expansions
    Stokhos::OrthogPolyApprox<int,double> u(basis), v(basis), w(basis);
    u.term(0,0) = 1.0;
    for (int i=0; i<d; i++) {
      u.term(i,1) = 0.4 / d;
      u.term(i,2) = 0.06 / d;
      u.term(i,3) = 0.002 / d;
    }

    // Compute expansion
    expn.log(v,u);
    expn.times(w,v,v);
    expn.plusEqual(w,1.0);
    expn.divide(v,1.0,w);

    // Print u and v
    std::cout << "v = 1.0 / (log(u)^2 + 1):" << std::endl;
    std::cout << "\tu = ";
    u.print(std::cout);
    std::cout << "\tv = ";
    v.print(std::cout);

    // Compute moments
    double mean = v.mean();
    double std_dev = v.standard_deviation();

    // Evaluate PCE and function at a point = 0.25 in each dimension
    Teuchos::Array<double> pt(d); 
    for (int i=0; i<d; i++) 
      pt[i] = 0.25;
    double up = u.evaluate(pt);
    double vp = 1.0/(std::log(up)*std::log(up)+1.0);
    double vp2 = v.evaluate(pt);
    
    // Print results
    std::cout << "\tv mean         = " << mean << std::endl;
    std::cout << "\tv std. dev.    = " << std_dev << std::endl;
    std::cout << "\tv(0.25) (true) = " << vp << std::endl;
    std::cout << "\tv(0.25) (pce)  = " << vp2 << std::endl;
    
    // Check the answer
    if (std::abs(vp - vp2) < 1e-2)
      std::cout << "\nExample Passed!" << std::endl;
  }
  catch (std::exception& e) {
    std::cout << e.what() << std::endl;
  }
}
Example #5
0
void deom::rem_sch (cx_cube& dtotal, const cx_cube& total, const double t) {

    const int nsav = nddo;
    dtotal.slices(0,nddo-1).zeros();

    for (int iado=0; iado<nsav; ++iado) {
        const cx_mat& ado = total.slice(iado);
        if (iado==0 || is_valid (ado)) {
            string key = keys(iado);
            const int tier = maps[key].tier;
            const cx_double gams = maps[key].gams;

            dtotal.slice(iado) += -deom_ci*(ham1*ado-ado*ham1)-gams*ado;
            for (int m=0; m<nmod; ++m) {
                qddo.slice(m) = qmd1.slice(m)*ado;
                ddoq.slice(m) = ado*qmd1.slice(m);
                dtotal.slice(iado) -= delt_res(m)*(
                        qmd1.slice(m)*(qddo.slice(m)-ddoq.slice(m))
                       -(qddo.slice(m)-ddoq.slice(m))*qmd1.slice(m));
            }

            if (tier < lmax) {
                for (int mp=0; mp<nind; ++mp) {
                    const int m = mp/nper;
                    const int p = mp%nper;
                    const int n = key[mp]-'0';
                    const cx_double sn = -deom_ci*sqrt((n+1)/coef_abs(m,p));
                    const cx_double cl = sn*coef_lft(m,p);
                    const cx_double cr = sn*coef_rht(m,p);
                    key[mp] = static_cast<char>(key[mp]+1);
                    const auto &xp = maps.emplace(key,hnod(nddo,tier+1,gams+expn(mp)));
                    if (!xp.second) {
                        int loc = xp.first->second.rank;
                        dtotal.slice(loc) += cl*qddo.slice(m)-cr*ddoq.slice(m);
                    } else {
                        keys(nddo) = key;
                        dtotal.slice(nddo) = cl*qddo.slice(m)-cr*ddoq.slice(m);
                        nddo += 1;
                    }
                    key[mp] = static_cast<char>(key[mp]-1);
                }
            }

            if (iado > 0) {
                for (int mp=0; mp<nind; ++mp) {
                    const int m = mp/nper;
                    const int p = mp%nper;
                    const int n = key[mp]-'0';
                    if (n > 0) {
                        key[mp] = static_cast<char>(key[mp]-1);
                        const cx_double sn = -deom_ci*sqrt(n*coef_abs(m,p));
                        const auto &xp = maps.emplace(key,hnod(nddo,tier-1,gams-expn(mp)));
                        if (!xp.second) {
                            int loc = xp.first->second.rank;
                            dtotal.slice(loc) += sn*(qddo.slice(m)-ddoq.slice(m)); 
                        } else {
                            keys(nddo) = key;
                            dtotal.slice(nddo) = sn*(qddo.slice(m)-ddoq.slice(m)); 
                            nddo += 1;
                        }
                        key[mp] = static_cast<char>(key[mp]+1);
                    }
                }
            }
        }
    }
}
Example #6
0
int loopstat()
{
 if(T[nt++].t==15)
 {
  stmtflag[no]=1;
  if(T[nt++].t==20)
  {
   if(expn())
   {
	if(T[nt++].t==21)
	{
	 if(stmt())
	  return 1;
	 else
	  return 0;
	}
	else
	{
	 strcpy(miss,")");
	 return 0;
	}
   }
   else
	return 0;
  }
  else
  {
   strcpy(miss,"(");
   return 0;
  }
 }
 else
 {
  nt--;
  if(T[nt++].t==16)
  {
   stmtflag[no]=1;
   if(T[nt++].t==20)
   {
	if(assstat())
	{
	 if(T[nt++].t==27)
	 {
	  if(expn())
	  {
	   if(T[nt++].t==27)
	   {
		if(assstat())
		{
		 if(T[nt++].t==21)
		 {
		  if(stmt())
		   return 1;
		 }
		 else
		 {
		  strcpy(miss,")");
		  return 0;
		 }
		}
	   }
	   else
	   {
		if(stmtflag[no]==0)
		 strcpy(miss,";");
		return 0;
	   }
	  }
	 }
	 strcpy(miss,";");
	 return 0;
	}
   }
   else
   {
	if(stmtflag[no]==1)
	 strcpy(miss,"(");
	return 0;
   }
  }
  else
  {
   nt--;
   return 0;
  }
 }
}