Exemple #1
0
def ruleGen(ruleNo, srcSpan=3, dstValues=[0, 1], srcValues=None):
    """generate a rule in the form of a list; each entry in the list
    consists of a src list (the ordered values in the previous step to match
    and a destinatino value (the new cell value)
    k == number of cell values (len(dstValues))
    srcSpan is number of previous values considered (3 here is an r of 1)
    srcValues for totalistic rules, where src and dst are not the same

    >>> ruleGen(3)
    [[[0, 0, 0], 1], [[0, 0, 1], 1], [[0, 1, 0], 0], [[0, 1, 1], 0], [[1, 0, 0], 0], [[1, 0, 1], 0], [[1, 1, 0], 0], [[1, 1, 1], 0]]
    >>> ruleGen(234, 5)
    [[[0, 0, 0, 0, 0], 0], [[0, 0, 0, 0, 1], 1], [[0, 0, 0, 1, 0], 0], [[0, 0, 0, 1, 1], 1], [[0, 0, 1, 0, 0], 0], [[0, 0, 1, 0, 1], 1], [[0, 0, 1, 1, 0], 1], [[0, 0, 1, 1, 1], 1], [[0, 1, 0, 0, 0], 0], [[0, 1, 0, 0, 1], 0], [[0, 1, 0, 1, 0], 0], [[0, 1, 0, 1, 1], 0], [[0, 1, 1, 0, 0], 0], [[0, 1, 1, 0, 1], 0], [[0, 1, 1, 1, 0], 0], [[0, 1, 1, 1, 1], 0], [[1, 0, 0, 0, 0], 0], [[1, 0, 0, 0, 1], 0], [[1, 0, 0, 1, 0], 0], [[1, 0, 0, 1, 1], 0], [[1, 0, 1, 0, 0], 0], [[1, 0, 1, 0, 1], 0], [[1, 0, 1, 1, 0], 0], [[1, 0, 1, 1, 1], 0], [[1, 1, 0, 0, 0], 0], [[1, 1, 0, 0, 1], 0], [[1, 1, 0, 1, 0], 0], [[1, 1, 0, 1, 1], 0], [[1, 1, 1, 0, 0], 0], [[1, 1, 1, 0, 1], 0], [[1, 1, 1, 1, 0], 0], [[1, 1, 1, 1, 1], 0L]]

    """
    dstNo = len(dstValues)  # number of possible cell values
    if srcValues == None:  # non totalistic riles
        # get number of possible outcomes, or arrangemnts of src states
        srcMatches = permutate.selections(dstValues, srcSpan)
    # for totalistic rules, src values not from selections of possibility
    # byt given directly in a list
    else:
        srcValues.sort()  # get from low to high, reverse of ws
        srcMatches = srcValues
    # gets next step array of values; note: these are reveresed from ws presentn
    ruleArray = [(ruleNo / pow(dstNo, i)) % dstNo
                 for i in range(len(srcMatches))]
    # bundle as pairs b/n src and dst
    r = [[srcMatches[x], ruleArray[x]] for x in range(len(srcMatches))]
    return r
Exemple #2
0
def ruleGen(ruleNo, srcSpan=3, dstValues=[0,1], srcValues=None):
    """generate a rule in the form of a list; each entry in the list
    consists of a src list (the ordered values in the previous step to match
    and a destinatino value (the new cell value)
    k == number of cell values (len(dstValues))
    srcSpan is number of previous values considered (3 here is an r of 1)
    srcValues for totalistic rules, where src and dst are not the same

    >>> ruleGen(3)
    [[[0, 0, 0], 1], [[0, 0, 1], 1], [[0, 1, 0], 0], [[0, 1, 1], 0], [[1, 0, 0], 0], [[1, 0, 1], 0], [[1, 1, 0], 0], [[1, 1, 1], 0]]
    >>> ruleGen(234, 5)
    [[[0, 0, 0, 0, 0], 0], [[0, 0, 0, 0, 1], 1], [[0, 0, 0, 1, 0], 0], [[0, 0, 0, 1, 1], 1], [[0, 0, 1, 0, 0], 0], [[0, 0, 1, 0, 1], 1], [[0, 0, 1, 1, 0], 1], [[0, 0, 1, 1, 1], 1], [[0, 1, 0, 0, 0], 0], [[0, 1, 0, 0, 1], 0], [[0, 1, 0, 1, 0], 0], [[0, 1, 0, 1, 1], 0], [[0, 1, 1, 0, 0], 0], [[0, 1, 1, 0, 1], 0], [[0, 1, 1, 1, 0], 0], [[0, 1, 1, 1, 1], 0], [[1, 0, 0, 0, 0], 0], [[1, 0, 0, 0, 1], 0], [[1, 0, 0, 1, 0], 0], [[1, 0, 0, 1, 1], 0], [[1, 0, 1, 0, 0], 0], [[1, 0, 1, 0, 1], 0], [[1, 0, 1, 1, 0], 0], [[1, 0, 1, 1, 1], 0], [[1, 1, 0, 0, 0], 0], [[1, 1, 0, 0, 1], 0], [[1, 1, 0, 1, 0], 0], [[1, 1, 0, 1, 1], 0], [[1, 1, 1, 0, 0], 0], [[1, 1, 1, 0, 1], 0], [[1, 1, 1, 1, 0], 0], [[1, 1, 1, 1, 1], 0L]]

    """
    dstNo = len(dstValues) # number of possible cell values
    if srcValues == None: # non totalistic riles
        # get number of possible outcomes, or arrangemnts of src states
        srcMatches = permutate.selections(dstValues, srcSpan)
    # for totalistic rules, src values not from selections of possibility
    # byt given directly in a list
    else:
        srcValues.sort() # get from low to high, reverse of ws
        srcMatches = srcValues
    # gets next step array of values; note: these are reveresed from ws presentn
    ruleArray = [(ruleNo/pow(dstNo,i)) % dstNo for i in range(len(srcMatches))] 
    # bundle as pairs b/n src and dst
    r = [[srcMatches[x], ruleArray[x]] for x in range(len(srcMatches))]
    return r
Exemple #3
0
    def _analyzeNth(self, srcData, order, wrap=0):
        """do 1 or more order analysis on data list
        optional wrapping determines if wrap start value from end
        not sure what to do if no connections are found: is this a dead end, 
        or should it be treated as an equal distribution (this is the default
        behaviour here..."""
        # get all symbol key combinations
        assert order >= 1

        data = srcData[:]  # make a copy to work on
        # if wrap is selected, append order# of begining to end
        if wrap:
            data = data + data[:order]

        symbols = self._symbols.keys()
        trans = permutate.selections(symbols, order)
        # go through all transition possibilities for this order
        for t in trans:
            # must convert to tuple
            #print _MOD, 'searching transition', t
            t = tuple(t)
            # every transition key has a list of weights defined initially
            # this will be removed below if no matches found
            self._weightSrc[t] = []
            # decode the transition key into the desired real sequence
            # this will be done for each possible transition
            subList = []
            for s in t:  # for each symbol label specified in the transition
                subList.append(self._symbols[s])
            # for each transition possible,
            # go through all adjacent segments of source data and compare
            for i in range(0, len(data)):
                # need one more than order, as that is what we compare to
                if i + order >= len(data): break
                dataSeg = data[i:i + order]
                assert len(dataSeg) == len(
                    subList)  # shuold always be the same
                if dataSeg == subList:  # match a segment, must update weights
                    dst = data[i + order]  # next value after segment
                    # get sym label for teh dst data value
                    dstSym = self._valueToSymbol(dst)
                    #print _MOD, 'matched, dst', dataSeg, dst
                    self._updateWeightList(self._weightSrc[t], dstSym)
                    #self._weightSrc[t] = wList
            # check for an empty weight string
            if len(self._weightSrc[t]) == 0:
                # not sure what to do: delete it?
                # this is a dead end and cannot be used to generate...
                del self._weightSrc[t]
Exemple #4
0
 def _analyzeNth(self, srcData, order, wrap=0):
     """do 1 or more order analysis on data list
     optional wrapping determines if wrap start value from end
     not sure what to do if no connections are found: is this a dead end, 
     or should it be treated as an equal distribution (this is the default
     behaviour here..."""
     # get all symbol key combinations
     assert order >= 1
     
     data = srcData[:] # make a copy to work on 
     # if wrap is selected, append order# of begining to end
     if wrap:
         data = data + data[:order]            
         
     symbols = self._symbols.keys()
     trans = permutate.selections(symbols, order)              
     # go through all transition possibilities for this order          
     for t in trans: 
         # must convert to tuple
         #print _MOD, 'searching transition', t
         t = tuple(t)
         # every transition key has a list of weights defined initially
         # this will be removed below if no matches found
         self._weightSrc[t] = []
         # decode the transition key into the desired real sequence
         # this will be done for each possible transition
         subList = []
         for s in t: # for each symbol label specified in the transition
             subList.append(self._symbols[s])
         # for each transition possible, 
         # go through all adjacent segments of source data and compare
         for i in range(0, len(data)):
             # need one more than order, as that is what we compare to
             if i + order >= len(data): break
             dataSeg = data[i:i+order]
             assert len(dataSeg) == len(subList) # shuold always be the same
             if dataSeg == subList: # match a segment, must update weights
                 dst = data[i+order] # next value after segment
                 # get sym label for teh dst data value
                 dstSym = self._valueToSymbol(dst)
                 #print _MOD, 'matched, dst', dataSeg, dst
                 self._updateWeightList(self._weightSrc[t], dstSym)
                 #self._weightSrc[t] = wList
         # check for an empty weight string
         if len(self._weightSrc[t]) == 0:
             # not sure what to do: delete it?
             # this is a dead end and cannot be used to generate...
             del self._weightSrc[t]