a pseudo-polynomial time algorithm for solving the 0-1 integer programming problem - polynomial-math

I want to show that the 0-1 integer programming problem is weakly NP-hard. But I cannot find a pseudo-polynomial time algorithm for it.
0-1 integer programming problem: Given an integer mXn matrix A and an integer m-vector b, whether there exists an integer n-vector x with elements in the set {0,1} such that Ax<=b.
Could anyone give me a concrete pseudo-polynomial time example?

Related

Convert 32 bit uniform distribution to uniform distribution on any int

Given a discrete uniform distribution D~U([0:2^N-1] from which a sample yields a number in the inclusive integer range [0, 2^N-1] for an integer N, I need a function convert such that for a sample d~D, convert(d, m) will have an integer uniform inclusive distribution Dc~U([0:m]).
Thoughts:
If the distribution is continuous, this is easy. Just cutoff the infinite representation of the number, and the uniformity is preserved.
I can't think of a way to do this for all numbers and keep uniformity.
I could re-roll for tie conditions, but am not able to formulate an algorithm.
What I eventually want, is a murmur hash on a custom range (m), rather than exact 32 bit numbers.

Solve linear programming equations with integer result

I am using the following matlab tool to solve my linear equations
x = linprog(f,A,b,Aeq,beq,lb,ub)
all things going well with me, but the result of x vector not integer values. so how can I set the x vector to be integer value or take value 0 or 1 only.(I mean solve linear equations for integer result).
let me explain more:
if I want to min x for the objective function 8X1 + X2
subject to
x1+2x2≥−14, −4x1−x2≤−33, 2x1+x2≤20
the result of X1,X2 not integer value.
If you have Matlab version 2014a above, then there is intlinprog for what you are looking for.
UPDATE:
Since you have Matlab 2012b, so i strongly suggest you to use this perfect tool at first, but you need something called Internet connection [j/k :-)]. By the way, there are some solutions:
something on Matlab exchange.
GLPK (GNU Linear Programming Kit)
answered question on stackoverflow

Calculate the variance of an integer vector in MATLAB

I need to calculate the variance of a large vector which is stored as uint8. The MATLAB var function however only accepts double and single types as input. The easiest way to calculate the variance would therefore be
vec = randi(255,1,100,'uint8');
var(single(vec))
This of course gives the correct result. However using single datatype increses the memory usage by a factor of 4. For large vectors (~ 1 million elements) this will quickly fill up the memory.
What I tried: The definition of the variance for a discrete random variable X is
(Source: Wikipedia)
I estimated the p's using the histogram, but then got stuck: To calculate the variance in a vectorized fashion, I would need to convert the x_i's to single or double.
Is there any possibility to calculate the variance without converting the whole vector to single or double?
If you're willing to work with uint16, you can do this, it creates only 3 floating point numbers (var and the 2 means), use Var(X)=Mean(X^2)-Mean(X)^2:
uivec=uint16(vec);
mean(uivec.^2)-mean(uivec)^2
So, not as good as keeping uint8 but still twice better than converting to single. It should work with uint16 because your input is uint8 and (2^8)^2=2^16.
If you want the exact same answer as var, you need to remember that MATLAB uses the unbiased estimator for var (it divides the sum by n-1 instead of n, where n is your number of samples) so you need to do:
n=length(vec);
v=mean(uivec.^2)-mean(uivec)^2*(n/(n-1))
then your v will be exactly equal to var(single(vec)).
No. The value of the variance is going to be a floating point value most likely, so you need to perform floating point operations.
p_i itself is the Probability mass function, so sum(p_i) should be one, therefore each p_i is a floating point number.
In addition, nu, the mean, will probably not be integer neither

Probability of generating a particular random number, such as in MATLAB

In real probability, there is a 0% chance that a random number p, selected from all of the real numbers in the interval (0,1), will be 0.5. However, what are the odds that
rand == 0.5
in MATLAB? I suppose this is like asking how many double-precision numbers are between zero and one, or maybe there are other factors at play.
No particular info on MATLAB's generator...
In general even simple pseudo-random generators have long enough cycles which would cover all values representable by double.
If MATLAB uses some other form of generating random numbers it would be even better - so assuming it uniformly covers whole range of double values.
I believe probability would be: distance between representable numbers around values you are interested divided by length of the interval. See What is the minimal step in double data type? (.NET) for discussion on the distance.
Looking at this question, we see that there are 262 - 252
doubles in the interval (0 1). Therefore, the probability of picking any single one (like 0.5) would be roughly equal to one divided by this number, or
>> p = 1/(2^62-2^52)
ans =
2.170523997312134e-019
However, as horchler already indicates, it also depends on the type of random number generator you use, as well as MATLAB's implementation thereof. Sadly, I have only basic knowledge on the implementaion details for each, but you can look here for a list of available random number generators in MATLAB and google a bit further for more precise numbers.
I am not sure whether Alexei was trying to say this, but inspired by him I think the probability will indeed be approximately the distance between numbers around 0.5.
Therefore I expect the probability to be approximately:
eps(0.5)
Which evaluates to 1.1102e-16
Given the monotonic nature of the difference between double numbers I would actually think this holds:
eps(0.5-eps(0.5)) <= yourprobability <= eps(0.5)
Implying a range of 5.5511e-17 to 1.1102e-16

How can I create a symbolic integer for use with my Fourier transform?

I am computing a Fourier transformation in MATLAB, when computing coefficients C[0] and C[n*f0], I got pretty nasty result because MATLAB doesn't recognize my variable "n" as integer. I currently compute with "n" as a symbolic variable (syms n;). How to change symbolic n to symbolic integer n?
Looking at the MATLAB documenation, to add the assumption "n is integer" in R2008b or later, you have to write
evalin(symengine,'assume(n,Type::Integer)')
This answers your question, however, I'm not really sure it solves your problem.
When you do a Fourier transform, you are performing a heavy numeric operation on your data, consequently all variables involved in that need to have concrete values. Your n probably should be an integer, but not just by type, it should contain an actual number. If you declare it using syms, it will potentially not contain a number, so you be sure you really need the symbolic toolbox!
If you do, and n is the result of a calculation that yield one specific integer, you can convert it to normal numerical form using uint32(n) or similar, see the help on conversions, e.g.
Y = fft(X,uint32(n))
Update: The error message you give in the comment implies that your n is in fact not an integer... I doubt you will be able to use it with fft.