How do you determine whether x succeeds or fails given a probability? - probability

I have x that follows a gamma distribution gamma(2.5,0.25). also, givin x the probability that a product is successful is modelled as
enter image description here
where μ = 15, and γ = 1
question: using R to simulate for 10000 independent products their x values, whether or
not they are successful.
My question is where to start to solve this kind of problem and is bayesian inference relevant here?
how can I be able to separate the x that succeded without knowing the threshold?

Related

Efficient way to get modulo for large number (e.g., find x for 100 mod x =1)

Alice has a integer x0 which she doesn't want Bob to know. Bob knows a very large integer y and also knows that y mod x0 = 1. So now Bob can solve the equation y mod x = 1 to get different x to see which one is correct (Bob can verify the correctness of the obtained x). Is it difficult for Bob to get x0? Are there any efficient way for him? One way I can think of is try and error as below but I guess it's low-efficient and hence is difficult to get real x0. Thank you!
Example: Bob wants to get x for 100 mod x = 1. Possible x are 3, 9, 11, 33, 99. Bob can verify the value. Assume the verification is fast. The true value that Alice has is 33. How difficult it is to get this 33?
for i in range(2, y):
if (y-1)%i == 0:
x = (y-1)/i
verify(x) // assume that verification is fast
if verification succeeds:
break
else:
continue
else:
continue
An efficient way to solve this would imply an efficient integer factorization algorithm: to factor N, choose y=N+1, and implement verify(x) such that it reports True only if x is a non-trivial factor of N (which is easy), then the algorithm to recover x0 will find a non-trivial factor of N. So it is unlikely that there will be a very efficient algorithm to do this.
But it also works the other way around: we need only generate the divisors of y-1 and verify them, not all possible numbers, and factoring y-1 and then generating the divisors from the factors is in many cases more efficient than brute-force. Even though factoring integers is difficult[proof needed], we have algorithms to do it that are better than brute-force, especially if the number contains small factors or repeated factors.
For example, factoring 240*310 is easy, and then listing the divisors is easy and there aren't too many of them (451 divisors), while a brute-force approach would take an unreasonable amount of time. In general we can easily factor any 64-bit number at least.

The "try every possible sequence until you get it right" algorithm

This is probably completely rudimentary, but I'm still not sure how to do it.
Suppose that I have a list action of functions/operators/what-have-you and an object x. For some stored value y, I want to check if it is possible to obtain y by applying the members of action, and return the shortest sequence of actions which takes x to y.
The easiest way to do this is to apply every possible sequence of actions to x in order, returning the first sequence to yield y (this will always be the shortest possible sequence).
I have a vague idea of how this might be done but I'm not clear on the specifcs - something like:
//Set the maximum number of steps (to prevent overflow)
n = whatever
//Algorithm
<<start>>
While i<n
u = x
sequence = []
<<begin loop-like thing
u = apply actions to u
sequence = sequence.append(action.index(last action))
end loop-like thing>>
i = i + 1
if u==y
print sequence
else
<<return to start>>
(I'm using <<stuff>> as a placeholder for when I don't know what stuff is).
For a concrete example of application, consider action to be the list of legal twists of a Rubik's cube, and x to be the starting (scrambled) state, and y to be the solved state. This solves the Rubik's cube using the fewest possible steps and prints the solution.
You could also do this to solve mazes, but that would be silly, because there are much faster ways to solve mazes.

Mathematica 2D limit computation

Wolfram Alpha and Mathematica (on my laptop) give zero for the limit shown in the image below.
This is okay if x and y approach the origin along the path y = x.
But what happens if x and y approach the origin along the path y = x^3?
I have been unable to find any Stack Overflow questions that address this issue.
Limits of a function f along path p depends on which path is taken. You hint at this in the question. If we insert y=x^3 into f, we get the constant 1/2. So the limit of f towards (0,0) along the path y=x^3 is 1/2.
Mathematica only computes limits along a one axis at a time. Even thought WolframAlpha makes it look like it knows how to compute the correct (x,y)->(0,0) it actually computes lim x->0 lim y->0 f(x,y).
This question and answer can be used to examine the situation graphically: https://mathematica.stackexchange.com/a/21549/11860

Network Flow: Can I change edge capacity while solving for max flow?

I want to know if I can change edge capacities in a network flow problem while solving it.
I have a supply/demand problem with goods A, B, and AB. A unit of demand for A will take one unit of A, B will take B, and AB will take one unit of AB or a unit of A and a unit of B. Given a list of supply and demand for each good, I want to figure out if there enough goods on hand to satisfy the demand.
So I my net work looks like this:
Let sX be supply of X.
Let dX be demand of X.
All flows go from left to right.
You can see that if I push x units of A, I have subtract x from the capacity going to (A+B). Similarly if I 'undo' a push, I have add capacity back to (A+B). So I have do this during the algorithm. Does that mess up the algorithm?
This is not a network flow problem. Suppose that sA = 10, sB = 10, dA = 10, dB = 10, dAB = 10. From the graph you can supply 10 As, Bs, and A+Bs, and therefore meet the demand. But in fact you need 20 As and 20 Bs to supply that need.
I do not know of a way for a simple flow network to represent the condition that you need the flow in one place to match the flow in another.
What you're describing is an interesting problem that I am sure has been studied, but I don't know what you call it.
This can be solved by turning it into a linear programming problem. See http://en.wikipedia.org/wiki/Linear_programming if you are not familiar with linear programming problems. Consider your simple case. You can start with 6 variables:
x is the flow from input A to output A.
y is the flow from input B to output B.
z is the flow from input AB to output AB.
w is the flow from A into A + B.
w' is the flow from B into A + B.
w'' is the flow from A + B into AB.
Of course the last 3 are all equal to each other. So we have 4 variables. (If we didn't note this we'd have more equations.) Now add the following inequalities:
0 ≤ x
0 ≤ y
0 ≤ z
0 ≤ w
x + w ≤ sA
y + w ≤ sB
z ≤ sAB
x ≤ dA
y ≤ dB
z + w ≤ dAB
This is a set of inequalities that says we're producing stuff, we aren't using more than our supply and we aren't creating more than the final demand for any particular thing. This defines our "feasible region".
Next we need an objective function, the thing that we're trying to maximize. The obvious choice is that we want to maximize the amount that we produce. So we want to maximize x + y + z + w.
The answer to your original question can then be found as follows. Given a set of available inputs, and available outputs, solve the above linear programming problem to optimize production. You are able to satisfy production goals if and only if the optimum level of production is dA + dB + dAB. And better yet, the solution you will get will tell you exactly how to satisfy production.

Which algorithm will be required to do this?

I have data of this form:
for x=1, y is one of {1,4,6,7,9,18,16,19}
for x=2, y is one of {1,5,7,4}
for x=3, y is one of {2,6,4,8,2}
....
for x=100, y is one of {2,7,89,4,5}
Only one of the values in each set is the correct value, the rest is random noise.
I know that the correct values describe a sinusoid function whose parameters are unknown. How can I find the correct combination of values, one from each set?
I am looking something like "travelling salesman"combinatorial optimization algorithm
You're trying to do curve fitting, for which there are several algorithms depending on the type of curve you want to fit your curve to (linear, polynomial, etc.). I have no idea whether there is a specific algorithm for sinusoidal curves (Fourier approximations), but my first idea would be to use a polynomial fitting algorithm with a polynomial approximation of the sine.
I wonder whether you need to do this in the course of another larger program, or whether you are trying to do this task on its own. If so, then you'd be much better off using a statistical package, my preferred one being R. It allows you to import your data and fit curves and draw graphs in just a few lines, and you could also use R in batch-mode to call it from a script or even a program (this is what I tend to do).
It depends on what you mean by "exactly", and what you know beforehand. If you know the frequency w, and that the sinusoid is unbiased, you have an equation
a cos(w * x) + b sin(w * x)
with two (x,y) points at different x values you can find a and b, and then check the generated curve against all the other points. Choose the two x values with the smallest number of y observations and try it for all the y's. If there is a bias, i.e. your equation is
a cos(w * x) + b sin(w * x) + c
You need to look at three x values.
If you do not know the frequency, you can try the same technique, unfortunately the solutions may not be unique, there may be more than one w that fits.
Edit As I understand your problem, you have a real y value for each x and a bunch of incorrect ones. You want to find the real values. The best way to do this is to fit curves through a small number of points and check to see if the curve fits some y value in the other sets.
If not all the x values have valid y values then the same technique applies, but you need to look at a much larger set of pairs, triples or quadruples (essentially every pair, triple, or quad of points with different y values)
If your problem is something else, and I suspect it is, please specify it.
Define sinusoid. Most people take that to mean a function of the form a cos(w * x) + b sin(w * x) + c. If you mean something different, specify it.
2 Specify exactly what success looks like. An example with say 10 points instead of 100 would be nice.
It is extremely unclear what this has to do with combinatorial optimization.
Sinusoidal equations are so general that if you take any random value of all y's these values can be fitted in sinusoidal function unless you give conditions eg. Frequency<100 or all parameters are integers,its not possible to diffrentiate noise and data theorotically so work on finding such conditions from your data source/experiment first.
By sinusoidal, do you mean a function that is increasing for n steps, then decreasing for n steps, etc.? If so, you you can model your data as a sequence of nodes connected by up-links and down-links. For each node (possible value of y), record the length and end-value of chains of only ascending or descending links (there will be multiple chain per node). Then you scan for consecutive runs of equal length and opposite direction, modulo some initial offset.

Resources