#! /bin/zsh

test -e $1.model || {
  echo "ERROR: you need to train a model" 1>&2
  echo "ERROR: run do-${1}-train in this directory" 1>&2
  exit 1
}

test -e t10k-labels-idx1-ubyte.gz || {
  echo "ERROR: you need to download t10k-labels-idx1-ubyte.gz" 1>&2
  echo "ERROR: from http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz" 1>&2
  exit 1
}

test -e t10k-images-idx3-ubyte.gz || {
  echo "ERROR: you need to download t10k-images-idx3-ubyte.gz" 1>&2
  echo "ERROR: from http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz" 1>&2 
  exit 1
}

paste -d' '                                                     \
  <(zcat t10k-labels-idx1-ubyte.gz | ./extract-labels)          \
  <(zcat t10k-images-idx3-ubyte.gz |                            \
    ./extractpixels | ./pixelngrams) |                          \
../../vowpalwabbit/vw -t -i $1.model -p $1.test.predictions
