packages feed

hirt-0.0.1.1: demo.sh

#!/bin/sh -v

function find_exe() {
    HIRT=
    [ -z "$HIRT" ] && type hirt 2>/dev/null && HIRT=hirt
    [ -z "$HIRT" ] && [ -x hirt ] && HIRT=./hirt
    [ -z "$HIRT" ] && [ -x dist/build/hirt/hirt ] && HIRT=dist/build/hirt/hirt
}

find_exe

if [ -z "$HIRT" ]; then
    echo "Could not find executable..."
    echo "Perhaps build it with:"
    echo "	cabal configure && cabal build"
    echo " or   cabal install hirt"
    exit 1
fi >&2


# a very simple sample
RESPONSES=/tmp/responses
TASKPARAM=/tmp/params
BAYES=/tmp/bayes

cat > "$RESPONSES" << EOF
contestant task result
c1 t1 0
c1 t2 0
c2 t1 0
c2 t2 1
c3 t2 1
c3 t1 1
EOF

# fit model with default options
"$HIRT" "$RESPONSES"

# the differences in loglikehood on this very small example are tiny,
# throwing off the JML estimate, let's try BFGS

"$HIRT" "$RESPONSES" --algo lbfgsb

# Better, but not quite there yet.
# We will increase the precision.

"$HIRT" "$RESPONSES" --algo lbfgsb --prec 1e-30

# Let's save task parameters for later use
# and show contestant ability estimates.

"$HIRT" "$RESPONSES" --algo lbfgsb --prec 1e-30 --otaskparam "$TASKPARAM" --otheta /dev/stdout

# Now, let's use the task parameter estimates
# to estimate contestant abilities.
# We will use one round of JML to leave task parameters fixed.

"$HIRT" "$RESPONSES" --algo jml -n 1 --itaskparam "$TASKPARAM" --otheta /dev/stdout

# Now we will show some statistics

"$HIRT" "$RESPONSES" --algo lbfgsb --prec 1e-30 --otaskparam /dev/stdout --otheta /dev/stdout \
    --taskstats count --taskstats solvedprop --taskstats loglikelihood --taskstats dloglikelihood \
    --thetastats count --thetastats solvedprop --thetastats loglikelihood --thetastats dloglikelihood \
    --thetastats fishersem --thetastats bootstrap

# Finally, we will plot a graph of the bayes expected a posteriori probability

"$HIRT" "$RESPONSES" --algo lbfgsb --prec 1e-30 --otaskparam /dev/stdout --otheta /dev/stdout \
    --obayesplot /tmp/bayes

cat > /tmp/plot.R << EOF
library(ggplot2)

x <- read.table(file="$BAYES", header=T)
p <- ggplot(data=x, aes(x=x, y=p, color=contestant)) +
     geom_line(size=1) +
     scale_color_brewer(palette="Set1",name="") +
     scale_x_continuous(expression(theta)) +
     scale_y_continuous("y")

ggsave(file="/tmp/plot.pdf", w=10, h=7, plot=p)
EOF

Rscript /tmp/plot.R