void SolverUnconstrained<Data,Problem>::lambda_LS( vector_type & _x, vector_type & _lambda_l, vector_type & _lambda_u ) { //symmetric_matrix_type __A ( _E_nL, _E_nL ); matrix_type __A ( _E_nL, _E_nL ); vector_type __b ( _E_nL ); // At = [ -I (l-x) 0; I 0 (x-u) ] --> AtA = [ I+(l-x)^2 -I; -I I+(x-u)^2 ] __A = zero_matrix<double>( _E_nL, _E_nL ); for ( int __i = 0; __i < _E_n; ++__i ) { __A( __i, __i ) = 1.0 + ( M_prob.x_l( __i )-_x ( __i ) )*( M_prob.x_l( __i )-_x ( __i ) ); __A( __i, _E_n+__i ) = -1.0; __A( _E_n+__i,__i ) = -1.0; __A( ( _E_n+__i ), _E_n+__i ) = 1.0+( _x ( __i )-M_prob.x_u( __i ) )*( _x ( __i )-M_prob.x_u( __i ) ); } // b = [ \nabla f; 0; 0 ] --> Atb = [ -\nabla f; \nabla f ] f_type __f_x; M_prob.evaluate( _x, __f_x, diff_order<1>() ); for ( int i = 0; i < _E_n; i++ ) { value_type val = __f_x.gradient( 0, i ); __b ( i ) = val; __b ( _E_n+i ) = -val; } // after solve __b = [ _lambda_l; _lambda_] = A\b //char __uplo = 'U'; int __info = 0; int __nrhs = 1; int __N = _E_nL; //dppsv_ ( &__uplo, &__N, &__nrhs, __A.data(), __b.data(), &__ldb, &__info ); //dppsv_ ( &__uplo, &__N, &__nrhs, __A.data().begin(), __b.data().begin(), &__N, &__info ); ublas::vector<int> __itype( __N ); //dspsv_( &__uplo, &__N, &__nrhs, __A.data().begin(), __itype.data().begin(), __b.data().begin(), &__N, &__info ); dgesv_( &__N,&__nrhs,__A.data().begin(),&__N,__itype.data().begin(),__b.data().begin(),&__N,&__info ); if ( __info!= 0 ) { std::ostringstream __err; __err << "[" << __PRETTY_FUNCTION__ << "] dppsv failed: " << __info << "\n" << "A = " << __A << "\n" << "B = " << __b << "\n"; throw std::out_of_range( __err.str() ); } for ( int i = 0; i < _E_n; i++ ) { _lambda_l ( i ) = __b ( i ); _lambda_u ( i ) = __b ( _E_n+i ); } }
void NonLinearSquare<Problem,Time>::doCompute( ) { __A = __p.jacobi(__x).transpose()*(__p.jacobi(__x)); __g = __p.jacobi(__x).transpose()*(__p.value(__x)); scalar max = fabs(__A(0,0)); for(int i=0; i<__n; i++){ if(fabs(__A(i,i))>max) max=__A(i,i); } __u = __tao*max; }
typename NonLinearSquare<Problem,Time>::scalar NonLinearSquare<Problem,Time>::doOneIteration() { /* Levenberg Marquardt method */ scalar e = 1e-8; scalar rho; Vector h; Vector x; __found = (sqrt(__g.dot(__g)) <= e); Matrix B(__A); Vector k(__g); for(int i=0; i<__n; i++){ B(i,i) = __A(i,i)+__u; k[i]=-__g[i]; } /* Solve linear equations */ h = B.solve(k); if ( h.dot(h) < e*(e+__x.dot(__x)) ) { __found = true; return sqrt(h.dot(h)); } else { x = __x + h; /* Judgment flag rho = (F(__x)-F(x))/L(h,u,g) */ rho = (__p.value(__x).dot(__p.value(__x))/2-__p.value(x).dot(__p.value(x))/2)/(0.5*h.dot(__u*h-__g)); if (rho > 0.0) { __x = x; __A = __p.jacobi(__x).transpose()*(__p.jacobi(__x)); __g = __p.jacobi(__x).transpose()*(__p.value(__x)); __found = ( sqrt(__g.dot(__g)) <= e ); scalar uu=1/3; if ( 1-(2*rho-1)*(2*rho-1)*(2*rho-1) > uu ) { uu = 1-(2*rho-1)*(2*rho-1)*(2*rho-1); } __u = __u*uu; __v = 2.0; } else { __u = __u*__v; __v = 2*__v; } return sqrt(__g.dot(__g)); } }
"Example: meta(nfmark gt 24)\n" \ " meta(indev shift 1 eq \"ppp\")\n" \ " meta(tcindex mask 0xf0 eq 0xf0)\n" \ "\n" \ "For a list of meta identifiers, use meta(list).\n"); } struct meta_entry { int id; char * kind; char * mask; char * desc; } meta_table[] = { #define TCF_META_ID_SECTION 0 #define __A(id, name, mask, desc) { TCF_META_ID_##id, name, mask, desc } __A(SECTION, "Generic", "", ""), __A(RANDOM, "random", "i", "Random value (32 bit)"), __A(LOADAVG_0, "loadavg_1", "i", "Load average in last minute"), __A(LOADAVG_1, "loadavg_5", "i", "Load average in last 5 minutes"), __A(LOADAVG_2, "loadavg_15", "i", "Load average in last 15 minutes"), __A(SECTION, "Interfaces", "", ""), __A(DEV, "dev", "iv", "Device the packet is on"), __A(SECTION, "Packet attributes", "", ""), __A(PRIORITY, "priority", "i", "Priority of packet"),
#include <bathos/types.h> #include <bathos/init.h> #include <bathos/io.h> #include <arch/hw.h> #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) /* * This table is needed to turn gpio number to address. The hairy * macros are used to shrink the source code. */ #define CFG_REG(port, bit) __GPIO_CFG_P ## port ## _ ## bit #define __A(port, bit) [GPIO_NR(port,bit)] = CFG_REG(port,bit) static u8 gpio_addr[] = { __A(0, 0), __A(0, 1), __A(0, 2), __A(0, 3), __A(0, 4), __A(0, 5), __A(0, 6), __A(0, 7), __A(0, 8), __A(0, 9), __A(0,10), __A(0,11), __A(1, 0), __A(1, 1), __A(1, 2), __A(1, 3), __A(1, 4), __A(1, 5), __A(1, 6), __A(1, 7), __A(1, 8), __A(1, 9), __A(1,10), __A(1,11), __A(2, 0), __A(2, 1), __A(2, 2), __A(2, 3), __A(2, 4), __A(2, 5), __A(2, 6), __A(2, 7), __A(2, 8), __A(2, 9), __A(2,10), __A(2,11), __A(3, 0), __A(3, 1), __A(3, 2), __A(3, 3), __A(3, 4), __A(3, 5), }; #define GPIO_MAX (ARRAY_SIZE(gpio_addr) - 1) /* This other table marks the ones where AF0 is swapped with AF1 */ static u16 gpio_weird[] = { __GPIO_WEIRDNESS_0, __GPIO_WEIRDNESS_1, __GPIO_WEIRDNESS_2, __GPIO_WEIRDNESS_3 };
#include <netlink/cbq.h> #include <netlink/helpers.h> #include <netlink/route/rtattr.h> /** * @ingroup qdisc * @defgroup cbq Class Based Queueing (CBQ) * @{ */ static struct { int i; const char *a; } ovl_strategies[] = { #define __A(id, name) { TC_CBQ_OVL_##id, #name }, __A(CLASSIC,classic) __A(DELAY,delay) __A(LOWPRIO,lowprio) __A(DROP,drop) __A(RCLASSIC,rclassic) #undef __A }; /** * Convert a CBQ OVL strategy to a character string * @arg type CBQ OVL strategy * @arg buf destination buffer * @arg len length of destination buffer * * Converts a CBQ OVL strategy to a character string and stores in the