threshold.hs

来自「Cores are generated from Confluence a mo」· HS 代码 · 共 60 行

HS
60
字号
-- | Time integrated threshold functions typically used in condition monitoring.module Language.Atom.Common.Threshold  ( boolThreshold  , floatingThreshold  ) whereimport Language.Atom-- | Boolean thresholding over time.  Output is set when internal counter hits limit, and cleared when counter is 0.boolThreshold :: Name -> Int -> Bool -> Term Bool -> System (Term Bool)boolThreshold name num init input = scope name $ do  assert "positiveNumber" $ num >= 0  state <- bool "state" init  count <- int  "count" (if init then num else 0)  rule "update" $ do    when $ value count >. 0 &&. value count <. num    count <== value count + mux input 1 (-1)  rule "low" $ do    when $ value count ==. 0    state <== false  rule "high" $ do    when $ value count ==. intC num    state <== true  return $ value state-- | Integrating threshold.  Output is set with integral reaches limit, and cleared when integral reaches 0.doubleThreshold :: Name -> Double -> Term Double -> System (Term Bool)doubleThreshold name lim input = scope name $ do  assert "positiveLimit" $ lim >= 0  state <- bool "state" False  sum <- double "sum" 0  (high,low) <- priority    rule "update"    sum <== value sum + input    low  rule "clear" $ do    when $ value sum <=. 0    state <== false    sum <== 0    high  rule "set" $ do    when $ value sum >=. doubleC lim    state <== true    sum <== doubleC lim    high  return  $ value state

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?