Comments (14)
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.
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.
@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.
Which specific issue were you trying to point to?
Is this a problem only in dunai or also in Yampa?
from yampa.
@idontgetoutmuch Please let us know the details. I'll close this issue in a couple of days otherwise. Thanks!
from yampa.
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
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
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.
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.
Isn't this a duplicate of ivanperez-keera/dunai#268 ?
from yampa.
Isn't this a duplicate of ivanperez-keera/dunai#268 ?
Probably
from yampa.
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
and after the fix
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.
I don't know what to do about tests that just hang. I don't understand yampa sufficiently to debug it.
from yampa.
This issue pertains to Yampa. I'm transferring it there.
from yampa.
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.
@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)
- `yampa`: Conformance with style guide
- `yampa`: module `FRP.Yampa.Event` exports internal function `maybeToEvent`
- Release 0.14.3
- Packages do not specify upper bounds of dependencies
- Release 0.14.4
- `yampa`: `Yampa.FRP.Task` does not define `return` in terms of `pure`
- `yampa`: Add link to new publication in README
- Release 0.14.5
- Yampa fails to compile with GHC 9.8.1, deepseq 1.5.0.0 HOT 1
- Update documentation of Diagrams example
- Release 0.14.6
- `yampa`: CI job fails due to missing release file for postgresql repository
- `yampa`: Simplify definition
- `yampa`: Simplify `isJustEdge`
- `yampa`: Simplify `FRP.Yampa.Task.isEdge`
- `yampa`: Examples include unnecessary imports
- Release 0.14.7
- `yampa-test`: Style violation: `where` does not appear on a single line
- `yampa-test`: Style violation: `tests/Test/FRP/Yampa/Task.hs` contains space above module declaration
- Release 0.14.8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yampa.