Esempio n. 1
0
 def process_file(self, source, target):
     #self.n_ins = 240
     with open(source, 'rb') as i:
         reader = csv.reader(i)
         (before, chords) = util.list_spectrum_data(reader, components=self.n_ins + 60, allow_no_chord=True)
     before = self.getFirstColumns(before, 0, self.n_ins)
     result = self.through_sda(self.model, before)
     with open(target, 'wb') as o:
         writer = csv.writer(o)
         writer.writerows(result)
Esempio n. 2
0
    def process_file(self, source, target):
        subnotes = 1
        with open(source, 'rb') as i:
            reader = csv.reader(i)
            (before, chords) = util.list_spectrum_data(reader,
                     components=self.n_ins + 12 * subnotes, allow_no_chord=True)
        result = None
        for offset in range(12):
            #data = numpy.asmatrix(before, dtype=theano.config.floatX)
            data = before
#            if extra_octave:
            start, end = offset * subnotes, offset * subnotes + self.n_ins
            data = data[:,start:end]
#            else:
#                data = numpy.roll(data, -offset * subnotes, axis=1)
            temp = self.through_sda(self.model, data)
            temp = numpy.roll(temp, offset * subnotes, axis=1)
            if result == None:
                result = numpy.zeros(temp.shape)
            result = numpy.add(result, temp)
#        result = self.through_sda(self.model, before)

#        s = result.shape[0]
#        s = 0
#        ss = numpy.zeros(shape=[s, s])
#        for i, v1 in enumerate(result):
#            for j, v2 in enumerate(result):
#                ss[i][j] = numpy.linalg.norm(self.normalize(v1) - self.normalize(v2))
#        for i in range(s):
#            eps = numpy.sort(ss[i])[int(s * 0.03)]
#            for j in range(s):
#                if ss[i][j] > eps:
#                    ss[i][j] = 1
#        result1 = numpy.zeros(shape = result.shape)
#        for i in range(s):
#            sumW = 0
#            for j in range(s):
#                w = 1 - ss[i][j]
#                result1[i] = numpy.add(result1[i], numpy.multiply(result[j], w))
#                sumW = sumW + w
#            result1[i] = numpy.multiply(result1[i], 1.0 / sumW)
            
        
        with open(target, 'wb') as o:
            writer = csv.writer(o)
            writer.writerows(result)
Esempio n. 3
0
def read_data():
    with open(train_file, 'rb') as f:
        reader = csv.reader(f)
        (array, chords) = util.list_spectrum_data(reader, components=ins, allow_non_majmin=False)
#    (array, chords) = util.shuffle_2(array, chords)
#    array = prepare_data(array)
#    chords = prepare_chords(chords)
    train = int(0.7 * len(array))
    test = int(0.9 * len(array))
    train_array = array[:train]
    train_chords = chords_to_array(chords[:train])
    
    test_array = array[train:test]
    test_chords = chords_to_array(chords[train:test])
    
    valid_array = array[test:]
    valid_chords = chords_to_array(chords[test:])
    print 'finished reading data'
    
    return [[train_array, train_chords], [test_array, test_chords], \
            [valid_array, valid_chords]]
Esempio n. 4
0
    def read_data(self):
        print 'reading data from ' + self.train_file
        with open(self.train_file, 'rb') as f:
            reader = csv.reader(f)
            (array, chords) = list_spectrum_data(reader, components=self.ins)
        
        array = self.prepare_data(array)
        chords = self.prepare_chords(chords)
#        array = numpy.asarray(array, dtype=theano.config.floatX)
        chords = numpy.asarray(chords, dtype=theano.config.floatX)
        
        train = int(0.7 * len(array))
        test = int(0.85 * len(array))
        tr = numpy.copy(array[:train])
        tr_ch = numpy.copy(chords[:train])
        train_array = theano.shared(array[:train], borrow = True)
        train_chords = theano.shared(chords[:train], borrow = True)
        
        test_array = theano.shared(array[train:test], borrow = True)
        test_chords = theano.shared(chords[train:test], borrow = True)
        
        valid_array = theano.shared(array[test:], borrow = True)
        valid_chords = theano.shared(chords[test:], borrow = True)
        
        shuffle_2_numpy(tr, tr_ch)
        train_shuffled = theano.shared(tr, borrow = True)
        chords_shuffled = theano.shared(tr_ch, borrow = True)
       
        if self.recurrent_layer >= 0:
            return [[train_shuffled, chords_shuffled], [test_array, test_chords], \
                    [valid_array, valid_chords], [train_array, train_chords]]
        else:
            del train_array
            del train_chords
            return [[train_shuffled, chords_shuffled], [test_array, test_chords], \
                    [valid_array, valid_chords]]