예제 #1
0
    def __init__(
            self,
            file,  # @ReservedAssignment
            distributed=False,
            safe=True,
            verbose=False):
        self._file = file

        real_file = file
        opened_file = False
        if isinstance(file, basestring):
            real_file = self.get_reader(file)
            opened_file = True

        if distributed:
            directory = os.path.dirname(real_file.file)
            filename = "{}.".format(os.path.basename(real_file.file))

            conns = list()
            for found_file in os.listdir(directory):
                if found_file.startswith(filename):
                    file_reader = self.get_reader(found_file)
                    conns.append(file_reader.read())
                    file_reader.close()
            conn_list = numpy.concatenate(conns)
        else:
            conn_list = real_file.read()

        if opened_file:
            real_file.close()

        FromListConnector.__init__(self, conn_list, safe, verbose)
예제 #2
0
    def __init__(
            self, file,  # @ReservedAssignment
            distributed=False, safe=True, verbose=False):

        real_file = file
        opened_file = False
        if isinstance(file, basestring):
            real_file = files.StandardTextFile(file, mode="r")
            opened_file = True

        conn_list = None
        if distributed:
            directory = os.path.dirname(real_file.file)
            filename = "{}.".format(os.path.basename(real_file.file))

            conns = list()
            for found_file in os.listdir(directory):
                if found_file.startswith(filename):
                    file_reader = files.StandardTextFile(found_file, mode="r")
                    conns.append(file_reader.read())
                    file_reader.close()
            conn_list = numpy.concatenate(conns)
        else:
            conn_list = real_file.read()

        if opened_file:
            real_file.close()

        FromListConnector.__init__(self, conn_list, safe, verbose)
예제 #3
0
    def __init__(self, conn_list, safe=True, verbose=False):
        """
        Creates a new FromListConnector.
        """

        if conn_list is None or len(conn_list) == 0:
            raise exceptions.InvalidParameterType(
                "The connection list for the FromListConnector must contain"
                " at least a list of tuples, each of which should contain:"
                " (pre_idx, post_idx, weight, delay)")

        conn_list, weights, delays, self._extra_conn_data = \
            self._split_conn_list(
                conn_list, ['pre', 'post', 'weight', 'delay'])

        CommonFromListConnector.__init__(self, conn_list, safe, verbose)
        self.set_weights_and_delays(weights, delays)
 def __init__(self, d_expression, allow_self_connections=True,
              weights=0.0, delays=None, space=Space(), safe=True,
              verbose=False, n_connections=None):
     """
     Creates a new DistanceDependentConnector. Uses the underlying machinery
     for FromListConnector.
     """
     self.d_expression = d_expression
     self.allow_self_connections = allow_self_connections
     self.space = space
     # weights may be a fixed value, a list of values,
     # a RandomDistribution object, or a distance_dependence function.
     self.weights = weights
     self.delays = delays   # and similar for this value
     self.connections_per_neuron = n_connections
     self.connectionSeeds = SeedInfo()
     FromListConnector.__init__(self, conn_list=None, safe=safe,
                                verbose=verbose)
예제 #5
0
    def generate_synapse_list(self, presynaptic_population,
                              postsynaptic_population, delay_scale,
                              weight_scale, synapse_type):
        conn_file = open(self._filename, 'r')
        file_lines = conn_file.readlines()
        for line in file_lines:
            line.strip()
            form1 = re.match(r"\[(\([^()]*\),\s*)*(\([^()]*\)\s*)\]", line)

            # form 1: a list of tuples
            if form1:
                conn_sublist = [
                    eval(conn.group(0))
                    for conn in re.finditer(r"\([^()]*\)", line)
                ]
            else:
                form2 = re.match(r"\(.*\)\s*", line)
                # form 2: a single tuple per line
                if form2:
                    conn_sublist = [
                        eval(form2.group(0).rstrip(", \a\b\f\n\r\t\v"))
                    ]
                else:
                    form3 = re.match(
                        r"((?:\[[^[\]\s]+\])|(?:[^[\],\s]+))((?:,\s*)" +
                        r"|\s+)((?:\[[^[\]\s]+\])|(?:[^[\],\s]+))" +
                        r"((?:,\s*)|\s+)((?:\+|\-)?\d+(?:\.\d+)?" +
                        r"(?:(?:E|e)(?:\+|\-)?\d+)?)((?:,\s*)|\s+)" +
                        r"((?:\+|\-)?\d+(?:\.\d+)?(?:(?:E|e)" +
                        r"(?:\+|\-)?\d+)?)\s*", line)

                    # form 3: a comma- or space-separated set of specifiers per
                    # line
                    if form3:
                        conn_sublist = [
                            (eval(form3.group(1)), eval(form3.group(3)),
                             float(form3.group(5)), float(form3.group(7)))
                        ]
                    else:
                        raise exceptions.ConfigurationException(
                            "Invalid connection file format")
            self._conn_list.extend(conn_sublist)
        return FromListConnector.generate_synapse_list(
            self, presynaptic_population, postsynaptic_population, delay_scale,
            weight_scale, synapse_type)
예제 #6
0
    def generate_synapse_list(
            self, presynaptic_population, postsynaptic_population, delay_scale,
            weight_scale, synapse_type):
        conn_file = open(self._filename, 'r')
        file_lines = conn_file.readlines()
        for line in file_lines:
            line.strip()
            form1 = re.match(r"\[(\([^()]*\),\s*)*(\([^()]*\)\s*)\]", line)

            # form 1: a list of tuples
            if form1:
                conn_sublist = [eval(conn.group(0)) for conn in
                                re.finditer(r"\([^()]*\)", line)]
            else:
                form2 = re.match(r"\(.*\)\s*", line)
                # form 2: a single tuple per line
                if form2:
                    conn_sublist = [eval(form2.group(0).rstrip(
                                    ", \a\b\f\n\r\t\v"))]
                else:
                    form3 = re.match(
                        r"((?:\[[^[\]\s]+\])|(?:[^[\],\s]+))((?:,\s*)" +
                        r"|\s+)((?:\[[^[\]\s]+\])|(?:[^[\],\s]+))" +
                        r"((?:,\s*)|\s+)((?:\+|\-)?\d+(?:\.\d+)?" +
                        r"(?:(?:E|e)(?:\+|\-)?\d+)?)((?:,\s*)|\s+)" +
                        r"((?:\+|\-)?\d+(?:\.\d+)?(?:(?:E|e)" +
                        r"(?:\+|\-)?\d+)?)\s*", line)

                    # form 3: a comma- or space-separated set of specifiers per
                    # line
                    if form3:
                        conn_sublist = [(eval(form3.group(1)),
                                         eval(form3.group(3)),
                                        float(form3.group(5)),
                                        float(form3.group(7)))]
                    else:
                        raise exceptions.ConfigurationException(
                            "Invalid connection file format")
            self._conn_list.extend(conn_sublist)
        return FromListConnector.generate_synapse_list(
            self, presynaptic_population, postsynaptic_population,
            delay_scale, weight_scale, synapse_type)
예제 #7
0
 def __init__(self, conn_file, distributed=False, safe=True, verbose=False):
     FromListConnector.__init__(self, safe=safe, verbose=verbose)
     if distributed:
         logger.warn("distributed loading of FromFileConnector files is "
                     "not supported and will be ignored")
     self._filename = conn_file
예제 #8
0
 def __init__(self, conn_file, distributed=False, safe=True, verbose=False):
     FromListConnector.__init__(self, safe=safe, verbose=verbose)
     if distributed:
         logger.warn("distributed loading of FromFileConnector files is "
                     "not supported and will be ignored")
     self._filename = conn_file