Пример #1
0
    def __init__(self):
        self.inodes = {b'.': llfuse.ROOT_INODE}
        storage = DictStorage()
        self.forest = forest.Forest(storage)
        self.ops = ops.Operations(self.forest)
        self.rctx_root = RequestContextIsh()
        self.rctx_user = RequestContextIsh(uid=42, gid=7, pid=123)
        self.ops.init()

        # Create root-owned directory + file + file in directory
        self.mkdir(llfuse.ROOT_INODE, b'root_dir', self.rctx_root)
        self.create(llfuse.ROOT_INODE,
                    b'root_file',
                    self.rctx_root,
                    data=b'root')
        self.create(self.inodes[b'root_dir'],
                    b'root_file_in',
                    self.rctx_root,
                    data=b'root2')

        # Create user-owned directory + file
        self.mkdir(llfuse.ROOT_INODE, b'user_dir', self.rctx_user)
        self.create(llfuse.ROOT_INODE,
                    b'user_file',
                    self.rctx_user,
                    data=b'user')
        self.create(self.inodes[b'user_dir'],
                    b'user_file_in',
                    self.rctx_user,
                    data=b'user2')

        # Ensure that stuff with 0 refcnt is gone?
        self.forest.flush()
Пример #2
0
 def __init__(self, *, storage=None):
     storage = storage or st.DictStorage()
     self.forest = forest.Forest(storage)
     self.ops = ops.Operations(self.forest)
     self.rctx_root = llfuse.RequestContext()
     self.rctx_user = llfuse.RequestContext(uid=42, gid=7, pid=123)
     self.ops.init()
def predict2():
    trainingRowIds = random.sample(range(1, len(data)), int(.01 * len(data)))
    f = forest.Forest(data, outcomeLabel, continuousAttributes, trainingRowIds)
    correct = sum(1 for rowId, row in enumerate(data)
                  if rowId > 0 and rowId not in trainingRowIds
                  and f.get_prediction(row) == row[outcomeLabelIndex])
    return 100 * correct / (len(data) - 1 - len(trainingRowIds))
def main(forest_file, nbest_file, weight_string, exhaustive=False):
    exhaustive = False
    ffile = open(forest_file, "r")
    nfile = open(nbest_file, "r")
    weights = forest.read_features(weight_string)

    expr = re.compile(
        '.*sent=(\d+).*nbest=(\d+).*totalcost=(\S+).*derivation={{{(.*?)}}}.*')

    sent = -1
    count = 0
    kbest = 0
    f = forest.Forest([])
    passed = True
    for line in nfile:
        m = re.match(expr, line)
        count = int(m.group(2))
        if sent != int(m.group(1)):
            sent = int(m.group(1))
            f = forest.read_forest(ffile.readline())
            if exhaustive:
                kbest = forest.kbest(f, weights)
        deriv = forest.read_tree(m.group(4))
        cost = float(m.group(3))
        if exhaustive:
            fderiv = kbest.next()
        else:
            fintersect = forest.kbest(forest.intersect_forest_tree(f, deriv),
                                      weights)
            fderiv = fintersect.next()
            empty = False
            try:
                fffff = fintersect.next()
            except StopIteration:
                empty = True
            assert (empty)
        s = fderiv.score  #forest.inner_prod(fderiv.features,weights)

        if abs(s - cost) > 0.01:
            print "==="
            print "%s: %s vs %s" % (count, s, cost)
            print deriv
            print fderiv
            print line
            print "==="
            passed = False
        count += 1
    if passed:
        print "passed"
    else:
        print "failed"
Пример #5
0
    def makeForest(self):
        """Create a forest, represented as a collection of roots and a
        dictionary of children, from the information contained in the
        src array."""
        children = {}
        roots = []
        for v in self.src.keys():
            children[v] = []

        for (u, v) in self.src.items():
            if v == None:
                roots.append(u)
            else:
                children[v].append(u)

        return forest.Forest(roots, children)
Пример #6
0
 def ensure_storage_matches_forest(self):
     f2 = forest.Forest(self.forest.storage)
     ops2 = ops.Operations(f2).init()
     todo = [(b'.', self.ops.lookup(llfuse.ROOT_INODE, b'.',
                                    self.rctx_root),
              ops2.lookup(llfuse.ROOT_INODE, b'.', self.rctx_root))]
     while todo:
         p, a1, a2 = todo.pop()
         _debug('considering %s', p)
         ad1 = attr_to_dict(a1)
         ad2 = attr_to_dict(a2)
         ad1.pop('st_ino')
         ad2.pop('st_ino')
         _debug(' ad1: %s', ad1)
         _debug(' ad2: %s', ad2)
         inode1 = self.forest.inodes.get_by_value(a1.st_ino)
         inode2 = f2.inodes.get_by_value(a2.st_ino)
         # TBD: What needs to be popped?
         assert ad1 == ad2
         if stat.S_ISDIR(a1.st_mode):
             # Moar TODO to be had! Yay
             for (n1, na1, o1), (n2, na2,
                                 o2) in zip(self.ops.readdir(a1.st_ino, 0),
                                            ops2.readdir(a2.st_ino, 0)):
                 assert n1 == n2
                 na1 = self.ops.lookup(a1.st_ino, n1, self.rctx_root)
                 na2 = ops2.lookup(a2.st_ino, n2, self.rctx_root)
                 todo.append((b'%s/%s' % (p, n1), na1, na2))
         elif stat.S_ISREG(a1.st_mode):
             # Ensure that what we know underneath matches direntry..
             s = inode1.size
             assert s == inode2.size
             assert s == inode1.stored_size
             assert s == inode2.stored_size
             if s <= 10 * const.BLOCK_SIZE_LIMIT:
                 assert inode1.read(0, s) == inode2.read(0, s)
             else:
                 assert inode1.read(0, 1) == inode2.read(0, 1)
                 assert inode1.read(s // 2, 1) == inode2.read(s // 2, 1)
                 assert inode1.read(s - 1, 1) == inode2.read(s - 1, 1)
         self.ops.forget1(a1.st_ino)
         ops2.forget1(a2.st_ino)
Пример #7
0
    def __init__(self, pace, pretrain_model, train_txt, iterations_update_forest,
        lr=0.05, num_trees=5, tree_depth=6, num_classes=67, predict=False):
        self.num_trees = num_trees
        self.num_classes = num_classes
        self.leaf_node_num = 2 ** (tree_depth - 1)
        self.lr = lr

        self.feat_layer = VGG_16()
        forest = ndf.Forest(n_tree=num_trees, tree_depth=tree_depth, n_in_feature=2622,
            num_classes=num_classes, iterations_update_forest=iterations_update_forest)
        model = ndf.NeuralDecisionForest(self.feat_layer, forest)
        model = model.cuda()
        self.model = model
       
        self.optimizer = torch.optim.Adam(self.model.parameters(), lr=lr)
        if not predict and pace < 2:
            print('load model from %s' % pretrain_model[0])
            self.feat_layer.load_weights(path=pretrain_model[0])
            init_mean, init_sigma = self.kmeans_label(train_txt)
            self.model.forest.dist.init_kmeans(init_mean, init_sigma)
Пример #8
0
    def __init__(self, list_dir, num_tree=5, depth=6, task_num=1):
        #super(Forest, self).__init__()
        feat_layer = VGG_16()
        feat_layer.load_weights()

        forest = ndf.Forest(n_tree=num_tree, tree_depth=depth, n_in_feature=128)
        model = ndf.NeuralDecisionForest(feat_layer, forest)

        self.leaf_node_num = 2 ** (depth - 1)
        model = model.cuda()
        self.model = model
        #self.dist = Pi(num_tree, self.leaf_node_num)
        init_mean, init_sigma = self.kmeans_label(list_dir)
        self.model.forest.dist.init_kmeans(init_mean, init_sigma)
        #self.optimizer = torch.optim.Adam(self.model.parameters(),lr=0.05, betas=(0.5, 0.999))
        lr = 0.05
        #conv1_w, conv1_b, conv2_fc8_w, conv2_fc8_b, linear_w, linear_b = find_params(self.model)
        # print(len(conv1_w), len(conv1_b), len(conv2_fc8_w), len(conv2_fc8_b), len(linear_w), len(linear_b))
        # input()
        # self.optimizer = torch.optim.SGD([{'params':conv1_w, 'lr':0.05}, {'params':conv1_b, 'lr':0.05, 'weight_decay':0},\
        #                     {'params':conv2_fc8_w, 'lr':0.05}, {'params':conv2_fc8_b, 'lr':0.05, 'weight_decay':0},\
        #                     {'params':linear_w, 'lr':0.05},{'params':linear_b, 'lr':0.05, 'weight_decay':0}], lr=0.05, momentum=0.9)
        param_list = feat_layer.get_weight_dict(lr)
        self.optimizer = torch.optim.SGD(param_list, lr=0.05, momentum=0.9)
        #self.optimizer = torch.optim.SGD([{'params':self.model.parameters(), 'lr':0.2}], lr=0.05, momentum=0.9)
        self.optimizers = [self.optimizer]
        def lambda_rule(iteration):
            if iteration < 10000:
                lr_l = 1
            if 10000 <= iteration and iteration < 20000:
                lr_l = 0.5
           # if 10000 <= iteration and iteration < 15000:
           #     lr_l = 0.5 ** 2
           # if 15000 <= iteration and iteration < 20000:
           #     lr_l = 0.5 ** 3
           # if 20000 <= iteration and iteration < 25000:
           #     lr_l = 0.5 ** 4
            if iteration >= 20000:
                lr_l = 0.5 ** 2
            return lr_l
        self.schedulers = [lr_scheduler.LambdaLR(optimizer, lr_lambda=lambda_rule) for optimizer in self.optimizers]
Пример #9
0
    def __init__(self):
        pygame.init()
        self._screen = pygame.display.set_mode(__screenSize__)
        self._font = pygame.font.SysFont('Arial',20)
        self._forest = ft.Forest()

        # input boxes for parameters
        self._input_boxes["humidity"] = ibox.InputBox(920, 465, 100, 30, self._screen, ft.HUMIDITY * 100, 100, 0.0, float, increment=1, decimals=1)
        self._input_boxes["lightning"] = ibox.InputBox(920, 525, 100, 30, self._screen, ft.LIGHTNING * 100, 100, 0.0, float, increment=0.001, decimals=3)
        self._input_boxes["new_growth"] = ibox.InputBox(920, 585, 100, 30, self._screen, ft.NEW_GROWTH * 100, 100, 0.0, float, increment=0.1, decimals=1)
        self._input_boxes["wind_strength"] = ibox.InputBox(1110, 720, 25, 30, self._screen, ft.WIND_STRENGTH, ft.WIND_MAX, 0, int, min_width=25, writeable=False)

        # buttons for wind direction
        self._wind_buttons["none"] = ibut.InputButton(1120, 650, 15, 15, self._screen, active=True)
        self._wind_buttons["north"] = ibut.InputButton(1100, 620, 55, 25, self._screen, text=str(ft.WINDS[1][2]))
        self._wind_buttons["east"] = ibut.InputButton(1155, 645, 55, 25, self._screen, text=str(ft.WINDS[2][2]))
        self._wind_buttons["south"] = ibut.InputButton(1100, 670, 55, 25, self._screen, text=str(ft.WINDS[3][2]))
        self._wind_buttons["west"] = ibut.InputButton(1045, 645, 55, 25, self._screen, text=str(ft.WINDS[4][2]))

        # buttons for wind strength
        self._ws_buttons["minus"] = ibut.InputButton(1080, 725, 20, 20, self._screen, text="-", blink=True)
        self._ws_buttons["plus"] = ibut.InputButton(1145, 725, 20, 20, self._screen, text="+", blink=True)
Пример #10
0
destination, timemin = ft.initialize_simulators(Sims,
                                                ntra,
                                                STATE_INIT,
                                                missionheading,
                                                plot=True)
print("destination : {} & timemin : {}".format(destination, timemin))
""" Create a Forest and launch a PMCTS """

##Exploration Parameters##
worker.RHO = 0.5  # Proportion between master utility and worker utility of node utility.
worker.UCT_COEFF = 1 / 2**0.5  # Exploration coefficient in the UCT formula.

budget = 100  # number of nodes we want to expand in each worker
frequency = 10  # number of steps performed by worker before writing the results into the master
forest = ft.Forest(listsimulators=Sims,
                   destination=destination,
                   timemin=timemin,
                   budget=budget)
master_nodes = forest.launch_search(STATE_INIT, frequency)
new_dict = deepcopy_dict(master_nodes)
forest.master = MasterTree(Sims, destination, nodes=new_dict)
forest.master.get_best_policy()
forest.master.plot_tree_uct()
forest.master.plot_tree_uct(1)
forest.master.plot_hist_best_policy(interactive=True)
forest.master.save_tree("my_tuto_results")
"""""" " Isochrones " """"""
""" Launch a search """

Boat.UNCERTAINTY_COEFF = 0
NUMBER_OF_SIM = 3  # <=20
SIM_TIME_STEP = 6  # in hours
Пример #11
0
if __name__ == '__main__':

    ft.LIGHTNING = 0
    ft.NEW_GROWTH = 0
    ft.WIND = 1
    ft.WIND_STRENGTH = 1
    ft.RIVER = None
    ft.CLOUDS = None

    densities = [d for d in np.arange(0.01, 1, 0.01)]
    percentageBurnt = []

    for density in densities:
        ft.TREE_RATIO = density
        forest = ft.Forest()

        done = False
        while done == False:

            forest.update()

            if forest._burnt == 0:
                #print("No more burning trees")
                done = True
                continue

        perc = (1 - (forest._tree / forest._init)) * 100
        percentageBurnt.append(perc)
        print(
            f"For density {density:.2f}, {perc:.2f}% of the trees have burnt")
Пример #12
0
N_DAYS_SIM = 4  # time horizon in days

sims = ft.create_simulators(Weathers, numberofsim=NUMBER_OF_SIM, simtimestep=SIM_TIME_STEP,
                            stateinit=STATE_INIT, ndaysim=N_DAYS_SIM)

# ft.play_multiple_scenarios(sims)
# sims[0].play_scenario()
# initialize the simulators to get common destination and individual time min


missionheading = 0
ntra = 50

destination, timemin = ft.initialize_simulators(sims, ntra, STATE_INIT, missionheading)
print("destination : " + str(destination) + "  &  timemin : " + str(timemin) + "\n")
forest = ft.Forest(listsimulators=sims, destination=destination, timemin=timemin)

ntra = 100
tree = forest.workers[0]
endpoint = []
endtimes = []
rewards = []


for i in range(ntra):

    tree.Simulator.state = list(STATE_INIT)

    dist, action = tree.Simulator.getDistAndBearing(tree.Simulator.state[1:], tree.destination)
    atDest, frac = Tree.is_state_at_dest(tree.destination, tree.Simulator.prevState, tree.Simulator.state)
Пример #13
0
            codec = st.CompressingTypedBlockCodec(codec)
        else:
            codec = st.TypedBlockCodec(codec)
        if args.backend == 'lmdb':
            backend = stlm.LMDBStorageBackend(
                codec=codec, filename=args.filename)
        else:
            backend = stsql.SQLiteStorageBackend(
                codec=codec, filename=args.filename)
        storage = st.DelayedStorage(backend=backend)
        storage.maximum_cache_size = args.cache_size

    else:
        storage = st.DictStorage()

    forest = forest.Forest(storage)
    ops = ops.Operations(forest)
    fuse_options = set(llfuse.default_options)
    fuse_options.remove('nonempty')  # TBD..
    fuse_options.add('fsname=test_fs')
    # fuse_options.add('large_read') # n/a on OS X?
    # fuse_options.add('blksize=%d' % const.BLOCK_SIZE_LIMIT) # n/a on OS X?
    fuse_options.add('max_read=%d' % (const.BLOCK_SIZE_LIMIT * 10))
    fuse_options.add('max_write=%d' % (const.BLOCK_SIZE_LIMIT * 10))
    fuse_options.add('slow_statfs')
    # fuse_options.add('novncache') # this works but what does it do?
    # fuse_options.add('noattrcache')  # this works but what does it do?
    fuse_options.add('allow_other')
    if args.debug:
        fuse_options.add('debug')
    llfuse.init(ops, args.mountpoint, fuse_options)
Пример #14
0
n.SIZE_OF_SAMPLE = int(sys.argv[3])

reader = dr.Reader()
reader.fetch_data()

numpy_data = reader.get_numpy_data()
data = reader.get_data()

if numpy_data.__sizeof__() == 0:
    print("Nie udało się pobrać danych")
    exit(1)
if data == []:
    print("Nie udało się pobrać danych")
    exit(1)

forest = forest.Forest(n.NUMBER_OF_STUMPS)

before = datetime.now()
forest.fit_forest_to_data(n.SIZE_OF_SAMPLE, data)
after = datetime.now()
diff = after - before
print("Czas dostosowania lasu dla całej próbki danych:",
      "%.3f" % (diff.total_seconds() * 1000), 'ms')

before = datetime.now()
validate.cross_validate(int(1 / n.TEST_DATA_PERCENTAGE), forest, data)
after = datetime.now()
diff = after - before
print("Czas wykonania walidacji:", "%.3f" % (diff.total_seconds()), 's')

exit(0)