Giter Club home page Giter Club logo

Comments (14)

idontgetoutmuch avatar idontgetoutmuch commented on June 15, 2024 1

This (lifted from https://github.com/miguel-negrao/test-integral/blob/main/app/Main.hs) works but I don't know how you could apply this to Yampa (thanks @miguel-negrao).

integral :: (Monad m, VectorSpace a s) => SF m a a
integral = integralFrom zeroVector

integralFrom :: (Monad m, VectorSpace a s) => a -> SF m a a
integralFrom a0 =
  zeroVector --> proc a -> do
    dt <- constM ask -< ()
    aPrev <- iPre zeroVector -< a
    accumulateWith (^+^) a0 -< (realToFrac dt / 2) *^ (a ^+^ aPrev)

from yampa.

idontgetoutmuch avatar idontgetoutmuch commented on June 15, 2024 1

Maybe this?

integral :: forall a s . (Fractional s, VectorSpace a s) => SF a a
integral = SF {sfTF = tf0}
  where
    tf0 a0 = (integralAux igrl0 a0, igrl0)

    igrl0  = zeroVector

    integralAux :: a -> a -> SF' a a
    integralAux igrl a_prev = SF' tf -- True
      where
        tf :: DTime -> a -> (SF' a a, a)
        tf dt a = (integralAux igrl' a, igrl')
          where
            igrl' = igrl ^+^ (realToFrac dt / 2) *^ (a ^+^ a_prev)

from yampa.

idontgetoutmuch avatar idontgetoutmuch commented on June 15, 2024 1

@chansey97 Full code is here: https://github.com/idontgetoutmuch/phd-jonathan-thaler/commits/literate-haskell-for-review. In particular, it should be possible to run this: https://github.com/idontgetoutmuch/phd-jonathan-thaler/blob/literate-haskell-for-review/SIRABM.lhs#L262.

from yampa.

ivanperez-keera avatar ivanperez-keera commented on June 15, 2024

Which specific issue were you trying to point to?

Is this a problem only in dunai or also in Yampa?

from yampa.

ivanperez-keera avatar ivanperez-keera commented on June 15, 2024

@idontgetoutmuch Please let us know the details. I'll close this issue in a couple of days otherwise. Thanks!

from yampa.

idontgetoutmuch avatar idontgetoutmuch commented on June 15, 2024

With

fallingBall :: Monad m => Pos -> Vel -> SF m () (Pos, Vel)
fallingBall p0 v0 = proc () -> do
  let g = -9.81
  v <- arr (\x -> v0 + x) <<< integral -< g
  p <- arr (\y -> p0 + y) <<< integral -< v
  returnA -< (p,v)

bouncingBall :: Monad m => Double -> Double -> SF m () (Double, Double)
bouncingBall p0 v0 =
  switch (fallingBall p0 v0 >>> (arr id &&& hitFloor))
         (\(p,v) -> bouncingBall p (-v))

hitFloor :: Monad m => SF m (Double,Double) (Event (Double,Double))
hitFloor = arr $ \(p,v) ->
  if p < 0 && v < 0 then Event (p,v) else noEvent

I get

image

But with

fallingBall :: Monad m => Pos -> Vel -> SF m () (Pos, Vel)
fallingBall p0 v0 = proc () -> do
  let g = -9.81
  v <- arr (\x -> v0 + x) <<< integral -< g
  p <- arr (\y -> p0 + y) <<< integralLinear v0 -< v
  returnA -< (p,v)

integralLinear :: Monad m => Double -> SF m Double Double
integralLinear initial = average >>> integral
  where
    average = (arr id &&& iPre initial) >>^ (\(x, y) -> (x ^+^ y) ^/ 2)

I get what I expect

image

Full code is here: https://github.com/idontgetoutmuch/phd-jonathan-thaler/commits/literate-haskell-for-review. In particular, it should be possible to run this: https://github.com/idontgetoutmuch/phd-jonathan-thaler/blob/literate-haskell-for-review/SIRABM.lhs#L262.

from yampa.

ivanperez-keera avatar ivanperez-keera commented on June 15, 2024

Thanks!

Based on past simulations, I think this is a problem with Yampa. If we can identify the problem there, we should fix it in Yampa and then just make bearriver adopt the same solution as Yampa (or one that is extensionally equivalent).

from yampa.

miguel-negrao avatar miguel-negrao commented on June 15, 2024

Isn't this a duplicate of ivanperez-keera/dunai#268 ?

from yampa.

idontgetoutmuch avatar idontgetoutmuch commented on June 15, 2024

Isn't this a duplicate of ivanperez-keera/dunai#268 ?

Probably

from yampa.

idontgetoutmuch avatar idontgetoutmuch commented on June 15, 2024

I made the change and with a test program it works.

Here's my test

fallingBall :: Double -> Double -> SF () (Double, Double)
fallingBall p0 v0 = proc () -> do
  let g = -9.81
  v <- arr (\x -> v0 + x) <<< integral -< g
  p <- arr (\y -> p0 + y) <<< integral -< v
  returnA -< (p,v)

bouncingBall :: Double -> Double -> SF () (Double, Double)
bouncingBall p0 v0 =
  switch (fallingBall p0 v0 >>> (arr id &&& hitFloor))
         (\(p,v) -> bouncingBall p (-v))

hitFloor :: SF (Double, Double) (Event (Double, Double))
hitFloor = arr $ \(p,v) ->
  if p < 0 && v < 0 then Event (p,v) else noEvent

Here's the problem

bouncingBallOld

and after the fix

bouncingBallNew

But if I run the yampa tests then they just hang :-(

I have put a PR here so you can try it yourself: #262

from yampa.

idontgetoutmuch avatar idontgetoutmuch commented on June 15, 2024

I don't know what to do about tests that just hang. I don't understand yampa sufficiently to debug it.

from yampa.

ivanperez-keera avatar ivanperez-keera commented on June 15, 2024

This issue pertains to Yampa. I'm transferring it there.

from yampa.

ivanperez-keera avatar ivanperez-keera commented on June 15, 2024

There are some small errors (the height going over 15 or under 0). What happens if you run this for a really long time? Do those always cancel out or do they accumulate?

from yampa.

chansey97 avatar chansey97 commented on June 15, 2024

@idontgetoutmuch Sorry, this may be a bit off-topic. Could you please tell me how you generate these signal diagrams with Yampa. Very thanks.

from yampa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.