1
Fork 0
mirror of https://github.com/Jaxan/ons-hs.git synced 2025-04-27 14:47:45 +02:00

Added run script for learning

This commit is contained in:
Joshua Moerman 2024-11-05 16:25:53 +01:00
parent c206b16cba
commit ce0fdd8e54
4 changed files with 75 additions and 2 deletions

View file

@ -114,8 +114,10 @@ values, that can be much faster.
## Changelog
version 0.2.2.0 (2024-11-05):
version 0.2.3.0 (2024-11-05):
* Updates the testing and benchmarking framework.
* Replaced benchmarking dependencies, making the build process much faster.
* Added an example teacher, and run script.
version 0.2.0.0 (2024-11-01):
* Resolves compiler warnings.

29
app/Teacher.hs Normal file
View file

@ -0,0 +1,29 @@
import System.IO (hFlush, stderr, stdout, hPutStrLn)
-- TODO: Actually implement interesting languages... Not sure yet how I want
-- to do equivalence queries. Maybe let the teacher respond with a test
-- query to the learner?
main :: IO ()
main = do
messages <- lines <$> getContents
mapM_ act messages
where
act message =
case message of
"ALPHABET" -> handleAlphabet
str -> case take 2 message of
"MQ" -> handleMQ (drop 3 message)
"EQ" -> handleEQ (drop 3 message)
handleAlphabet = do
putStrLn "ATOMS"
hFlush stdout
handleMQ str = do
-- accepts any string
putStrLn "Y"
hPutStrLn stderr $ "MQ received: " <> str
hFlush stdout
handleEQ str = do
-- immediately accepts the hypothesis
putStrLn "Y"
hPutStrLn stderr $ "EQ received: " <> str
hFlush stdout

View file

@ -1,6 +1,6 @@
cabal-version: 2.2
name: ons-hs
version: 0.2.2.0
version: 0.2.3.0
synopsis: Implementation of the ONS (Ordered Nominal Sets) library in Haskell
description: Nominal sets are structured infinite sets. They have symmetries which make them finitely representable. This library provides basic manipulation of them for the total order symmetry. It includes: products, sums, maps and sets. Can work with custom data types.
homepage: https://github.com/Jaxan/ons-hs
@ -55,6 +55,17 @@ executable ons-hs-lstar
ExampleAutomata,
IO
executable ons-hs-teacher
import: stuff
hs-source-dirs: app
main-is: Teacher.hs
build-depends:
mtl,
ons-hs
other-modules:
ExampleAutomata,
IO
executable ons-hs-minimise
import: stuff
hs-source-dirs: app

31
run-lstar.sh Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Example usage of how to run lstar against a non-interactive teacher. This
# script will create two fifos for the learner and teacher to communicate over.
# The communication is not visible, only output to stderr will be shown in
# the terminal
# safety flags, remove x if you don't like all the output
set -euxo pipefail
# create temporary directory, and names for the fifo queues (not files)
tempdir=$(mktemp -d run-lstar.temp.XXXXXX)
queryfifo="$tempdir/queries"
answerfifo="$tempdir/answers"
# find the binary for the learner and teacher.
# The haskell project must be built beforehard (cabal build all)
lstar=$(cabal list-bin ons-hs-lstar)
teacher=$(cabal list-bin ons-hs-teacher)
# make the connection for the processes
mkfifo $queryfifo $answerfifo
# run the teacher in the background
$teacher < $queryfifo > $answerfifo &
# run the learning algorithm, measuring its time
time $lstar > $queryfifo < $answerfifo
# clean up
rm -r $tempdir