Esempio n. 1
0
def spaun(dimensions):
    """
    Builds the Spaun network.

    See [1]_ for more details.

    Parameters
    ----------
    dimensions : int
        Number of dimensions for vector values

    Returns
    -------
    net : `nengo.Network`
        benchmark network

    References
    ----------
    .. [1] Chris Eliasmith, Terrence C. Stewart, Xuan Choo, Trevor Bekolay,
       Travis DeWolf, Yichuan Tang, and Daniel Rasmussen (2012). A large-scale
       model of the functioning brain. Science, 338:1202-1205.

    Notes
    -----
    This network needs to be installed via

    .. code-block:: bash

        pip install git+https://github.com/drasmuss/spaun2.0.git
    """

    # pylint: disable=import-outside-toplevel
    from _spaun.configurator import cfg
    from _spaun.vocabulator import vocab
    from _spaun.experimenter import experiment
    from _spaun.modules.stim import stim_data
    from _spaun.modules.vision import vis_data
    from _spaun.modules.motor import mtr_data
    from _spaun.spaun_main import Spaun

    vocab.sp_dim = dimensions
    cfg.mtr_arm_type = None

    cfg.set_seed(1)
    experiment.initialize(
        "A",
        stim_data.get_image_ind,
        stim_data.get_image_label,
        cfg.mtr_est_digit_response_time,
        "",
        cfg.rng,
    )
    vocab.initialize(stim_data.stim_SP_labels, experiment.num_learn_actions,
                     cfg.rng)
    vocab.initialize_mtr_vocab(mtr_data.dimensions, mtr_data.sps)
    vocab.initialize_vis_vocab(vis_data.dimensions, vis_data.sps)

    return Spaun()
Esempio n. 2
0
def spaun(dimensions):
    """
    Builds the Spaun network from [1]_

    Parameters
    ----------
    dimensions : int
        Number of dimensions for vector values

    Returns
    -------
    net : `nengo.Network`
        benchmark network

    References
    ----------
    .. [1] Chris Eliasmith, Terrence C. Stewart, Xuan Choo, Trevor Bekolay,
       Travis DeWolf, Yichuan Tang, and Daniel Rasmussen (2012). A large-scale
       model of the functioning brain. Science, 338:1202-1205.

    Notes
    -----
    This network needs to be installed via

    .. code-block:: bash

        pip install git+https://github.com/drasmuss/spaun2.0.git
    """

    from _spaun.configurator import cfg
    from _spaun.vocabulator import vocab
    from _spaun.experimenter import experiment
    from _spaun.modules.stim import stim_data
    from _spaun.modules.vision import vis_data
    from _spaun.modules.motor import mtr_data
    from _spaun.spaun_main import Spaun

    vocab.sp_dim = dimensions
    cfg.mtr_arm_type = None

    cfg.set_seed(1)
    experiment.initialize(
        "A", stim_data.get_image_ind, stim_data.get_image_label,
        cfg.mtr_est_digit_response_time, "", cfg.rng)
    vocab.initialize(
        stim_data.stim_SP_labels, experiment.num_learn_actions, cfg.rng)
    vocab.initialize_mtr_vocab(mtr_data.dimensions, mtr_data.sps)
    vocab.initialize_vis_vocab(vis_data.dimensions, vis_data.sps)

    return Spaun()
Esempio n. 3
0
def build_spaun(dimensions):
    vocab.sp_dim = dimensions
    cfg.mtr_arm_type = None

    cfg.set_seed(1)
    experiment.initialize('A', vis_data.get_image_ind,
                          vis_data.get_image_label,
                          cfg.mtr_est_digit_response_time, cfg.rng)
    vocab.initialize(experiment.num_learn_actions, cfg.rng)
    vocab.initialize_mtr_vocab(mtr_data.dimensions, mtr_data.sps)
    vocab.initialize_vis_vocab(vis_data.dimensions, vis_data.sps)

    with Spaun() as net:
        nengo_dl.configure_settings(
            trainable=False,
            simplifications=[
                graph_optimizer.remove_constant_copies,
                graph_optimizer.remove_unmodified_resets,
                # graph_optimizer.remove_zero_incs,
                graph_optimizer.remove_identity_muls
            ])

    return net
Esempio n. 4
0
    cfg.backend = 'spinn'

print "BACKEND: %s" % cfg.backend.upper()

# ----- Batch runs -----
for n in range(args.n):
    print("\n======================== RUN %i OF %i ========================" %
          (n + 1, args.n))

    # ----- Seeeeeeeed -----
    if args.seed < 0:
        seed = int(time.time())
    else:
        seed = args.seed

    cfg.set_seed(seed)
    print "MODEL SEED: %i" % cfg.seed

    # ----- Model Configurations -----
    vocab.sp_dim = args.d
    cfg.data_dir = args.data_dir

    # Parse --config options
    if args.config is not None:
        print "USING CONFIGURATION OPTIONS: "
        for cfg_options in args.config:
            cfg_opts = cfg_options.split('=')
            cfg_param = cfg_opts[0]
            cfg_value = cfg_opts[1]
            if hasattr(cfg, cfg_param):
                print "  * cfg: " + str(cfg_options)
Esempio n. 5
0
def create_spaun_model(n, args, max_probe_time):
    print("\n======================== RUN %i OF %i ========================" %
          (n + 1, args.n))

    # ----- Seeeeeeeed -----
    if args.seed < 0:
        seed = int(time.time())
    else:
        seed = args.seed

    cfg.set_seed(seed)
    print "MODEL SEED: %i" % cfg.seed

    # ----- Model Configurations -----
    vocab.sp_dim = args.d
    cfg.data_dir = args.data_dir

    # Parse --config options
    if args.config is not None:
        print "USING CONFIGURATION OPTIONS: "
        for cfg_options in args.config:
            cfg_opts = cfg_options.split('=')
            cfg_param = cfg_opts[0]
            cfg_value = cfg_opts[1]
            if hasattr(cfg, cfg_param):
                print "  * cfg: " + str(cfg_options)
                setattr(cfg, cfg_param, eval(cfg_value))
            elif hasattr(experiment, cfg_param):
                print "  * experiment: " + str(cfg_options)
                setattr(experiment, cfg_param, eval(cfg_value))
            elif hasattr(vocab, cfg_param):
                print "  * vocab: " + str(cfg_options)
                setattr(vocab, cfg_param, eval(cfg_value))

    # ----- Check if data folder exists -----
    if not (os.path.isdir(cfg.data_dir) and os.path.exists(cfg.data_dir)):
        raise RuntimeError('Data directory "%s"' % (cfg.data_dir) +
                           ' does not exist. Please ensure the correct path' +
                           ' has been specified.')

    # ----- Enable debug logging -----
    if args.debug:
        nengo.log('debug')

    # ----- Experiment and vocabulary initialization -----
    experiment.initialize(args.s, vis_data.get_image_ind,
                          vis_data.get_image_label,
                          cfg.mtr_est_digit_response_time, cfg.rng)
    vocab.initialize(experiment.num_learn_actions, cfg.rng)
    vocab.initialize_mtr_vocab(mtr_data.dimensions, mtr_data.sps)
    vocab.initialize_vis_vocab(vis_data.dimensions, vis_data.sps)

    # ----- Configure output log files -----
    mpi_savename = None
    mpi_saveext = None
    probe_cfg = None
    probe_anim_cfg = None
    anim_probe_data_filename = None
    if cfg.use_mpi:
        sys.path.append('C:\\Users\\xchoo\\GitHub\\nengo_mpi')

        mpi_save = args.mpi_save.split('.')
        mpi_savename = '.'.join(mpi_save[:-1])
        mpi_saveext = mpi_save[-1]

        cfg.probe_data_filename = get_probe_data_filename(mpi_savename,
                                                          suffix=args.tag)
    else:
        cfg.probe_data_filename = get_probe_data_filename(suffix=args.tag)

    # ----- Initalize looger and write header data -----
    logger.initialize(cfg.data_dir, cfg.probe_data_filename[:-4] + '_log.txt')
    cfg.write_header()
    experiment.write_header()
    vocab.write_header()
    logger.flush()

    # ----- Raw stimulus seq -----
    print "RAW STIM SEQ: %s" % (str(experiment.raw_seq_str))

    # ----- Spaun proper -----
    model = Spaun()

    # ----- Display stimulus seq -----
    print "PROCESSED RAW STIM SEQ: %s" % (str(experiment.raw_seq_list))
    print "STIMULUS SEQ: %s" % (str(experiment.stim_seq_list))

    # ----- Calculate runtime -----
    # Note: Moved up here so that we have data to disable probes if necessary
    runtime = args.t if args.t > 0 else experiment.get_est_simtime()

    # ----- Set up probes -----
    make_probes = not args.noprobes

    if runtime > max_probe_time and make_probes:
        print(">>> !!! WARNING !!! EST RUNTIME > %0.2fs - DISABLING PROBES" %
              max_probe_time)
        make_probes = False

    if make_probes:
        print "PROBE FILENAME: %s" % cfg.probe_data_filename
        probe_cfg = default_probe_config(model, vocab, cfg.sim_dt,
                                         cfg.data_dir, cfg.probe_data_filename)

    # ----- Set up animation probes -----
    if args.showanim or args.showiofig or args.probeio:
        anim_probe_data_filename = cfg.probe_data_filename[:-4] + '_anim.npz'
        print "ANIM PROBE FILENAME: %s" % anim_probe_data_filename
        probe_anim_cfg = default_anim_config(model, vocab, cfg.sim_dt,
                                             cfg.data_dir,
                                             anim_probe_data_filename)

    # ----- Neuron count debug -----
    print "MODEL N_NEURONS:  %i" % (get_total_n_neurons(model))
    if hasattr(model, 'vis'):
        print "- vis  n_neurons: %i" % (get_total_n_neurons(model.vis))
    if hasattr(model, 'ps'):
        print "- ps   n_neurons: %i" % (get_total_n_neurons(model.ps))
    if hasattr(model, 'bg'):
        print "- bg   n_neurons: %i" % (get_total_n_neurons(model.bg))
    if hasattr(model, 'thal'):
        print "- thal n_neurons: %i" % (get_total_n_neurons(model.thal))
    if hasattr(model, 'enc'):
        print "- enc  n_neurons: %i" % (get_total_n_neurons(model.enc))
    if hasattr(model, 'mem'):
        print "- mem  n_neurons: %i" % (get_total_n_neurons(model.mem))
    if hasattr(model, 'trfm'):
        print "- trfm n_neurons: %i" % (get_total_n_neurons(model.trfm))
    if hasattr(model, 'dec'):
        print "- dec  n_neurons: %i" % (get_total_n_neurons(model.dec))
    if hasattr(model, 'mtr'):
        print "- mtr  n_neurons: %i" % (get_total_n_neurons(model.mtr))

    # ----- Connections count debug -----
    print "MODEL N_CONNECTIONS: %i" % (len(model.all_connections))

    return (model, mpi_savename, mpi_saveext, runtime, make_probes, probe_cfg,
            probe_anim_cfg, anim_probe_data_filename)
Esempio n. 6
0
    cfg.backend = 'spinn'

print "BACKEND: %s" % cfg.backend.upper()

# ----- Batch runs -----
for n in range(args.n):
    print ("\n======================== RUN %i OF %i ========================" %
           (n + 1, args.n))

    # ----- Seeeeeeeed -----
    if args.seed < 0:
        seed = int(time.time())
    else:
        seed = args.seed

    cfg.set_seed(seed)
    print "MODEL SEED: %i" % cfg.seed

    # ----- Model Configurations -----
    vocab.sp_dim = args.d
    cfg.data_dir = args.data_dir

    # Parse --config options
    if args.config is not None:
        print "USING CONFIGURATION OPTIONS: "
        for cfg_options in args.config:
            cfg_opts = cfg_options.split('=')
            cfg_param = cfg_opts[0]
            cfg_value = cfg_opts[1]
            if hasattr(cfg, cfg_param):
                print "  * cfg: " + str(cfg_options)