From a5f278c4cb0ae82b325eb172a793b7fca92b4860 Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Mon, 15 May 2023 16:19:05 +0800 Subject: [PATCH] experiment design --- __pycache__/computation.cpython-38.pyc | Bin 1546 -> 1546 bytes __pycache__/controller_db.cpython-38.pyc | Bin 6642 -> 6884 bytes __pycache__/firm.cpython-38.pyc | Bin 5719 -> 5736 bytes __pycache__/model.cpython-38.pyc | Bin 7705 -> 7897 bytes __pycache__/orm.cpython-38.pyc | Bin 3359 -> 3398 bytes conf_experiment.yaml | 2 -- controller_db.py | 32 ++++++++++++++++------- firm.py | 1 + model.py | 4 +++ oa.csv | 3 +++ orm.py | 5 ++-- xv.csv | 3 +++ 12 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 oa.csv create mode 100644 xv.csv diff --git a/__pycache__/computation.cpython-38.pyc b/__pycache__/computation.cpython-38.pyc index a9c363952314fa44abdfd9668fa257cc15457e91..b3f66d9b30de9cf424f5a36beddd81db23411371 100644 GIT binary patch delta 50 zcmeC;>EhuH<>lpK0D{2di7A>Jd8?TjWj1#*8!$4mY~ID<%*ZRt!N|hI!^FYJ0mJ|a CBnY1X delta 50 zcmeC;>EhuH<>lpK00Q@gi765rd8?Tjr8jpn8!$35Z{Ee?%*ZRl!N|hI!^FYJ0mK0R C-UwR& diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index e923c1bcd2cfad1fe0c7ea45f7e8588a08234409..526c82db299f8926f85d5e25b37225f6fdc6a4ad 100644 GIT binary patch delta 1610 zcmZ`&OKclO7@k?L*Xu{@_1jKE>pn0|TdKC9m#P)1nm(dFKu#gBq+M-2V`ZJSoz8Ak zH>?$eOCQi8%3MHDDZL@o11LS9N(doN+~KlUI3ZLCBo0(Sn19_zgv74q+kd|K|M{Q$ z``FKWldlX7#gKTe{$i2`)mzCCeD~J&#zBoB61LNNCirIc>`_D%61j{>q%Y|?nkVX< z#6F`r676HXK=E>s#O~nb(jBCi=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za@@Ggk3v17 zb)_k!X$v%sR5+t@l34}i7_J*~zzx>fyNjxh^UWd_B0UO z>kUr;oW(aIC0M{~k+X0PA4ZmsUr^4HDRBL(SA@JSsW8`PHX7Z$=t^By=kgRzM{_WZ zB6_Cy7Ae8%rZA%x((B#<#opO_9DTsx4ZIpZ=$})HHhvkOgeCkfz5(-CO$@{PxRsdA zn-o@2;06|JEA>Sob}2UNlwJ7o)&ub#ew4@kw$B zT6iRNBCN+*fa>1Y^}V-K407qJWj5OlQL;{!LZyGldI@XkLr}sy>D$FqYR9tQYqaZ= z!s=H2DxJTK<;)AkZxpqtJPmZn?;Cm?;)>BJ3~QPD^Yi38sGuB?&x?``(ykCtbLI1b z2IzU+`xBlZ%w4t2gSF zE&Ivo5CQ!sa*TlPTy7A2sKAX_wrSTFo5HTG@NQza$Vhi7Z{uv?bhy{hjblc{NQGX) ztwIeB;FH4K`R+?-n=Niy@;GhfSHE!ky31N^FIm@U3H#cLyu2nyXtS3I!UT87oALML eO!}kwtStS?% diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index 6edc95eb6a99e215b0b2392c95dab1cc3baacbac..46f7a845d240e154809fe3213ab7f11befc10c7f 100644 GIT binary patch delta 130 zcmcbv^FoI=l$V!_0SG2uOHA3ck$1k3g&L5T&QQY;D_6_d!BE4P#gNTb!~$k9X0sQu z07aN4G8M7}GZaYxm1;5fhtiA;qo z!3;$bKn0piMck902&wU~0Xb}pOpILrt8^y&ibza05dOxX-jDfEnJL5qH-`A4pcM-BOWv;!HWVReNb#`q5Gb}AMe>{ zF%|=fuqTb0Hc_LVBt7#FaPuZyI2tb|-n>Yi#h945$xObP@0;1(*?pebIUSk^2K_** z@@2++nAr^d(DB@cQN=O2Y^-5UMtvXgPIJrmm7~^t8(K$Pm4o3k7gUi><{`7v48Var z)Ug30Fqyu=Ty&Yk2!~d{!8)r!0};ycvfuWQl2?(qyz7x$VHZs~6zRG+x&kJ;+`+s- zT+;Q{!131G8&J^1uER|>2re%xga!5t1uJitw@HKfa6zZ|szUWh4dkmxZ{^R1rMTTu zkI{ymHOOIu5ehn(0f*aq4eId*R51mvMtN^O;p$Id4o#2AmkpH}A=cHYZNg4EdKHsk zvIN*&3jdp-4u;7bWm*zqkOa5lqXymil<76K9CLg``I3-hroP6+HnmKvld73GNJ^+j z)jjDJ`zms<3;y!u?f!%X(NcrYk6 zN`8Q_pbIr>w$93Y97K$y{T`tz#F%o2Rf36#!q>=sKrx}P5{gdc;^g+oEQ6c|4E^Ze zzt?+d!JI7)SoZ8uy$j%h4VFEWTJG*deak%+1dKQCzaYeOIjYXgQ-cjhhuAu6> z%T?_QLe?W$ik%$d0SsW6y0ezXIdb4F*5VW~js9dyV+O`ZLor5MoP|lvC{Jonb0@Zp z^u4Cy@7heY!K`v~vOUqjpUut0afV0bUe_v~kj3sd>D$Dfq6u0W0SyB!jYjY-pla^Q zW2y7#N|Abs)ACo!!uztE?o8T>JUDj16f;ZHrCEDvK@<+j*XfP6tRhRwJ(fc~N4yV= QkTE6ad*-nyKlhCO20X0R!vFvP delta 683 zcmYjNOKVd>6rMBpnWssbo7^;yjUctyg;FSJMT?5M@dee5ZHc`xaxbRd2Sj8>7wJkZ z+RmyA@m^3D-4w|>e;^B8+dm+R3thX2XB5$a^YP93&N=g)`E+`BF~6M4r3s#m{kHSr zFF0x#9rV7`P^CHrJWL z^!QLhJUuvInnM=|*L=yqqc0(#{@5R54Y&o*!21o!;v!STt77ZPp9g!DXeut_gBDY| zkWgef28)Dgk-?O>l8^z^2{$mWxm9lBh-zdr+}|b+t&*rF`TrTLPC1mxFlBV2Ro`XSduqsB45FUx+P0J3Y_}gOE3EKU&UMK2r i1YTXNHg__2q(VbEPpC`) diff --git a/__pycache__/orm.cpython-38.pyc b/__pycache__/orm.cpython-38.pyc index 90978242ab591d8527d546b0682c6b873a2bbc15..2005766c736a73967a28f86f216e3cd1a6139b10 100644 GIT binary patch delta 266 zcmbO)bxevcl$V!_0SJ6wB&KljZ{%}gW}GxRkhwsSHI*%eC55$@DM}z!FoivZBZV`C ztCu-SD1|$Pr-dO(c=I)89Y#jm$;_;Zj3Sd&Sv?GSGE*wzi<49H5{okPqXa;_%)HE! z_@dO@{IbNHD2}}N;>6s7oYY%vdGVPgsYR2gup02*;?9fDO{|D7DauUDnS6v*TSg1$ zo?ChP86!6fb01;k zasz4uDr3}Pn*5MQN{x$=4FdnLu<|gnF|hq-W8q=sU}9t9Viph=kPr~!0@?upp=m!~ delta 247 zcmX>mHD8J^l$V!_0SGD=CZ=ffZRB%eW^9`r$Xp;QkiwqAk;0k6)yo_un8KaH)4~uX zwD}RU4kM$*WPVmfM&ZeZtRCv@nJE?VsTBoL9C`7@iMa(iskhkj;xkK9i*9k}#pfng z#FrFhCgx0D#cDA5Ijgpm8qls{86d&I$i>LV#KX+P2*!*8oAuZ(Ffs;A{?GoN(Pr~| zjvhwFq{%g0yBR|^TW}v?^l$-c5@6(E)B$1;&B4qCG=hVXg^`O%hzZ0NVisUzV*tYc bEKEEg)_*n@pgJZtCN5?HF#!nyA&@EnoG~+V diff --git a/conf_experiment.yaml b/conf_experiment.yaml index 5e04018..0137445 100644 --- a/conf_experiment.yaml +++ b/conf_experiment.yaml @@ -6,9 +6,7 @@ meta_seed: 0 test: # only for test scenarios n_sample: 1 n_iter: 20 - n_max_trial: 10 not_test: # normal scenarios n_sample: 50 n_iter: 20 - n_max_trial: 10 diff --git a/controller_db.py b/controller_db.py index 0f4052a..4931aa7 100644 --- a/controller_db.py +++ b/controller_db.py @@ -72,20 +72,34 @@ class ControllerDB: g_product_js = json.dumps(nx.adjacency_data(g_bom)) # insert exp - for idx_exp, dct in enumerate(list_dct): - self.add_experiment_1(idx_exp, self.dct_parameter['n_max_trial'], - dct, g_product_js) # same g_bom for all exp - print(f'Inserted experiment for exp {idx_exp}!') + df_xv = pd.read_csv("xv.csv", index_col=None) + # read the OA table + df_oa = pd.read_fwf("oa.csv", index_col=None) + for idx_scenario, row in df_oa.iterrows(): + dct_exp_para = {} + for idx_col, para_level in enumerate(row): + dct_exp_para[df_xv.columns[idx_col]] = \ + df_xv.iloc[para_level, idx_col] + # different initial removal + for idx_init_removal, dct_init_removal in enumerate(list_dct): + self.add_experiment_1(idx_scenario, + idx_init_removal, + dct_init_removal, + g_product_js, + **dct_exp_para) + print(f"Inserted experiment for scenario {idx_scenario}, " + f"init_removal {idx_init_removal}!") - def add_experiment_1(self, idx_exp, n_max_trial, - dct_lst_init_remove_firm_prod, g_bom): + def add_experiment_1(self, idx_scenario, idx_init_removal, + dct_lst_init_remove_firm_prod, g_bom, n_max_trial): e = Experiment( - idx_exp=idx_exp, + idx_scenario=idx_scenario, + idx_init_removal=idx_init_removal, n_sample=int(self.dct_parameter['n_sample']), n_iter=int(self.dct_parameter['n_iter']), - n_max_trial=n_max_trial, dct_lst_init_remove_firm_prod=dct_lst_init_remove_firm_prod, - g_bom=g_bom) + g_bom=g_bom, + n_max_trial=n_max_trial) db_session.add(e) db_session.commit() diff --git a/firm.py b/firm.py index bb4f4e3..05c0b7e 100644 --- a/firm.py +++ b/firm.py @@ -157,6 +157,7 @@ class FirmAgent(ap.Agent): lst_firm_size = [ firm.revenue_log for firm in self.model.a_lst_total_firms if product in firm.a_lst_product + and product not in firm.a_lst_product_removed ] prod_accept = self.revenue_log / sum(lst_firm_size) if self.model.nprandom.choice([True, False], diff --git a/model.py b/model.py index fc6754f..1c47f75 100644 --- a/model.py +++ b/model.py @@ -220,6 +220,10 @@ class Model(ap.Model): lost_percent = n_up_product_removed / len( product.a_predecessors()) lst_size = self.a_lst_total_firms.revenue_log + lst_size = [firm.revenue_log for firm in self.a_lst_total_firms + if product in firm.a_lst_product + and product not in firm.a_lst_product_removed + ] std_size = (firm.revenue_log - min(lst_size) + 1) / (max(lst_size) - min(lst_size) + 1) prod_remove = 1 - std_size * (1 - lost_percent) diff --git a/oa.csv b/oa.csv new file mode 100644 index 0000000..f2b804b --- /dev/null +++ b/oa.csv @@ -0,0 +1,3 @@ +X1 +0 +1 diff --git a/orm.py b/orm.py index 9779f80..3b90e57 100644 --- a/orm.py +++ b/orm.py @@ -43,16 +43,17 @@ class Experiment(Base): __tablename__ = f"{db_name_prefix}_experiment" id = Column(Integer, primary_key=True, autoincrement=True) - idx_exp = Column(Integer, nullable=False) + idx_scenario = Column(Integer, nullable=False) + idx_init_removal = Column(Integer, nullable=False) # fixed parameters n_sample = Column(Integer, nullable=False) n_iter = Column(Integer, nullable=False) # variables - n_max_trial = Column(Integer, nullable=False) dct_lst_init_remove_firm_prod = Column(PickleType, nullable=False) g_bom = Column(Text(4294000000), nullable=False) + n_max_trial = Column(Integer, nullable=False) sample = relationship( 'Sample', back_populates='experiment', lazy='dynamic') diff --git a/xv.csv b/xv.csv new file mode 100644 index 0000000..1459667 --- /dev/null +++ b/xv.csv @@ -0,0 +1,3 @@ +n_max_trial +5 +10