本文整理匯總了Python中net.Net.calculate_outputs方法的典型用法代碼示例。如果您正苦於以下問題:Python Net.calculate_outputs方法的具體用法?Python Net.calculate_outputs怎麽用?Python Net.calculate_outputs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.Net
的用法示例。
在下文中一共展示了Net.calculate_outputs方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: IscasOracleOld
# 需要導入模塊: from net import Net [as 別名]
# 或者: from net.Net import calculate_outputs [as 別名]
class IscasOracleOld(IscasOracle):
def __init__(self, sisc_file, inputs, mutated_gates, **options):
super(IscasOracleOld, self).__init__(None, [], [], **options)
self.sisc_file = sisc_file
self.mutated_gates = mutated_gates
self.net = Net(*SimpleParser(open(sisc_file)).parse(), **options)
for c,i in enumerate(self.net.inputs):
self.net.inputs[i] = inputs[c] == 1
orig_gates = self.net.mutate_net(mutated_gates)
self.net.calculate_outputs()
self.net.mutate_net(orig_gates)
self.comp_calls = 0
self.check_calls = 0
self.comp_time = 0
self.check_time = 0
self.scs = set()
self.components = TwoWayDict(dict(enumerate(self.net.gates.keys())))
def setup_net(self):
pass
示例2: generate_iscas_faults
# 需要導入模塊: from net import Net [as 別名]
# 或者: from net.Net import calculate_outputs [as 別名]
def generate_iscas_faults(file, num_mutated_gates):
net = Net(*SimpleParser(open(file)).parse())
net.generate_random_inputs()
net.calculate_outputs()
original_outputs = dict(net.outputs)
tries = 0
while tries < 100:
gates = random.sample(net.gates.values(), num_mutated_gates)
mutated_gates = []
tries += 1
for g in gates:
m = Gate(*g)
m.type = GATE_MUTATION[m.type]
mutated_gates.append(m)
original_gates = net.mutate_net(mutated_gates)
net.reset_outputs()
net.calculate_outputs()
net.mutate_net(original_gates)
if net.outputs != original_outputs:
return [file, net.input_values_compact(), mutated_gates]
print "Failed to generate fault for " + file + " within 100 tries."
net.finished()
示例3: generate_independent_faults
# 需要導入模塊: from net import Net [as 別名]
# 或者: from net.Net import calculate_outputs [as 別名]
def generate_independent_faults(file, num_gates_to_mutate, exclude_gates=[]):
net = Net(*SimpleParser(open(file)).parse())
if len(net.outputs) < num_gates_to_mutate:
net.finished()
raise Exception("Cannot create %d independent mutations for net with %d outputs" % (num_gates_to_mutate, len(net.outputs)))
try_num = 1
log.info("Trying to generate %d independent fault(s) for %s" % (num_gates_to_mutate, file))
while try_num < 2*(2**len(net.inputs)): # try about two times the number of possible input combinations
try_num += 1
net.generate_random_inputs()
log.debug("=== Trying input %s" % net.inputs)
net.reset_outputs() # unconstrain all outputs at the beginning
net.calculate_outputs()
previous_outputs = dict(net.outputs)
log.debug("Original Outputs: %s" % previous_outputs)
net.reset_outputs()
gates_to_try = filter(lambda g: g.output not in exclude_gates, net.gates.values())
mutated_gates = []
immutable_outputs = set()
while len(mutated_gates) < num_gates_to_mutate:
while gates_to_try:
log.debug("Previous output: %s" % previous_outputs)
random.shuffle(gates_to_try)
gate = gates_to_try.pop()
mutated_gate = Gate(*gate)
mutated_gate.type = GATE_MUTATION[mutated_gate.type]
log.debug("Mutating %s to %s" % (gate, mutated_gate))
net.mutate_net([mutated_gate])
if not net.calculate_outputs():
log.debug("Unsatisfiable, undoing mutation.")
net.mutate_net([gate]) # restore original gate
break
new_outputs = dict(net.outputs)
log.debug("New output: %s" % new_outputs)
changed_outputs = set([g for g in new_outputs if new_outputs[g] != previous_outputs[g]])
if changed_outputs:
log.debug("found mutation")
immutable_outputs |= changed_outputs
log.debug("Immutable outputs: %s" % immutable_outputs)
mutated_gates.append(mutated_gate)
previous_outputs = new_outputs
for o in net.outputs: # unconstrain all outputs that didn't change
if o not in immutable_outputs:
net.outputs[o] = None
break
else:
log.debug("undoing mutation, trying next")
net.mutate_net([gate])
for o in net.outputs: # unconstrain all outputs that didn't change (in the last step)
if o not in immutable_outputs:
net.outputs[o] = None
# end while gates_to_try
if not gates_to_try and len(mutated_gates) < num_gates_to_mutate:
log.debug("no more gates to try :(")
break
# end while len(mutated_gates) < num_gates_to_mutate:
if not len(mutated_gates) < num_gates_to_mutate:
break
net.finished()
# end while try_num < 2*(2**len(net.inputs)):
if len(mutated_gates) < num_gates_to_mutate:
return None
return [file, net.input_values_compact(), mutated_gates]