analytics
Friday, January 16, 2015
material
I made this material by breaking up cotton balls very finely and coating them with graphite powder, then mixing that up with 2 part epoxy and forming it. It is really impressively hard and strong. Beating on it with a hammer on the driveway doesn't leave any visible marks (and makes such a loud noise I might make a video), and cutting into it with a knife only makes a slight mark in the outermost surface probably just into the epoxy coating...
**After polishing the outer surface flat with Aluminum Oxide Sand paper, after the surface was flattened it smoothed the sand paper instead of further smoothing the material
I found I was able to drill holes through it without compromising the strength of the bulk structure or it breaking into pieces around the hole...
Wednesday, January 14, 2015
Sort worm
A sort worm is a creature I made whose genes work on a list, this one I made works on lists of 10 items like so:
[2, 8, 7, 4, 5, 3, 6, 9, 0, 1]
I chose to use 25 genes as being roughly 10*log(10) of the form:
[a,b] where a and b are positions on the list and the gene is expressed by comparing items in the list at those positions and swapping them if the number at the lower position is greater than the one at the higher position. "His" dna is:
[[1, 4], [7, 9], [2, 6], [0, 7], [1, 7], [6, 8], [3, 5], [3, 8], [2, 4], [2, 3], [5, 7], [0, 6], [6, 9], [8, 9], [0, 2], [3, 6], [4, 8], [0, 1], [5, 6], [7, 9], [4, 6], [1, 3], [4, 7], [6, 7], [3, 5]]
So working on the given list:
[2, 8, 7, 4, 5, 3, 6, 9, 0, 1] original list
[2, 5, 7, 4, 8, 3, 6, 9, 0, 1] swapped items 1 and 4 (0 indexed) because the rightmost is less than the leftmost of the two
[2, 5, 7, 4, 8, 3, 6, 1, 0, 9] swapped 7 and 9...
[2, 5, 6, 4, 8, 3, 7, 1, 0, 9] etc...
[1, 5, 6, 4, 8, 3, 7, 2, 0, 9]
[1, 2, 6, 4, 8, 3, 7, 5, 0, 9]
[1, 2, 6, 4, 8, 3, 0, 5, 7, 9]
[1, 2, 6, 3, 8, 4, 0, 5, 7, 9]
[1, 2, 6, 3, 8, 4, 0, 5, 7, 9]
[1, 2, 6, 3, 8, 4, 0, 5, 7, 9]
[1, 2, 3, 6, 8, 4, 0, 5, 7, 9]
[1, 2, 3, 6, 8, 4, 0, 5, 7, 9]
[0, 2, 3, 6, 8, 4, 1, 5, 7, 9]
[0, 2, 3, 6, 8, 4, 1, 5, 7, 9]
[0, 2, 3, 6, 8, 4, 1, 5, 7, 9]
[0, 2, 3, 6, 8, 4, 1, 5, 7, 9]
[0, 2, 3, 1, 8, 4, 6, 5, 7, 9]
[0, 2, 3, 1, 7, 4, 6, 5, 8, 9]
[0, 2, 3, 1, 7, 4, 6, 5, 8, 9]
[0, 2, 3, 1, 7, 4, 6, 5, 8, 9]
[0, 2, 3, 1, 7, 4, 6, 5, 8, 9]
[0, 2, 3, 1, 6, 4, 7, 5, 8, 9]
[0, 1, 3, 2, 6, 4, 7, 5, 8, 9]
[0, 1, 3, 2, 5, 4, 7, 6, 8, 9]
[0, 1, 3, 2, 5, 4, 6, 7, 8, 9]
This finished result is pretty typical that 2 items are 1 position out of order...
A lot of times it gets it perfectly and the worst I've seen it do is 4 items needing to be swapped 1 position.
Testing this dna on 100 random lists gives that this will be the average result.
**finding the dna**
To find this above sequence of dna I:
1. Created 10 sort worms with random dna
Then repeat these steps below for 1000 generations
2. "Breed" all worms each worm with every other, where every new worm gets each gene from one of its parents to make its dna.
3. Reduce this list of worms to the 5 best performers as the average root mean squared of how out of order the list is after he uses his dna on 100 random lists.
4. Add 5 more random worms to the 5 you're left with.
At the end this worm above was the best performer.
**Source Code**
import random
class creature():
def __init__(self):
self.dna = []
def new(self, dnalength, listlength):
self.dnalength = dnalength
self.listlength = listlength
crudelist = []
for i in range(0, listlength-1):
for j in range(i+1, listlength):
crudelist.append([i,j])
random.shuffle(crudelist)
self.dna = crudelist[0:dnalength]
def childof(self, a, b):
self.dnalength = a.dnalength
self.listlength = a.listlength
for i in range(0, len(a.dna)):
g = random.randint(0, 1)
if g == 0:
self.dna.append(a.dna[i])
else:
self.dna.append(b.dna[i])
def statictest(self, numtimes, testlist):
avep = 0
for i in range(0, numtimes):
testlist = self.usegenes(testlist)
p = self.checklist(testlist)
avep += p
return avep*1.0 / numtimes
def testme(self, numtimes):
avep = 0
for i in range(0, numtimes):
testlist = []
for j in range(0, self.listlength):
testlist.append(random.random())
testlist = self.usegenes(testlist)
p = self.checklist(testlist)
avep += p
return avep*1.0 / numtimes
def checklist(self, testlist):
totalscore = 0
for i in range(0, len(testlist)):
lessthan = 0
for j in range(0, len(testlist)):
if testlist[j] < testlist[i]:
lessthan +=1
score = (i - lessthan)**2.0
totalscore +=score
return totalscore**.5
def usegenes(self, testlist):
for j in range(0, self.dnalength):
if testlist[self.dna[j][0]] > testlist[self.dna[j][1]]:
temp = testlist[self.dna[j][0]]
testlist[self.dna[j][0]] = testlist[self.dna[j][1]]
testlist[self.dna[j][1]] = temp
return testlist
def main():
creatures = []
numcreatures = 400
survivors = 5
dnalength = 25
listlength = 10
numtests = 100
generations = 3000
testlist = []
performance = []
for j in range(0, listlength):
testlist.append(random.random())
for i in range(0, numcreatures):
c = creature()
c.new(dnalength, listlength)
creatures.append(c)
for i in range(0, generations):
performance = []
creatures2 = []
for j in range(0, len(creatures)):
c = creatures[j]
performance.append([c.testme(numtests), j])
performance = sorted(performance)
for j in range(0, survivors):
creatures2.append(creatures[performance[j][1]])
for j in range(0, survivors):
c = creature()
c.new(dnalength, listlength)
creatures2.append(c)
creatures = creatures2
max = len(creatures)
for k in range(0, max-1):
for l in range(k+1, max):
c = creature()
c.childof(creatures[k], creatures[l])
creatures.append(c)
print(performance)
print(creatures[0].dna)
main()
[2, 8, 7, 4, 5, 3, 6, 9, 0, 1]
I chose to use 25 genes as being roughly 10*log(10) of the form:
[a,b] where a and b are positions on the list and the gene is expressed by comparing items in the list at those positions and swapping them if the number at the lower position is greater than the one at the higher position. "His" dna is:
[[1, 4], [7, 9], [2, 6], [0, 7], [1, 7], [6, 8], [3, 5], [3, 8], [2, 4], [2, 3], [5, 7], [0, 6], [6, 9], [8, 9], [0, 2], [3, 6], [4, 8], [0, 1], [5, 6], [7, 9], [4, 6], [1, 3], [4, 7], [6, 7], [3, 5]]
So working on the given list:
[2, 8, 7, 4, 5, 3, 6, 9, 0, 1] original list
[2, 5, 7, 4, 8, 3, 6, 9, 0, 1] swapped items 1 and 4 (0 indexed) because the rightmost is less than the leftmost of the two
[2, 5, 7, 4, 8, 3, 6, 1, 0, 9] swapped 7 and 9...
[2, 5, 6, 4, 8, 3, 7, 1, 0, 9] etc...
[1, 5, 6, 4, 8, 3, 7, 2, 0, 9]
[1, 2, 6, 4, 8, 3, 7, 5, 0, 9]
[1, 2, 6, 4, 8, 3, 0, 5, 7, 9]
[1, 2, 6, 3, 8, 4, 0, 5, 7, 9]
[1, 2, 6, 3, 8, 4, 0, 5, 7, 9]
[1, 2, 6, 3, 8, 4, 0, 5, 7, 9]
[1, 2, 3, 6, 8, 4, 0, 5, 7, 9]
[1, 2, 3, 6, 8, 4, 0, 5, 7, 9]
[0, 2, 3, 6, 8, 4, 1, 5, 7, 9]
[0, 2, 3, 6, 8, 4, 1, 5, 7, 9]
[0, 2, 3, 6, 8, 4, 1, 5, 7, 9]
[0, 2, 3, 6, 8, 4, 1, 5, 7, 9]
[0, 2, 3, 1, 8, 4, 6, 5, 7, 9]
[0, 2, 3, 1, 7, 4, 6, 5, 8, 9]
[0, 2, 3, 1, 7, 4, 6, 5, 8, 9]
[0, 2, 3, 1, 7, 4, 6, 5, 8, 9]
[0, 2, 3, 1, 7, 4, 6, 5, 8, 9]
[0, 2, 3, 1, 6, 4, 7, 5, 8, 9]
[0, 1, 3, 2, 6, 4, 7, 5, 8, 9]
[0, 1, 3, 2, 5, 4, 7, 6, 8, 9]
[0, 1, 3, 2, 5, 4, 6, 7, 8, 9]
This finished result is pretty typical that 2 items are 1 position out of order...
A lot of times it gets it perfectly and the worst I've seen it do is 4 items needing to be swapped 1 position.
Testing this dna on 100 random lists gives that this will be the average result.
**finding the dna**
To find this above sequence of dna I:
1. Created 10 sort worms with random dna
Then repeat these steps below for 1000 generations
2. "Breed" all worms each worm with every other, where every new worm gets each gene from one of its parents to make its dna.
3. Reduce this list of worms to the 5 best performers as the average root mean squared of how out of order the list is after he uses his dna on 100 random lists.
4. Add 5 more random worms to the 5 you're left with.
At the end this worm above was the best performer.
**Source Code**
import random
class creature():
def __init__(self):
self.dna = []
def new(self, dnalength, listlength):
self.dnalength = dnalength
self.listlength = listlength
crudelist = []
for i in range(0, listlength-1):
for j in range(i+1, listlength):
crudelist.append([i,j])
random.shuffle(crudelist)
self.dna = crudelist[0:dnalength]
def childof(self, a, b):
self.dnalength = a.dnalength
self.listlength = a.listlength
for i in range(0, len(a.dna)):
g = random.randint(0, 1)
if g == 0:
self.dna.append(a.dna[i])
else:
self.dna.append(b.dna[i])
def statictest(self, numtimes, testlist):
avep = 0
for i in range(0, numtimes):
testlist = self.usegenes(testlist)
p = self.checklist(testlist)
avep += p
return avep*1.0 / numtimes
def testme(self, numtimes):
avep = 0
for i in range(0, numtimes):
testlist = []
for j in range(0, self.listlength):
testlist.append(random.random())
testlist = self.usegenes(testlist)
p = self.checklist(testlist)
avep += p
return avep*1.0 / numtimes
def checklist(self, testlist):
totalscore = 0
for i in range(0, len(testlist)):
lessthan = 0
for j in range(0, len(testlist)):
if testlist[j] < testlist[i]:
lessthan +=1
score = (i - lessthan)**2.0
totalscore +=score
return totalscore**.5
def usegenes(self, testlist):
for j in range(0, self.dnalength):
if testlist[self.dna[j][0]] > testlist[self.dna[j][1]]:
temp = testlist[self.dna[j][0]]
testlist[self.dna[j][0]] = testlist[self.dna[j][1]]
testlist[self.dna[j][1]] = temp
return testlist
def main():
creatures = []
numcreatures = 400
survivors = 5
dnalength = 25
listlength = 10
numtests = 100
generations = 3000
testlist = []
performance = []
for j in range(0, listlength):
testlist.append(random.random())
for i in range(0, numcreatures):
c = creature()
c.new(dnalength, listlength)
creatures.append(c)
for i in range(0, generations):
performance = []
creatures2 = []
for j in range(0, len(creatures)):
c = creatures[j]
performance.append([c.testme(numtests), j])
performance = sorted(performance)
for j in range(0, survivors):
creatures2.append(creatures[performance[j][1]])
for j in range(0, survivors):
c = creature()
c.new(dnalength, listlength)
creatures2.append(c)
creatures = creatures2
max = len(creatures)
for k in range(0, max-1):
for l in range(k+1, max):
c = creature()
c.childof(creatures[k], creatures[l])
creatures.append(c)
print(performance)
print(creatures[0].dna)
main()
Thursday, January 1, 2015
Limit vs. Limit graphs to analyze infinite series
f(x) = 1/x^3 as x goes to infinity will reach 0, and the integral from 1 to infinity will reach 1/2. I find it interesting to parameterize a 2 variable curve where one variable s is the function's value at t and the other r is the partial integral from 1 up to t, and make a plot of s vs. r like below.
This shows the behavior of f(x) over the entire x axis from 1 to infinity as it relates to the integral to that point.
It leads to an interesting proof of the infinite sum of geometric series... Here I plot the sum of 1/2^n up to t vs. the value of each individual term at t...
The value of the first term is 1 and the sum of just that term is of course 1, and the next term is 1/2 and the sum of the first two terms is 1.5, and it precedes linearly all the way to a term being 0 and the sum of the infinite terms being 2. But if you know all the points lie on the same line you can use just the first two terms to derive a line that shows ultimately the infinite sum will reach the r axis at 1/(1-1/2). And generalize that to any geometric series.
This shows the behavior of f(x) over the entire x axis from 1 to infinity as it relates to the integral to that point.
It leads to an interesting proof of the infinite sum of geometric series... Here I plot the sum of 1/2^n up to t vs. the value of each individual term at t...
The value of the first term is 1 and the sum of just that term is of course 1, and the next term is 1/2 and the sum of the first two terms is 1.5, and it precedes linearly all the way to a term being 0 and the sum of the infinite terms being 2. But if you know all the points lie on the same line you can use just the first two terms to derive a line that shows ultimately the infinite sum will reach the r axis at 1/(1-1/2). And generalize that to any geometric series.
Monday, December 29, 2014
Shortnet definition and source code
I'm defining the Shortnet of a group of points to be the subset S of the collection of every possible line connecting pairs of points C, such that every line crossing a line shorter than itself has been removed.
Example: You have your points...
Then you create all the lines connecting every point pairwise...
Then you remove any line that crosses a line shorter than itself...
There will never be any lines that cross left as one or the other of each pair of lines that cross is removed.
Source Code using PIL drawing library and Python:
import random
import Image, ImageDraw
def cross(a1, b1, c1, d1, a2, b2, c2, d2):
if (-a2*b1+a2*d1+c2*b1-c2*d1+b2*a1-b2*c1-d2*a1+d2*c1)== 0:
return False
if (-a2*b1+a2*d1+c2*b1-c2*d1+b2*a1-b2*c1-d2*a1+d2*c1) == 0:
return False
s = 1.0*(a1*d1-d2*a1+d2*c1-c1*b1+c2*b1-c2*d1)/(-a2*b1+a2*d1+c2*b1-c2*d1+b2*a1-b2*c1-d2*a1+d2*c1)
t = 1.0*(-b2*c1+a2*d1+b2*c2-a2*d2+d2*c1-c2*d1)/(-a2*b1+a2*d1+c2*b1-c2*d1+b2*a1-b2*c1-d2*a1+d2*c1)
if s > 0 and s < 1.0:
if t > 0 and t < 1.0:
return True
return False
def gen(num):
points = []
for i in range(0, num):
point = [random.randint(100, 700), random.randint(100, 700)]
points.append(point)
return points
def shorter(a1, b1, c1, d1, a2, b2, c2, d2):
d1 = ((c1 - a1)**2.0 + (d1 - b1)**2.0)**.5
d2 = ((c2 - a2)**2.0 + (d2 - b2)**2.0)**.5
if d1 <= d2:
return True
else:
return False
def makelines(points):
lines = []
for i in range(0, len(points)-1):
for j in range(i+1, len(points)):
lines.append([points[i][0], points[i][1], points[j][0], points[j][1]])
return lines
def picklines(lines):
marked = []
for i in range(0, len(lines)):
marked.append(True)
for i in range(0, len(lines)-1):
for j in range(i+1, len(lines)):
if cross(lines[i][0], lines[i][1], lines[i][2], lines[i][3], lines[j][0], lines[j][1], lines[j][2], lines[j][3]):
if shorter(lines[i][0], lines[i][1], lines[i][2], lines[i][3], lines[j][0], lines[j][1], lines[j][2], lines[j][3]):
marked[j] = False
else:
marked[i] = False
for i in range(0, len(lines)):
if marked[i] == False:
lines[i] = False
return lines
def drawlines(d, lines):
for line in lines:
if line != False:
d.line(line)
def drawpoints(d, points):
for point in points:
d.ellipse([point[0]-10, point[1]-10, point[0]+10, point[1]+10], fill=(255,0,0))
def main():
points = gen(10)
plot = Image.new("RGB", [800, 800])
d = ImageDraw.Draw(plot)
drawpoints(d, points)
plot.save("dots.png")
lines = makelines(points)
drawlines(d, lines)
plot.save("all.png")
plot = Image.new("RGB", [800, 800])
d = ImageDraw.Draw(plot)
drawpoints(d, points)
lines = picklines(lines)
drawlines(d, lines)
plot.save("shortnet.png")
main()
Example: You have your points...
Then you create all the lines connecting every point pairwise...
Then you remove any line that crosses a line shorter than itself...
Here is one with 50 points:
Source Code using PIL drawing library and Python:
import random
import Image, ImageDraw
def cross(a1, b1, c1, d1, a2, b2, c2, d2):
if (-a2*b1+a2*d1+c2*b1-c2*d1+b2*a1-b2*c1-d2*a1+d2*c1)== 0:
return False
if (-a2*b1+a2*d1+c2*b1-c2*d1+b2*a1-b2*c1-d2*a1+d2*c1) == 0:
return False
s = 1.0*(a1*d1-d2*a1+d2*c1-c1*b1+c2*b1-c2*d1)/(-a2*b1+a2*d1+c2*b1-c2*d1+b2*a1-b2*c1-d2*a1+d2*c1)
t = 1.0*(-b2*c1+a2*d1+b2*c2-a2*d2+d2*c1-c2*d1)/(-a2*b1+a2*d1+c2*b1-c2*d1+b2*a1-b2*c1-d2*a1+d2*c1)
if s > 0 and s < 1.0:
if t > 0 and t < 1.0:
return True
return False
def gen(num):
points = []
for i in range(0, num):
point = [random.randint(100, 700), random.randint(100, 700)]
points.append(point)
return points
def shorter(a1, b1, c1, d1, a2, b2, c2, d2):
d1 = ((c1 - a1)**2.0 + (d1 - b1)**2.0)**.5
d2 = ((c2 - a2)**2.0 + (d2 - b2)**2.0)**.5
if d1 <= d2:
return True
else:
return False
def makelines(points):
lines = []
for i in range(0, len(points)-1):
for j in range(i+1, len(points)):
lines.append([points[i][0], points[i][1], points[j][0], points[j][1]])
return lines
def picklines(lines):
marked = []
for i in range(0, len(lines)):
marked.append(True)
for i in range(0, len(lines)-1):
for j in range(i+1, len(lines)):
if cross(lines[i][0], lines[i][1], lines[i][2], lines[i][3], lines[j][0], lines[j][1], lines[j][2], lines[j][3]):
if shorter(lines[i][0], lines[i][1], lines[i][2], lines[i][3], lines[j][0], lines[j][1], lines[j][2], lines[j][3]):
marked[j] = False
else:
marked[i] = False
for i in range(0, len(lines)):
if marked[i] == False:
lines[i] = False
return lines
def drawlines(d, lines):
for line in lines:
if line != False:
d.line(line)
def drawpoints(d, points):
for point in points:
d.ellipse([point[0]-10, point[1]-10, point[0]+10, point[1]+10], fill=(255,0,0))
def main():
points = gen(10)
plot = Image.new("RGB", [800, 800])
d = ImageDraw.Draw(plot)
drawpoints(d, points)
plot.save("dots.png")
lines = makelines(points)
drawlines(d, lines)
plot.save("all.png")
plot = Image.new("RGB", [800, 800])
d = ImageDraw.Draw(plot)
drawpoints(d, points)
lines = picklines(lines)
drawlines(d, lines)
plot.save("shortnet.png")
main()
Friday, December 19, 2014
Parallelizable convex hull algorithm
Suppose you have a number of points in any number of dimensions, here I will just show 2.
First find the centroid, and the point farthest from that centroid Pc and construct the circle or n-dimensional sphere to it from the centroid... (Centroid shown in blue)
Now consider all the straight lines C to P(i) to B(i) from the Centroid to each Point and continuing on to a point on the Bounding region. Make a list of Pc and all points P(i) such that P(i) to B(i) is shorter than any other line from a different point P(j) to B(i).
First find the centroid, and the point farthest from that centroid Pc and construct the circle or n-dimensional sphere to it from the centroid... (Centroid shown in blue)
Now consider all the straight lines C to P(i) to B(i) from the Centroid to each Point and continuing on to a point on the Bounding region. Make a list of Pc and all points P(i) such that P(i) to B(i) is shorter than any other line from a different point P(j) to B(i).
This last step is the part that can be done in parallel, passing the entire set to as many processors as there are points and each one finding the solution for its given point. The points that are closest to their respective bounding point than any other point is to that bounding point are the hull.
Tuesday, December 9, 2014
recursive formula for points on the unit circle of regular 2^n gon's
I found that formulas of this type:
describe the points on a circle corresponding to regular 2^(n+1)-gons where n is the number of square root symbols in the formulas and a,b,c... are each 1 or 2. For example a 16-gon
I haven't quite figured out where each point will be on the unit circle by the signs of the terms though.
Monday, December 8, 2014
Fast parallelizable way to generate approximate points for a circle without using trig functions
This method starts with the four points of the bounding square...
Then replaces each point with two points (1- root 2/2) away from the sides... This is basically like truncating every corner to the right proportion...
Then iterates this process but using .25 instead of (1-root 2/2) that I found by experiment works very well. I suppose for perfect accuracy there is a recursive series involving root 2 but it approaches .25 so quickly that I didn't bother with it.
Then replaces each point with two points (1- root 2/2) away from the sides... This is basically like truncating every corner to the right proportion...
Then iterates this process but using .25 instead of (1-root 2/2) that I found by experiment works very well. I suppose for perfect accuracy there is a recursive series involving root 2 but it approaches .25 so quickly that I didn't bother with it.
I found 4 iterations is enough for fairly large circles...
And in the end you have an list with all the points in counter clockwise order around the circle.
Python source code (Using PIL for drawing)
import Image, ImageDraw
def plot(points, draw):
for i in range(0, len(points)-1):
draw.line([points[i], points[i+1]])
draw.line([points[len(points)-1], points[0]])
def truncate(points):
newpoints = []
param = .29
if len(points)>4:
param = .25
for i in range(0, len(points)-1):
x1 = points[i+1][0]*(param)+points[i][0]*(1.0-param)
y1 = points[i+1][1]*(param)+points[i][1]*(1.0-param)
x2 = points[i+1][0]*(1.0-param)+points[i][0]*(param)
y2 = points[i+1][1]*(1.0-param)+points[i][1]*(param)
newpoints.append((x1, y1))
newpoints.append((x2, y2))
x1 = points[0][0]*(param)+points[len(points)-1][0]*(1.0-param)
y1 = points[0][1]*(param)+points[len(points)-1][1]*(1.0-param)
x2 = points[0][0]*(1.0-param)+points[len(points)-1][0]*(param)
y2 = points[0][1]*(1.0-param)+points[len(points)-1][1]*(param)
newpoints.append((x1, y1))
newpoints.append((x2, y2))
return newpoints
def main():
points = [(100,100),(100,700),(700,700),(700,100)]
for i in range(1, 5):
p = Image.new("RGB", [800,800])
draw = ImageDraw.Draw(p)
points = truncate(points)
plot(points, draw)
p.save("plots"+str(i)+".png")
main()
Subscribe to:
Posts (Atom)















