Beispiel #1
0
 //==========================================================================
 // null space basis up to epsi
 //==========================================================================
   tab_t null(base_t epsi = -1 )const
   {
     epsi =  epsi < 0 ? nt2::eps(w_(1)) : epsi;
     int j = numel(w_);
     for(; (j > 0) && (w_(j)<= epsi); j--);
     j++;
     return nt2::fliplr(trans(vt()(_(j, last_index<1>(vt_)), _)));
   }
Beispiel #2
0
 // /////////////////////////////////////////////////////////////////////////////
 // return rank up to epsi
 // /////////////////////////////////////////////////////////////////////////////
 size_t     rank(base_t epsi = Eps<base_t>())
 {
   size_t r = 0;
   base_t thresh = n_*epsi*nt2::max(nt2::abs(w_(_)));
   for(int i=1; i <= n_; ++i)
     {
       if(nt2::abs(w_(i)) > thresh) ++r;
     }
   return r;
 }
Beispiel #3
0
extern "C" void* call_poll_cq_w_wrap(void* wrap_)
{
  wrap_Connector* w_(static_cast<wrap_Connector*>(wrap_) );
  w_->connector_->poll_cq(w_->s_ctx_);
  
  delete w_;
  return 0;
}
Beispiel #4
0
void ftrl_proximal::update(SparseVector<float> x, float p, float y)
{
    for (SparseVector<float>::InnerIterator it(x); it; ++it)
    {
        int i = it.index();
        float x_i = it.value();
        float g = (p - y) * x_i;
        float sigma = (sqrt(n_(i) + g * g) - sqrt(n_(i))) / alpha_;
        z_(i) += g - sigma * w_(i);
        n_(i) += g * g;
    }
}
Beispiel #5
0
    //==========================================================================
    // Return matrix rank up to epsi
    //==========================================================================
     size_t      rank(base_t epsi = -1) const
    {
      epsi =  (epsi < 0) ?  nt2::max(n_, m_)*nt2::eps(w_(1)): epsi;
//       size_t r = 0;
//       for(int i=1; i <= numel(w_); ++i)
//         {
//           if (w_(i) > epsi)
//             ++r;
//           else
//             return r;
//         }
//       return r;
      return  size_t(sum(if_one_else_zero(gt(w_, epsi))(_)));
    }
Beispiel #6
0
float ftrl_proximal::predict(SparseVector<float> x)
{
    double wTx = 0.0;

    for (SparseVector<float>::InnerIterator it(x); it; ++it)
    {
        int i = it.index();
        int sign = 0;
        if(z_(i) < 0)
            sign =-1;
        else 
            sign = 1;

        if(z_(i) * sign <= lambda1_)
            w_(i) = 0.0;
        else 
            w_(i) = (sign * lambda1_ - z_(i)) / ((beta_ + sqrt(n_(i))) / alpha_ + lambda2_);

        wTx += w_(i) * it.value();
    }

    return 1.0 / (1.0 + exp(-max(min(wTx, 35.0), -35.0)));
}
Beispiel #7
0
void FEM::init_localmass(double localmass[][4], int cells){
    const double h = 1./cells;
  int dim, num;

  ELEMENTS::Interval Element;
  dim = Element.dimension();
  num = Element.getNumberOfCorners();
  std::vector<std::vector<double> > Stencil;
  std::vector<double> data(num*dim,0.);
  
  for(int i = 0; i < cells; ++i)
  {
    data[0] = i*h;
    data[1] = (i+1)*h;
    Element(data);
    Stencil = Element.integrate(C_(1) * v_()*w_());
    localmass[i][0] = Stencil[0][0];
    localmass[i][1] = Stencil[0][1];
    localmass[i][2] = Stencil[1][0];
    localmass[i][3] = Stencil[1][1];
  }
}
Beispiel #8
0
 tab_t pinv(base_t epsi = -1 )const
 {
   epsi = epsi < 0 ? nt2::eps(w_(1)) : epsi;
   tab_t w1 = nt2::if_else( gt(w_, length(a_)*epsi), nt2::rec(w_), Zero<base_t>());
   return mtimes(trans(vt_), mtimes(from_diag(w1), trans(u_)));
 }
Beispiel #9
0
template<class XPR> result_type solve(const XPR & b,
                                      base_t epsi = Mone<base_t>() )const{
  epsi =  epsi < 0 ? nt2::eps(w_(1)) : epsi;
  tab_t w1 = nt2::if_else( gt(w_, length(a_)*epsi), nt2::rec(w_), Zero<base_t>());
  return mtimes(trans(vt_), mtimes(from_diag(w1), mtimes(trans(u_), b)));
  }
Beispiel #10
0
 //==========================================================================
 // Return matrix norm
 //==========================================================================
 base_t     norminv()       const { return  nt2::rec(w_(nt2::min(m_, n_))); }
Beispiel #11
0
 //==========================================================================
 // Return matrix norm
 //==========================================================================
 base_t     norm()       const { return  w_(1); }
Beispiel #12
0
 //==========================================================================
 // Return matrix condition number
 //==========================================================================
 base_t     cond()       const
 {
   base_t r =  w_(1)/w_(nt2::min(m_, n_));
   return is_nan(r) ? Inf<base_t>() : r;
 }
Beispiel #13
0
 void operator()(nt2::blocked_range<std::size_t> const& r)
 {
     out_ = w_(out_,r.begin(),r.size());
 };
Beispiel #14
0
 // /////////////////////////////////////////////////////////////////////////////
 // return condition number
 // /////////////////////////////////////////////////////////////////////////////
 base_t     cond() const {return  nt2::abs(w_(1)/w_(numel(w_))); }