本文整理汇总了Python中system.System.solve方法的典型用法代码示例。如果您正苦于以下问题:Python System.solve方法的具体用法?Python System.solve怎么用?Python System.solve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类system.System
的用法示例。
在下文中一共展示了System.solve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from system import System [as 别名]
# 或者: from system.System import solve [as 别名]
def main(inp):
"""
Main interface
"""
if inp is None:
# generate basis of system
graph = nx.gnp_random_graph(10, 0.6)
dim = len(graph.nodes())
assert nx.is_connected(graph), 'Graph not connected'
orig_A = nx.to_numpy_matrix(graph)
orig_B = np.random.uniform(10, 20, size=dim)
nz = np.nonzero(orig_A)
orig_A[nz] = np.random.uniform(2, 5, size=len(nz[0]))
print('Original A:\n', orig_A)
print('Original B:', orig_B)
omega = 3
OMEGA_list = [2.9,3.05,3.1,3.2]#np.arange(3.7, 4.3, 0.05)
# generate solutions
data = []
for OMEGA in tqdm(OMEGA_list):
runs = []
for i in trange(dim):
mask = np.ones(dim, dtype=bool)
mask[i] = 0
Bvec = orig_B.copy()
Bvec[mask] = 0
syst = System(orig_A, Bvec, omega, OMEGA)
sols, ts = syst.solve(0.01, 100)
pdiffs = Reconstructor.extract_phase_differences(sols, ts, syst.Phi)
#print(pdiffs)
#System.plot_solution(syst.Phi(ts), sols, ts)
if pdiffs is not None:
runs.append(pdiffs)
if len(runs) > 0:
data.append(((OMEGA, omega), runs))
# cache results
fname = '{}_{}'.format(datetime.now().strftime('%Y%m%d%H%M%S'), dim)
np.save('cache/{}'.format(fname), {
'data': data,
'ts': ts,
'orig_A': orig_A,
'orig_B': orig_B
})
else:
data, ts = inp.item()['data'], inp.item()['ts']
orig_A, orig_B = inp.item()['orig_A'], inp.item()['orig_B']
dim = orig_A.shape[0]
print('Original A:\n', orig_A)
print('Original B:', orig_B)
# reconstruct parameters
recon = Reconstructor(ts, data, dim)
rec_A, rec_B = recon.reconstruct()
print('Reconstructed A:\n', rec_A)
print('Reconstructed B:', rec_B)
# plot result
bundle = DictWrapper({
'orig_A': orig_A,
'orig_B': orig_B,
'rec_A': rec_A,
'rec_B': rec_B
})
show_reconstruction_overview(bundle, verbose=dim < 20)