search for: b_vec

Displaying 2 results from an estimated 2 matches for "b_vec".

2011 Nov 03
5
Is it possible to vectorize/accelerate this?
...te fast because of R and vectorizing, but it has a very slow for loop. The adjacent element of a vector (in terms of index number) depends conditionally on the former value of itself. Like a simple cumulating function (eg. cumsum) but with condition. Let's show me an example: a_vec = rnorm(100) b_vec = rep(0, 100) b_vec[1]=a_vec[1] for (i in 2:100){b_vec[i]=ifelse(abs(b_vec[i-1]+a_vec[i])>1, a_vec[i], b_vec[i-1]+a_vec[i])} print(b_vec) (The behaviour is like cumsum's, but when the value would excess 1.0 then it has another value from a_vec.) Is it possible to make this faster? I experie...
2009 Feb 16
2
solve.QP with box and equality constraints
...strain 1st and 4th values to be <1, 2nd and 3rd >0 (a = diag(c(-1,1,1,-1))) (b = c(1,0,0,1)) # this is correct according to these constraints, but I need 0 >= a <= 1 for all a and each row to sum to 1 solve.QP(Dmat = XX,dvec=Xy,Amat = a,bvec=b) #my guess at the constraint matrix and b_vec... (a2 = rbind( c(1,0,1,0), #specify the two cells in the 'row' I want to sum to one(???) c(0,1,0,1), # likewise kronecker(diag(rep(1,4)),c(1,-1)) #create positive and negative constraint pairs ) ) (b2 = c(1,1,rep(0:1,times=4))) solve.QP(Dmat = XX,dvec=Xy,Amat = a2,bvec=b2,meq...