Number of Choices in a permutation given one option is fixed - statistics

I am in doubt about result of the following :
Each person can choose whether to wear a black tux or a grey tux, and whether to wear blue, yellow, or green coloured tie. In how many ways will you distribute all possible sets to 6 different people and no set repeats given that person 1 wants only a black tux.
A possible explanation will be helpful.

First of all, I don't think this question belongs on this stackexchange website. However what the hell I'll answer anyway.
So there are 6 people that can choose from 2 sets, the tux (2 options) and the tie (3 options)
Let's simplify a bit, one person can choose from 6 (3 * 2) options. A person with a fixed tux choice will only have 3 (3 * 1) options.
So to calculate it, we first take the person with limited choice and multiply that with the options the others still have.
-> the total number of options would be 3 * 5 * 4 * 3 * 2 * 1 = 360
(At least I'm fairly certain, as with most on this exchange, I'm a programmer rather than a mathematician)

For the suits you just subtract one person because one is already fixed.
The other 5 can each decide for one of 2 choices. This is similar to a coin flip for each person. That makes 2^5 combinations.
Then they choose the ties, where all 6 have 3 options. Following the example of the coin flip (but with 3 possible outcomes) we have 3^6 combinations for the ties.
Now just add the options together, because the decisions between suit and tie don't depend on each other. This will give you 729 outcomes for the ties and 32 outcomes for the tux's.
Hope I could make things clearer for you.

Related

From a random sequence, make appear an specific answer 5 times

I am implementing an N-back task with visual stimuli.
The stimuli is going to appear 20 times (randomly), but the correct answer must appear 5 times.
To generate a random sequence I can use "randint". But how can I tell to python to generate 5 times the correct answer.
Example of a 0-back.
The circle appears 20 times, but only 5 times it is the same as what it is needed.
So, I created 2 arrays.
right_answer, contains the position that I want to repeat 4 times.
wrong_answers, contains the other 8 positions. Each one repeats twice.
I concatenated them and then applied a permutation with a seed. With this, the array will be permuted but I will assure that the specific position/answer appear 4 times.
right_answer = np.array([[510,642],[510,642],\
[510,642],[510,642]])
wrong_answers = np.array([[510,382],[510,512],\
[640,382],[640,512],[640,642],\
[770,382],[770,512],[770,642],\
[510,382],[510,512],\
[640,382],[640,512],[640,642],\
[770,382],[770,512],[770,642]])
concat=np.concatenate((right_answer, wrong_answers))
positions = np.random.RandomState(seed=42).permutation(concat)
print (positions)

UML relationship calculation

(a) If there are 6 authors, what's the minimum and the maximum number of books? What's the minimum and the maximum number of readers?
(b) If there are 6 readers, what's the minimum and the maximum number of books? What's the minimum and the maximum number of authors?
If you don't know the exact numbers, just create an instance diagram according to the class diagram. I'll show you the a) part of the questions. Minimum: You've got six authors, so draw six objects typed by an Author. Every author must have at least one book. So draw one object typed by a Book. Well, every book can have up to two authors. Well, draw two links between the book and two authors. You still have 4 authors without a book. Repeat the steps above. You will end up with 3 books and 6 links. As for the Readers: there is no need do have one connected with a book. So the minimum is zero. If you did it well you should have something like this:
The similar way you do with the maximum. You will ended up with this:
So now you are able to do the b) part of your question.

Can dynamic programming problems always be represented as DAG

I am trying to draw a DAG for Longest Increasing Subsequence {3,2,6,4,5,1} but cannot break this into a DAG structure.
Is it possible to represent this in a tree like structure?
As far as I know, the answer to the actual question in the title is, "No, not all DP programs can be reduced to DAGs."
Reducing a DP to a DAG is one of my favorite tricks, and when it works, it often gives me key insights into the problem, so I find it always worth trying. But I have encountered some that seem to require at least hypergraphs, and this paper and related research seems to bear that out.
This might be an appropriate question for the CS Stack Exchange, meaning the abstract question about graph reduction, not the specific question about longest increasing subsequence.
Assuming following Sequence, S = {3,2,6,4,5,1,7,8} and R = root node. Your tree or DAG will look like
R
3 2 4 1
6 5 7
8
And your result is the longest path (from root to the node with the maximum depth) in the tree (result = {r,1,7,8}).
The result above show the longest increasing sequence in S. The Tree for the longest increasing subsequence in S look as follows
R
3 2 6 4 5 1 7 8
6 4 7 5 7 7 8
7 5 8 7 8 8
8 7 8
8
And again the result is the longest path (from root to the node with the maximum depth) in the tree (result = {r,2,4,5,7,8}).
The answer to this question should be YES.
I'd like to cite the following from here: The Soul of Dynamic Programming
Formulations and Implementations.
A DP must have a corresponding DAG (most of the time implicit), otherwise we cannot find a valid order for computation.
For your case, Longest Increasing Subsequence can be represented as some DAG like the following:
The task is amount to finding the longest path in that DAG. For more information please refer to section 6.2 of Algorithms, Dynamic programming.
Yes, It is possible to represent longest Increasing DP Problem as DAG.
The solution is to find the longest path ( a path that contains maximum nodes) from every node to the last node possible for that particular node.
Here, S is the starting node, E is the ending node and C is count of nodes between S and E.
S E C
3 5 3
2 5 3
6 6 1
4 5 2
5 5 1
1 1 1
so the answer is 3 and it is very easy to generate solution as we have to traverse the nodes only.
I think it might help you.
Reference: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/lecture-videos/lecture-20-dynamic-programming-ii-text-justification-blackjack/

Dynamic Programming algorithm shortest path between two

There's an algorithm currently driving me crazy.
I've seen quite a few variations of it, so I'll just try to explain the easiest one I can think about.
Let's say I have a project P:
Project P is made up of 4 sub projects.
I can solve each of those 4 in two separate ways, and each of those modes has a specific cost and a specific time requirement:
For example (making it up):
P: 1 + 2 + 3 + 4 + .... n
A(T/C) Ta1/Ca1 Ta2/Ca2 etc
B(T/C) Tb1/Cb1 etc
Basically I have to find the combination that of those four modes which has the lowest cost. And that's kind of easy, the problem is: the combination has to be lower than specific given time.
In order to find the lowest combination I can easily write something like:
for i = 1 to n
aa[i] = min(aa[i-1],ba[i-1]) + value(a[i])
bb[i] = min(bb[i-1],ab[i-1]) + value(b[i])
ba[i] = min(bb[i-1],ab[i-1]) + value(b[i])
ab[i] = min(aa[i-1],ba[i-1]) + value(a[i])
Now something like is really easy and returns the correct value every time, the lowest at the last circle is gonna be the correct one.
Problem is: if min returns modality that takes the last time, in the end I'll have the fastest procedure no matter the cost.
If if min returns the lowest cost, I'll have the cheapest project no matter the amount of time taken to realize it.
However I need to take both into consideration: I can do it easily with a recursive function with O(2^n) but I can't seem to find a solution with dynamic programming.
Can anyone help me?
If there are really just four projects, you should go with the exponential-time solution. There are only 16 different cases, and the code will be short and easy to verify!
Anyway, the I'm pretty sure the problem you describe is the knapsack problem, which is NP-hard. So, there will be no exact solution that's sub-exponential unless P=NP. However, depending on what "n" actually is (is it 4 in your case? or the values of the time and cost?) there may be a pseudo-polynomial time solution. The Wikipedia article contains descriptions of these.

PySide/PyQt, is is possible to make sliders dependent i.e. give them a combined maximum

In pyside or pyqt:
Say that I have 3 sliders whose combined value mustn't exceed 9 or/and that it would always have to be 9. Is there an inbuilt way to make them depended in such a way, or do I have to program them.
Illustration:
0123456789
1 ---------|
2 |---------
3 |---------
0123456789
1 ---|------
2 ---|------
3 ---|------
The available slots and singals on a QSlider mean that there would be no way to automatically have them all connect. To do this you would need to create a custom widget or at the least code in some additional logic.

Resources