analytics

Monday, January 30, 2012

Comparing distributions

I was thinking if you have these various distributions, like here are four different normal distributions:
I got to wondering how you could find out if you randomly pick a number from say the green distribution, how often a number picked from say the red distribution would be greater. One way of doing it is simulating say a million trials on a computer and seeing how often one was bigger than the other. So doing that first:
The answer is 94.8768%

  But I was more interested in an exact solution so I thought of this formula:

I'll explain the reasoning in a second, let's see that it works first:

It came out to 94.8753% or pretty much the same. 
Anyway Maple makes it look really ugly but the just above is evaluating the integral in the next image up with the two distributions and over a suitable interval. And you see the result is the same to within a couple millionths as the computer simulation. Probably my formula is correct so I'll explain the reasoning:
Looking at the bounds of integration the inner integral is from r to d and the outer is from a to d, that means the integral is only being evaluated over points q,r where q is greater than r. Like for a particular r in the outer integral the inner one looks at every q greater than that r up to d and so on. Q>R
So for every possible pair of q,r such that q>r the function being evaluated is X(q)*Y(r) which is to say the probability of choosing a point q,r. There's a certain probability of picking a q from X and a certain probability of picking an r from Y so X(q)*Y(r) is the probability of picking both. So when you add up all those infinitesimal probabilities you end up with the total probability of picking a pair such that q > r for those two distributions. 
So in other words you have the probability if you pick a number from each distribution that the first is greater than the second. 
*Edit* 
This formula scales to any number of variables, incidentally. Here is an example where you have 6 independent uniform variables ranging from 0 to 1. And you want to know the likelihood of them being chosen so that each one you choose is bigger than the last one. 
So it turns out 1/6! which makes sense there are 6! possible orderings and any one should be one over that probability. The 1^6 I just wrote it like that so you could see it would be six distributions multiplied together. 

*UPDATE 2
Another interesting thing to do is something like calculate the probability that 3 uniformly random numbers between 0 and 1 will be able to form a triangle. You can set up the integral like this:
C is forced to be between b and a+b and b is greater than a. But there are 3 ways to choose which variable will be the hypotenuse so all in all there is a 50% chance that the three numbers will be able to form a triangle. 

Saturday, January 28, 2012

My campaign

I thought I could run for senator and have this website where people could discuss each bill and vote on it and I promised however the vote on the site came out that is how I would vote. Each bill could have a page something like:

Tuesday, January 24, 2012

Ping Pong waterer

I removed the other blog post about the rain barrel water distributor. Here is my new design:
Basically there is a rain bucket with a hose going to the bottom, and on the other end there is the top of a plastic soda bottle with a ping pong ball in it. Water will I hope drain from the rain barrel that's at a higher elevation but as the water gets higher in the container being filled the ping pong ball floats until it blocks off the water from filling it any more. Then as a pet or a plant drinks the water the ping pong ball sinks with the level of the water and open the flow from the barrel again.

*EDIT*
Works like a charm here is a picture. The orange thing in the neck of the bottle is the ping pong ball. The only thing different from the design above is there has to be a hole in the bottle just below where the ping pong ball seals it off so the air can get out of the bottle.


To see how this problem is normally solved look at this:
http://en.wikipedia.org/wiki/Float_valve
Mine's a lot simpler isn't it?


Monday, January 9, 2012

Sum of sine of decreasing angles

I thought of this sum to check and see if Maple knew how to calculate it:

You see you add the sum of the sin of pi/2, pi/4, pi/8... But maple does not know what it is.
But I found that it seems to have a finite limit...

It seems to be converging to something like 2.481... which doesn't get any google results for the first few digits the way most well known mathematical limits would. 
Just a reminder the sin(pi/2) = 1, the sin(pi/4)=sq(2)/2, and then:
sin(pi/8)=


So anyway when you add these all up it apparently has a finite sum but it doesn't seem anyone has mentioned this particular limit before. 

Thursday, January 5, 2012

one formula for regular polyhedra

I never realized this before but one formula does the area for every regular polygon's area given a perimeter and a number of sides. And then the limit as the number of sides goes to infinity gives a formula for the area of the circle based on circumference.

Wednesday, December 28, 2011

From boolean algebra to regular algebra

Consider the following two tables, the first shows the bitwise XOR function for the first few binary numbers and the second shows the same table converted to decimal:
Bitwise Xor is defined as you look at the two numbers say (0010 and 1011) and a new number is formed that has a 1 in position i if the ith digit of either of the two starting numbers is 1 but not both. So for 0010 and 1011 XOR would give 1001.
There are 16 of these basic bitwise logical functions, another one is AND which gives a 1 in each position if both of the starting numbers have a 1 in that position. 
I'll also define one more the bitshift which takes say L(111) and produces 1110 which is just the original number with a 0 added onto the end. 
From these 3 basic operations we can define addition as the program:
add(A,B):
  t = XOR(A,B)
  u = L(AND(A,B))
  if u not equal to 0:
    add(t, u)
  else:
    return t

For example adding these:
A=111 B=101 
t=010 
u=1010 
where t is XOR(A,B) and u is AND(A,B) but shifted 1 position to the left. Then add is called on this t and u, to get:
t=1000 
u=0100 
then since u is still not 0 add is called again:
t = 1100 
u=0000
now u is 0 so the program is done and returns t which is 1100. Note that 111+101 = 1100 is 7+5=12.



Friday, December 16, 2011

Social Messaging

I thought of this idea for a social service that works like a collaborative email that's authenticated on a server and allows you to manage different groups to share different content with.
First of all you compose a message with any kind of webpage content you would like, pictures, links, attached files, whatever. And you choose what groups to send the message to.  Example:
Then a message is sent to the server to make sure whoever you are sending it to has put you in a list of people they want to receive messages from (you can only get spam from people you've authorized!):
If it is verified, the message goes to the person you're sending it to's inbox where they can see new messages:
The neat thing is on each message it gives everyone the message was sent to a place to edit the message, the server will send the update to everyone the message was originally sent to:

The app provides an interface to quickly add and remove different contacts from different groups:

There's also an interface for seeing who has sent you a contact invite or for you to send contact invites, also to remove someone from your contact list. Then they will no longer be able to send you a message. To make a connection between two people both people have to confirm by entering their password which the server verifies. 

So it's pretty simple the server I make doesn't even have to store anyone's files except temporarily it merely keeps a database of who is authorized to send messages to whom and sends the message along. I feel like it combines the best aspects of email, google+, facebook, and google wave. 

UPDATE 1:
I finished the message editing part of the program here are a couple screenshots:
Here I'm viewing a message about fire and I've filled out a comment including a picture of a bucket of water.

When I click submit it adds my comment to the main message: 
So so far so good, next is the part of the program for selecting different messages. 

Update 2:
Now I've got the main message selection window done. When you click on one of your groups/person on the left it will only show you messages from anyone in that group or from that person.