Exemplo n.º 1
0
    def __init__(self):

        print '* Becoming self-aware'
        self.settings = settings = load_config('config/settings.yaml')
        self.secrets = secrets = load_config('config/secrets.yaml')

        self.ENABLED = self.settings.plugins.values().pop(0)
        self.active = True
        self.brain = cortex.Cortex(self)

        # The pulse file is set as a measure of how
        # long the bot has been spinning its gears
        # in a process. If it can't set the pulse
        # for too long, a signal kills it and reboots.
        # Note: this has become less of an issue
        # since all the bot's commands became threaded
        print '* Establishing pulse'
        self.setpulse()

        print '* Running monitor'

        while True:
            sleep(0.1)
            self.brain.monitor()
            if mktime(localtime()) - self.lastpulse > 10:
                self.setpulse()
Exemplo n.º 2
0
    def __init__(self, num_sensors, num_actions, brain_name='test_brain'):
        """
        Configure the Brain.

        Parameters
        ----------
        num_sensors, num_actions : int
            Value for ``self.num_sensors`` and ``self.num_actions``.
        brain_name : str, optional
            A unique identifying name for the brain. 
            The default is 'test_brain'.
        """
        # Include two extra sensors. These are for explicitly sensing reward
        # and punshment.
        self.num_sensors = num_sensors + 2
        # Always include an extra action. The last is the 'do nothing' action.
        self.num_actions = num_actions + 1
        self.backup_interval = 1e5
        self.name = brain_name
        self.log_dir = os.path.normpath(os.path.join(mod_path, '..', 'log'))
        if not os.path.isdir(self.log_dir):
            os.makedirs(self.log_dir)
        self.pickle_filename = os.path.join(self.log_dir,
                                            '{0}.pickle'.format(brain_name))

        self.cortex = cortex.Cortex(self.num_sensors)
        self.num_features = self.cortex.size
        self.timestep = 0

        # Initialize all the components of the ``brain``.
        self.amygdala = amygdala.Amygdala(self.num_features)
        self.cerebellum = cerebellum.Cerebellum(self.num_features,
                                                self.num_actions)
        self.ganglia = ganglia.Ganglia(self.num_features, self.num_actions)
Exemplo n.º 3
0
    def _create_blocks(self):
        #create the environment-agent interface (decoder)
        self.decoder = decoder.Decoder(self, -1)
        #create the "hippocampus" / state tracer
        self.action_buffer = OrNode(self.network, (self.n_actions, 1), -1)
        self.hippocampus = hippocampus.Hippocampus(self, -1)
        #create the "cortex" / reward estimator
        #create the action encoder
        if self.n_replicates > 1:
            self.cortex = cortex.MultiCortex(self,
                                             -1,
                                             noisy=self.noisy,
                                             n_replicates=self.n_replicates,
                                             dynrange=self.dynrange)
            self.encoder = encoder.MultiEncoder(self, -1)
        else:
            self.cortex = cortex.Cortex(self, -1, noisy=self.noisy)
            self.encoder = encoder.Encoder(self, -1)

        #create stubs for SNIP
        self.stubs['state'] = self.network.createInputStubGroup(
            size=self.n_states)
        self.stubs['action'] = self.network.createInputStubGroup(
            size=self.n_actions)
        self.stubs['reward'] = self.network.createInputStubGroup(size=1)
        self.stubs['punishment'] = self.network.createInputStubGroup(size=1)
        self.stubs['draw'] = self.network.createInputStubGroup(size=1)
Exemplo n.º 4
0
def build_v1_cortex():
    strengths = 1.0  #0.526315789473684
    v1_strength = strengths * 0.5  #1.0/3.0
    v1_inhib = False
    print "strengths:%.5f" % strengths
    print "v1_strength:%.5f" % v1_strength
    print "v1_inhib:", v1_inhib
    print "--- Building Visual Cortex ---"
    c.start_timer()
    # retina.shape = (12,12)x
    # v1.shape = (14,14)x
    retina = RetinalLayer(12, 12, 'Retina')  #emerg: 12x12
    v1 = c.Layer(14, 14, 'V1')  #,k=0.3) #emerg: 14x14
    c.print_timer("made layers")

    ret_v1_p = RetinaV1PositiveConnection(retina,
                                          v1, (12, 12),
                                          strength=strengths)
    ret_v1_n = RetinaV1NegativeConnection(retina,
                                          v1, (12, 12),
                                          strength=strengths)
    v1_v1 = c.FixedMountainConnection(v1,
                                      v1, (11, 11),
                                      inhib=v1_inhib,
                                      strength=v1_strength)  #emerg: 11x11
    c.print_timer("made connections")

    network = c.Cortex([retina, v1], [ret_v1_p, ret_v1_n, v1_v1],
                       'Visual Cortex')
    network.print_structure()
    network.load_data('../data/v1 tests/weights/')
    return network
Exemplo n.º 5
0
    def reload(self, quiet=False):
        if self.brain.values and len(self.brain.values[0]):
            quiet = True

        if not quiet:
            self.brain.act('strokes out.')
        else:
            self.brain.act('strokes out.', False, OWNER)

        self.active = False

        import settings
        import secrets
        import datastore
        import util
        import autonomic
        import cortex
        reload(settings)
        reload(secrets)
        reload(datastore)
        reload(autonomic)
        reload(util)
        reload(cortex)
        self.brain = cortex.Cortex(self)
        self.brain.loadbrains(True)
        self.brain.getnames()

        self.active = True

        if not quiet:
            self.brain.act('comes to.')
        else:
            self.brain.act('comes to.', False, OWNER)
Exemplo n.º 6
0
    def __init__(self):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        print '* Pinging IRC'

        self.sock.connect((HOST, PORT))

        self.sock.send('NICK %s\n' % NICK)
        self.sock.send('USER %s %s bla :%s\n' % (IDENT, HOST, REALNAME))
        self.sock.send('JOIN %s\n' % CHANNEL)

        self.sock.setblocking(0)

        self.ENABLED = ENABLED
        self.active = True
        self.brain = cortex.Cortex(self)

        # The pulse file is set as a measure of how
        # long the bot has been spinning its gears
        # in a process. If it can't set the pulse
        # for too long, a signal kills it and reboots.
        print '* Establishing pulse'
        self.setpulse()

        print '* Running monitor'

        while True:
            sleep(0.1)
            self.brain.monitor()
            if mktime(localtime()) - self.lastpulse > 10:
                self.setpulse()
Exemplo n.º 7
0
 def _create_blocks(self):
     #create the environment-agent interface (decoder)
     self.decoder = decoder.Decoder(self, 0)
     #create the "hippocampus" / state tracer
     self.hippocampus = hippocampus.Hippocampus(self, 1)
     #create the "cortex" / reward estimator
     self.cortex = cortex.Cortex(self, 2)
     #create the action encoder
     self.encoder = encoder.Encoder(self, 3)
Exemplo n.º 8
0
    def reload(self, quiet=False):
        if self.brain.values and len(self.brain.values[0]):
            quiet = True

        if not quiet:
            self.brain.act('strokes out.')
        else:
            self.brain.act('strokes out.', False, self.secrets.owner)

        # TODO broken.
        #for channel in self.secrets.channels:
        #    name, attr = channel.popitem()
        #    if attr.primary:
        #        continue
        #    self.brain.brainmeats['channeling'].leave(name)

        self.active = False

        self.settings = settings = load_config('config/settings.yaml')
        self.secrets = secrets = load_config('config/secrets.yaml')

        import datastore
        import util
        import staff
        import autonomic
        import cortex
        import thalamus
        import id

        reload(datastore)
        reload(autonomic)
        reload(util)
        reload(staff)
        reload(cortex)
        reload(thalamus)
        reload(id)

        self.brain = cortex.Cortex(self, True)
        self.thalamus = thalamus.Thalamus(self, self.brain)

        self.brain.thalamus = self.thalamus
        self.active = True

        metacortex.cx = self.brain

        if not quiet:
            self.brain.act('comes to.')
        else:
            self.brain.act('comes to.', False, self.secrets.owner)
Exemplo n.º 9
0
    def __init__(self):

        raw_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        print '* Pinging IRC'

        raw_socket.connect((HOST, PORT))

        if USE_SSL:
            self.sock = ssl.wrap_socket(raw_socket)
        else:
            self.sock = raw_socket

        if IRC_PASS:
            self.sock.send('PASS %s\n' % IRC_PASS)

        self.sock.send('USER %s %s bla :%s\n' % (IDENT, HOST, REALNAME))
        self.sock.send('NICK %s\n' % NICK)

        if HAS_NICKSERV and BOT_PASS:
            self.sock.send('PRIVMSG NickServ :identify %s\n' % BOT_PASS)

        # Some servers require a pause prior to being able to join a channel
        sleep(2)

        self.sock.setblocking(0)

        self.ENABLED = ENABLED
        self.active = True
        self.brain = cortex.Cortex(self)

        # The pulse file is set as a measure of how
        # long the bot has been spinning its gears
        # in a process. If it can't set the pulse
        # for too long, a signal kills it and reboots.
        # Note: this has become less of an issue
        # since all the bot's commands became threaded
        print '* Establishing pulse'
        self.setpulse()

        print '* Running monitor'

        while True:
            sleep(0.1)
            self.brain.monitor()
            if mktime(localtime()) - self.lastpulse > 10:
                self.setpulse()
Exemplo n.º 10
0
    def __init__(self):

        print '* Becoming self-aware'
        self.settings = load_config('config/settings.yaml')
        self.secrets = load_config('config/secrets.yaml')
        self.active = True
        self.logger = Hyperthymesia()

        try:
            self.brain = cortex.Cortex(self)
        except Exception as e:
            self.logger.warn('Drain bamaged... Stroking... out...')
            sys.exit()

        self.thalamus = thalamus.Thalamus(self, self.brain)
        self.thalamus.connect()
        self.brain.thalamus = self.thalamus
        self.brain.logger = self.logger

        metacortex.cx = self.brain

        # The pulse file is set as a measure of how
        # long the bot has been spinning its gears
        # in a process. If it can't set the pulse
        # for too long, a signal kills it and reboots.
        # Note: this has become less of an issue
        # since all the bot's commands became threaded
        print '* Establishing pulse'
        self.setpulse()

        print '* Running monitor'

        while True:
            sleep(0.1)

            # Slight race condition on reloads
            if not self.brain.thalamus: continue

            self.brain.monitor()
            if mktime(localtime()) - self.lastpulse > 10:
                self.setpulse()
Exemplo n.º 11
0
def build_visual_cortex():
    strengths = 1.0
    v1_strength = strengths * 0.5
    v1_inhib = False
    print "strengths:%.5f" % strengths
    print "v1_strength:%.5f" % v1_strength
    print "v1_inhib:", v1_inhib
    print "--- Building Visual Cortex ---"
    c.start_timer()
    # retina.shape = (12,12)x
    # v1.shape = (14,14)x
    retina = RetinalLayer(36, 36, 'Retina')  #emerg: 12x12
    v1 = c.Layer(168, 168, 'V1')  #emerg: 14x14
    v4 = c.Layer(24, 24, 'V4')
    it = c.OutputLayer(10, 10, 'IT')
    c.print_timer("made layers")

    ret_v1_p = RetinaV1PositiveConnection(retina,
                                          v1, (12, 12),
                                          strength=strengths,
                                          fixed=True)
    ret_v1_n = RetinaV1NegativeConnection(retina,
                                          v1, (12, 12),
                                          strength=strengths,
                                          fixed=True)
    v1_v1 = c.FixedMountainConnection(v1,
                                      v1, (7, 7),
                                      inhib=v1_inhib,
                                      strength=v1_strength)  #emerg: 11x11
    v1_v4 = c.Connection(v1, v4, (12, 12))
    v4_it = c.Connection(v4, it, None)
    it_v4 = c.Connection(it, v4, None)
    c.print_timer("made connections")

    network = c.Cortex([retina, v1, v4, it],
                       [ret_v1_p, ret_v1_n, v1_v4, v4_it, it_v4],
                       'Visual Cortex')
    network.print_structure()
    network.load_data()
    return network
Exemplo n.º 12
0
    def reload(self, quiet=False):
        if self.brain.values and len(self.brain.values[0]):
            quiet = True

        if not quiet:
            self.brain.act('strokes out.')
        else:
            self.brain.act('strokes out.', False, OWNER)

        channels = self.brain.channels.keys()
        for channel in channels:
            if channel == CHANNEL:
                continue
            self.brain.brainmeats['channeling'].leave(channel)

        self.active = False

        import settings
        import secrets
        import datastore
        import util
        import autonomic
        import cortex
        reload(settings)
        reload(secrets)
        reload(datastore)
        reload(autonomic)
        reload(util)
        reload(cortex)
        self.brain = cortex.Cortex(self)
        self.brain.loadbrains(True)
        self.brain.getnames()

        self.active = True

        if not quiet:
            self.brain.act('comes to.')
        else:
            self.brain.act('comes to.', False, OWNER)
Exemplo n.º 13
0
def main():
    # Configure logging for the main module
    logging.basicConfig(format='%(asctime)s %(message)s')
    logger = logging.getLogger(__name__)

    try:
        with open('config.yaml') as config_file:
            config = yaml.safe_load(config_file.read())
    except IOError:
        config = {}
    # Initialize the start-up machine state
    #mach = machine.Machine()
    ctex = cortex.Cortex(config)
    ctex.event_loop()
    return
    for score in range(0, 1001, 250):
        #disp.show_score(score)
        time.sleep(1)


    #cortext = cortex.Cortex(machine, display)
    return 0
Exemplo n.º 14
0
    def reload(self, quiet=False):
        if self.brain.values and len(self.brain.values[0]):
            quiet = True

        if not quiet:
            self.brain.act('strokes out.')
        else:
            self.brain.act('strokes out.', False, self.secrets.owner)

        for channel in self.secrets.channels:
            name, attr = channel.popitem()
            if attr.primary:
                continue
            self.brain.brainmeats['channeling'].leave(name)

        self.active = False

        self.settings = settings = load_config('config/settings.yaml')
        self.secrets = secrets = load_config('config/secrets.yaml')

        import datastore
        import util
        import autonomic
        import cortex
        reload(datastore)
        reload(autonomic)
        reload(util)
        reload(cortex)
        self.brain = cortex.Cortex(self)
        self.brain.loadbrains(True)
        self.brain.getnames()

        self.active = True

        if not quiet:
            self.brain.act('comes to.')
        else:
            self.brain.act('comes to.', False, self.secrets.owner)
Exemplo n.º 15
0
# top level module for sk8

import monad  # globals
import cortex
import portal
import eyes
import wheels

monad.eyes = eyes.Eyes()  # fly the drone, recv video & telemetry, maintain map
monad.wheels = wheels.Wheels()  # drive the skateboard via the arduino
monad.cortex = cortex.Cortex()  # read map, plot route
#monad.portal = portal.Portal()  # webserver, human interface

monad.cortex.command('wakeup')