Generating randomisations for an experimental design Python [on hold]
up vote
-3
down vote
favorite
I am learning python for work and am trying to generate a matrix containing an experimental set up. The design requires a number of individuals (n) to see a number of options (k) in a random(ish) order. The number of times each option follows the others needs to be the same - so 1 will be seen after 2 the same number of times as 2 is seen after 1 etc. I have done this but it's very costly time wise and would appreciate any ideas for optimisation.
The matrix has the number of options 'k' someone could see along the x and the number of people 'n' on the y.
I generate a matrix from one to k on each row and then randomise each row using random.shuffle. Then create another matrix mapping number to the position in which it appears. For example (1 3 2) would go to (0 2 1). Each position is then compared to give a matrix that tells you how many times 1 appears before 2 (not necessarily adjacently), 2 appears before 1, and so on. The matrix elements (i,j) are then compared to (j, i) and if they are all equal then the design has been reached. If not the original matrix is reshuffled and the process begins again.
My code takes user input for the number of people (must be even) and number of options they see.
If a condition could be added so that everything is seen in the same position the same number of times that would also be advantageous.
python
New contributor
Becky W is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Mast, 200_success, Vogel612♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Mast, 200_success, Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-3
down vote
favorite
I am learning python for work and am trying to generate a matrix containing an experimental set up. The design requires a number of individuals (n) to see a number of options (k) in a random(ish) order. The number of times each option follows the others needs to be the same - so 1 will be seen after 2 the same number of times as 2 is seen after 1 etc. I have done this but it's very costly time wise and would appreciate any ideas for optimisation.
The matrix has the number of options 'k' someone could see along the x and the number of people 'n' on the y.
I generate a matrix from one to k on each row and then randomise each row using random.shuffle. Then create another matrix mapping number to the position in which it appears. For example (1 3 2) would go to (0 2 1). Each position is then compared to give a matrix that tells you how many times 1 appears before 2 (not necessarily adjacently), 2 appears before 1, and so on. The matrix elements (i,j) are then compared to (j, i) and if they are all equal then the design has been reached. If not the original matrix is reshuffled and the process begins again.
My code takes user input for the number of people (must be even) and number of options they see.
If a condition could be added so that everything is seen in the same position the same number of times that would also be advantageous.
python
New contributor
Becky W is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Mast, 200_success, Vogel612♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Mast, 200_success, Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
2
Welcome to Code Review! We review code. Where's your code?
– Mast
2 days ago
3
Welcome to Code Review! It appears that you had a link to github, which I brought forth on your textMy code. Note that the code must be embedded directly here for it to be reviewed. From the Help center page What topics can I ask about here?: "It is fine to post supplementary code on a third-party site, but the most important parts of the code must be embedded directly in the question."
– Sᴀᴍ Onᴇᴌᴀ
2 days ago
@Solomon Ucko - please don't add the code from github - the OP needs to do it. See this meta answer and its siblings for the reasons.
– Sᴀᴍ Onᴇᴌᴀ
yesterday
add a comment |
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
I am learning python for work and am trying to generate a matrix containing an experimental set up. The design requires a number of individuals (n) to see a number of options (k) in a random(ish) order. The number of times each option follows the others needs to be the same - so 1 will be seen after 2 the same number of times as 2 is seen after 1 etc. I have done this but it's very costly time wise and would appreciate any ideas for optimisation.
The matrix has the number of options 'k' someone could see along the x and the number of people 'n' on the y.
I generate a matrix from one to k on each row and then randomise each row using random.shuffle. Then create another matrix mapping number to the position in which it appears. For example (1 3 2) would go to (0 2 1). Each position is then compared to give a matrix that tells you how many times 1 appears before 2 (not necessarily adjacently), 2 appears before 1, and so on. The matrix elements (i,j) are then compared to (j, i) and if they are all equal then the design has been reached. If not the original matrix is reshuffled and the process begins again.
My code takes user input for the number of people (must be even) and number of options they see.
If a condition could be added so that everything is seen in the same position the same number of times that would also be advantageous.
python
New contributor
Becky W is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am learning python for work and am trying to generate a matrix containing an experimental set up. The design requires a number of individuals (n) to see a number of options (k) in a random(ish) order. The number of times each option follows the others needs to be the same - so 1 will be seen after 2 the same number of times as 2 is seen after 1 etc. I have done this but it's very costly time wise and would appreciate any ideas for optimisation.
The matrix has the number of options 'k' someone could see along the x and the number of people 'n' on the y.
I generate a matrix from one to k on each row and then randomise each row using random.shuffle. Then create another matrix mapping number to the position in which it appears. For example (1 3 2) would go to (0 2 1). Each position is then compared to give a matrix that tells you how many times 1 appears before 2 (not necessarily adjacently), 2 appears before 1, and so on. The matrix elements (i,j) are then compared to (j, i) and if they are all equal then the design has been reached. If not the original matrix is reshuffled and the process begins again.
My code takes user input for the number of people (must be even) and number of options they see.
If a condition could be added so that everything is seen in the same position the same number of times that would also be advantageous.
python
python
New contributor
Becky W is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Becky W is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 days ago
Sᴀᴍ Onᴇᴌᴀ
7,67561748
7,67561748
New contributor
Becky W is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
Becky W
1
1
New contributor
Becky W is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Becky W is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Becky W is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Mast, 200_success, Vogel612♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Mast, 200_success, Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Mast, 200_success, Vogel612♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Mast, 200_success, Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
2
Welcome to Code Review! We review code. Where's your code?
– Mast
2 days ago
3
Welcome to Code Review! It appears that you had a link to github, which I brought forth on your textMy code. Note that the code must be embedded directly here for it to be reviewed. From the Help center page What topics can I ask about here?: "It is fine to post supplementary code on a third-party site, but the most important parts of the code must be embedded directly in the question."
– Sᴀᴍ Onᴇᴌᴀ
2 days ago
@Solomon Ucko - please don't add the code from github - the OP needs to do it. See this meta answer and its siblings for the reasons.
– Sᴀᴍ Onᴇᴌᴀ
yesterday
add a comment |
2
Welcome to Code Review! We review code. Where's your code?
– Mast
2 days ago
3
Welcome to Code Review! It appears that you had a link to github, which I brought forth on your textMy code. Note that the code must be embedded directly here for it to be reviewed. From the Help center page What topics can I ask about here?: "It is fine to post supplementary code on a third-party site, but the most important parts of the code must be embedded directly in the question."
– Sᴀᴍ Onᴇᴌᴀ
2 days ago
@Solomon Ucko - please don't add the code from github - the OP needs to do it. See this meta answer and its siblings for the reasons.
– Sᴀᴍ Onᴇᴌᴀ
yesterday
2
2
Welcome to Code Review! We review code. Where's your code?
– Mast
2 days ago
Welcome to Code Review! We review code. Where's your code?
– Mast
2 days ago
3
3
Welcome to Code Review! It appears that you had a link to github, which I brought forth on your text
My code. Note that the code must be embedded directly here for it to be reviewed. From the Help center page What topics can I ask about here?: "It is fine to post supplementary code on a third-party site, but the most important parts of the code must be embedded directly in the question."– Sᴀᴍ Onᴇᴌᴀ
2 days ago
Welcome to Code Review! It appears that you had a link to github, which I brought forth on your text
My code. Note that the code must be embedded directly here for it to be reviewed. From the Help center page What topics can I ask about here?: "It is fine to post supplementary code on a third-party site, but the most important parts of the code must be embedded directly in the question."– Sᴀᴍ Onᴇᴌᴀ
2 days ago
@Solomon Ucko - please don't add the code from github - the OP needs to do it. See this meta answer and its siblings for the reasons.
– Sᴀᴍ Onᴇᴌᴀ
yesterday
@Solomon Ucko - please don't add the code from github - the OP needs to do it. See this meta answer and its siblings for the reasons.
– Sᴀᴍ Onᴇᴌᴀ
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
Welcome to Code Review! We review code. Where's your code?
– Mast
2 days ago
3
Welcome to Code Review! It appears that you had a link to github, which I brought forth on your text
My code. Note that the code must be embedded directly here for it to be reviewed. From the Help center page What topics can I ask about here?: "It is fine to post supplementary code on a third-party site, but the most important parts of the code must be embedded directly in the question."– Sᴀᴍ Onᴇᴌᴀ
2 days ago
@Solomon Ucko - please don't add the code from github - the OP needs to do it. See this meta answer and its siblings for the reasons.
– Sᴀᴍ Onᴇᴌᴀ
yesterday