# Cmstan argument for different initial files for corresponding chains

**URL:** <https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990>\
**Category:** Developers\
**Created:** [June 16, 2020, 5:53pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990 "2020-06-16T17:53:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [June 16, 2020, 5:53pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/1 "2020-06-16T17:53:05Z")

</div>

In [cross-chain warmup](https://discourse.mc-stan.org/t/cross-chain-warmup-adaptation-using-mpi/12912/76) I need to allow different chains to have different init point. @rok_cesnovar @mitzimorris @bbbales2 @avehtari what’s your suggestion? I’m thinking in addition to `init=filename` we can allow `init=directory name` to point to a directory where cmdstan can read multiple init files.

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [June 16, 2020, 6:07pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/2 "2020-06-16T18:07:30Z")

</div>

And the directory would have some standard way of naming the files?

What about a comma separated list of files? Would that work?

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [June 16, 2020, 6:08pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/3 "2020-06-16T18:08:16Z")

</div>

> [@rok\_cesnovar](#):
>
> What about a comma separated list of files?

Something like that is my preference

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [June 16, 2020, 8:12pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/4 "2020-06-16T20:12:12Z")

</div>

> [@rok\_cesnovar](#):
>
> What about a comma separated list of files? Would that work?

What if instead of 4 chains I have 12 chains so 12 init files?

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [June 16, 2020, 8:19pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/5 "2020-06-16T20:19:58Z")

</div>

Good point!

Hm, how about a wildcard?

init=subfolder/\*.data.R

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [June 16, 2020, 8:21pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/6 "2020-06-16T20:21:47Z")

</div>

> [@rok\_cesnovar](#):
>
> Hm, how about a wildcard?
> 
> init=subfolder/\*.data.R

I like this. Now I need to figure out how to do that in C++.

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [June 16, 2020, 8:36pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/7 "2020-06-16T20:36:23Z")

</div>

Boost filesystem would be my choice. C++17 filesystem is based on it I think.

There are a few ideas here: [https://stackoverflow.com/questions/1257721/can-i-use-a-mask-to-iterate-files-in-a-directory-with-boost](https://stackoverflow.com/questions/1257721/can-i-use-a-mask-to-iterate-files-in-a-directory-with-boost)

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [June 19, 2020, 3:28pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/8 "2020-06-19T15:28:04Z")

</div>

is this about calling CmdStan via CmdStanR?  
CmdStanPy allows the following options for the `inits` argument:

- **inits** –Specifies how the sampler initializes parameter values. Initialization is either uniform random on a range centered on 0, exactly 0, or a dictionary or file of initial values for some or all parameters in the model. The default initialization behavior will initialize all parameter values on range [-2, 2] on the _unconstrained_ support. If the expected parameter values are too far from this range, this option may improve adaptation. The following value types are allowed:
  - Single number n \> 0 - initialization range is [-n, n].
  - 0 - all parameters are initialized to 0.
  - dictionary - pairs parameter name : initial value.
  - string - pathname to a JSON or Rdump data file.
  - list of strings - per-chain pathname to data file.

[https://cmdstanpy.readthedocs.io/en/latest/api.html#cmdstanpy.CmdStanModel.sample](https://cmdstanpy.readthedocs.io/en/latest/api.html#cmdstanpy.CmdStanModel.sample)

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [June 19, 2020, 3:33pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/9 "2020-06-19T15:33:46Z")

</div>

ignore above - you’re talking about something in Torsten?

just added something to CmdStan that has to parse a comma-separated list - `boost::algorithm::split` is your friend - [https://github.com/stan-dev/cmdstan/blob/465a2d2491e303d19fd06750a0a720299ef551dd/src/cmdstan/stansummary\_helper.hpp#L193-L196](https://github.com/stan-dev/cmdstan/blob/465a2d2491e303d19fd06750a0a720299ef551dd/src/cmdstan/stansummary_helper.hpp#L193-L196)

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [June 19, 2020, 4:10pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/10 "2020-06-19T16:10:21Z")

</div>

Thanks. I’m talking about cmdstan, as I’m working on a branch that tests cross-chain warmup.

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [June 19, 2020, 5:45pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/11 "2020-06-19T17:45:38Z")

</div>

~~CmdStan already allows a strng of filenames as value for arg “init”~~

CmdStan allows a string value for arg “init”, so using the split on that string should work.

you’re controlling the multiple chains from a single invocation of command?  
sorry for not keeping up with this one.

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [June 19, 2020, 6:20pm UTC](https://discourse.mc-stan.org/t/cmstan-argument-for-different-initial-files-for-corresponding-chains/15990/12 "2020-06-19T18:20:34Z")

</div>

> [@mitzimorris](#):
>
> you’re controlling the multiple chains from a single invocation of command?

Yes

```bash
mpiexec -n 4 ./8school sample data file=8school.data.R init=init.R

```

runs 4 communicating chains using a same init.R, but I’d like to issue 1.init.R, 2.init.R, 3.init.R, and 4.init.R to corresponding chain.
