Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#96 #125

Merged
merged 3 commits into from
Apr 11, 2018
Merged

#96 #125

merged 3 commits into from
Apr 11, 2018

Conversation

MaximilianPi
Copy link
Collaborator

I hope its clear now...
check also spelling and grammar

added the several ways for parallelization
Copy link
Contributor

@TankredO TankredO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization, spelling



#### 3. Multi-core and cluster calculations
If you want to do your calculations on a cluster there are several ways to achieve it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... run your calculations ...

#### 3. Multi-core and cluster calculations
If you want to do your calculations on a cluster there are several ways to achieve it.

In the first case you want to parallize n internal (not overall chains) on n cores. The argument "parallel = T" in "createBayesianSetup" allows only at most parallelization on 3 cores for the SMC, DEzs and DreamsSamplers. But by setting "parallel = n" to n cores in the "createBayesianSetup" and giving the settings list a "startValue" matrix with n rows, the internal chains of DEzs and DREAMzs will be parallelized on n cores. This works only for the DEzs and DREAMzs samplers.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and passing/providing the settings list ...


```

In the second case you want to parallize n internal chains on n cores with a external parallilzed likelihood function. Unlike the previous case, that way DEzs, DREAMzs, and SMC samplers can be paralllized.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parallelized

likelihood <- function(X) sum(dnorm(c(1:10), mean = X, log = T))

## Definition of the likelihood which will be calculated in parallel. Instead of the parApply function, we could also define a costly parallelized likelihood
Plikelihood <- function(param) parallel::parApply(cl = cl, X = param, MARGIN = 1, FUN = likelihood)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better pLikelihood or PLikelihood or something like that

out <- runMCMC(bayesianSetup, settings, sampler = "DEzs")
```

In a another case your likelihood requires a costly model which is parallized. Start your cluster and export your model, the required libraries, and dlls. Now you can start your calculations with the argument "parallel = external" in createBayesianSetup.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • a
    parallelized

### Create Cluster with n Cores
cl <- parallel::makeCluster(n)

## export your model
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are those commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it doesn't exist("complexModel")...all other examples can be run

# return(ll)
}

## create BayesianSetup and settings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are sometimes writing BayesianSetup and sometimes Bayesian Setup. Maybe unify this.

cl <- parallel::makeCluster(n)
parallel::clusterEvalQ(cl, library(BayesianTools))

## calculate parallel n Chains, for each Chain the likelihood will be calculated on one core
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chains -> chains

In the second case you want to parallize n internal chains on n cores with a external parallilzed likelihood function. Unlike the previous case, that way DEzs, DREAMzs, and SMC samplers can be paralllized.

```{r, eval = FALSE}
### Create Cluster with n Cores
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization

@@ -213,9 +213,103 @@ BS <- createBayesianSetup(likelihood, parallel = "external", ...)
runMCMC(BS, sampler = "SMC", ...)
```

The in-build parallelization only allows the parallelization of the internal chains of SMC, DEzs and DREAMzs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

built-in

@TankredO TankredO merged commit 3a17045 into development Apr 11, 2018
@florianhartig florianhartig deleted the #96 branch June 8, 2018 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants