Ejemplo n.º 1
0
def init_sdrs():
    problems = []
    folder_name = os.path.join('Data', 'encoded')
    for sub_folder in os.listdir(folder_name):
        f = os.path.join(folder_name, sub_folder)
        problems += parse_images.get_problems(f)

    for problem in problems:
        assert problem['SDRs'].shape == (9, 32, 32)
        problem['Input'] = problem['SDRs'][:3].reshape((3, -1))
        problem['Output'] = problem['SDRs'][3:].reshape((6, -1))

    num_cols = len(problems[0]['Input'][0])
    bckTM = BTM(numberOfCols=num_cols,
                cellsPerColumn=15,
                initialPerm=0.5,
                connectedPerm=0.5,
                minThreshold=10,
                newSynapseCount=10,
                activationThreshold=10,
                pamLength=10)

    layers = [(bckTM, bk_tm_compute)]

    return (layers, problems)
Ejemplo n.º 2
0
def main(args):
    if args.data == 'imgs':
        folder_name = 'Data/Problems'
        problems = parse_images.get_problems(folder_name)

    elif args.data == 'sdrs':
        folder_name = 'Data/Problems_sdr'
        problems = parse_images.get_problems(folder_name)

    elif args.data == 'symbolic':
        folder_name = 'Data/Problems_txt'
        problems = read_symbolic_problems.get_problems(folder_name)
        cell_size = len(problems[0]['Input'][0])

    agent = LSTMAgent(cell_size)
    print('Train')
    agent.train(problems[:5], 30)
    print('Test')
    agent.run(problems[:5])
Ejemplo n.º 3
0
def main(args):
    problems = []
    if args.data == 'imgs':
        #folder_name = 'Data/Problems'
        #problems = parse_images.get_problems(folder_name)
        folder_name = 'Data/raw'
        for sub_folder in os.listdir(folder_name):
            f = os.path.join(folder_name, sub_folder)
            problems += parse_images.get_problems(f)
    elif args.data == 'sdrs':
        #folder_name = 'Data/Problems_sdr'
        #problems = parse_images.get_problems(folder_name)
        folder_name = 'Data/encoded'
        for sub_folder in os.listdir(folder_name):
            f = os.path.join(folder_name, sub_folder)
            problems += parse_images.get_problems(f)
    elif args.data == 'symbolic':
        if args.nn == 'conv':
            print(
                "Please use the fully connected network for this type of data."
            )
            return
        folder_name = 'Data/desc'
        problems = read_symbolic_problems.get_yml_problems(folder_name)

    if args.nn == 'fc':
        # fully connected
        problems = reshape_fc(problems)
        print(problems[0]['Input'].shape)

        agent = Agent()
        agent.init_fc(len(problems[0]['Input'][0]))
        errs = agent.train(problems, args.nn, 1500, args.ex)

    if args.nn == 'conv':
        # conv
        problems = reshape_fc(problems)
        print(problems[0]['Input'].shape)

        agent = Agent()
        agent.init_conv(len(problems[0]['Input'][0]))
        errs = agent.train(problems, args.nn, 500, args.ex)
Ejemplo n.º 4
0
def init_imgs(write_output):
    #problems = parse_images.get_problems(folder_name)

    folder_name = 'Data/raw'
    problems = []
    for sub_folder in os.listdir(folder_name):
        f = os.path.join(folder_name, sub_folder)
        problems += parse_images.get_problems(f)
    print(len(problems))

    for problem in problems:
        problem['Input'] = problem['Input'].reshape((3, -1))
        problem['Output'] = problem['Output'].reshape((6, -1))

    # dimenstions
    num_cols1 = len(problems[0]['Input'][0])
    tm_cols = num_cols1
    layers = []
    if not write_output:
        num_cols2 = num_cols1 / 2
        num_cols3 = num_cols2 / 2
        sp1 = SpatialPooler(inputDimensions=(num_cols1, ),
                            columnDimensions=(num_cols2, ),
                            numActiveColumnsPerInhArea=-1,
                            localAreaDensity=0.05)

        sp2 = SpatialPooler(inputDimensions=(num_cols2, ),
                            columnDimensions=(num_cols3, ),
                            numActiveColumnsPerInhArea=-1,
                            localAreaDensity=0.05)
        tm_cols = num_cols3
        layers = [(sp1, sp_compute), (sp2, sp_compute)]

    bckTM = BTM(numberOfCols=tm_cols,
                cellsPerColumn=10,
                initialPerm=0.5,
                connectedPerm=0.5,
                minThreshold=10,
                newSynapseCount=10,
                activationThreshold=10,
                pamLength=10)

    layers += [(bckTM, bk_tm_compute)]
    return (layers, problems)
Ejemplo n.º 5
0
                _, cost = self.sess.run([self.train_step, self.err],
                                        feed_dict={
                                            self.X: window,
                                            self.lr: learning_rate
                                        })
                errs += [cost]

        return errs


if __name__ == '__main__':
    folder_name = 'Data/raw'
    problems = []
    for sub_folder in os.listdir(folder_name):
        f = os.path.join(folder_name, sub_folder)
        problems += get_problems(f)
    print(len(problems))
    #folder_name = 'Data/Problems'
    #problems = get_problems(folder_name)
    input_windows = get_windows(problems)
    (num_windows, height, width) = input_windows.shape
    print("Get Windows Done")
    '''
    for win in input_windows:
        print(np.sum(win) * 100 / (height * width))
    '''
    enc = Encoder(height * width)
    print("Encoder Done")
    errs = enc.train(input_windows)
    print("Train Done")
    print("Show decoded data")