Answered step by step
Verified Expert Solution
Question
1 Approved Answer
how do I pass in changes to config using set_initial_status or any other way? I need to set model parameters and am not sure how
how do I pass in changes to config using set_initial_status or any other way? I need to set model parameters and am not sure how to do that. I am not familiar with Python classes and everything I try gives me an error.
from tqdm import tqdm class VolatileThreshold: def __init__(self, graph): self.G = graph self.config = None self.status = {n: 0 for n in graph.nodes} self.threshold = {n: 0 for n in graph.nodes} self.num_sample = 0 # since the graph is connected self.N = len(graph.nodes) def set_initial_status(self, config): self.config = config # set threshold thred = config.__dict__['config']['nodes']['threshold'] for n in self.G.nodes: self.threshold[n] = thred[n] # set number of samples self.num_sample = config.__dict__['config']['model']['num_sample'] # set seed nodes if 'fraction_infected' in config.__dict__['config']['model']: seed_nodes = random.sample( self.G.nodes(), int(config.__dict__['config']['model']['fraction_infected'] * len(self.G.nodes()))) else: seed_nodes = config.__dict__['config']['status']['Infected'] for n in seed_nodes: self.status[n] = 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started