analytics

Tuesday, July 14, 2015

Circle through two points on the Complex Plane

This formula makes a clockwise circle on the complex plane starting at point (x,y) and theta = 0,  and going through (a,b) at theta = pi, then back around to (a,b) at  theta=2*pi...





So you can use it to solve certain problems like what if you go 1/5th of the way from point (3,5) to point (-4,2) along a circular arc? The circular arc connecting the two points is:


But that is all the way with theta going to pi, one fifth of that would be pi/5 so:

One fifth of the way between those tow points along the circle is roughly at 4.38, 2.27...

**Solving for angles between unit vectors**
Another thing to do is say we have the unit vector ((2^1/2) / 2, (2^1/2) / 2), and we want to know the angle between that and ((3^1/2)/2), (1/2)) we can first make a circle with that start point and negative times each coordinate as the final point like so:

Then solve for when the formula above equals the chosen point:

It's pi/12 between those two vectors... If the angle had been the same but counterclockwise it would have read as -pi/12!

Thursday, July 9, 2015

heirarchial search

I had an idea for a website that lets you search for web pages by categories like in the picture. Each drop down box would have a list of perhaps the most popular 100 categories or subcategories and you can search deeper and deeper into the categories as far as you want and then it gives you a list of web pages that fit there in the heirarchy...


**Google to Hierarchical**

I think a way to seed the site from Google results would be to use the following to check whether one keyword could be a subcategory of another... 


R(S) is the number of results when searching for keyword S
For example:
R(sport) = 4,040,000,000
means there are that many search results on Google for the word "sport"
R(baseball) = 480,000,000
R(sport, baseball) = 476,000,000
So, R(sport, baseball) is searching for pages that match both the keywords baseball and sport, and that is almost as many as just searching for baseball by itself. So perhaps we can conclude that baseball is a subcategory of sport because R(sport) is larger... 
R(animal) = 2,200,000,000
R(anteater) = 864,000
R(animal, anteater) = 561,000
So it's not as good of a match for the subcategory relation by percentage but maybe because it's more than half as many we can keep it as a possible candidate... There might be a different keyword than animal that fits anteater better...
R(anteater, baseball) = 194,000Much less than 50% of the results for anteater alone so these probably don't have a subcategory relationship... 

So one way to start might be to look at R(x,y) where x and y are one of the top 1000 most searched for things on Google and use the information with the method above to form a category tree of the data...


Monday, July 6, 2015

Focoid's with source code

In this picture the blue dot is the centroid of all the black dots, and the red dots are what I call the focoids... The physical interpretation is that if these dots all weighed the same and were on a weightless plate, the centroid would be the place you could put one support to balance out the plate, and the focoids are two points where you could put supports so the plate would balance and there would be an even amount of weight on both supports...
I call them the focoids because of the analogy, the center of a circle is to the centroid as the focii of an ellipse are to the focoids...
In the program I wrote the dots are divided into 2 groups during the process of finding the focoids, the two groups each being a collection of points whose centroid is focoid 1 and the other whose centroid is focoid 2, so it is natural to make those points of each group a new set and find the focoids of each of those, and one could recurse until the last focoids found are the points of the original set as the centroid of just one point is the point in question... Below is shown the points from the leftmost group of the original points and it's centroid and focoids...


The program below can extend to any number and arrangement of points...


**Go Source Code**

package main

import (
    "fmt"
    "math"
)
func distance(a []float64, b []float64) float64{
    var c float64 = math.Pow(float64(a[0]-b[0]), 2) + math.Pow(float64(a[1]-b[1]), 2)
    return c
}
func centroid(a [][]float64) []float64{
    sumx :=0.0
    sumy :=0.0
    for i :=0; i<len(a); i++{
        sumx+=float64(a[i][0])
        sumy+=float64(a[i][1])
    }
    sumx /= float64(len(a))
    sumy /= float64(len(a))
    var c = []float64{
        sumx,sumy,
        }
    return c
}
func focoids(a [][]float64) ([][]float64, [][]float64, []float64, []float64){
    c := centroid(a)
    var centerred = []float64{0.0, 0.0}
    var centerblue = []float64{0.0, 0.0}
    var reds = make([][]float64, 0)
    var blues = make([][]float64,0)
    nred := 0.0
    nblue := 0.0
    for i:=0; i < len(a); i++{
        x := float64(a[i][0])
        y := float64(a[i][1])
        l := float64(len(a))
        cvx :=(c[0]-x)/distance(c, a[i])
        cvy :=(c[1]-y)/distance(c, a[i])
        c2x := (c[0]*l - x)/(l-1)-cvx
        c2y := (c[1]*l - y)/(l-1)-cvy
        c2 := []float64{c2x, c2y}
        cv := []float64{cvx, cvy}
        c2[0] /= distance(c2, cv)
        c2[1] /= distance(c2, cv)
        d := cv[0]*c2[1]-cv[1]*c2[0]
        if d < 0{
            reds = append(reds, a[i])
            centerred[0] += x
            centerred[1] += y
            nred += 1 
        }
        if d > 0{
            blues = append(blues, a[i])
            centerblue[0] += x
            centerblue[1] += y
            nblue += 1
            
        }
    }
    centerred[0]/=nred
    centerred[1]/=nred
    centerblue[0]/=nblue
    centerblue[1]/=nblue
    return reds, blues, centerred, centerblue
    
    
}
func main() {
    var a = [][]float64{
        {283,265},
        {119,99},
        {309,84},
        {461,151},
        {77,445},
        {284,451},
        {139,236},
        {678,207},
        {174,594},
        {491,525},
        {664,440},
        {531,671},
        {369,701},
    }

    var reds = make([][]float64, 0)
    var blues = make([][]float64, 0)
    var centerred = make([]float64, 2)
    var centerblue = make([]float64, 2)
    reds, blues, centerred, centerblue = focoids(a)
    fmt.Println(reds,blues)
    fmt.Println(centerred, centerblue)
    reds, blues, centerred, centerblue = focoids(blues)
    fmt.Println(reds,blues)
    fmt.Println(centerred, centerblue)
}


Thursday, June 25, 2015

Comparison of 16 note scale to 12 note scale

I noticed Western Music's 12 note scale in black is pretty close to a 16 note scale shifted off of a power of 2 about 5 hz left or right and leaving out 4 notes...
Also notice how many nice rational harmonies there are like C=256, E=320, G=384 in the standard notation with the new frequencies, and 320/256 = 1.25 and 384/320 = 1.2... A at 432 over G at 384 gives 1.125 for the ratio etc...

And I noticed that in standard notation with the new frequencies E:C is 1+1/4, G:E is 1+1/5, and the highest C:G is 1+1/3 making the nice 4-5-3 ratios for that chord.

Thursday, June 18, 2015

archimedean spiral bluish noise

I noticed that if you make an archimedean spiral in polar coordinates starting at the origin that goes to [1,0] at theta = 2*pi, you can solve for the next point on the curve that is a distance 1 from the last point, and it has a sort of blue noise look to the pattern of the dots...
In fact it's easy to prove that every point is at least distance 1 apart so it has that quality that blue noise has...
The maple commands to solve for the next point...
If you add a couple more points at the very middle of the spiral and crop to an offset square it starts to look very blue noisy...

Maybe it would look even better if you vary randomly the length instead of just 1 apart around the curve a little more or equal to 1...


Sunday, June 14, 2015

"Thresher": Sorting networks for 2^n inputs

As an example here is the "Thresher" sorting network for n=4 or 16 inputs, it has 99 comparators and 15 depth...

The pattern might be more obvious from looking at the code listed below but it is completely procedurally generated for any number of inputs that are a power of 2, and it's the same pattern every time. The 32 input network, for example, gets harder to draw but I found that it sorts random input as many times as I've tried... The depth for X inputs is always X-1...

This source code allows one to change in main the power of 2 of the size of the network, and it designs the Thresher network and tests it on a randomly ordered list of that size... The code runs really fast, it designed the 32 input Thresher sorting network and tested it almost instantly...
**Go Source Code**
package main
import (
    "fmt"    "math/rand"    "time")
func swap(l []int, x int, y int){
    if l[x] > l[y]{
        temp:=l[y]
        l[y]=l[x]
        l[x] = temp
    }
}
func y(l [] int, y int, a int, b int){
    for i:=a; i<=b; i*=2{
        x:=y
        j:=0        for x+i+j <= len(l)-1{
            fmt.Println(x+j, x+j+i)
            swap(l, x+j, x+j+i)
            j += 1            if j == i{
                x=x+j+i
                j = 0                            }
                    }
    }
}
func z(l [] int, y int, a int, b int){
    c:=0        for i:=a; i>b; i--{
        x:=y
        x+=c
        c+=1        j:=0        for x+j+i <= len(l)-1{
            fmt.Println(x+j, x+j+i)
            swap(l, x+j, x+j+i)
            j += 1            if j == i{
                x=x+j+i
                j = 0                            }
                    }
    }
}
func sortn(l [] int){
    c:=0    for i:=2; i <= len(l)/2; i*=2{
        y(l, c, 1, len(l)/i)
        c+=1        b:=len(l)/(2*i)
        if b > 1{
            z(l, c, len(l)/i-1, len(l)/(2*i))            }else{
            z(l, c, len(l)/i-1, 0)            }
            }
}
func main() {
    rand.Seed(time.Now().UTC().UnixNano())
    l := make([] int, 32)
    for i:=0; i<32; i++{
        l[i] = rand.Intn(100)
    }
    sortn(l)
    fmt.Println(l)
    }

Monday, June 8, 2015

Symetrical sorting network

This is a sorting network of 67 comparators and 10 depth, but with the obvious symmetry it suggests that there might be designs that can be found for any power of 2... The lighter colored part is how a lot of the best designs start, the rest is what I came up with to finish it...
Notes:
To make the pattern more complete but less optimal, there can be added a group of comparisons distance 5 apart between the group of 6 apart and 4 apart, so I'll conjecture that it's always possible to make a network extending the pattern above of log[2](n)+n/2 depth for N a power of 2, though I'm not sure about the total number of comparators because as you can see in the above they decreased in number down to when the comparisons were 3 apart when they suddenly went all the way across... And then again when they were 1 apart... Maybe that always happens when the comparators are n/(2^i) - 1 apart for i greater than or equal to 2? I'm not sure, a 32 item network would be really hard to test because of the size of 2^32, maybe there can be some proofs constructed to determine that... Or alternatively maybe just build one according to the plan described for 1024 items and try a great number of random arrangements of that many items and if it sorts them all there's a good probability it always works...