Skip to content

Commit

Permalink
Merge pull request #58 from eth-cscs/release-0.5.6
Browse files Browse the repository at this point in the history
Release 0.5.6
  • Loading branch information
statrita2004 committed Feb 27, 2019
2 parents 5360498 + 8f84efb commit e8a78c9
Show file tree
Hide file tree
Showing 19 changed files with 831 additions and 575 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -6,7 +6,7 @@ algorithms and other likelihood-free inference schemes. It presently includes:

* RejectionABC
* PMCABC (Population Monte Carlo ABC)
* SMCABC (Sequential Monte Carlo ABC)
* SMCABC (Sequential Monte Carlo ABC)
* RSMCABC (Replenishment SMC-ABC)
* APMCABC (Adaptive Population Monte Carlo ABC)
* SABC (Simulated Annealing ABC)
Expand All @@ -26,9 +26,9 @@ scientists by providing
# Documentation
For more information, check out the

* [Documentation](http://abcpy.readthedocs.io/en/v0.5.5)
* [Examples](https://github.com/eth-cscs/abcpy/tree/v0.5.5/examples) directory and
* [Reference](http://abcpy.readthedocs.io/en/v0.5.5/abcpy.html)
* [Documentation](http://abcpy.readthedocs.io/en/v0.5.6)
* [Examples](https://github.com/eth-cscs/abcpy/tree/v0.5.6/examples) directory and
* [Reference](http://abcpy.readthedocs.io/en/v0.5.6/abcpy.html)


Further, we provide a
Expand All @@ -55,7 +55,7 @@ finally CSCS (Swiss National Super Computing Center) for their generous support.

There is a paper in the proceedings of the 2017 PASC conference. In case you use
ABCpy for your publication, we would appreciate a citation. You can use
[this](https://github.com/eth-cscs/abcpy/blob/v0.5.5/doc/literature/DuttaS-ABCpy-PASC-2017.bib)
[this](https://github.com/eth-cscs/abcpy/blob/v0.5.6/doc/literature/DuttaS-ABCpy-PASC-2017.bib)

BibTex reference.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.5.5
0.5.6
13 changes: 8 additions & 5 deletions abcpy/acceptedparametersmanager.py
Expand Up @@ -92,7 +92,8 @@ def get_mapping(self, models, is_root=True, index=0):
Returns
-------
list
The first entry corresponds to the mapping of the root model, as well as all its parents. The second entry corresponds to the next index in depth-first search.
The first entry corresponds to the mapping of the root model, as well as all its parents. The second entry
corresponds to the next index in depth-first search.
"""

# Implement a dfs to discover all nodes of the model
Expand All @@ -104,9 +105,9 @@ def get_mapping(self, models, is_root=True, index=0):

# Only parameters that are neither root nor Hyperparameters are included in the mapping
if(not(is_root) and not(isinstance(model, ModelResultingFromOperation))):
for i in range(model.get_output_dimension()):
mapping.append((model, index))
index+=1
#for i in range(model.get_output_dimension()):
mapping.append((model, index))
index+=1

for parent in model.get_input_models():
parent_mapping, index = self.get_mapping([parent], is_root= False, index=index)
Expand Down Expand Up @@ -139,13 +140,15 @@ def get_accepted_parameters_bds_values(self, models):

# The self.accepted_parameters_bds.value() list has dimensions d x n_steps, where d is the number of free parameters
accepted_bds_values = [[] for i in range(len(self.accepted_parameters_bds.value()))]

# Add all columns that correspond to desired parameters to the list that is returned
for model in models:
for prob_model, index in mapping:
if(model==prob_model):
for i in range(len(self.accepted_parameters_bds.value())):
accepted_bds_values[i].append(self.accepted_parameters_bds.value()[i][index])
accepted_bds_values = [np.array(x).reshape(-1, ) for x in accepted_bds_values]
#accepted_bds_values = [np.array(x).reshape(-1, ) for x in accepted_bds_values]

return accepted_bds_values

def _reset_flags(self, models=None):
Expand Down
15 changes: 4 additions & 11 deletions abcpy/continuousmodels.py
Expand Up @@ -87,7 +87,7 @@ def forward_simulate(self, input_values, k, rng=np.random.RandomState(), mpi_com
samples = np.zeros(shape=(k, self.get_output_dimension()))
for j in range(0, self.get_output_dimension()):
samples[:, j] = rng.uniform(input_values[j], input_values[j+self.get_output_dimension()], k)
return [np.array(x) for x in samples]
return [np.array(x).reshape(-1,) for x in samples]


def get_output_dimension(self):
Expand Down Expand Up @@ -189,7 +189,7 @@ def forward_simulate(self, input_values, k, rng=np.random.RandomState(), mpi_com
mu = input_values[0]
sigma = input_values[1]
result = np.array(rng.normal(mu, sigma, k))
return [np.array([x]) for x in result]
return [np.array([x]).reshape(-1,) for x in result]


def get_output_dimension(self):
Expand Down Expand Up @@ -270,7 +270,7 @@ def forward_simulate(self, input_values, k, rng=np.random.RandomState(), mpi_com
mean = input_values[0]
df = input_values[1]
result = np.array((rng.standard_t(df,k)+mean))
return [np.array([x]) for x in result]
return [np.array([x]).reshape(-1,) for x in result]


def _check_input(self, input_values):
Expand Down Expand Up @@ -346,20 +346,13 @@ def __init__(self, parameters, name='Multivariate Normal'):
raise TypeError('Input for Multivariate Normal has to be of type list.')
if len(parameters)<2:
raise ValueError('Input for Multivariate Normal has to be of length 2.')
if not isinstance(parameters[0], list):
raise TypeError('Input for mean of MultivarateNormal has to be of type list.')
if not isinstance(parameters[1], list):
raise TypeError('Input for covariance of MultivarateNormal has to be of type list.')

## This part confuses me as you say mean may not be list!!

mean = parameters[0]
if isinstance(mean, list):
self._dimension = len(mean)
input_parameters = InputConnector.from_list(parameters)
elif isinstance(mean, ProbabilisticModel):
self._dimension = mean.get_output_dimension()
input_parameters = parameters
input_parameters = InputConnector.from_list(parameters)

super(MultivariateNormal, self).__init__(input_parameters, name)
self.visited = False
Expand Down
12 changes: 7 additions & 5 deletions abcpy/discretemodels.py
Expand Up @@ -369,9 +369,8 @@ def forward_simulate(self, input_values, k, rng=np.random.RandomState()):
list: [np.ndarray]
A list containing the sampled values as np-array.
"""

result = np.array(rng.randint(input_values[0], input_values[1], size=k, dtype=np.int64))
return [np.array([x]) for x in result]
result = np.array(rng.randint(input_values[0], input_values[1]+1, size=k, dtype=np.int64))
return [np.array([x]).reshape(-1,) for x in result]

def get_output_dimension(self):
return self._dimension
Expand All @@ -391,8 +390,11 @@ def pmf(self, input_values, x):
float:
The pmf evaluated at point x.
"""
upperbound, lowerbound = input_values[0], input_values[1]
pmf = 1. / (upperbound - lowerbound + 1)
lowerbound, upperbound = input_values[0], input_values[1]
if x >= lowerbound and x <= upperbound:
pmf = 1. / (upperbound - lowerbound + 1)
else:
pmf = 0
self.calculated_pmf = pmf
return pmf

15 changes: 9 additions & 6 deletions abcpy/graphtools.py
Expand Up @@ -134,6 +134,7 @@ def _recursion_pdf_of_prior(self, models, parameters, mapping=None, is_root=True
# At the beginning of calculation, obtain the mapping
if(is_root):
mapping, garbage_index = self._get_mapping()

# The pdf of each root model is first calculated seperately
result = [1.]*len(models)

Expand All @@ -146,9 +147,9 @@ def _recursion_pdf_of_prior(self, models, parameters, mapping=None, is_root=True
for mapped_model, model_index in mapping:
if(mapped_model==model):
parameter_index = model_index
for j in range(model.get_output_dimension()):
relevant_parameters.append(parameters[parameter_index])
parameter_index+=1
#for j in range(model.get_output_dimension()):
relevant_parameters.append(parameters[parameter_index])
#parameter_index+=1
break
if(len(relevant_parameters)==1):
relevant_parameters = relevant_parameters[0]
Expand Down Expand Up @@ -210,7 +211,7 @@ def _get_mapping(self, models=None, index=0, is_not_root=False):
# If this model corresponds to an unvisited free parameter, add it to the mapping
if(is_not_root and not(model.visited) and not(isinstance(model, Hyperparameter)) and not(isinstance(model, ModelResultingFromOperation))):
mapping.append((model, index))
index+=model.get_output_dimension()
index+= 1 #model.get_output_dimension()
# Add all parents to the mapping, if applicable
for parent in model.get_input_models():
parent_mapping, index = self._get_mapping([parent], index=index, is_not_root=True)
Expand Down Expand Up @@ -240,6 +241,7 @@ def _get_names_and_parameters(self):
return_value = []

for model, index in mapping:

return_value.append((model.name, self.accepted_parameters_manager.get_accepted_parameters_bds_values([model])))

return return_value
Expand Down Expand Up @@ -318,10 +320,11 @@ def set_parameters(self, parameters, models=None, index=0, is_root=True):
for model in models:
# New parameters should only be set in case we are not at the root
if not is_root and not isinstance(model, ModelResultingFromOperation):
new_output_values = np.array(parameters[index:index + model.get_output_dimension()])
#new_output_values = np.array(parameters[index:index + model.get_output_dimension()])
new_output_values = np.array(parameters[index]).reshape(-1,)
if not model.set_output_values(new_output_values):
return [False, index]
index += model.get_output_dimension()
index += 1 #model.get_output_dimension()
model.visited = True

# New parameters for all parents are set using a depth-first search
Expand Down

0 comments on commit e8a78c9

Please sign in to comment.