How to pass a list of vectors with various length and list of matrices with various dimensions in Stan model?Supplying seed to Stan doesn't guarantee the same chainsHow to speed up STAN when fitting a random effect model on a large, sparse dataframe?How to define a set of vectors with various length in Stan modelMixture Models in Stan - vectorizationstan number of effective sample sizestan - difficulty vectorizingInteger matrix in stan getting flattenedHow to have a variable in the data block of Stan be an array of length J >= 1?How to update a brmsfit object with a modified brms-generated stan model marginalizing over a distribution of weightsHow to pass multiple columns of weights to brms
Why would anyone ever invest in a cash-only etf?
Can you place a support header in the ceiling?
Why force the nose of 737 Max down in the first place?
Does Wolfram Mathworld make a mistake describing a discrete probability distribution with a probability density function?
Is it okay for me to decline a project on ethical grounds?
How could Nomadic scholars effectively memorize libraries worth of information
Is there an antonym(a complementary antonym) for "spicy" or "hot" regarding food (I do NOT mean "seasoned" but "hot")?
Exploiting the delay when a festival ticket is scanned
How long until two planets become one?
Why did Windows 95 crash the whole system but newer Windows only crashed programs?
Must a song using the A minor scale begin or end with an Am chord? If not, how can I tell what the scale is?
Why is の所 used after ドア in this sentence?
How can religions be structured in ways that allow inter-faith councils to work?
What language is Raven using for her attack in the new 52?
Incrementing add under condition in pandas
Is there a wealth gap in Boston where the median net worth of white households is $247,500 while the median net worth for black families was $8?
Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?
Why did some Apollo missions carry a grenade launcher?
How likely is fragmentation on a table with 40000 products likely to affect performance
Did the Americans trade destroyers in the "destroyer deal" that they would later need themselves?
Should I accept an invitation to give a talk from someone who might review my proposal?
Telling manager project isn't worth the effort?
Does dual boot harm a laptop battery or reduce its life?
Irreducible factors of primitive permutation group representation
How to pass a list of vectors with various length and list of matrices with various dimensions in Stan model?
Supplying seed to Stan doesn't guarantee the same chainsHow to speed up STAN when fitting a random effect model on a large, sparse dataframe?How to define a set of vectors with various length in Stan modelMixture Models in Stan - vectorizationstan number of effective sample sizestan - difficulty vectorizingInteger matrix in stan getting flattenedHow to have a variable in the data block of Stan be an array of length J >= 1?How to update a brmsfit object with a modified brms-generated stan model marginalizing over a distribution of weightsHow to pass multiple columns of weights to brms
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to pass the data as a list of vectors with various length and a list of matrices with the same number of rows but with a different number of columns. Is there a way to pass the data in Rstan?
stan rstan rstanarm
add a comment |
I need to pass the data as a list of vectors with various length and a list of matrices with the same number of rows but with a different number of columns. Is there a way to pass the data in Rstan?
stan rstan rstanarm
1
There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.
– Bob Carpenter
Mar 27 at 14:17
Thanks so much,
– Scarlet Rice
Mar 27 at 21:49
add a comment |
I need to pass the data as a list of vectors with various length and a list of matrices with the same number of rows but with a different number of columns. Is there a way to pass the data in Rstan?
stan rstan rstanarm
I need to pass the data as a list of vectors with various length and a list of matrices with the same number of rows but with a different number of columns. Is there a way to pass the data in Rstan?
stan rstan rstanarm
stan rstan rstanarm
asked Mar 26 at 19:31
Scarlet RiceScarlet Rice
1
1
1
There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.
– Bob Carpenter
Mar 27 at 14:17
Thanks so much,
– Scarlet Rice
Mar 27 at 21:49
add a comment |
1
There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.
– Bob Carpenter
Mar 27 at 14:17
Thanks so much,
– Scarlet Rice
Mar 27 at 21:49
1
1
There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.
– Bob Carpenter
Mar 27 at 14:17
There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.
– Bob Carpenter
Mar 27 at 14:17
Thanks so much,
– Scarlet Rice
Mar 27 at 21:49
Thanks so much,
– Scarlet Rice
Mar 27 at 21:49
add a comment |
1 Answer
1
active
oldest
votes
The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.
Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf
or -Inf
as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.
Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.
Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.
– Scarlet Rice
Mar 27 at 21:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55364960%2fhow-to-pass-a-list-of-vectors-with-various-length-and-list-of-matrices-with-vari%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.
Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf
or -Inf
as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.
Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.
Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.
– Scarlet Rice
Mar 27 at 21:50
add a comment |
The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.
Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf
or -Inf
as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.
Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.
Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.
– Scarlet Rice
Mar 27 at 21:50
add a comment |
The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.
Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf
or -Inf
as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.
Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.
The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.
Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf
or -Inf
as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.
Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.
answered Mar 27 at 1:49
Ben GoodrichBen Goodrich
3,5371 gold badge8 silver badges14 bronze badges
3,5371 gold badge8 silver badges14 bronze badges
Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.
– Scarlet Rice
Mar 27 at 21:50
add a comment |
Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.
– Scarlet Rice
Mar 27 at 21:50
Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.
– Scarlet Rice
Mar 27 at 21:50
Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.
– Scarlet Rice
Mar 27 at 21:50
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55364960%2fhow-to-pass-a-list-of-vectors-with-various-length-and-list-of-matrices-with-vari%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.
– Bob Carpenter
Mar 27 at 14:17
Thanks so much,
– Scarlet Rice
Mar 27 at 21:49