コード例 #1
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
 def send(self):
     smsg = DecodedMsg()
     smsg.set_counter(self.counter)
     smsg.set_perform_svd(self.perform_svd)
     if self.perform_svd:
         smsg.set_A(self.A[self.perform_svd - 1])
     self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #2
0
ファイル: Decoded2.py プロジェクト: ab39826/IndexCoding
	def receive(self, src, msg):
		m = DecodedMsg(msg.dataGet())
		self.counter = m.get_counter()
		timeformat = '%Y/%d/%m %H:%M:%S'
		print 'Received message %s: counter: %d' % (time.strftime(timeformat), self.counter)
		if m.get_perform_svd():
			print '  svd received:'
			Svals = m.get_A()
			print Svals
			U,S,V = np.linalg.svd(self.A)
			print '  svd check:'
			print [s**2 for s in S]
			self.perform_svd = 0
コード例 #3
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def send(self):
		smsg = DecodedMsg()
		smsg.set_counter(self.counter)
		smsg.set_perform_svd(self.perform_svd)
		if self.perform_svd:
			smsg.set_A(self.A[self.perform_svd-1])
		self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #4
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def receive(self, src, msg):
		time.sleep(1)
		m = DecodedMsg(msg.dataGet())
		self.counter = m.get_counter()
		timeformat = '%Y/%d/%m %H:%M:%S'
		print 'Received message %s: counter: %d' % (time.strftime(timeformat), self.counter)
		print ' current row: ', m.get_current_row()
		print ' true current row: ', self.current_row
		z = np.array(m.get_V_row())
		z = z[0:self.current_row+1]
		print z
		V = self.A[:m.get_current_row()+1]
		#U, S, W = np.linalg.svd(V.T)
		#print S
		Vnull = V[ :, [1,3,5,7] ]
		#U,S,V = np.linalg.svd(Vnull.T)
		#print S
		print np.matrix(Vnull).T*np.matrix(z).T
		
		#U, s, W = np.linalg.svd(Vnull.T)
		#print W.T

		#print self.A[m.get_current_row()][:]
		#print m.get_current_row()
		#print S
		#V_null = self.A[0:self.current_row+1,[1,3, 9, 14]]
		#U, S, W = np.linalg.svd(V_null)
		#print S
		#if m.get_perform_svd() == self.N:
			##print '  svd received:'
			#Svals = m.get_W()
			#print 'Rx svd: ', Svals
			#U,S,V = np.linalg.svd(self.A)
			##S = [s**2 for s in S]
			##print '  svd check:'
			#print 'PC svd: ', S
			#self.perform_svd = 0
			#self.A = make_A_matrix(self.N)
			#print 'MSE: ', np.linalg.norm(np.array(S)-np.array(Svals),2)
			#proctime = time.time() - self.prevtime
			#print 'Elapsed time: %f seconds' % proctime
		#else:
			#self.prevtime = time.time()
			#self.perform_svd += 1
		self.counter += 1
		self.current_row = (self.current_row + 1) % self.N
		#if self.current_row == 0:
			#self.A = make_A_matrix(self.N)
		self.send()
コード例 #5
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
    def send(self):
        smsg = DecodedMsg()
        #this line here needs to be changed to just be random coefficients.
        blah = np.random.randn(1, self.N)
        smsg.set_V_coeff(blah[0, :])

        #smsg.set_V_coeff(self.A[self.current_row])

        smsg.set_crow(self.current_row)
        smsg.set_data([1])
        self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #6
0
 def initialSend(self):
     #print 'initial send'
     smsg1 = DecodedMsg()
     smsg1.set_crow(255)
     smsg1.set_V_coeff(self.data[(2, 4, 6), :])
     #only send the nonzero side information (j<A in tinyos code)?
     self.mif.sendMsg(self.source, 0xFFFF, smsg1.get_amType(), 0, smsg1)
コード例 #7
0
ファイル: Decoded2.py プロジェクト: ab39826/IndexCoding
 def receive(self, src, msg):
     m = DecodedMsg(msg.dataGet())
     self.counter = m.get_counter()
     timeformat = '%Y/%d/%m %H:%M:%S'
     print 'Received message %s: counter: %d' % (time.strftime(timeformat),
                                                 self.counter)
     if m.get_perform_svd():
         print '  svd received:'
         Svals = m.get_A()
         print Svals
         U, S, V = np.linalg.svd(self.A)
         print '  svd check:'
         print[s**2 for s in S]
         self.perform_svd = 0
         self.A = make_A_matrix(self.N)
     self.counter += 1
     self.perform_svd = self.counter % (self.N + 1)
     self.send()
コード例 #8
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def send(self):
		smsg = DecodedMsg()
		#this line here needs to be changed to just be random coefficients.
		blah = np.random.randn(1,self.N)
		smsg.set_V_coeff(blah[0,:])
		
		
		#smsg.set_V_coeff(self.A[self.current_row])

		smsg.set_crow(self.current_row)
		smsg.set_data([1])
		self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #9
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def initialSend(self):
		#print 'initial send'
		smsg1 = DecodedMsg()
		smsg1.set_crow(255)
		smsg1.set_V_coeff(self.data[(2,4,6),:])
		#only send the nonzero side information (j<A in tinyos code)?
		self.mif.sendMsg(self.source, 0xFFFF, smsg1.get_amType(), 0, smsg1)
コード例 #10
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def receive(self, src, msg):
		m = DecodedMsg(msg.dataGet())
		self.counter = m.get_counter()
		timeformat = '%Y/%d/%m %H:%M:%S'
		print 'Received message %s: counter: %d' % (time.strftime(timeformat), self.counter)
		if m.get_perform_svd() == self.N:
			#print '  svd received:'
			Svals = m.get_A()
			print 'Rx svd: ', Svals
			U,S,V = np.linalg.svd(self.A)
			#S = [s**2 for s in S]
			#print '  svd check:'
			print 'PC svd: ', S
			self.perform_svd = 0
			self.A = make_A_matrix(self.N)
			print 'MSE: ', np.linalg.norm(np.array(S)-np.array(Svals),2)
			proctime = time.time() - self.prevtime
			print 'Elapsed time: %f seconds' % proctime
		else:
			self.prevtime = time.time()
			self.perform_svd += 1
		self.counter += 1
		self.send()
コード例 #11
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
 def receive(self, src, msg):
     m = DecodedMsg(msg.dataGet())
     self.counter = m.get_counter()
     timeformat = '%Y/%d/%m %H:%M:%S'
     print 'Received message %s: counter: %d' % (time.strftime(timeformat),
                                                 self.counter)
     if m.get_perform_svd() == self.N:
         #print '  svd received:'
         Svals = m.get_A()
         print 'Rx svd: ', Svals
         U, S, V = np.linalg.svd(self.A)
         #S = [s**2 for s in S]
         #print '  svd check:'
         print 'PC svd: ', S
         self.perform_svd = 0
         self.A = make_A_matrix(self.N)
         print 'MSE: ', np.linalg.norm(np.array(S) - np.array(Svals), 2)
         proctime = time.time() - self.prevtime
         print 'Elapsed time: %f seconds' % proctime
     else:
         self.prevtime = time.time()
         self.perform_svd += 1
     self.counter += 1
     self.send()
コード例 #12
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
    def send(self):
        smsg = DecodedMsg()
        #print 'type of A is ', type(self.A)
        print 'cr ', self.A[self.current_row]
        #print 'type of cr ', type(self.A[self.current_row])

        #random coefficients instead
        #rndRow = np.random.randn(1,self.N)
        #print 'random row is', rndRow[0,:]
        #print self.rndV
        #self.rndV = np.bmat([[self.rndV], [rndRow]])
        #print 'matrix of random rows is'
        #print self.rndV
        #smsg.set_V_coeff(rndRow[0,:])
        #also change data symbols
        #self.rndSym = np.dot(rndRow[0,:],self.data)
        #smsg.set_data(self.rndSym)

        smsg.set_V_coeff(self.A[self.current_row])
        smsg.set_data(self.sym[self.current_row])  #use current row each time?
        #print type(self.A[0,0])
        smsg.set_crow(self.current_row)

        self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #13
0
    def receive(self, src, msg):
        time.sleep(1)
        m = DecodedMsg(msg.dataGet())
        self.counter = m.get_counter()
        timeformat = '%Y/%d/%m %H:%M:%S'
        print 'Received message %s: counter: %d' % (time.strftime(timeformat),
                                                    self.counter)
        print ' current row: ', m.get_current_row()
        print ' true current row: ', self.current_row
        z = np.array(m.get_V_row())
        z = z[0:self.current_row + 1]
        print z
        V = self.A[:m.get_current_row() + 1]
        #U, S, W = np.linalg.svd(V.T)
        #print S
        Vnull = V[:, [1, 3, 5, 7]]
        #U,S,V = np.linalg.svd(Vnull.T)
        #print S
        print np.matrix(Vnull).T * np.matrix(z).T

        #U, s, W = np.linalg.svd(Vnull.T)
        #print W.T

        #print self.A[m.get_current_row()][:]
        #print m.get_current_row()
        #print S
        #V_null = self.A[0:self.current_row+1,[1,3, 9, 14]]
        #U, S, W = np.linalg.svd(V_null)
        #print S
        #if m.get_perform_svd() == self.N:
        ##print '  svd received:'
        #Svals = m.get_W()
        #print 'Rx svd: ', Svals
        #U,S,V = np.linalg.svd(self.A)
        ##S = [s**2 for s in S]
        ##print '  svd check:'
        #print 'PC svd: ', S
        #self.perform_svd = 0
        #self.A = make_A_matrix(self.N)
        #print 'MSE: ', np.linalg.norm(np.array(S)-np.array(Svals),2)
        #proctime = time.time() - self.prevtime
        #print 'Elapsed time: %f seconds' % proctime
        #else:
        #self.prevtime = time.time()
        #self.perform_svd += 1
        self.counter += 1
        self.current_row = (self.current_row + 1) % self.N
        #if self.current_row == 0:
        #self.A = make_A_matrix(self.N)
        self.send()
コード例 #14
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def send(self):
		smsg = DecodedMsg()
		#print 'type of A is ', type(self.A)
		print 'cr ', self.A[self.current_row]
		#print 'type of cr ', type(self.A[self.current_row])
		
		#random coefficients instead
		#rndRow = np.random.randn(1,self.N)
		#print 'random row is', rndRow[0,:]
		#print self.rndV
		#self.rndV = np.bmat([[self.rndV], [rndRow]])
		#print 'matrix of random rows is'
		#print self.rndV
		#smsg.set_V_coeff(rndRow[0,:])
		#also change data symbols
		#self.rndSym = np.dot(rndRow[0,:],self.data)
		#smsg.set_data(self.rndSym)

		smsg.set_V_coeff(self.A[self.current_row])
		smsg.set_data(self.sym[self.current_row]) #use current row each time?
		#print type(self.A[0,0])
		smsg.set_crow(self.current_row)		

		self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #15
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def send(self):
		smsg = DecodedMsg()
		smsg.set_V_coeff(self.A[self.current_row])
		smsg.set_crow(self.current_row)
		smsg.set_data(self.sym[self.current_row]) #use current row each time?
		self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #16
0
    def receive(self, src, msg):
        time.sleep(1)
        m = DecodedMsg(msg.dataGet())
        timeformat = '%Y/%d/%m %H:%M:%S'
        print 'Received message %s:' % time.strftime(timeformat)
        print ' true current row: ', self.current_row

        ## get received data from mote
        rec_row = m.get_crow()
        print rec_row

        x_mote = np.array(m.get_V_coeff())
        #x_mote = x_mote[0:self.current_row+1]

        print 'mote result: ', x_mote

        #print 'selfsym ' , self.sym

        ## check functionality in python
        V = self.A[:self.current_row + 1]
        #U, S, W = np.linalg.svd(V.T)
        #print S
        Vnull = V[:, [1, 3, 5, 7]]
        z = nullvec(Vnull.T)
        #ant_vec = np.mat('[0; 0; 0; 0; .1; 0; .2; 0]')
        ant_vec = np.multiply(np.mat('[0; 0; 1; 0; 1; 0; 1; 0]'), self.data)

        Vant = V * ant_vec

        #if len(z)>0:
        #print 'antidoteresult: ',z.T*Vant
        #else:
        #print 'antidoteresult: ',[]

        if len(z) > 0:
            #x_python = np.dot(z.T, V[:,0])
            #print x_python
            #print np.shape(z), np.shape(Vnull)
            #print np.matrix(Vnull).T*np.matrix(z)
            #print self.sym[0]
            #nulldata = z.T*self.sym[0]*np.ones((self.current_row+1,1))
            #print self.sym
            #print z.T
            #print self.sym[:self.current_row+1]
            nulldata = z.T * self.sym[:self.current_row + 1]
            antdata = z.T * Vant
            finalresult = nulldata - antdata
            maindimension = V[:, [0]]
            xdot = z.T * maindimension
            finalresult = (finalresult / xdot)
            print 'final Python result: ', finalresult

        else:
            print[]
        #U,S,V = np.linalg.svd(Vnull.T)
        #print S

        self.current_row = (self.current_row + 1) % self.N
        #if self.current_row == 0:
        #self.A = make_A_matrix(self.N)
        self.send()
コード例 #17
0
 def send(self):
     smsg = DecodedMsg()
     smsg.set_V_coeff(self.A[self.current_row])
     smsg.set_crow(self.current_row)
     smsg.set_data(self.sym[self.current_row])  #use current row each time?
     self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #18
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
    def receive(self, src, msg):
        time.sleep(1)
        m = DecodedMsg(msg.dataGet())
        timeformat = '%Y/%d/%m %H:%M:%S'
        print 'Received message %s:' % time.strftime(timeformat)
        print ' true current row: ', self.current_row

        ## get received data from mote
        rec_row = m.get_crow()
        print rec_row

        x_mote = np.array(m.get_V_coeff())
        #x_mote = x_mote[0:self.current_row+1]

        print 'mote result: ', x_mote

        ## check functionality in python
        V = self.A[:self.current_row + 1]
        #print 'A', self.A
        #print 'V', V
        #U, S, W = np.linalg.svd(V.T)
        #print S
        Vnull = V[:, [1, 3, 5, 7]]
        z = nullvec(Vnull.T)
        #print z
        ant_vec = np.mat('[0; 0; :1; 0; 1; 0; 1; 0]')

        Vant = V * ant_vec

        if len(z) > 0:
            print 'antidoteresult: ', z.T * Vant
        else:
            print 'antidoteresult: ', []

        if len(z) > 0:
            #x_python = np.dot(z.T, V[:,0])
            #print x_python
            #print np.shape(z), np.shape(Vnull)
            #print np.matrix(Vnull).T*np.matrix(z)
            nulldata = z.T * np.ones((self.current_row + 1, 1))
            antdata = z.T * Vant
            finalresult = nulldata - antdata
            maindimension = V[:, [0]]
            xdot = z.T * maindimension
            finalresult = (finalresult / xdot)
            print 'final result: ', finalresult

        else:
            print[]
        #U,S,V = np.linalg.svd(Vnull.T)
        #print S

        #U, s, W = np.linalg.svd(Vnull.T)
        #print W.T

        #print self.A[m.get_current_row()][:]
        #print m.get_current_row()
        #print S
        #V_null = self.A[0:self.current_row+1,[1,3, 9, 14]]
        #U, S, W = np.linalg.svd(V_null)
        #print S
        #if m.get_perform_svd() == self.N:
        ##print '  svd received:'
        #Svals = m.get_W()
        #print 'Rx svd: ', Svals
        #U,S,V = np.linalg.svd(self.A)
        ##S = [s**2 for s in S]
        ##print '  svd check:'
        #print 'PC svd: ', S
        #self.perform_svd = 0
        #self.A = make_A_matrix(self.N)
        #print 'MSE: ', np.linalg.norm(np.array(S)-np.array(Svals),2)
        #proctime = time.time() - self.prevtime
        #print 'Elapsed time: %f seconds' % proctime
        #else:
        #self.prevtime = time.time()
        #self.perform_svd += 1
        self.current_row = (self.current_row + 1) % self.N
        #if self.current_row == 0:
        #self.A = make_A_matrix(self.N)
        self.send()
コード例 #19
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def send(self):
		smsg = DecodedMsg()
		smsg.set_counter(self.counter)
		smsg.set_current_row(self.current_row)
		smsg.set_V_row(self.A[self.current_row])
		self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #20
0
 def send(self):
     smsg = DecodedMsg()
     smsg.set_counter(self.counter)
     smsg.set_current_row(self.current_row)
     smsg.set_V_row(self.A[self.current_row])
     self.mif.sendMsg(self.source, 0xFFFF, smsg.get_amType(), 0, smsg)
コード例 #21
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def receive(self, src, msg):
		time.sleep(1)
		m = DecodedMsg(msg.dataGet())
		timeformat = '%Y/%d/%m %H:%M:%S'
		print 'Received message %s:' % time.strftime(timeformat)
		print ' true current row: ', self.current_row


		## get received data from mote
		rec_row = m.get_crow()
		print rec_row

		x_mote = np.array(m.get_V_coeff())
		#x_mote = x_mote[0:self.current_row+1]


		print 'mote result: ', x_mote

		

		## check functionality in python
		V = self.A[:self.current_row+1]
		#print 'A', self.A
		#print 'V', V
		#U, S, W = np.linalg.svd(V.T)
		#print S
		Vnull = V[ :, [1,3,5,7] ]
		z = nullvec(Vnull.T)
		#print z
		ant_vec = np.mat('[0; 0; :1; 0; 1; 0; 1; 0]')

		Vant = V*ant_vec
		
		if len(z)>0:
			print 'antidoteresult: ',z.T*Vant
		else:
			print 'antidoteresult: ',[]

		if len(z)>0:
			#x_python = np.dot(z.T, V[:,0])
			#print x_python
			#print np.shape(z), np.shape(Vnull)
			#print np.matrix(Vnull).T*np.matrix(z)
			nulldata= z.T*np.ones((self.current_row+1,1))
			antdata = z.T*Vant
			finalresult = nulldata - antdata
			maindimension = V[:,[0]]
			xdot = z.T*maindimension
			finalresult = (finalresult/xdot)
			print 'final result: ',finalresult

			
		else:
			print []
		#U,S,V = np.linalg.svd(Vnull.T)
		#print S

		
		#U, s, W = np.linalg.svd(Vnull.T)
		#print W.T

		#print self.A[m.get_current_row()][:]
		#print m.get_current_row()
		#print S
		#V_null = self.A[0:self.current_row+1,[1,3, 9, 14]]
		#U, S, W = np.linalg.svd(V_null)
		#print S
		#if m.get_perform_svd() == self.N:
			##print '  svd received:'
			#Svals = m.get_W()
			#print 'Rx svd: ', Svals
			#U,S,V = np.linalg.svd(self.A)
			##S = [s**2 for s in S]
			##print '  svd check:'
			#print 'PC svd: ', S
			#self.perform_svd = 0
			#self.A = make_A_matrix(self.N)
			#print 'MSE: ', np.linalg.norm(np.array(S)-np.array(Svals),2)
			#proctime = time.time() - self.prevtime
			#print 'Elapsed time: %f seconds' % proctime
		#else:
			#self.prevtime = time.time()
			#self.perform_svd += 1
		self.current_row = (self.current_row + 1) % self.N
		#if self.current_row == 0:
			#self.A = make_A_matrix(self.N)
		self.send()
コード例 #22
0
ファイル: Decoded.py プロジェクト: ab39826/IndexCoding
	def receive(self, src, msg):
		time.sleep(1)
		m = DecodedMsg(msg.dataGet())
		timeformat = '%Y/%d/%m %H:%M:%S'
		print 'Received message %s:' % time.strftime(timeformat)
		print ' true current row: ', self.current_row


		## get received data from mote
		rec_row = m.get_crow()
		print rec_row

		x_mote = np.array(m.get_V_coeff())
		#x_mote = x_mote[0:self.current_row+1]


		print 'mote result: ', x_mote

		#print 'selfsym ' , self.sym

		

		## check functionality in python

		V = self.A[:self.current_row+1,:]
		#change to same random thing?
		#V = np.asarray(self.rndV[1:,:])
		#also update symbols each time based on new random coeffs
		#self.sym = V*self.data

		#print self.A[:self.current_row+1,:]
		#print 'V is'
		#print V

		#print 'symbols to python'
		#print self.sym[:self.current_row+1]
		#print 'symbols over the air'
		#print self.rndSym
		#print self.sym2
		
		#U, S, W = np.linalg.svd(V.T)
		#print S
		Vnull = V[ :, [1,3,5,7] ]
		z = nullvec(Vnull.T)
		#ant_vec = np.mat('[0; 0; 0; 0; .1; 0; .2; 0]')
		ant_vec = np.multiply(np.mat('[0; 0; 1; 0; 1; 0; 1; 0]'), self.data)

		Vant = V*ant_vec
		
		#if len(z)>0:
			#print 'antidoteresult: ',z.T*Vant
		#else:			
			#print 'antidoteresult: ',[]

		if len(z)>0:
			#x_python = np.dot(z.T, V[:,0])
			#print x_python
			#print np.shape(z), np.shape(Vnull)
			#print np.matrix(Vnull).T*np.matrix(z)
			#print self.sym[0]
			#nulldata = z.T*self.sym[0]*np.ones((self.current_row+1,1))
			#print self.sym
			#print z.T
			#print self.sym[:self.current_row+1]
			nulldata = z.T*self.sym[:self.current_row+1]
			antdata = z.T*Vant
			finalresult = nulldata - antdata
			maindimension = V[:,[0]]
			xdot = z.T*maindimension
			finalresult = (finalresult/xdot)
			print 'final Python result: ',finalresult

			
		else:
			print []
		#U,S,V = np.linalg.svd(Vnull.T)
		#print S

		self.current_row = (self.current_row + 1) % self.N
		if self.current_row == 0:
			self.A = make_A_matrix(self.N)
			self.sym = self.A*self.data
		self.send()