本文整理汇总了Python中network.Network类的典型用法代码示例。如果您正苦于以下问题:Python Network类的具体用法?Python Network怎么用?Python Network使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Network类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: Webserver
class Webserver(object):
def __init__(self):
cherrypy.engine.subscribe('stop', self.stop)
self.net = Network(WEBSERVER_IP, WEBSERVER_PORT)
# spusti se pri zapinani
def stop(self):
# spusti se pri vypinani
pass
@cherrypy.expose
def index(self):
# exposed metoda -- zavolali jsme /
return base.render()
def doit(self, action, value):
# spustit ledky
data = dict()
data["key"] = action
data["value"] = value
self.net.send(data, SERVER_IP, SERVER_PORT)
@cherrypy.expose
def set(self, value):
self.doit("set", value)
return self.index()
@cherrypy.expose
def get(self, value):
self.doit("get", value)
tmp = self.net.recv()
# should be recv
return tmp
开发者ID:fialakarel,项目名称:haut-webserver,代码行数:35,代码来源:haut-webserver.py
示例2: create_system
def create_system(options, full_system, system, piobus=None, dma_ports=[]):
system.ruby = RubySystem()
ruby = system.ruby
# Create the network object
(network, IntLinkClass, ExtLinkClass, RouterClass, InterfaceClass) = Network.create_network(options, ruby)
ruby.network = network
protocol = buildEnv["PROTOCOL"]
exec "import %s" % protocol
try:
(cpu_sequencers, dir_cntrls, topology) = eval(
"%s.create_system(options, full_system, system, dma_ports,\
ruby)"
% protocol
)
except:
print "Error: could not create sytem for ruby protocol %s" % protocol
raise
# Create the network topology
topology.makeTopology(options, network, IntLinkClass, ExtLinkClass, RouterClass)
# Initialize network based on topology
Network.init_network(options, network, InterfaceClass)
# Create a port proxy for connecting the system port. This is
# independent of the protocol and kept in the protocol-agnostic
# part (i.e. here).
sys_port_proxy = RubyPortProxy(ruby_system=ruby)
if piobus is not None:
sys_port_proxy.pio_master_port = piobus.slave
# Give the system port proxy a SimObject parent without creating a
# full-fledged controller
system.sys_port_proxy = sys_port_proxy
# Connect the system port for loading of binaries etc
system.system_port = system.sys_port_proxy.slave
setup_memory_controllers(system, ruby, dir_cntrls, options)
# Connect the cpu sequencers and the piobus
if piobus != None:
for cpu_seq in cpu_sequencers:
cpu_seq.pio_master_port = piobus.slave
cpu_seq.mem_master_port = piobus.slave
if buildEnv["TARGET_ISA"] == "x86":
cpu_seq.pio_slave_port = piobus.master
ruby.number_of_virtual_networks = ruby.network.number_of_virtual_networks
ruby._cpu_ports = cpu_sequencers
ruby.num_of_sequencers = len(cpu_sequencers)
# Create a backing copy of physical memory in case required
if options.access_backing_store:
ruby.access_backing_store = True
ruby.phys_mem = SimpleMemory(range=system.mem_ranges[0], in_addr_map=False)
开发者ID:uart,项目名称:gem5-mirror,代码行数:60,代码来源:Ruby.py
示例3: trainnetwork
def trainnetwork():
training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
network= Network([1200,30,10])
network.SGD(training_data,30,10,.5,test_data=test_data)
network.save("network.txt")
开发者ID:shivamgargsya,项目名称:Intelligent_Car,代码行数:7,代码来源:trainnetwork.py
示例4: set_response
def set_response(self):
if self.from_iso.is_network_request():
Network.set_response(self)
elif self.from_iso.is_transaction_request():
self.set_transaction_response()
elif self.from_iso.is_reversal_request():
self.set_reversal_response()
开发者ID:opensipkd,项目名称:iso8583-forwarder,代码行数:7,代码来源:__init__.py
示例5: generate_network_list
def generate_network_list(nn_param_choices):
"""Generate a list of all possible networks.
Args:
nn_param_choices (dict): The parameter choices
Returns:
networks (list): A list of network objects
"""
networks = []
# This is silly.
for nbn in nn_param_choices['nb_neurons']:
for nbl in nn_param_choices['nb_layers']:
for a in nn_param_choices['activation']:
for o in nn_param_choices['optimizer']:
# Set the parameters.
network = {
'nb_neurons': nbn,
'nb_layers': nbl,
'activation': a,
'optimizer': o,
}
# Instantiate a network object with set parameters.
network_obj = Network()
network_obj.create_set(network)
networks.append(network_obj)
return networks
开发者ID:namlehai,项目名称:neural-network-genetic-algorithm,代码行数:33,代码来源:brute.py
示例6: breed
def breed(self, mother, father):
"""Make two children as parts of their parents.
Args:
mother (dict): Network parameters
father (dict): Network parameters
Returns:
(list): Two network objects
"""
children = []
for _ in range(2):
child = {}
child['activation'] = random.choice([mother.network['activation'], father.network['activation']])
child['optimizer'] = random.choice([mother.network['optimizer'], father.network['optimizer']])
child['epochs'] = random.choice([mother.network['epochs'], father.network['epochs']])
layer_parent = random.choice([mother, father])
child['nb_layers'] = layer_parent.network['nb_layers']
child['nb_neurons'] = []
child['nb_neurons'].extend(layer_parent.network['nb_neurons'])
# Now create a network object.
network = Network(self.nn_param_choices)
network.create_set(child)
if self.mutate_chance > random.random():
network = self.mutate(network)
children.append(self.mutate(network))
return children
开发者ID:jsalatas,项目名称:HandsFreeWear,代码行数:35,代码来源:optimizer.py
示例7: NetworkServer
class NetworkServer(util.DaemonThread):
def __init__(self, config):
util.DaemonThread.__init__(self)
self.debug = False
self.config = config
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
self.request_id = 0
self.requests = {}
def add_client(self, client):
for key in ['status', 'banner', 'updated', 'servers', 'interfaces']:
value = self.network.get_status_value(key)
client.response_queue.put({'method':'network.status', 'params':[key, value]})
with self.lock:
self.clients.append(client)
print_error("new client:", len(self.clients))
def remove_client(self, client):
with self.lock:
self.clients.remove(client)
print_error("client quit:", len(self.clients))
def send_request(self, client, request):
with self.lock:
self.request_id += 1
self.requests[self.request_id] = (request['id'], client)
request['id'] = self.request_id
if self.debug:
print_error("-->", request)
self.pipe.send(request)
def run(self):
self.network.start()
while self.is_running():
try:
response = self.pipe.get()
except util.timeout:
continue
if self.debug:
print_error("<--", response)
response_id = response.get('id')
if response_id:
with self.lock:
client_id, client = self.requests.pop(response_id)
response['id'] = client_id
client.response_queue.put(response)
else:
# notification
m = response.get('method')
v = response.get('params')
for client in self.clients:
if m == 'network.status' or v in client.subscriptions.get(m, []):
client.response_queue.put(response)
self.network.stop()
print_error("server exiting")
开发者ID:DoctorBud,项目名称:electrum,代码行数:60,代码来源:daemon.py
示例8: train_mnist_worker
def train_mnist_worker(params):
net_id = params.get('net-id', 'nn')
layers = [784]
layers.extend([int(i) for i in params.get('layers', [15])])
layers.append(10)
net_params = {}
net_params['epochs'] = int(params.get('epochs', 1))
net_params['mini_batch_size'] = int(params.get('mini-batch-size', 4))
net_params['eta'] = float(params.get('eta', 0.1))
net_params['lmbda'] = float(params.get('lmbda', 0.0001))
net_params['layers'] = layers
redis.set(redis_key('params', net_id), json.dumps(net_params))
redis.set(redis_key('status', net_id), 'train_mnist: started')
net = Network(layers)
training_data, validation_data, test_data = load_data_wrapper()
redis.set(redis_key('status', net_id), 'train_mnist: training with mnist data')
net.SGD(training_data, net_params['epochs'],
net_params['mini_batch_size'],
net_params['eta'],
net_params['lmbda'])
redis.set(redis_key('data', net_id), net.tostring())
redis.set(redis_key('status', net_id), 'train_mnist: trained')
开发者ID:kressi,项目名称:neural_net,代码行数:25,代码来源:net_runner.py
示例9: train
def train(job_id, border, n_hidden_layer, eta):
print "Job ID: %d" % job_id
metric_recorder = MetricRecorder(config_dir_path='.', job_id=job_id)
C = {
'X_dirpath' : '../../../data/train/*',
'y_dirpath' : '../../../data/train_cleaned/',
'mini_batch_size' : 500,
'batchsize' : 500000,
'limit' : 30,
'epochs' : 100,
'patience' : 20000,
'patience_increase' : 2,
'improvement_threshold' : 0.995,
'validation_frequency' : 5000,
'lmbda' : 0.0,
'training_size' : None,
'validation_size' : None,
'algorithm' : 'RMSProp'
}
training_data = BatchProcessor(
X_dirpath='../../../data/train/*',
y_dirpath='../../../data/train_cleaned/',
batchsize=C['batchsize'],
border=border,
limit=C['limit'],
dtype=theano.config.floatX)
validation_data = BatchProcessor(
X_dirpath='../../../data/valid/*',
y_dirpath='../../../data/train_cleaned/',
batchsize=C['batchsize'],
border=border,
limit=C['limit'],
dtype=theano.config.floatX)
C['training_size'] = len(training_data)
C['validation_size'] = len(validation_data)
print "Training size: %d" % C['training_size']
print "Validation size: %d" % C['validation_size']
metric_recorder.add_experiment_metainfo(constants=C)
metric_recorder.start()
n_in = (2*border+1)**2
net = Network([FullyConnectedLayer(n_in=n_in, n_out=n_hidden_layer),
FullyConnectedLayer(n_in=n_hidden_layer, n_out=1)],
C['mini_batch_size'])
result = net.train(tdata=training_data, epochs=C['epochs'],
mbs=C['mini_batch_size'], eta=eta,
vdata=validation_data, lmbda=C['lmbda'],
momentum=None, patience_increase=C['patience_increase'],
improvement_threshold=C['improvement_threshold'],
validation_frequency=C['validation_frequency'],
metric_recorder=metric_recorder)
print 'Time = %f' % metric_recorder.stop()
print 'Result = %f' % result
return float(result)
开发者ID:codingluke,项目名称:ba-thesis-code,代码行数:60,代码来源:train.py
示例10: get_sample_from_network_file
def get_sample_from_network_file(network_file):
"""Given a network_file path, it creates the sample value as its id
1: 23.6438
2: 23.4968
...
>>> print get_sample_from_network_file('/Users/smcho/code/PyCharmProjects/contextAggregator/test_files/data/10_100_10_10/tree/tree10_10_2_0.txt')
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
"""
if not os.path.exists(network_file):
raise RuntimeError("No file %s exists" % network_file)
n = Network(network_file)
ids = n.get_host_ids()
result = []
for id in ids[0:-1]:
result.append("%d: %d\n" % (id, id))
result.append("%d: %d" % (ids[-1], ids[-1]))
return "".join(result)
开发者ID:prosseek,项目名称:Efficient-Decentralized-Context-Sharing-via-Aggregation-Simulation,代码行数:28,代码来源:utils.py
示例11: define_options
def define_options(parser):
# By default, ruby uses the simple timing cpu
parser.set_defaults(cpu_type="TimingSimpleCPU")
parser.add_option("--ruby-clock", action="store", type="string",
default='2GHz',
help="Clock for blocks running at Ruby system's speed")
parser.add_option("--access-backing-store", action="store_true", default=False,
help="Should ruby maintain a second copy of memory")
# Options related to cache structure
parser.add_option("--ports", action="store", type="int", default=4,
help="used of transitions per cycle which is a proxy \
for the number of ports.")
# network options are in network/Network.py
# ruby mapping options
parser.add_option("--numa-high-bit", type="int", default=0,
help="high order address bit to use for numa mapping. " \
"0 = highest bit, not specified = lowest bit")
parser.add_option("--recycle-latency", type="int", default=10,
help="Recycle latency for ruby controller input buffers")
protocol = buildEnv['PROTOCOL']
exec "import %s" % protocol
eval("%s.define_options(parser)" % protocol)
Network.define_options(parser)
开发者ID:MortezaRamezani,项目名称:gem5,代码行数:30,代码来源:Ruby.py
示例12: test_train
def test_train(self):
border = 2
mbs = 500
n_in = (2*border+1)**2
tdata = BatchProcessor(
X_dirpath=config.data_dir_path + 'train/*',
y_dirpath=config.data_dir_path + 'train_cleaned/',
batchsize=5000, border=border,
limit=1, dtype=theano.config.floatX,
random=True, random_mode='fully',
rnd=rnd)
vdata = BatchProcessor(
X_dirpath=config.data_dir_path + 'train/*',
y_dirpath=config.data_dir_path + 'train_cleaned/',
batchsize=5000, border=border,
limit=1, dtype=theano.config.floatX,
random=False, rnd=rnd)
net = Network([
FullyConnectedLayer(n_in=25, n_out=19, rnd=rnd),
FullyConnectedLayer(n_in=19, n_out=1, rnd=rnd),
], mbs)
cost = net.train(tdata=tdata, epochs=1, mbs=mbs, eta=0.1,
eta_min=0.01, vdata=vdata, lmbda=0.0,
momentum=0.95, patience_increase=2,
improvement_threshold=0.995,
validation_frequency=1, algorithm='rmsprop',
early_stoping=False)
self.assertTrue(float(cost) < 1.0)
开发者ID:codingluke,项目名称:ba-thesis-code,代码行数:28,代码来源:test_network.py
示例13: run_simulation
def run_simulation(network_dir, condition, test_sub_name, disconnection_rate=0.0, drop_rate=0.0, threshold=sys.maxint):
"""
Network directory should contain network and sample files
"""
test_name = os.path.basename(network_dir)
print "%s - %s - %s disconnect(%4.2f) drop(%4.2f) threshold(%d)" % (network_dir, test_name, test_sub_name, disconnection_rate, drop_rate, threshold)
network_file_path = os.path.join(network_dir, test_name + ".txt")
assert os.path.exists(network_file_path), "No network file %s exists " % network_file_path
sample_file_path = os.path.join(network_dir, test_name + ".sample.txt")
assert os.path.exists(sample_file_path), "No network file %s exists " % sample_file_path
network = Network(network_file_path)
host_ids = network.get_host_ids() # [h0, h1, h2]
hosts = []
for h in host_ids:
hosts.append(Host(h))
neighbors = network.get_network() # {0:[1], 1:[0,2], 2:[1]}
test_directory, sample = make_ready_for_test(network_dir=network_dir, test_name=test_name, condition=condition, test_sub_name=test_sub_name)
if test_sub_name.startswith("single"):
propagation_mode = ContextAggregator.SINGLE_ONLY_MODE
else:
propagation_mode = ContextAggregator.AGGREGATION_MODE
config = {"hosts":hosts, "neighbors":neighbors,
"test_directory":test_directory, "sample":sample,
"disconnection_rate":disconnection_rate, "drop_rate":drop_rate,
ContextAggregator.PM:propagation_mode,
"threshold":threshold}
simulation = AggregationSimulator.run(config=config)
return simulation
开发者ID:prosseek,项目名称:Efficient-Decentralized-Context-Sharing-via-Aggregation-Simulation,代码行数:32,代码来源:run_simulation.py
示例14: make_ready_for_test
def make_ready_for_test(network_dir, test_name, condition, test_sub_name):
"""
>>> test_files_directory = get_test_files_directory()
>>> result = make_ready_for_test(test_files_directory, "normal", "test1","aggregate")
>>> len(result) == 2
True
"""
sample_name = get_sample_name(test_name)
sample_file_path = os.path.join(network_dir, sample_name)
# There should be sample files
assert os.path.exists(sample_file_path), "No sample file at %s" % sample_file_path
net_file_path = os.path.join(network_dir, test_name + ".txt")
dot_file_path = net_file_path + ".dot"
if os.path.exists(net_file_path):
if not os.path.exists(dot_file_path):
n = Network(net_file_path)
dumb = n.dot_gen(dot_file_path)
# get the target root file
test_report_directory = network_dir + os.sep + condition
test_report_sub_directory = test_report_directory + os.sep + test_sub_name
if os.path.exists(test_report_sub_directory):
shutil.rmtree(test_report_sub_directory)
os.makedirs(test_report_sub_directory)
sample = Sample()
sample.read(sample_file_path)
return test_report_sub_directory, sample
开发者ID:prosseek,项目名称:Efficient-Decentralized-Context-Sharing-via-Aggregation-Simulation,代码行数:32,代码来源:run_simulation.py
示例15: breed
def breed(self, mother, father):
"""Make two children as parts of their parents.
Args:
mother (dict): Network parameters
father (dict): Network parameters
Returns:
(list): Two network objects
"""
children = []
for _ in range(2):
child = {}
# Loop through the parameters and pick params for the kid.
for param in self.nn_param_choices:
child[param] = random.choice(
[mother.network[param], father.network[param]]
)
# Now create a network object.
network = Network(self.nn_param_choices)
network.create_set(child)
# Randomly mutate some of the children.
if self.mutate_chance > random.random():
network = self.mutate(network)
children.append(network)
return children
开发者ID:namlehai,项目名称:neural-network-genetic-algorithm,代码行数:33,代码来源:optimizer.py
示例16: __init__
def __init__(self, scen_inst) :
Network.__init__(self, scen_inst)
''' For each node in the scenario '''
for node in self._scen_inst.get_nodes() :
''' Add a wireless interface to the node (eth0) '''
node.get('interfaces')['eth0'] = Model(type='wireless', range=20, ssid='wlan0')
开发者ID:di,项目名称:school,代码行数:7,代码来源:networkdef.py
示例17: Aging
class Aging(object):
'''
classdocs
'''
def __init__(self, run_num, cyclic_data):
'''
Aging class manages network through cycles.
'''
# The network of this aging instance.
self.network = Network(START_NUM_AGENT, cyclic_data)
# The instance that stores the cycle values for a network for all cycles.
# The array that keeps the number of agents to be added to the network for each cycle.
# The number of agents is determined randomly by poisson distribution.
self.agent_entry_array = random.poisson(LAMBDA_POISSON, NUMBER_OF_CYCLES + 1)
self.run_cycles(run_num, cyclic_data)
def run_cycles(self, run_num, cyclic_data):
for cycle in range(1, NUMBER_OF_CYCLES + 1):
cyclic_data.set_cycle(cycle)
self.network.plot_map(run_num, cycle - 1)
print "============== cycle =", cycle,", run =", str(run_num),"=================\r\r"
self.network.calculate_network()
# self.network.manage_exit()
number_entering_agents = self.agent_entry_array[cycle]
self.network.manage_breakthrough(number_entering_agents)
# print "POISSON = ", number_entering_agents
# self.network.manage_entry(number_entering_agents, cycle)
self.network.reset()
self.network.plot_map(run_num, cycle)
开发者ID:altay-oz,项目名称:tech_market_simulations,代码行数:30,代码来源:aging.py
示例18: test_send_message_correct_call_when_message_is_too_long
def test_send_message_correct_call_when_message_is_too_long(self):
message_content = ""
for i in range(256):
message_content += 'm'
assert len(message_content) == 256
with pytest.raises(ValueError):
Network.send_message(self.socket_mock, message_content)
开发者ID:chyla,项目名称:pat-lms,代码行数:8,代码来源:test_network.py
示例19: test_secret
def test_secret(self, config):
network = Network(config['server'], config['port'], config['secret'], config['verify_ssl'])
response = network.get_ip('test_domain')
res = response != 'connection_error' and response != 'wrong_secret'
if not res:
print "Could not verify secret."
return res
开发者ID:nivwusquorum,项目名称:private-domains,代码行数:8,代码来源:config.py
示例20: lambdas_to_plan
def lambdas_to_plan(game, d):
result = Network(game)
for slot, term in d.items():
term = parse_lambda(term)
term = binarize_term(term)
term = unfold_numbers(term)
result.add_goal(Goal(term, slot))
return result
开发者ID:Vlad-Shcherbina,项目名称:icfpc2011-tbd,代码行数:8,代码来源:network_bot.py
注:本文中的network.Network类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论