def add_sample_space(self, samples):
        "Adds space for n samples, where n can also be negative (deletes space). New space is filled up with \"0\""

        if not self.cont_data:
            print "Warning ADC-Result: Tried to resize empty array!"
            return

        length = len(self.y[0])

        self.x = numarray.resize(self.x, (length+samples))

        for i in range(self.get_number_of_channels()):
            self.y[i] = numarray.resize(self.y[i], (length+samples))

        self.index.append((length, len(self.y[0])-1))
def notes_roc(la, lb, eps):
    from numarray import transpose, add, resize
    """ creates a matrix of size len(la)*len(lb) then look for hit and miss
    in it within eps tolerance windows """
    gdn, fpw, fpg, fpa, fdo, fdp = 0, 0, 0, 0, 0, 0
    m = len(la)
    n = len(lb)
    x = resize(la[:][0], (n, m))
    y = transpose(resize(lb[:][0], (m, n)))
    teps = (abs(x - y) <= eps[0])
    x = resize(la[:][1], (n, m))
    y = transpose(resize(lb[:][1], (m, n)))
    tpitc = (abs(x - y) <= eps[1])
    res = teps * tpitc
    res = add.reduce(res, axis=0)
    for i in range(len(res)):
        if res[i] > 1:
            gdn += 1
            fdo += res[i] - 1
        elif res[i] == 1:
            gdn += 1
    fpa = n - gdn - fpa
    return gdn, fpw, fpg, fpa, fdo, fdp
def notes_roc (la, lb, eps):
    from numarray import transpose, add, resize 
    """ creates a matrix of size len(la)*len(lb) then look for hit and miss
    in it within eps tolerance windows """
    gdn,fpw,fpg,fpa,fdo,fdp = 0,0,0,0,0,0
    m = len(la)
    n = len(lb)
    x =           resize(la[:][0],(n,m))
    y = transpose(resize(lb[:][0],(m,n)))
    teps =  (abs(x-y) <= eps[0]) 
    x =           resize(la[:][1],(n,m))
    y = transpose(resize(lb[:][1],(m,n)))
    tpitc = (abs(x-y) <= eps[1]) 
    res = teps * tpitc
    res = add.reduce(res,axis=0)
    for i in range(len(res)) :
        if res[i] > 1:
            gdn+=1
            fdo+=res[i]-1
        elif res [i] == 1:
            gdn+=1
    fpa = n - gdn - fpa
    return gdn,fpw,fpg,fpa,fdo,fdp
 def normalize(self, dim=-1):
     """ If dim=-1 all elements sum to 1.  Otherwise sum to specific dimension, such that 
     sum(Pr(x=i|Pa(x))) = 1 for all values of i and a specific set of values for Pa(x)
     """
     if dim == -1 or len(self.cpt.shape) == 1:
         self.cpt /= self.cpt.sum()            
     else:
         ndim = self.assocdim[dim]
         order = range(len(self.names_list))
         order[0] = ndim
         order[ndim] = 0
         tcpt = na.transpose(self.cpt, order)
         t1cpt = na.sum(tcpt, axis=0)
         t1cpt = na.resize(t1cpt,tcpt.shape)
         tcpt = tcpt/t1cpt
         self.cpt = na.transpose(tcpt, order)
Beispiel #5
0
def file2matrix(fileName):
    """
        Given a file "fileName", this script converts the contents of the 
        file to a numarray matrix of size (m,) or (m,n).
    """
    # Open the file
    open1 = open(fileName, 'r')
    line = open1.readline()

    # A single line from the file is read. This should be the number
    # of columns. Spliting "line" results in a list, the length of
    # which is the number of columns: cols
    cols = len(line.split())

    # x is the placeholder for the data.
    # The placeholder matrix is made of concatenating
    # every line that is read from the file.
    # The type code is float.
    x = numarray.zeros(cols, type='f')

    while (line):
        temp = []
        list_elements = line.split()
        for e in list_elements:
            temp.append(float(e))
        x = numarray.concatenate((x, numarray.array(temp)))
        line = open1.readline()

    open1.close()

    # concatenate((x,x)) is along the dimension 1,
    # each new addition is an increase in columns,
    # the total length of x gives m*n. We determine
    # the rows as
    rows = len(x) / cols

    # We have added an aritifical row, so if row == 2
    # the file has tuple, hence the data consists of
    # everything after our artificial set of columns
    if rows == 2:
        return x[cols:]
    else:
        # If there are m+1 rows, we resize the data to (m+1)xn
        # and return everything other than the artificial first
        # row of zeros
        x = numarray.resize(x, (rows, cols))
        return x[1:, :]
Beispiel #6
0
  def __init__(self, baseAddr, size = None, endAddr = None, openTime = None):
    if self.vertices is None:
        self.__class__.vertices = numarray.resize(0.0,(4,3))

    self.order = self.newOrder()
    if openTime is None:
        self.openTime = time()
    else:
        self.openTime = openTime
    self.closeTime = None

    self.baseAddr = baseAddr
    if size is None:
      if endAddr is None:
        raise Exception, 'Either size or endAddr must have a value'
      else:
        self.endAddr = endAddr
    else:
      self.endAddr = baseAddr + size
Beispiel #7
0
def GetPHTitration(prefix):

    from numarray import resize, array
    inputfile = "%s%s" % (prefix,'.sinout')
    outputfile = "%s%s" % (prefix,'.pHtitr')

    f = open(inputfile)
    all_lines = f.readlines()
    f.close()

    IS = []; pH = []
    for line_counter, line in enumerate(all_lines):
        if line[0:12] == 'IONIC. STRN.':
            i = 1
            current_line = all_lines[line_counter + i ]
            while current_line != '\n':
                IS.append("%5.3F" % float(current_line[2:13]))
                i += 1
                current_line = all_lines[line_counter + i]

        if line[0:19] == '        IONIC STRN.':
            number_IS = len(IS)
            j = 4; number_pH = 0
            current_line = all_lines[line_counter + j]
            while current_line != '\n':
                pH.append("%5.2F" % float(current_line[0:6]))
                j += 1
                current_line = all_lines[line_counter + j]
            number_pH = len(pH)
            all_data = resize(array(0.0),[number_IS,number_pH,4])
            break

    i = 0
    for line_counter, line in enumerate(all_lines):
        if line[0:19] == '        IONIC STRN.':

            j = 4
            current_line = all_lines[line_counter + j]
            while current_line != '\n':
                tmp_H = current_line[36:44]
                tmp_q = current_line[44:52]
                if tmp_H == ' ****** ': tmp_H = 0
                if tmp_q == ' ****** ': tmp_q = 0
                all_data[i,j-4,0] = float(tmp_H)
                all_data[i,j-4,1] = float(tmp_q)
                all_data[i,j-4,2] = float(current_line[54:62])
                all_data[i,j-4,3] = float(current_line[63:71])
                j += 1
                current_line = all_lines[line_counter + j]
            i += 1
            
    out = ["%s%s%s" % ('#pH titration of ',prefix,' at IS values:\n')]
    for i in range(number_IS):
        out.append("%s%s%s" % ('#\t',IS[i],'\n'))

    out.append('\tpH\t')
    for i in range(number_IS):
        out.append("%s%s%s%s" % ('IS',i,'_boundH','\t'))
        out.append("%s%s%s%s" % ('IS',i,'_charge','\t'))
        out.append("%s%s%s%s" % ('IS',i,'_dGtot','\t'))
        out.append("%s%s%s%s" % ('IS',i,'_dGH','\t'))
    out.append('\n')
    
    for i in range(number_pH):
        out.append("%s%s" % (str(i),'\t'))
        out.append("%s%s" % (pH[i],'\t'))
        for j in range(number_IS):
            for k in range(4):
                out.append("%5.3F%s" % (all_data[j,i,k],'\t'))
        out.append('\n')

    g = open(outputfile,'w')
    g.write("".join(out))
    g.close()

    print outputfile, 'written.'