Example #1
0
def handle_revision(revision):
    print "revision: %s" % revision
    filename = os.path.join("mtn2cache", "revision", revision)
    if not os.path.exists(filename):
        data = Child(*MTN + ["au", "get_revision", revision]).stdout
        try:
            file(filename, "w").write(data)
        except:
            os.unlink(filename)
            raise

    filename = os.path.join("mtn2cache", "manifest", revision)
    if not os.path.exists(filename):
        data = Child(*MTN + ["au", "get_manifest_of", revision]).stdout
        try:
            file(filename, "w").write(data)
        except:
            os.unlink(filename)
            raise

    filename = os.path.join("mtn2cache", "certs", revision)
    if not os.path.exists(filename):
        data = Child(*MTN + ["au", "certs", revision]).stdout
        try:
            file(filename, "w").write(data)
        except:
            os.unlink(filename)
            raise
def main():
    c = Child(300, 100)
    print(c.money, c.faceValue)
    c.play()
    c.eat()
    #注意:父类中方法名相同,默认调用的是在括号中排前面的父类中的方法
    c.func()
Example #3
0
    def adjust_child_corrals(self, n_cor_full):
        childs = []
        corrals = []
        for i, row in enumerate(self.cells):
            for j, col in enumerate(row):
                if col[1]:
                    childs.append((i, j))
                elif col[2]:
                    corrals.append((i, j))

        idx_taken = []
        while True:
            if n_cor_full == 0:
                break

            r_idx = random.randint(0, len(childs) - 1)
            if r_idx not in idx_taken:
                idx_taken.append(r_idx)
                child_pos = childs[r_idx]
                corral_pos = corrals[r_idx]
                self.cells[child_pos[0]][child_pos[1]][1] = 0
                self.cells[corral_pos[0]][corral_pos[1]][2] = 2
                n_cor_full -= 1

        n = 0
        n_childs = {}
        for i, row in enumerate(self.cells):
            for j, col in enumerate(row):
                if col[1]:
                    n_childs[n] = Child(n, (i, j))
                    n += 1
        self.childs = n_childs
Example #4
0
def main(controller, cosine_annealing_scheduler):
    running_reward = 0
    child = Child(dropout_rate=float(args.dropout),
                  use_auxiliary=args.use_auxiliary).to(device)

    child_optimizer = optim.SGD(child.parameters(),
                                lr=0.05,
                                momentum=0.9,
                                weight_decay=1e-4,
                                nesterov=True)
    cosine_lr_scheduler = cosine_annealing_scheduler(child_optimizer, lr=0.05)

    for epoch in range(150):
        cosine_lr_scheduler.step()
        child = train_child(epoch, controller, child, child_optimizer)
        torch.save(child.state_dict(), './save_model/child.pth')
        torch.save(controller.state_dict(), './save_model/controller.pth')

        if epoch < 150 - 1:
            controller_model, running_reward = train_controller(
                controller, child, running_reward)

    final_model = model
    final_acc = test_final_model(final_model)
    print('training is done. Final accuarcy is ', final_acc)
Example #5
0
def main():
    c = Child(3000, 100)
    print(c.money, c.face_value)
    c.play()
    c.eat()
    # 注意:父类中方法名相同,默认调用括号中排前面的父类的方法。
    c.func()
Example #6
0
def main():
    c = Child(300, 100)
    print(c.money, c.faceValue)
    c.play()
    c.eat()
    #注意:父类中方法名相同,默认调用的是在class(参数括号)中派遣
    c.func()
Example #7
0
 def remote_takeProxy(self, name, transport):
     '''设置代理通道
     @param addr: (hostname,port)hostname 根节点的主机名,根节点的端口
     '''
     log.msg('node [%s] takeProxy ready' % name)
     child = Child(name, name)
     self.childsmanager.addChild(child)
     child.setTransport(transport)
Example #8
0
def handle_parents(revision):
    parents = Child(*MTN +
                    ["au", "parents", revision]).stdout.strip().split('\n')
    if not parents:
        return
    print "revision: %s (parents: %s)" % (revision, parents)
    for parent in parents:
        filename = os.path.join("mtn2cache", "patch", parent + "-" + revision)
        curfilename = os.path.join("mtn2cache", "manifest", revision)
        parfilename = os.path.join("mtn2cache", "manifest", parent)
        if not os.path.exists(filename):
            diff = Child(*DIFF + [parfilename, curfilename]).stdout
            try:
                file(filename, "w").write(diff)
            except:
                os.unlink(filename)
                raise
Example #9
0
 def remote_takeProxy(self, name, transport):
     '''设置代理通道
     @param name: 根节点的名称
     '''
     log.msg('node [%s] takeProxy ready' % name)
     child = Child(name, name)
     self.childsmanager.addChild(child)
     child.setTransport(transport)
     self.doChildConnect(name, transport)
Example #10
0
 def add_childs(self):
     childs = {}
     n = self.n_childs
     while n:
         i, j = self.get_rand_tuple()
         if not any(self.cells[i][j]):
             self.cells[i][j][1] = 1
             childs[n] = Child(n, (i, j))
             n -= 1
     return childs
Example #11
0
 def remote_takeProxy(self, name, transport):
     """设置代理通道
     @param name: 根节点的名称
     """
     logger.info('>1 node [%s] takeProxy ready' % name)
     child = Child(self._index, name)
     self._index += 1
     self.childsmanager.addChild(child)
     child.setTransport(transport)
     self.doChildConnect(name, transport)
     logger.info('>2 node [%s] takeProxy ready' % name)
Example #12
0
def test_ctrl():
    # obtain datasets
    t = time.time()
    images, labels = read_data()
    t = time.time() - t
    print('read dataset consumes %.2f sec' % t)
    # config of a model
    class_num = 10
    child_num_layers = 6
    out_channels = 32
    batch_size = 32
    device = 'gpu'
    epoch_num = 4
    # files to print sampled archs
    child_filename = 'child_file.txt'
    ctrl_filename = 'controller_file.txt'
    child_file = open(child_filename, 'w')
    ctrl_file = open(ctrl_filename, 'w')
    # create a controller
    ctrl = Controller(child_num_layers=child_num_layers)
    # create a child, set epoch to 1; later this will be moved to an over epoch
    child = Child(images, labels, class_num, child_num_layers, out_channels,
                  batch_size, device, 1)
    print(len(list(child.net.graph)))
    # print(child.net.graph)
    # train multiple epochs
    for _ in range(epoch_num):
        # sample an arch
        ctrl.ctrl.net_sample()
        sample_arch = ctrl.ctrl.sample_arch
        print_sample_arch(sample_arch, child_file)
        # train a child model
        # t = time.time()
        # child.train(sample_arch)
        # t = time.time() - t
        # print('child training time %.2f sec' % t)

        # train controller
        t = time.time()
        ctrl.train(child, ctrl_file)
        t = time.time() - t
        print('ctrller training time %.2f sec' % t)
Example #13
0
 def openChild(self):
     Child(self.parent, self)
Example #14
0
def main():
    c = Child(3000, 100)
    print(c.money, c.faceValue)
    c.play()
    c.eat()
    c.func()
Example #15
0
def main():
    xiaohua = Child(30000,100)
    xiaohua.play()#父类Father方法
    xiaohua.eat()#父类Mother方法
    xiaohua.fun()#多继承的几个父类有相同名称的方法,继承对象列表第一个父类的方法
Example #16
0
from father import Father
from mother import Mother
from child import Child

#child继承了两个父类:Father和Mother,两个父类都有Func方法,当子类调用func方法时,默认调用的是继承括号中的第一个父类
c = Child(1000,100)
print(c.faceValue,c.money)
c.eat()
c.play()
c.func()
Example #17
0
import random
from child import Child

population = []
for i in range(0, 200):
    c = Child()
    c.randomize()
    population.append(c)

while (1):
    selection = []
    for i in population:
        i.calc_fitness()
        i.show()
        print("Fitness is ", i.fitness)
        if i.fitness == 28:
            find()
        for j in range(0, i.fitness):
            selection.append(i)
    population = []
    print("length is ", len(selection))
    for i in range(0, 200):
        a = random.randint(0, len(selection) - 1)
        #print ("a is ", a)
        b = random.randint(0, len(selection) - 1)
        #print ("b is ", b)
        c = selection[a].crossover(selection[b])
        population.append(c)


def find():
Example #18
0
def main():
    c = Child(30, 300)
    print(c.money, c.faceValue)

    # 注意:父类中方法相同,默认调用的是括号内排前面的
    c.func()
Example #19
0
def main():
    c = Child(1000, 30)
    print(c.money, c.faceValue)
    c.play()
    c.feed()
    c.same()  # if super class have the same function,calling the funtion return the first super class's
Example #20
0
from child import Child
from uuid import uuid4

child = Child(str(uuid4()), "http://localhost:8000")
child.start()
Example #21
0
def distance(lon1, lat1, lon2, lat2):
    return wikimeasure(lon1, lat1, lon2, lat2)


children = {}

with open('nicelist.txt') as f:
    for line in f.readlines():
        vals = line.split(';')
        id = vals[0]
        long = float(vals[1])
        lat = float(vals[2])
        weight = int(vals[3])

        children[id] = Child(id, long, lat, weight)

out = []
dist = 0.0


def measure(santalong, santalat, ordering, children):
    d = 0.0

    long = santalong
    lat = santalat

    for i in ordering:
        child = children[i]
        childlong, childlat = child.long, child.lat
        d += distance(long, lat, childlong, childlat)
Example #22
0
def handle_branch(branch):
    print "branch: %s" % branch
    heads = Child(*MTN + ["au", "heads", branch]).stdout.strip().split('\n')
    for head in heads:
        handle_head(head)
Example #23
0
def handle_head(head):
    print "head: %s" % head
    ancestors = Child(*MTN +
                      ["au", "ancestors", head]).stdout.strip().split('\n')
    pool.map(handle_revision, ancestors)
    pool.map(handle_parents, ancestors)
Example #24
0
def main():
    branches = Child(*MTN + ["au", "branches"]).stdout.strip().split('\n')
    for branch in branches:
        handle_branch(branch)
Example #25
0
 def setUpClass(self):
     print('Set up class')
     self.sue = Child("sue")
Example #26
0
def main():

    obj = Child()
    obj.display()
Example #27
0
#coding: utf-8
from parent import Parent
from child import Child

parent = Parent()
parent.hogehoge()

child = Child()
child.hogehoge()
Example #28
0
def main():
    c = Child(1111, 100)
    c.play()
    c.eat()
    #注意:父类中方法名相同,默认调用的是在括号中排前面的父类中的方法
    c.func()
Example #29
0
from child import Child
'''
测试模块

演示多继承的结构和使用:

子类:Child

直接父类(多个):Father、Mother

注意:

由于有多个直接父类,多个父类都要自己给其属性赋值,

避免混淆,我们使用类名.__init__(...)这样格式的构造调用
'''
c = Child(100000000, '漂亮', 'python')
print(c.money, c.faceValue, c.work)
c.playing()
c.shopping()
c.smoking()
Example #30
0
from child import Child;

michael = Child("Michael", "Jackson", 5, 30);
# print(michael.lastName);
# print(michael.nrOfToys);

michael.show_info();