damp prob removal first than sample

This commit is contained in:
HaoYizhi 2023-06-10 19:02:43 +08:00
parent 0e40f90559
commit a8259fdc7d
3 changed files with 2 additions and 4 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,6 @@
import agentpy as ap import agentpy as ap
import pandas as pd import pandas as pd
import numpy as np import numpy as np
# import random
import networkx as nx import networkx as nx
from firm import FirmAgent from firm import FirmAgent
from product import ProductAgent from product import ProductAgent
@ -14,7 +13,6 @@ class Model(ap.Model):
def setup(self): def setup(self):
self.sample = self.p.sample self.sample = self.p.sample
self.int_stop_times, self.int_stop_t = 0, None self.int_stop_times, self.int_stop_t = 0, None
# self.random = random.Random(self.p.seed)
self.nprandom = np.random.default_rng(self.p.seed) self.nprandom = np.random.default_rng(self.p.seed)
self.int_n_iter = int(self.p.n_iter) self.int_n_iter = int(self.p.n_iter)
@ -373,13 +371,13 @@ class Model(ap.Model):
std_size = (firm.revenue_log - min(lst_size) + std_size = (firm.revenue_log - min(lst_size) +
1) / (max(lst_size) - min(lst_size) + 1) 1) / (max(lst_size) - min(lst_size) + 1)
prob_remove = 1 - std_size * (1 - lost_percent) prob_remove = 1 - std_size * (1 - lost_percent)
# damp prod
prob_remove = prob_remove ** self.flt_diff_remove
# sample prob # sample prob
prob_remove = self.nprandom.uniform( prob_remove = self.nprandom.uniform(
prob_remove - 0.1, prob_remove + 0.1) prob_remove - 0.1, prob_remove + 0.1)
prob_remove = 1 if prob_remove > 1 else prob_remove prob_remove = 1 if prob_remove > 1 else prob_remove
prob_remove = 0 if prob_remove < 0 else prob_remove prob_remove = 0 if prob_remove < 0 else prob_remove
# damp prod
prob_remove = prob_remove ** self.flt_diff_remove
if self.nprandom.choice([True, False], if self.nprandom.choice([True, False],
p=[prob_remove, p=[prob_remove,
1 - prob_remove]): 1 - prob_remove]):