Beispiel #1
0
 BOOST_FORCEINLINE static void doit2(const T& a, value_type& b, Out0& r)
 {
   r.resize(extent(a));
   typedef typename A0::index_type       index_type;
   typedef table<value_type, index_type> result_type;
   bool is_ltz_b = is_ltz(b); 
   if(is_ltz(b)) b = -b; 
   value_type m = nt2::trunc(b);
   value_type f = b-m;
   result_type q, t;
   // tie(q, t) = schur(a,'N'/*"complex"*/); // t is complex schur form.        result_type e, v;
   if (false && isdiagonal(t))
     {
       t = nt2::from_diag(nt2::pow(diag_of(t), m));
       if(is_ltz_b) t = nt2::inv(t);        
       r = nt2::mtimes(q, nt2::mtimes(t, nt2::trans(nt2::conj(q))));
       return;
     }
   else
     { //use iterative method
       r = nt2::eye(nt2::size(a), meta::as_<value_type>());
       result_type rf = r;
       if (m)
         {
           result_type a00 = a;
           while (m >= nt2::One<value_type>())
             {
               if (nt2::is_odd(m))
                 {
                   r =  nt2::mtimes(a00, r);
                 }
               a00 =  nt2::mtimes(a00, a00);
               m =  nt2::trunc(m/2); //Half<value_type>(); or >> 1
             }
         }
       if(!f)
         {
           if(is_ltz_b) r = nt2::inv(r); 
           return;
         }
       else
         {
           result_type a00 = nt2::sqrtm(a);
           value_type thresh = nt2::Half<value_type>();
           while (f > Zero<value_type>())
             {
               if (f >= thresh)
                 {
                   rf = nt2::mtimes(rf, a00);
                   f -= thresh;
                 }
               thresh *= nt2::Half<value_type>();
               a00 =  nt2::sqrtm(a00);
             }
         }
       r= nt2::mtimes(r, rf);
       if(is_ltz_b) r = nt2::inv(r); 
     }
 }
Beispiel #2
0
    BOOST_FORCEINLINE static void conf_bounds(const A0& a0, A1& a1,
                                              const M2x2 pcov,
                                              const value_type& normz,
                                              Out0 & p)
    {
      typedef typename boost::proto::result_of::child_c<A1&,1>::type         Out1;
      typedef typename boost::proto::result_of::child_c<A1&,2>::type         Out2;

      //      NT2_DISPLAY(a0.extent());   NT2_DISPLAY(a1.extent());
      p.resize(a0.extent());
      const In0& x  = boost::proto::child_c<0>(a0);
      //      NT2_DISPLAY(x);
      const In1& a = boost::proto::child_c<1>(a0);
      //      NT2_DISPLAY(a);
      const In2& b = boost::proto::child_c<2>(a0);
      //       NT2_DISPLAY(b);
      BOOST_AUTO_TPL(z, x/b);
      //       NT2_DISPLAY(z);
      //       NT2_DISPLAY(nt2::gammainc(z, a));
      //       NT2_DISPLAY(size(p));
      p =  nt2::exp(z); //nt2::gammainc(z, a);
      //       NT2_DISPLAY(p);
      //      Out0& p = boost::proto::child_c<0>(a1);
      //      NT2_DISPLAY(p);
      BOOST_AUTO_TPL(itp, (p/nt2::oneminus(p)));
      //       NT2_DISPLAY(itp);
      BOOST_AUTO_TPL(dp, nt2::rec(p*oneminus(p))); // derivative of logit(p) w.r.t. p
      //       NT2_DISPLAY(dp);
      BOOST_AUTO_TPL(da, dgammainc(z,a)*dp);       // dlogitp/da = dp/da * dlogitp/dp
      //       NT2_DISPLAY(da);
      BOOST_AUTO_TPL(db, -nt2::exp(a*nt2::log(z)-z-nt2::gammaln(a)-nt2::log(b))* dp); // dlogitp/db = dp/db * dlogitp/dp
      //      NT2_DISPLAY(db);
      BOOST_AUTO_TPL(varLogitp, pcov(1,1)*sqr(da) + (Two<value_type>()*pcov(1,2)*da + pcov(2,2)*db)*db);
      //       NT2_DISPLAY(varLogitp);
      //       NT2_DISPLAY(normz);
      BOOST_AUTO_TPL(exp_halfwidth, nt2::exp(normz*nt2::sqrt(varLogitp)));
      //       NT2_DISPLAY(exp_halfwidth);
      Out1 & plo = boost::proto::child_c<1>(a1);
      Out2 & pup = boost::proto::child_c<2>(a1);
      plo.resize(a0.extent());
      pup.resize(a0.extent());
      //      std::cout << "1" << std::endl;
      plo = itp*exp_halfwidth;
      //      std::cout << "2" << std::endl;
      pup = itp/exp_halfwidth;
      //      std::cout << "3" << std::endl;
      plo /= nt2::oneplus(plo);
      //      std::cout << "4" << std::endl;
      pup /= nt2::oneplus(pup);
      //      std::cout << "5" << std::endl;
    }
Beispiel #3
0
 BOOST_FORCEINLINE static void doit1(const value_type& a, T& b, Out0& r)
 {
   r.resize(extent(b));
   r =  nt2::expm(nt2::log(a)*b);
 }