本文整理汇总了Python中utils.Logger.register方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.register方法的具体用法?Python Logger.register怎么用?Python Logger.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Logger
的用法示例。
在下文中一共展示了Logger.register方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self, in_th, min_th, max_th, delta_th, k):
"""
CTOR
@param in_th Initial threshold.
@param min_th Minimum threshold.
@param max_th Maximum threshold.
@param k Bayesian k factor.
"""
Logger.register('bayes_decision', ['threshold', 'decision', 'risk'])
self._feedback = self._feedback_prev = -1
self._delta_th = delta_th
self._min_th_limit = min_th
self._max_th_limit = max_th
self._k = k
self._th = in_th
self.init(in_th)
self._th_dec = {}
self._xx = {};
self._xx[0] = {0: "00", 1: "01"}
self._xx[1] = {0: "10", 1: "11"}
示例2: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self, th=0):
"""
CTOR
@param th Decision threshold.
"""
ThresholdAlgorithm.__init__(self, th)
Logger.register('energy_decision', ['energy', 'decision'])
self._xx = {};
self._xx[0] = {0: "00", 1: "01"}
self._xx[1] = {0: "10", 1: "11"}
示例3: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self, number_cpes, feedback_control, increase_rate, decrease_rate):
"""
CTOR
@param number_cpes Number of cpes.
@param feedback_control
@param increase_rate The increase rate (float).
@param decrease_rate The decrease rate (float).
"""
self._fb_cycle = 0
self._reward = [1.0] * number_cpes
self._total_idle = self._total_occ = 0
Logger.register('sdc', ['decision', ])
示例4: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self, name="PktBitRate"):
"""
CTOR
@param name Instance name.
"""
OpERABase.__init__(self, name)
self._pkts = {'cur': 0, 'total': 0, 'counting': 0, 'accumulated': 0}
self._bps = {'cur': 0, 'total': 0, 'counting': 0}
# OpERA base method
self.register_scheduling(self._tick, delay_sec=1) # pylint: disable=E1101
Logger.register(name, ['bps', 'pkts', 'pkt_accumulated'])
示例5: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self, threshold, waveforms=WAVEFORMS):
"""
CTOR
@param threshold Decision threshold
@param waveforms Array of known patterns
"""
ThresholdAlgorithm.__init__(self, threshold=threshold)
self._waveforms = waveforms
Logger.register('waveform_decision', ['decision', ])
self._xx = {};
self._xx[0] = {0: "00", 1: "01"}
self._xx[1] = {0: "10", 1: "11"}
示例6: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self, input_len, algo1, algo2):
gr.sync_block.__init__(self,
name="hier",
in_sig = [np.dtype((np.float32, input_len)), np.dtype((np.complex64, input_len))], #pylint: disable=E1101
#in_sig = [np.dtype((np.float32, input_len)), np.dtype((np.float32, input_len))], #pylint: disable=E1101
out_sig= None #pylint: disable=E1101
)
self.algo1 = algo1
self.algo2 = algo2
Logger.register('hier', ['decision',] )
self._xx = {};
self._xx[0] = {0: "00", 1: "01"}
self._xx[1] = {0: "10", 1: "11"}
示例7: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self, Np, P, L, th=0):
"""
CTOR
@param Np
@param P
@param L
@param th Decision threshold.
"""
ThresholdAlgorithm.__init__(self, th)
Logger.register('cyclo_decision', ['decision', ])
from opera import cyclo_fam_calcspectrum_vcf
self._algorithm = cyclo_fam_calcspectrum_vcf(Np, P, L)
self._xx = {};
self._xx[0] = {0: "00", 1: "01"}
self._xx[1] = {0: "10", 1: "11"}
示例8: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self,
name="SNREstimator",
algorithm=SVR,
alpha=0.001):
"""
CTOR
@param name
@param algorithm
@param alpha
"""
self._estimator = digital.probe_mpsk_snr_est_c(algorithm, 10000, alpha)
UHDGenericArch.__init__(self,
name=name,
input_signature=self._estimator.input_signature(),
output_signature=self._estimator.output_signature())
Logger.register(name, ['snr', ])
self.register_scheduling(lambda: Logger.append(name, 'snr', self.get_snr()), delay_sec=0.2) #pylint: disable=E1101
示例9: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self, learner, manager, a_feedback_strategy):
"""
CTOR
@param learner Algorithm that will be adjusted.
@param manager
@param a_feedback_strategy FeedbackTimeStrategy object.
"""
AbstractAlgorithm.__init__(self)
self._learner = learner
self._manager = manager
self._strategy = a_feedback_strategy
self._valid_feedback = True
self._count = 0
self._iteraction = 0
self._time = 0
# Debug information
Logger.register('feedback_algorithm', ['total_feedback', 'activation', 'count', 'time'])
示例10: receiver_loop
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def receiver_loop(tb, channel_list, channel, options):
"""
UP LOOP
@param tb
@param channel_list
@param channel
@param options
"""
import xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer
class MyNamespace:
"""
"""
pass
g_namespace = MyNamespace()
g_namespace.tb = tb
g_namespace.options = options
g_namespace.server_run = True
class StoppableXMLRPCServer(SimpleXMLRPCServer):
"""Override of TIME_WAIT"""
allow_reuse_address = True
def __init__(self, options):
SimpleXMLRPCServer.__init__(self, options)
self.stop = False
def serve_forever(self):
while not self.stop:
self.handle_request()
print 'exiting server'
def shutdown(self):
self.stop = True
return 0
server = StoppableXMLRPCServer((options.slave_addr, 8000))
g_namespace.th = Thread(target=server.serve_forever )
# Flag que indica quando a execucao deve parar
# Flag that indicates when the execution must stop.
g_namespace.run = False
g_namespace.interferer_channel = 0
def set_channel(channel):
"""
RPC for changing the channel.
@param channel
"""
print "Received command to handoff to channel ", channel
if not g_namespace.options.tx_only:
g_namespace.tb.tx.center_freq = channel_list[channel]
g_namespace.tb.rx.center_freq = channel_list[channel]
g_namespace.interferer_channel = channel
return 1
def close_app():
"""
Closes the app.
"""
print "Received command to close"
g_namespace.run = False
return 1
def client_started():
"""
Notifies that the execution has started.
"""
g_namespace.run = True
return 1
Logger.register('receiver', ['channel', 'pkt', 'start_time'])
Logger.set('receiver', 'start_time', time.time())
# Registra funcoes no servidor XML e inicia thread do servidor
# Registers functions in the XML server and starts the server thread.
server.register_function(set_channel, 'set_channel')
server.register_function(close_app, 'close_app')
server.register_function(client_started, 'client_started')
g_namespace.th.start()
print "Receiver listening for commands in port 8000"
print "\t... Waiting for client_started call"
while g_namespace.run == False:
1;
print "\t...client connected"
global t_rcv, t_cor
channel = 0
#.........这里部分代码省略.........
示例11: transmitter_loop
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def transmitter_loop(tb, channel_list, channel, options):
"""
US LOOP
@param tb
@param channel_list
@param channel
@param options
"""
# Connect to slave device
import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://%s:8000/" % options.slave_addr)
start_t = time.time()
proxy.client_started()
proxy.set_channel(channel)
Logger.register('transmitter', ['channel', 'status', 'pkt'])
class TNamespace():
"""
"""
pass
# Sensing -> TX loop
t_namespace = TNamespace()
t_namespace.pkt_s = 0
t_namespace.status = 0
while time.time() < (start_t + options.duration):
can_transmit = True
if not options.tx_only:
# Sense
decision, t_namespace.status = tb.rx.sense_channel(channel_list[channel], options.sensing_duration)
# Update
print t_namespace.status
if t_namespace.status > 0.000005: # GMSK threahold
#if t_namespace.status > 0.000000005 :
print str(channel_list[channel]) + ' is occupied'
t_now = time.clock()
## Q-NOISE AQUI.
channel = (channel + 1) % len(channel_list)
####
can_transmit = False
# Change channel
proxy.set_channel(channel)
tb.tx.center_freq = channel_list[channel]
tb.rx.center_freq = channel_list[channel]
# Transmit
if can_transmit:
payload = 0
if options.pkt_size > 1:
bytelist = [1] * (options.pkt_size/4)
payload = pack('%sH' % len(bytelist), *bytelist)
else:
bytelist = ['a', ]
payload = pack('%sc' % 1, *bytelist)
# thred sending packets
def send_thread():
while t_namespace.pkt_sending:
tb.tx.send_pkt(payload)
t_namespace.pkt_s += 1
#t_namespace.count += 1
# init thread
th = Thread(target=send_thread)
t_namespace.pkt_sending = True
th.start()
# wait for options.sending_duration
time.sleep(options.sending_duration)
# stop sending
t_namespace.pkt_sending = False
th.join()
Logger.append('transmitter', 'channel', channel)
Logger.append('transmitter', 'status', t_namespace.status)
Logger.append('transmitter', 'pkt', t_namespace.pkt_s)
proxy.close_app()
示例12: cognitive_radio_loop
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def cognitive_radio_loop(options, radio, channel_list):
"""
Program loop here.
@param options
@param radio A RadioDevice instance.
@param channel_list List of Channel objects.
"""
# Export my server
command = callback_radio(radio)
my_rpc = RPCExporter(addr=("143.54.83.30", 8000 + options.my_id))
my_rpc.register_function('command', command)
my_rpc.start()
# Wait broker start
while not command.run:
1
####
#Import OTHER RADIOS RPCS
####
rpc_arr = []
RADIOS = [0, 3]
for i in RADIOS:
rpc_cli = RPCImporter(addr="http://%s:%d" % (HOSTS_IP[i], 8000 + i))
rpc_cli.register_function('command')
rpc_arr.append(rpc_cli)
# Import PassiveRadio RPC calls
bs_rpc = RPCImporter(addr="http://%s:9000" % (options.broker_ip))
bs_rpc.register_function('command')
# Register parameters for transmission
Logger.register('radio', ['tx_pkts', 'rx_pkts', 'rx2_pkts' , 'channel', 'operation', 'receiver', 'starving',
'total_tx', 'total_rx', 'total_starving'])
# loop
pkt_len = options.pkt_len
payload = struct.pack('%sB' % pkt_len, *[options.my_id] * pkt_len)
print '##### Entering Transmitter loop'
c_starving = 0
while command.run:
"""
######## FUNCOES:
######## Functions:
---- BW do canal
---- channel's bandwidth.
radio.get_bandwidth()
---- Num. simbolos na modulacao
---- Number of symbols in the modulation.
radio.{tx,rx}.symbols()
---- B/S da modulacao
---- B/S of the modulation.
radio.{tx,rx}.bits_per_symbol()
---- Pkt/s NO ULTIMO SEGUNDO
---- Pkt/s in the last second.
radio.{tx,rx}.counter.get_pkts()
---- b/s NO ULTIMO SEGUNDO.
---- b/s in the last second.
radio.{tx,rx}.counter.get_bps()
---- Pacotes acumulados desde a ultima chamada.
---- Accumulated packages since the last call.
radio.{tx,rx}.counter.get_pkt_accumulated(clear = False)
---- Troca de canal. channel eh um objeto Channel
---- Channel changing. channel is a Channel object
radio.set_channel(channel)
#################
"""
# sense
while not command.sense and command.run:
1
if not command.run:
break
sense_data = []
radio.set_gain(0)
for channel in channel_list:
decision, energy = radio.ss.sense_channel(channel, 0.1)
sense_data.append((decision, float(energy), channel.get_channel()))
print 'Channel energy: ', energy
bs_rpc.command([options.my_id, 'sense_data', sense_data])
while not command.transmission:
1
# tx pkts is the number of packets transmitted
# globs.instant_rx is the number of packets received.
# Is global cause it is hard to be synchronized with the TX dev when WE are the RX
#.........这里部分代码省略.........
示例13: __init__
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
def __init__(self, alpha=0.3, gamma=1.0, epsilon=0.1, verbose=False,
min_th=0.0, max_th=100.0, delta_th=1.0):
"""
CTOR
@param alpha
@param gamma
@param epsilon Probability of executing a random action
@param verbose
@param min_th The lowest threshold
@param max_th The highest threshold
@param delta_th
"""
# "The learning rate determines to what extent the newly
# acquired information will override the old information. A factor of 0
# will make the agent not learn anything, while a factor of 1 would make
# the agent consider only the most recent information."
self.alpha = float(alpha)
# According to Wikipedia: "The discount factor determines the importance
# of future rewards. A factor of 0 will make the agent "opportunistic" by only
# considering current rewards, while a factor approaching 1 will make it
# strive for a long-term high reward."
self.gamma = float(gamma)
# Probabilidade de executar uma acao randomicamente.
# Probability of executing a random action
self.epsilon = float(epsilon)
#
self.verbose = verbose
# min_th is the lowest threshold
self.min_th = min_th
# max_th is the highest threshold
self.max_th = max_th
# gap is the... gap between states, so, the number of states
# will be (max_th - min_th) / gap
self.gap = delta_th
# The feedback
self._feedback = 0.0
# Number of Increase Actions in sequence
self.action_i = 0
# Number of Decrease Actions in sequence
self.action_d = 0
# Set to '1' when a feedback is received
self.feedback_received = True
# Count how many feedbacks are received by the algorithm.
# Used only for info gathering
self.feedback_counter = 0
#
self.cycle_counter = 0
self.cycle_counter_max = int(406383 / 8)
# Execution Time of this class
self.m_time = 0.0
# Enum for actions
self.action = Actions()
# Load in self.actions the possible actions
self.actions = self.get_action_list()
# Load in self.states the possible actions
self.states = self.get_state_list()
# How many states?
self.nstates = len(self.states)
# Max jump
self.max_jump = int(self.nstates / 50)
# Map the threshold value to the index of this threshold in self.states
self.state_map = {'0.0': 0}
for i in range(self.nstates):
self.state_map[self.states[i]] = i
# How many actions I'm using?
self.nactions = len(self.actions)
# Build an empty q_table with size (nactions * nstates)
self.q_table = self.build_q_table()
# Guess what?
self.s = self.get_initial_state()
self.a = self.e_greedy_selection(self.s)
# May be messy
if self.verbose:
self.print_q_table()
Logger.register('bayes_learning', ['hypothesis', 'feedback', 'state', 'reward', 'action'])
示例14: open
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
radio.sensing._component.set_center_freq(1)
print "--- Setting ch_status to 1"
Logger._ch_status = 1
else:
radio.sensing._component.set_center_freq(0)
print "--- Setting ch_status to 0"
Logger._ch_status = 0
if t_tot == 0:
tb.start()
time.sleep(t_next)
t_tot += t_next
if t_tot >= 10.0:
break
################################################################################
tfin = time.clock()
tb.stop()
tb.wait()
enable = False
Logger.register("global", ["clock"])
Logger.set("global", "clock", tfin - tin)
_sdir = "/%s_%02d_%02d/" % (options.sensing, options.ph1 * 10, pfa)
_dir = "single/ebn0_{ebn0}".format(ebn0=ebn0)
Logger.dump(_dir, _sdir, options.it)
Logger.clear_all()
with open("log.txt", "a+") as log:
log.write(_dir + _sdir)
示例15: open
# 需要导入模块: from utils import Logger [as 别名]
# 或者: from utils.Logger import register [as 别名]
Logger._ch_status = 1
else:
radio.ed._component.set_center_freq(0)
print "--- Setting ch_status to 0"
Logger._ch_status = 0
if t_tot == 0:
tb.start()
time.sleep(t_next)
t_tot += t_next
if t_tot >= 10.0:
break;
################################################################################
tb.stop()
tb.wait()
tfin = time.clock()
enable = False
Logger.register('global', ['clock', ])
Logger.set('global', 'clock', tfin - tin)
_sdir = '/ata_%s_%02d_%02d/' % (options.sensing, options.ph1 * 10, pfa)
_dir = "single/ebn0_{ebn0}".format(ebn0=ebn0)
Logger.dump(_dir, _sdir, options.it)
Logger.clear_all()
# wait for thread model_channel finish
#t_mc.join()
with open("log.txt", "a+") as log:
log.write(_dir + _sdir )