Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

BUG: Sampler should accept betas as an int #13

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
language: python
cache: pip
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7-dev"
- "3.7"
- "3.8"
install:
- make init
script:
Expand Down
10 changes: 10 additions & 0 deletions ptemcee/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

__all__ = ['make_ladder', 'Sampler']

import operator
import attr
import itertools
import numpy as np
Expand Down Expand Up @@ -185,6 +186,15 @@ def _validate_ndim(self, attribute, value):

@betas.validator
def _validate_betas(self, attribute, value):
try:
# see if betas is an integer.
v = operator.index(value)
if v < 1:
raise ValueError("Need at least one temperature")
return
except TypeError:
pass

if len(value) < 1:
raise ValueError('Need at least one temperature!')
if (value < 0).any():
Expand Down
7 changes: 7 additions & 0 deletions ptemcee/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ def test_temp_inf(self):
betas=make_ladder(self.ndim, self.ntemps, Tmax=self.Tmax))
self.check_sampler(sampler, p0=self.p0)

def test_betas(self):
sampler = Sampler(self.nwalkers, self.ndim,
LogLikeGaussian(self.icov),
LogPriorGaussian(self.icov, cutoff=self.cutoff),
betas=20)
assert sampler.betas.shape[0] == 20

def test_gaussian_adapt(self):
sampler = Sampler(self.nwalkers, self.ndim,
LogLikeGaussian(self.icov),
Expand Down