Пример #1
0
    def __init__(
        self,
        configs=(),  # block configuration
        labels=(0, 1),  # labels
        min_val=-1.0,  # ScalarEncoder minimum input value
        max_val=1.0,  # ScalarEncoder maximum input value
        num_i=1024,  # ScalarEncoder number of statelets
        num_ai=128,  # ScalarEncoder number of active statelets
        num_s=32,  # PatternClassifier number of statelets
        num_as=8,  # PatternClassifier number of active statelets
        pct_pool=0.8,  # PatternClassifier pool percentage
        pct_conn=0.5,  # PatternClassifier initial connection percentage
        pct_learn=0.25):  # PatternClassifier learn percentage

        # seed the random number generator
        bb.seed(0)

        # build blocks from config descriptions if given
        blocks = get_blocks(configs)
        self.encoders = blocks["encoders"]
        self.pc = blocks["pattern_classifier"]

        if len(self.encoders) == 0:
            self.encoders.append(ScalarEncoder(min_val, max_val, num_i,
                                               num_ai))

        if self.pc == None:
            num_l = len(labels)
            self.pc = PatternClassifier(labels, num_s, num_as, 20, 2, 1,
                                        pct_pool, pct_conn, pct_learn)

        for encoder in self.encoders:
            self.pc.input.add_child(encoder.output)
Пример #2
0
    def __init__(
        self,
        num_spc=10,  # number of statelets per column
        num_dps=10,  # number of coincidence detectors per statelet
        num_rpd=12,  # number of receptors per coincidence detector
        d_thresh=6,  # coincidence detector threshold
        perm_thr=20,  # receptor permanence threshold
        perm_inc=2,  # receptor permanence increment
        perm_dec=1,  # receptor permanence decrement
        random_state=None):  # random state integer

        if isinstance(random_state, int):
            bb.seed(random_state)

        self.obj = bb.SequenceLearner(num_spc, num_dps, num_rpd, d_thresh,
                                      perm_thr, perm_inc, perm_dec)
Пример #3
0
    def __init__(
        self,
        configs=(),  # block configuration
        min_val=-1.0,  # minumum value
        max_val=1.0,  # maximum value
        num_i=1024,  # ScalarEncoder number of statelets
        num_ai=128,  # ScalarEncoder number of active statelets
        num_s=512,  # PatternPooler number of statelets
        num_as=8,  # PatternPooler number of active statelets
        num_spc=10,  # SequenceLearner number of statelets per column
        num_dps=10,  # SequenceLearner number of coincidence detectors per statelet
        num_rpd=12,  # SequenceLearner number of receptors per coincidence detector
        d_thresh=6,  # SequenceLearner coincidence detector threshold
        pct_pool=0.8,  # PatternPooler pool percentage
        pct_conn=0.5,  # PatternPooler initial connection percentage
        pct_learn=0.25):  # PatternPooler learn percentage

        self.min_val = min_val
        self.max_val = max_val

        # seed the random number generator
        bb.seed(0)

        # build blocks from config descriptions if given
        blocks = get_blocks(configs)
        self.encoders = blocks["encoders"]
        self.pp = blocks["pattern_pooler"]
        self.sl = blocks["sequence_learner"]

        if len(self.encoders) == 0:
            self.encoders.append(ScalarEncoder(min_val, max_val, num_i,
                                               num_ai))

        if self.pp == None:
            self.pp = PatternPooler(num_s, num_as, 20, 2, 1, pct_pool,
                                    pct_conn, pct_learn)

        if self.sl == None:
            self.sl = SequenceLearner(num_spc, num_dps, num_rpd, d_thresh, 1,
                                      1, 0)

        for encoder in self.encoders:
            self.pp.input.add_child(encoder.output)

        self.sl.input.add_child(self.pp.output)

        self.initialized = False
Пример #4
0
    def __init__(
            self,
            num_s=512,  # number of statelets
            num_as=8,  # number of active statelets
            perm_thr=20,  # receptor permanence threshold
            perm_inc=2,  # receptor permanence increment
            perm_dec=1,  # receptor permanence decrement
            pct_pool=0.8,  # pooling percentage
            pct_conn=0.5,  # initially connected percentage
            pct_learn=0.25,  # learn percentage
            random_state=None):  # random state integer

        if isinstance(random_state, int):
            bb.seed(random_state)

        self.obj = bb.PatternPooler(num_s, num_as, perm_thr, perm_inc,
                                    perm_dec, pct_pool, pct_conn, pct_learn)
Пример #5
0
# sequence_learning.py
#
# TODO: this is out of data and needs updating!!!
# ==============================================================================
import os
import errno
import math
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import brainblocks.bb_backend as bb
from brainblocks.blocks import SymbolsEncoder, SequenceLearner
from sklearn import preprocessing

# seed for deterministic random generator
bb.seed(0)

# printing boolean arrays neatly
np.set_printoptions(
    precision=3,
    suppress=True,
    threshold=1000000,
    linewidth=100,
    formatter={'bool': lambda bin_val: 'X' if bin_val else '-'})


def mkdir_p(path):
    try:
        os.makedirs(path)
    except OSError as exc:
        if exc.errno == errno.EEXIST and os.path.isdir(path):