Skip to content

Commit

Permalink
Update reputation buying AND debugging info in Java RS
Browse files Browse the repository at this point in the history
  • Loading branch information
akolonin committed Sep 2, 2019
1 parent 852106b commit 18e12db
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
Binary file modified reputation/bin/Aigents.jar
Binary file not shown.
38 changes: 33 additions & 5 deletions reputation/reputation_buying.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get_prob_100(prob):
True - ratings with ratings values in range from 0.0 to 1.0 as values and respective financial transaction costs as weights
rs - reputation service as either AigentsAPIReputationService or AigentsCLIReputationService or any other
"""
def reputation_simulate(good_agent,bad_agent,since,sim_days,ratings,threshold=40,plro=100,rs=None,verbose=False,silent=False):
def reputation_simulate(good_agent,bad_agent,since,sim_days,ratings,threshold=40,plro=100,rs=None,verbose=False,silent=False,commission=2.0):
random.seed(1) # Make it deterministic
memories = {} # init blacklists of compromised ones
encounters = {} # init list of all encounters per agent
Expand All @@ -215,6 +215,8 @@ def reputation_simulate(good_agent,bad_agent,since,sim_days,ratings,threshold=40
actual_bad_volume = 0
actual_good_volume = 0
actual_good_to_bad_volume = 0
expected_good_volume = 0
entire_volume = 0

good_consumers = [i for i in range(good_agent['buyers'][0],good_agent['buyers'][1]+1)]
bad_consumers = [i for i in range(bad_agent['buyers'][0],bad_agent['buyers'][1]+1)]
Expand Down Expand Up @@ -261,6 +263,7 @@ def reputation_simulate(good_agent,bad_agent,since,sim_days,ratings,threshold=40
bad_agents_transactions = bad_agent['transactions']
good_agents_count = len(good_agents)
bad_agents_count = len(bad_agents)
good_consumers_count = len(good_consumers)
#good_agents_values = good_agent['values']
#bad_agents_values = bad_agent['values']
#good_agents_volume = good_agents_count * good_agents_transactions * good_agents_values[0]
Expand All @@ -271,12 +274,33 @@ def reputation_simulate(good_agent,bad_agent,since,sim_days,ratings,threshold=40
+ (('rs' if rs.get_parameters()['weighting'] == True else 'nw') if rs is not None else '')
transactions = 'transactions' + str(len(all_agents)) + '_' + code + '.tsv'


#assign qualities
all_qualities = [0.0, 0.25, 0.5, 0.75, 1.0]
good_seller_qualities = []
bad_seller_qualities = []
for quality in all_qualities:
if quality*100 >= threshold:
good_seller_qualities.append(quality)
else:
bad_seller_qualities.append(quality)

test_good_products = 0
costs = {}
qualities = {}
budgets = {}
for product in all_products:
costs[product] = 10
qualities[product] = rand_list(bad_agent['qualities']) if product in bad_agents else rand_list(good_agent['qualities'])
cost = 10 #TODO price categories
costs[product] = cost
quality = rand_list(bad_seller_qualities) if product in bad_products else rand_list(good_seller_qualities)
qualities[product] = quality
entire_volume += cost * good_consumers_count
if product in good_products:
expected_good_volume += cost * good_consumers_count
for consumer in good_consumers:
budgets[consumer] = budgets[consumer] + cost if consumer in budgets else cost
#print(qualities)
#print(budgets)
#print(test_good_products,expected_good_volume,bad_seller_qualities,good_seller_qualities)

#if verbose:
# print('Good:',len(good_agents),good_agents_values[0],good_agents_transactions,len(good_agents)*good_agents_values[0]*good_agents_transactions)
Expand Down Expand Up @@ -308,10 +332,14 @@ def reputation_simulate(good_agent,bad_agent,since,sim_days,ratings,threshold=40
for agent in good_consumers:
daily_selections = {}
for t in range(0, good_agents_transactions):
budget = budgets[agent]
if budget <= 0: # out of cash already
continue
other = pick_product(ranks,all_products,agent,memories,bad_agents,encounters,threshold)
if other is None:
continue
cost = costs[other]
budgets[agent] = budget - cost # subtract from budget
buys += 1
actual_good_volume += cost
# while ratings range is [0.0, 0.25, 0.5, 0.75, 1.0], we rank good agents as [0.25, 0.5, 0.75, 1.0]
Expand Down Expand Up @@ -374,4 +402,4 @@ def ratio_str(x,y,round_digits = None):

if silent is not True:
print('PLRo='+str(plro),'agents='+str(len(good_consumers))+'/'+str(len(bad_consumers))+'/'+str(len(good_products))+'/'+str(len(bad_products)),'days='+str(sim_days),end =" ")
print('Organic:',str(actual_good_volume),'Sponsored:',str(actual_bad_volume),'Organic2Sponsored:',actual_good_to_bad_volume,'Organic/Sponsored:',ratio_str(actual_good_volume,actual_bad_volume,2),'LTS:',ratio_str(actual_good_to_bad_volume,actual_good_volume,2),'PFS:',ratio_str(actual_good_to_bad_volume,actual_bad_volume,2))
print('Expect:',str(expected_good_volume),'Organ:',str(actual_good_volume),'Spons:',str(actual_bad_volume),'Organ2Spons:',actual_good_to_bad_volume,'Organ/Spons:',ratio_str(actual_good_volume,actual_bad_volume,2),'OMU:',ratio_str(actual_good_volume,expected_good_volume,2),'LTS:',ratio_str(actual_good_to_bad_volume,actual_good_volume,2),'PFS:',ratio_str(actual_good_to_bad_volume,actual_bad_volume*commission,2))
30 changes: 18 additions & 12 deletions reputation/reputation_buying_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ def dict_sorted(d):
return s


rs = AigentsAPIReputationService('http://localtest.com:1180/', '[email protected]', 'q', 'a', False, 'test', True)
#rs = PythonReputationService()
rs.set_parameters({'fullnorm':True,'weighting':False,'logratings':False,'denomination':False,'unrated':False,'default':0.5,'decayed':0.5,'conservatism':0.5,'ratings':1.0,'spendings':0.0})

verbose = False

good_transactions = 1
bad_transactions = 1
threshold = 40 # 3-4-5 stars
threshold = 60 # 4-5 stars
#threshold = 60 # 4-5 stars
#threshold = 80 # 5 stars

good_agent = {"buyers":[1,800], "products":[1001,1800], "qualities":[0.5,0.75,1.0], "transactions": good_transactions}
Expand All @@ -75,8 +69,13 @@ def dict_sorted(d):
#bad_agent = {"buyers":[4,5], "products":[9,10], "qualities":[0.0,0.25], "transactions": bad_transactions}
#days = 5

#rs = AigentsAPIReputationService('http://localtest.com:1180/', '[email protected]', 'q', 'a', False, 'test', True)
rs = PythonReputationService()
rs.set_parameters({'fullnorm':True,'weighting':False,'logratings':False,'denomination':False,'unrated':False,'default':0.5,'decayed':0.5,'conservatism':0.5,'ratings':1.0,'spendings':0.0})
verbose = False


"""
# Blending Anti-biased with Predictiveness
print("RS=Anti-biased_def5_dec5_c9", end =" ")
Expand Down Expand Up @@ -114,7 +113,7 @@ def dict_sorted(d):
print("RS=Pred+A-B_def5_dec5_c1", end =" ")
rs.set_parameters({'rating_bias':True,'predictiveness':1.0,'fullnorm':True,'weighting':True ,'logratings':False,'denomination':True ,'unrated':False ,'default':0.5,'decayed':0.5,'conservatism':0.1,'ratings':1.0,'spendings':0.0})
reputation_simulate(good_agent,bad_agent, datetime.date(2018, 1, 1), days, True, threshold, 30, rs, verbose)

"""

"""
# Exploring Anti-biased
Expand All @@ -132,16 +131,23 @@ def dict_sorted(d):
"""


"""

# Exploring threshold and PLRo

#print("RS=A-B_def5_dec5_c9", end =" ")
#rs.set_parameters({'rating_bias':True,'predictiveness':0.0,'fullnorm':True,'weighting':True ,'logratings':False,'denomination':True ,'unrated':False,'default':0.5,'decayed':0.5,'conservatism':0.9,'ratings':1.0,'spendings':0.0})
#print("RS=Pred_def5_dec5_c1", end =" ")
#rs.set_parameters({'rating_bias':False,'predictiveness':1.0,'fullnorm':True,'weighting':True ,'logratings':False,'denomination':True ,'unrated':False ,'default':0.5,'decayed':0.5,'conservatism':0.1,'ratings':1.0,'spendings':0.0})

for threshold in [40,60,80]:
print('threshold='+str(threshold))
reputation_simulate(good_agent,bad_agent, datetime.date(2018, 1, 1), days, True, threshold, 0, None, verbose)
reputation_simulate(good_agent,bad_agent, datetime.date(2018, 1, 1), days, True, threshold, 0, rs, verbose)
reputation_simulate(good_agent,bad_agent, datetime.date(2018, 1, 1), days, True, threshold, 25, rs, verbose)
reputation_simulate(good_agent,bad_agent, datetime.date(2018, 1, 1), days, True, threshold, 30, rs, verbose)
reputation_simulate(good_agent,bad_agent, datetime.date(2018, 1, 1), days, True, threshold, 50, rs, verbose)
reputation_simulate(good_agent,bad_agent, datetime.date(2018, 1, 1), days, True, threshold, 75, rs, verbose)
reputation_simulate(good_agent,bad_agent, datetime.date(2018, 1, 1), days, True, threshold, 70, rs, verbose)
reputation_simulate(good_agent,bad_agent, datetime.date(2018, 1, 1), days, True, threshold, 100, rs, verbose)
"""


"""
# Exploring PLRo-s and different RS-es except Predictive so far
Expand Down

0 comments on commit 18e12db

Please sign in to comment.