示例#1
0
    def test_model_good(self):
        # compile on instantiation, override model name
        model = CmdStanModel(model_name='bern', stan_file=BERN_STAN)
        self.assertEqual(BERN_STAN, model.stan_file)
        self.assertTrue(model.exe_file.endswith(BERN_EXE.replace('\\', '/')))
        self.assertEqual('bern', model.name)

        # default model name
        model = CmdStanModel(stan_file=BERN_STAN)
        self.assertEqual(BERN_BASENAME, model.name)

        # instantiate with existing exe
        model = CmdStanModel(stan_file=BERN_STAN, exe_file=BERN_EXE)
        self.assertEqual(BERN_STAN, model.stan_file)
        self.assertTrue(model.exe_file.endswith(BERN_EXE))

        # instantiate with existing exe only - no model
        model2 = CmdStanModel(exe_file=BERN_EXE)
        self.assertEqual(BERN_EXE, model2.exe_file)
        with self.assertRaises(RuntimeError):
            model2.code()
        with self.assertRaises(RuntimeError):
            model2.compile()

        # instantiate, don't compile
        os.remove(BERN_EXE)
        model = CmdStanModel(stan_file=BERN_STAN, compile=False)
        self.assertEqual(BERN_STAN, model.stan_file)
        self.assertEqual(None, model.exe_file)
示例#2
0
    def test_model_good(self):
        stan = os.path.join(DATAFILES_PATH, 'bernoulli.stan')
        exe = os.path.join(DATAFILES_PATH, 'bernoulli' + EXTENSION)

        # compile on instantiation
        model = CmdStanModel(stan_file=stan)
        self.assertEqual(stan, model.stan_file)
        self.assertTrue(model.exe_file.endswith(exe.replace('\\', '/')))

        # instantiate with existing exe
        model = CmdStanModel(stan_file=stan, exe_file=exe)
        self.assertEqual(stan, model.stan_file)
        self.assertTrue(model.exe_file.endswith(exe))

        # instantiate with existing exe only - no model
        exe = os.path.join(DATAFILES_PATH, 'bernoulli' + EXTENSION)
        model2 = CmdStanModel(exe_file=exe)
        self.assertEqual(exe, model2.exe_file)
        self.assertEqual('bernoulli', model2.name)
        with self.assertRaises(RuntimeError):
            model2.code()
        with self.assertRaises(RuntimeError):
            model2.compile()

        # instantiate, don't compile
        os.remove(exe)
        model = CmdStanModel(stan_file=stan, compile=False)
        self.assertEqual(stan, model.stan_file)
        self.assertEqual(None, model.exe_file)
示例#3
0
    def test_exe_only(self):
        model = CmdStanModel(stan_file=BERN_STAN)
        self.assertEqual(BERN_EXE, model.exe_file)
        exe_only = os.path.join(DATAFILES_PATH, 'exe_only')
        shutil.copyfile(model.exe_file, exe_only)

        model2 = CmdStanModel(exe_file=exe_only)
        with self.assertRaises(RuntimeError):
            model2.code()
        with self.assertRaises(RuntimeError):
            model2.compile()
        self.assertFalse(model2._fixed_param)
示例#4
0
    def test_model_good_no_source(self):
        stan = os.path.join(datafiles_path, 'bernoulli.stan')
        exe = os.path.join(datafiles_path, 'bernoulli' + EXTENSION)
        model = CmdStanModel(stan_file=stan)

        model2 = CmdStanModel(exe_file=exe)
        self.assertEqual(exe, model2.exe_file)
        self.assertEqual('bernoulli', model2.name)

        with self.assertRaises(RuntimeError):
            model2.code()
        with self.assertRaises(RuntimeError):
            model2.compile()
示例#5
0
 def test_print(self):
     stan = os.path.join(datafiles_path, 'bernoulli.stan')
     model = CmdStanModel(stan_file=stan)
     self.assertEqual(code, model.code())
示例#6
0
 def test_print(self):
     model = CmdStanModel(stan_file=BERN_STAN)
     self.assertEqual(CODE, model.code())
示例#7
0
 def test_print(self):
     stan = os.path.join(DATAFILES_PATH, 'bernoulli.stan')
     model = CmdStanModel(stan_file=stan)
     self.assertEqual(CODE, model.code())