chrisnc / hvx

Disciplined Convex Programming in Haskell
Other
22 stars 8 forks source link

Add multiply-by-positive-constant primitive hmulpos. #9

Open cheater opened 7 years ago

cheater commented 7 years ago

Following your tips I have rewritten the "concatenation" function a little and it seems I have found a simple primitive that should provide stronger monotonicity.

varsAsVect xs = vOut
  -- | Take a list of scalar variables and output them as a single vector Expr
  where
    vOut = foldl' (+~) (head vs) (tail vs)
    xsIndices = zip ([0..] :: [Int]) xs
    vs = f <$> xsIndices
    f (ind, x) = v *~+ x
      where
        v = EConst $ orthonormal ind

    orthonormal i = assoc (n, 1) 0.0 [((i, 0), 1.0)]
    n = length xs

here *~+ is exactly the same as *~ except you can only have non-negative constants on the left, or it will throw an exception. Is my understanding correct that this requirement on the left argument will preserve monotonicity of the right argument?

chrisnc commented 7 years ago

I'm still skeptical about adding more exports. Also it seems unrelated to the other changes you're making.