I need answer of a question about binomial distribution [closed] - data-mining

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
Let X be a binomial random variable with mean Np and variance Np(1−p).
Show that the ratio X/N also has a binomial distribution with mean p and
variance p(1 − p)/N.

Let r = X/N. Since X has a binomial distribution, r also has the
same distribution. The mean and variance for r can be computed as follows:
Mean , E[r] = E[X/N] = E[X]/N = (N p)/N = p .
Variance , E[(r − E[r])2] = E[(X/N − E[X/N])2] = E[(X − E[X])2]/N2 = N p(1 − p)/N2 = p(1 − p)/N

Related

How to write a log base 10 function in c++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I know that it may seem a duplicate question, but I could not find my answer in previous questions.
I mean how to write a log base 10 function by simple loops and not using built in log function in c++.
The easiest way is to calculate the natural logarithm (ln) with a Taylor series. Once you have found the natural logarithm, just divide it by ln(10) and you get the base-10 log.
The Taylor series is quite simple to implement in C. If z is the number for which you are seeking the log, you just have to loop a few iterations multiplying an accumulator by (z-1) each time. To a limit, the more iterations you run, the more accurate your result will be. Check it a few times against the libC log10() version until you are happy with the precision.
This is a "numeric approach". There are other numeric solutions to finding the logarithm of a number which can give more accurate results. Some of them can be found in that Wikipedia link I gave you.
Assuming by "log base 10" you mean "the number of times n can be divided by 10 before resulting in a value < 10":
log = 0;
// Assume n has initial value N
while ( n >= 10 ) {
// Invariant: N = n * 10^log
n /= 10;
log += 1;
}
You'll get faster convergence with Newton's Method. Use something like this (hand written not compiled or tested uses f(r) = 2**r - x to compute log2(x) ):
double next(double r, double x) {
static double one_over_ln2 = 1.4426950408889634;
return r - one_over_ln2 * (1 - x / (1 << static_cast<int>(r)));
double log2(double x) {
static double epsilon = 0.000000001; // change this to change accuracy
double r = x / 2;. // better first guesses converge faster
double r2 = next(r, x);
double delta = r - r2;
while (delta * delta > epsilon) {
r = r2;
r2 = next(r, x);
delta = r - r2
}
return r2;
}
double log10(double x) {
static double log2_10 = log2(10);
return log2(x) / log2_10;
}

How can I do this more elegantly? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a 2D point A inside the [0,1]² square.
The square is divided into 9 subsquares (of equal dimensions)
http://www.noelshack.com/2015-23-1433689273-capture.png
I want to know which subsquare the point A belongs to.
I can do a if elseif else on the first coordinate, then inside each branch, another if else if else on the second coordinate.
There is a lot of code repeating (the check on the second coordinate)
Is there a better way ?
The trouble is, it is not clear what your 2D point is, what you want the sub-square value as, etc. So a definitive answer is difficult. But anyway, I will make some assumptions and see if I am right about what you are asking...
Assuming you had a point A with a coordinate such as:
float point[2] = {0.1224, 0.4553}
Then to work out where it is inside the square you can do some simple maths:
float x = point[0] * 3;
float y = point[1] * 3; //Multiply both by 3
int xIdx = floor(x);
int yIdx = floor(y); //Floor the result - this gives a number 0 to 2
int cell = yIdx * 3 + xIdx + 1; // Calculate the cell index (based on your diagram)
Now you could generalise this for any point - for example the point might be (1.23343, 2.6768) - by simply removing the integer part from the point - leaving a number between 0 and 1. The integer part would be the super cell, and the fractional part would be converted into the sub cell as above.

Simplify (a + b) XOR (c + b) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Is it possible to simplify (a+b)xor(c+b)? What is the contribution of b to the final result?
Note that I'm mixing boolean algebra with arithmetic, xor is a bitwise exclusive or on corresponding bits and + is a standard addition on 8 bits, that wraps around when overflown.
a, b, c are unsigned char;
We can use an SMT solver to test our hypothesis that your formula can be simplified. You can head over to http://rise4fun.com:
x = BitVec('x', 8)
y = BitVec('y', 8)
z = BitVec('z', 8)
print simplify((x + z) ^ (y + z))
and the result, anticlimactically, is:
x + z ^ y + z
Which means your formula cannot be further simplified.
(a+b)xor(c+b)
--------------
=((not(a+b))*(c+b))+((a+b)*(not(c+b)))
-----------------------
=((not a)*(not b)*(c+b))+((a+b)*(not c)*(not b))
----
=((not a)(not b)*c) + (a*(not c)(not b))
----
=(not b)((not a)c + a(not c))
----
=(not b)(a xor c)
----

gaussian filter kernel values [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
can anyone tell me how to generate a 2d gaussian filter kernel using the gaussian filter equation? how does the x and y value vary?
ref: http://en.wikipedia.org/wiki/Gaussian_function
To generate the kernel is quite simple. If your problem is in applying the kernel, you need to update the question.
The kernel is simply a square matrix of values, generally an odd number size so that there's a clearly defined center. To fill it, the x and y values go from -(n-1)/2 to (n-1)/2 where n is the size of the matrix.
double half_n = (n - 1) / 2.0;
for (i = 0; i < n; ++i)
{
double x = i - half_n;
for (j = 0; j < n; ++j)
{
double y = j - half_n;
kernel[i][j] = // use formula with x and y here
}
}

solving T(n) = 2T(n/2) + log n [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I am trying to solve T(n) = 2T(n/2) + log n
substituted n = 2^k
T(2^k) = 2T(2^(k-1)) + k
T(2^k) = 2^2 T(2^(k-1)) + 2(k-1) + k
after k steps
T(2^k) = 2^k T(1) + 2^(k-1) + 2 * (2^(k-2)) +....+k
So basically I need to sum a term of i*2^i where i = 1 to log n - 1.
And I could not find an easy way to sum these terms. Am I doing something wrong ? Is there any other way to solve this recursion ? would master theorem work her ? if yes than how ?
Thanks.
first you should define a recursive export,say T(1)
then:
since T(2^k) = 2T(2^(k-1)) + k; *
we define g(k) = T(2^k)/2^k;
then * come into:
g(k) = g(k-1) + k/2^k = g(1) + sum(i/2^i); i=2,3,4...k
where g(1) = T(1)/2 = c;
where you could then unfold the sum expression and define it = y;
then unfold the expression of y/2;
y-y/2 is a geometric progression, so youcan solve it
as I worked out, sum = 3/2 - (k+2)/2^k;
so T(n) = 2^k * g(k) = (3/2+c)*n - (2+logn)
Wolfram|Alpha gives a closed form solution:
for a constant c_1 that is fixed by the initial condition.
By the way, log(n)/log(2) = lg(n), where lg is the base two logarithm.