from bayeslite.shell.hook import bayesdb_shell_cmd
from bdbcontrib.general_utils import ArgparseError, ArgumentParser

import bdbexp

experiments = {
    'haystacks' : bdbexp.haystacks,
    'hyperparams' : bdbexp.hyperparams,
    'infer' : bdbexp.infer,
    'kl_divergence' : bdbexp.kl_divergence,
    'permute' : bdbexp.permute,
    'predictive_pdf' : bdbexp.predictive_pdf,
    'recover' : bdbexp.recover
    }

@bayesdb_shell_cmd('experiment')
def experiment(self, argin):
    '''
    Launch an experimental inference quality test.
    USAGE: .experiment <exp_name> [exp_args ...]

    <exp_name>
        permute         kl_divergence
        haystacks       predictive_pdf
        hyperparams     recover
        infer

    [exp_args]
        To see experiment specific arguments, use
        .experiment <exp_name> --help

    Examples:
    bayeslite> .experiment predictive_pdf --help
    bayeslite> .experiment haystacks --n_iter=200 --n_distractors=4
    '''
    expname = argin.split()[0] if argin != '' else argin
    if expname not in experiments:
        print 'Invalid experiment {}'.format(expname)
        print 'For help use: .help experiment'
        return

    try:
        experiments[argin.split()[0]].main(argin.split()[1:], halt=True)
    except ArgparseError as e:
        self.stdout.write('%s' % (e.message,))
        return
    except SystemExit:
        return  # This happens when --help is invoked.

@@ -1,54 +1,192 @@
-from bayeslite.shell.hook import bayesdb_shell_cmd
+import argparse%0Aimport math%0Aimport shlex%0A%0Afrom bayeslite import core%0Afrom bayeslite.shell.hook import bayesdb_shell_cmd%0Afrom bayeslite.sqlite3_util import sqlite3_quote_name%0Aimport bdbexp%0A
 %0Afro
@@ -250,31 +250,16 @@
 Parser%0A%0A
-import bdbexp%0A%0A
 experime
@@ -379,52 +379,40 @@
    '
-kl_divergence' : bdbexp.kl_divergenc
+permute' : bdbexp.permut
 e,%0A    '
 perm
@@ -403,31 +403,31 @@
 rmute,%0A    '
-permute
+recover
 ' : bdbexp.p
@@ -429,93 +429,108 @@
 exp.
-permute,%0A    'predictive_pdf' : bdbexp.predictive_pdf,%0A    'recover' : bdbexp.recover
+recover,%0A    'univariate_kl' : bdbexp.univariate_kldiv,%0A    'univariate_pdf' : bdbexp.univariate_pdf
 %0A   
@@ -570,16 +570,20 @@
 t')%0Adef 
+run_
 experime
@@ -751,21 +751,21 @@
     
-kl_divergence
+univariate_kl
 %0A   
@@ -785,25 +785,25 @@
 s       
-predictiv
+univariat
 e_pdf%0A  

Update experiment names.