Commit 0e62f678 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

wta: Fix whitespace

parent dcb87ef9
......@@ -4,12 +4,12 @@
module IndexedTransition (IndexedTransition(..), maxIndex, fromIndex) where
import Data.Vector (Vector)
import qualified Data.Vector as V
import Data.Maybe
import Data.Tuple
import Data.Vector ( Vector )
import qualified Data.Vector as V
import Data.Maybe
import Data.Tuple
import Types
import Types
newtype IndexedTransition = Index { fromIndexd :: Integer }
deriving newtype (Num, Eq, Ord)
......@@ -17,14 +17,14 @@ newtype IndexedTransition = Index { fromIndexd :: Integer }
maxIndex :: WTASpec m -> IndexedTransition
maxIndex spec =
let n = numStates spec
let n = numStates spec
(t, _) = transitionsPerState spec
in Index (fromIntegral n * t)
in Index (fromIntegral n * t)
fromIndex :: WTASpec m -> IndexedTransition -> (State, Transition ())
fromIndex spec (Index i) =
let n = numStates spec
(t, symbolSums) = transitionsPerState spec
let n = numStates spec
(t , symbolSums ) = transitionsPerState spec
(state, stateTransition) = i `divMod` t
......@@ -35,31 +35,33 @@ fromIndex spec (Index i) =
arityTransition = stateTransition - (symbolSums V.! arity)
symbolBounds :: Vector Int = V.cons (numSymbols spec V.! arity) (V.replicate arity n)
symbolBounds :: Vector Int =
V.cons (numSymbols spec V.! arity) (V.replicate arity n)
symbolDigits = decodeFromInt symbolBounds arityTransition
symbol = V.head symbolDigits
symbol = V.head symbolDigits
successors = V.tail symbolDigits
trans = Transition
{ weight = ()
, summand = aritySummand spec arity
, symbol = symbol
, successors = V.map State successors
}
in (State (fromIntegral state), trans)
trans = Transition { weight = ()
, summand = aritySummand spec arity
, symbol = symbol
, successors = V.map State successors
}
in (State (fromIntegral state), trans)
index :: WTASpec m1 -> Int -> Transition m2 -> IndexedTransition
index spec state trans =
let (t, symbolSums) = transitionsPerState spec
arity :: Int = summandArity spec (summand trans)
symbolBounds :: Vector Int = V.cons (numSymbols spec V.! arity) (V.replicate arity (numStates spec))
arityIdx :: Integer = encodeAsInt symbolBounds (V.cons (symbol trans) (V.map fromState $ successors trans))
arity :: Int = summandArity spec (summand trans)
symbolBounds :: Vector Int = V.cons
(numSymbols spec V.! arity)
(V.replicate arity (numStates spec))
arityIdx :: Integer = encodeAsInt
symbolBounds
(V.cons (symbol trans) (V.map fromState $ successors trans))
stateLocal :: Integer = symbolSums V.! arity + arityIdx
in Index $ (fromIntegral state) * t + stateLocal
in Index $ (fromIntegral state) * t + stateLocal
-- Helpers
......@@ -69,22 +71,22 @@ summandArity spec summand = V.findIndices (/= 0) (numSymbols spec) V.! summand
aritySummand :: WTASpec m -> Int -> Int
aritySummand spec arity =
let arities = numSymbols spec
in V.length (V.filter (/= 0) (V.take arity arities))
in V.length (V.filter (/= 0) (V.take arity arities))
transitionsPerState :: WTASpec m -> (Integer, Vector Integer)
transitionsPerState spec =
let n = numStates spec
tPerSymbol = (V.imap (\i syms -> fromIntegral $ syms * n ^ i) (numSymbols spec))
tPerSymbol =
(V.imap (\i syms -> fromIntegral $ syms * n ^ i) (numSymbols spec))
runningTotal = V.scanl' (+) 0 tPerSymbol
in (V.last runningTotal, runningTotal)
in (V.last runningTotal, runningTotal)
encodeAsInt :: Vector Int -> Vector Int -> Integer
encodeAsInt maxBounds digits =
let factors = V.prescanr' (*) 1 (fmap fromIntegral maxBounds)
in sum (V.zipWith (*) factors (fmap fromIntegral digits))
in sum (V.zipWith (*) factors (fmap fromIntegral digits))
decodeFromInt :: Vector Int -> Integer -> Vector Int
decodeFromInt maxBounds encoded =
V.map (fromIntegral . fst) $ V.postscanr' doDigit (0, encoded) (fmap fromIntegral maxBounds)
decodeFromInt maxBounds encoded = V.map (fromIntegral . fst)
$ V.postscanr' doDigit (0, encoded) (fmap fromIntegral maxBounds)
where doDigit bound (_, current) = (swap $ current `divMod` bound)
......@@ -118,11 +118,9 @@ parseZeroFreq =
)
<|> (NumTransitions <$> Options.option
Options.auto
( Options.long "transitions"
<> Options.metavar "NUM"
<> Options.help
("Number of transitions to generate. They will be distributed randomly over states."
)
(Options.long "transitions" <> Options.metavar "NUM" <> Options.help
("Number of transitions to generate. They will be distributed randomly over states."
)
)
)
......@@ -158,7 +156,7 @@ main = do
randGen <- getStdGen
-- let zeroFreq = computeProbability spec (optEdgeConfig opts)
-- hPutStrLn stderr $ "p hacking: " ++ show zeroFreq
wta <- runGenerator
wta <- runGenerator
(GeneratorConfig spec (optEdgeConfig opts) (optDifferentValues opts))
genWTA
putStrLn $ "# Random state for this automaton: '" <> show randGen <> "'"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment