Example #1
0
    def indices(self, states):
        """
        indices(states) -> index_array
        
        returns an array of the enumeration indices for the
        states stored in the array 'states'.
        """
        if self.stoc_vec is None:
            states = numpy.asarray(states)
        else:
            states = numpy.asarray(states[self.stoc_vec, :])

            # assume states is a two dimensional array with
            # potentially non unique rows

            #  due to non-uniqueness, there is a bit of messing
            # about in order to reduce the states to
            # a unique set, find the indices for those states, then
            # invert the unique operation
        #pdb.set_trace()
        unique_states, unique_inverse = lexarrayset.unique(states,
                                                           return_inverse=True)

        # subtlety : we need the boolean array members to correspond
        # to the ordered states and thus also to the current index,
        # hence we test to see which elements of ordered_states
        # are contained in the unique states
        #
        # note that this differs from the members query in the
        # contains method

        members = lexarrayset.member(self.ordered_states, unique_states)
        #member_index = numpy.array(self.index[members] + self.offset)
        member_index = numpy.arange(len(self.index))[members]
        return member_index[unique_inverse]
Example #2
0
    def indices(self, states):
        """
        indices(states) -> index_array
        
        returns an array of the enumeration indices for the
        states stored in the array 'states'.
        """
        if self.stoc_vec == None:
            states = numpy.asarray(states)
        else:
            states = numpy.asarray(states[self.stoc_vec,:])

            # assume states is a two dimensional array with
            # potentially non unique rows

            #  due to non-uniqueness, there is a bit of messing
            # about in order to reduce the states to
            # a unique set, find the indices for those states, then
            # invert the unique operation
        #pdb.set_trace()
        unique_states, unique_inverse = lexarrayset.unique(states,return_inverse=True)

            # subtlety : we need the boolean array members to correspond
            # to the ordered states and thus also to the current index,
            # hence we test to see which elements of ordered_states
            # are contained in the unique states
            #
            # note that this differs from the members query in the
            # contains method

        members = lexarrayset.member(self.ordered_states, unique_states)
        #member_index = numpy.array(self.index[members] + self.offset)
        member_index = numpy.arange(len(self.index))[members]
        return member_index[unique_inverse]
Example #3
0
 def reinitialise(self, initial_states):
     """
     reinitialise the StateEnumeration with the given 'initial_states'
     """
     
     initial_states = numpy.asarray(initial_states)
     
     self.unordered_states = lexarrayset.unique(initial_states)
     self.index = numpy.arange(self.unordered_states.shape[1])
     self.update_ordering()
     self.offset = 0
Example #4
0
 def extend(self, sigma):
     """
     Adds the states in the array 'sigma' to the state enumeration.
     
     These states must be disjoint to the existing states in this
     enumeration.
     
     The indexing of existing states in this enumeration will be
     unchanged.
     """
     
     sigma_unique = lexarrayset.unique(numpy.asarray(sigma))
     
     self.unordered_states = numpy.hstack((self.unordered_states,
                                           sigma_unique))
     index = numpy.arange(self.size, self.size+sigma_unique.shape[1])
     self.index = numpy.concatenate((self.index, index))
     self.update_ordering()
Example #5
0
    def extend(self, sigma):
        """
        Adds the states in the array 'sigma' to the state enumeration.
        
        These states must be disjoint to the existing states in this
        enumeration.
        
        The indexing of existing states in this enumeration will be
        unchanged.
        """

        sigma_unique = lexarrayset.unique(numpy.asarray(sigma))

        self.unordered_states = numpy.hstack(
            (self.unordered_states, sigma_unique))
        index = numpy.arange(self.size, self.size + sigma_unique.shape[1])
        self.index = numpy.concatenate((self.index, index))
        self.update_ordering()
Example #6
0
 def contains(self, states):
     """
     contains(states) -> bool_array
     
     returns a boolean array of flags indicates which of the
     states stored in the array 'states' are contained in the
     state enumeration.
     """
     if self.stoc_vec == None:
         states = numpy.asarray(states)
     else:
         states = numpy.asarray(states[self.stoc_vec,:])
     unique_states, unique_inverse = lexarrayset.unique(states,return_inverse=True)
     # subtlety : we need the boolean array members to correspond to the
     # unique states, hence we test to see which elements of the unique
     # states are contained in the ordered states
     #
     # note that this differs from the members query in the indices
     # method
     members = lexarrayset.member(unique_states,self.ordered_states)
     return members[unique_inverse]
Example #7
0
 def contains(self, states):
     """
     contains(states) -> bool_array
     
     returns a boolean array of flags indicates which of the
     states stored in the array 'states' are contained in the
     state enumeration.
     """
     if self.stoc_vec is None:
         states = numpy.asarray(states)
     else:
         states = numpy.asarray(states[self.stoc_vec, :])
     unique_states, unique_inverse = lexarrayset.unique(states,
                                                        return_inverse=True)
     # subtlety : we need the boolean array members to correspond to the
     # unique states, hence we test to see which elements of the unique
     # states are contained in the ordered states
     #
     # note that this differs from the members query in the indices
     # method
     members = lexarrayset.member(unique_states, self.ordered_states)
     return members[unique_inverse]