text stringlengths 1 93.6k |
|---|
from fastRender import fastRender,loadPrecomputedRenderings
|
from time import time
|
import numpy as np
|
import cv2
|
t = str(time())
|
seed(t)
|
print "seed:",t
|
class InverseRender(GeneticAlgorithm):
|
def __init__(self):
|
# self.originalProgram = Sequence([Circle(AbsolutePoint(3,3),1),
|
# Circle(AbsolutePoint(8,3),1),
|
# Circle(AbsolutePoint(3,6),1),
|
# Circle(AbsolutePoint(8,6),1),
|
# Line([AbsolutePoint(4,3),AbsolutePoint(7,3)], True)])
|
# self.target = render([str(self.originalProgram)], showImage = True, yieldsPixels = True)[0]
|
self.target = loadImage("challenge.png")
|
self.history = {}
|
#print "Program that we are trying to match:",self.originalProgram
|
self.cumulativeRenderTime = 0.0
|
loadPrecomputedRenderings()
|
def randomIndividual(self):
|
return Sequence.sample()
|
def mutate(self,x):
|
return x.mutate()
|
def fastPixels(self, programs):
|
return [fastRender(p) for p in programs ]
|
def mapFitness(self, programs):
|
renderStart = time()
|
pixels = self.fastPixels(programs)
|
self.cumulativeRenderTime += (time() - renderStart)
|
def f(x): # fitness
|
return -asymmetricBlurredDistance(self.target,x)
|
ds = map(f,pixels)
|
return ds
|
r = InverseRender()
|
_,history = r.beam(100000, 5, 10)
|
print "Rendered",len(r.history),"images in",(r.cumulativeRenderTime),"seconds."
|
animateMatrices([ fastRender(x) for x in history ],"stochasticGeneticAlgorithm.gif")
|
# <FILESEP>
|
#!/usr/local/bin/python
|
'''
|
Yahoo-Groups-Archiver, Text Archive Script Copyright 2019 Robert Lancaster and others
|
YahooGroups-Archiver, a simple python script that allows for all
|
messages in a public Yahoo Group to be archived.
|
The Text Archive Script allows you to take the downloaded json documents
|
and turn them yearly archives of emails sorted into text documents.
|
Note that the archive-group.py script must be run first.
|
This program is free software: you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as published by
|
the Free Software Foundation, either version 3 of the License, or
|
(at your option) any later version.
|
This program is distributed in the hope that it will be useful
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU General Public License for more details.
|
You should have received a copy of the GNU General Public License
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
'''
|
import email
|
import HTMLParser
|
import json
|
import os
|
import sys
|
from datetime import datetime
|
from natsort import natsorted, ns
|
#To avoid Unicode Issues
|
reload(sys)
|
sys.setdefaultencoding('utf-8')
|
def archiveYahooMessage(file, archiveFile, messageYear, format):
|
try:
|
f = open(archiveFile, 'a')
|
f.write(loadYahooMessage(file, format))
|
f.close()
|
print 'Yahoo Message: ' + file + ' archived to: archive-' + str(messageYear) + '.txt'
|
except Exception as e:
|
print 'Yahoo Message: ' + file + ' had an error:'
|
print e
|
def loadYahooMessage(file, format):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.