DeprecationWarningの解決

前提・実現したいこと

PythonにてSIRモデルの作成をしています.
random.sampleを用いてネットワークから重複無しでランダムにノードを抽出したところ,以下のエラーが出ました.
サポートが受けられなくなること以外に不具合は起きるのかどうかという点について教えていただきたいです.
また,プログラム自体は動くので問題ないのですが,同様の処理を行う操作があればそれについても教えていただきたいです.

発生している問題・エラーメッセージ

***の部分はPCのユーザーネームです

C:\Users\***\AppData\Local\Temp/ipykernel_15232/3309964543.py:61: DeprecationWarning: Sampling from a set deprecated since Python 3.9 and will be removed in a subsequent version. posibility_id1 = random.sample(self.network.nodes, l) C:\Users\***\AppData\Local\Temp/ipykernel_15232/3309964543.py:62: DeprecationWarning: Sampling from a set deprecated since Python 3.9 and will be removed in a subsequent version. posibility_id2 = random.sample(self.network.nodes, m) C:\Users\***\AppData\Local\Temp/ipykernel_15232/3309964543.py:63: DeprecationWarning: Sampling from a set deprecated since Python 3.9 and will be removed in a subsequent version. posibility_id3 = random.sample(self.network.nodes, n)

該当のソースコード

元のコードが長いので一部のみ記載させていただきます

Python

from enum import Enum import random import networkx as nx import numpy as np class State(Enum): I1 = 'Infection1' I2 = 'Infection2' I3 = 'Infection3' S = 'Susceptible' R = 'Recovered' class SirModel: def __init__(self, N=80000, m=22): self.N = N # ネットワーク設定 self.network = nx.barabasi_albert_graph(N, m) self.infection1_nodes = [] self.infection2_nodes = [] self.infection3_nodes = [] self.recovered_nodes = [] def init_source(self, l=1, m=1, n=1): for i in range(self.N): self.network.nodes[i]['state'] = State.S posibility_id1 = random.sample(self.network.nodes, l) posibility_id2 = random.sample(self.network.nodes, m) posibility_id3 = random.sample(self.network.nodes, n) for i in posibility_id1: self.network.nodes[i]['state'] = State.I1 self.infection1_nodes.append(i) for j in posibility_id2: self.network.nodes[j]['state'] = State.I2 self.infection2_nodes.append(j) for k in posibility_id3: self.network.nodes[k]['state'] = State.I3 self.infection3_nodes.append(k)

試したこと

ネットで検索

補足情報(FW/ツールのバージョンなど)

Pytohn3, Jupyter Notebook

コメントを投稿

0 コメント