Upload files to ''

This commit is contained in:
Jakub Pogodziński 2022-01-23 19:00:30 +01:00
parent 2452afa6b4
commit 3d1e44418f

196
main.py
View File

@ -15,14 +15,14 @@ def fuzzy(goalsV, xGPerMatchV, shotsPerMatchV, onTargetPerMatchV):
goals_md = fuzz.trimf(goals, [10, 15, 20])
goals_hi = fuzz.trapmf(goals, [15, 20, 35, 100])
xGPerMatch_lo = fuzz.trapmf(xGPerMatch, [0, 0, 0.2, 0.5])
xGPerMatch_md = fuzz.trimf(xGPerMatch, [0.2, 0.5, 0.7])
xGPerMatch_hi = fuzz.trapmf(xGPerMatch, [0.5, 0.7, 2, 10])
xGPerMatch_md = fuzz.trapmf(xGPerMatch, [0.2, 0.5, 0.7, 1])
xGPerMatch_hi = fuzz.trapmf(xGPerMatch, [0.75, 1, 2, 10])
shotsPerMatch_lo = fuzz.trapmf(shotsPerMatch, [0, 0, 1, 2])
shotsPerMatch_md = fuzz.trapmf(shotsPerMatch, [1, 2, 3, 4])
shotsPerMatch_hi = fuzz.trapmf(shotsPerMatch, [3, 4, 4.5, 10])
onTargetPerMatch_lo = fuzz.trapmf(onTargetPerMatch, [0, 0, 0.5, 1])
onTargetPerMatch_md = fuzz.trimf(onTargetPerMatch, [0.5, 1, 1.5])
onTargetPerMatch_hi = fuzz.trimf(onTargetPerMatch, [1, 1.5, 5])
onTargetPerMatch_lo = fuzz.trapmf(onTargetPerMatch, [0, 0, 0.25, 0.75])
onTargetPerMatch_md = fuzz.trapmf(onTargetPerMatch, [0.25,0.5, 1, 1.25])
onTargetPerMatch_hi = fuzz.trapmf(onTargetPerMatch, [1, 1.5,3.5, 5])
ocena_lo = fuzz.trapmf(ocena, [0, 0, 40, 50])
ocena_md = fuzz.trapmf(ocena, [40, 50, 60, 80])
ocena_hi = fuzz.trapmf(ocena, [70, 80, 100, 100])
@ -90,19 +90,26 @@ def fuzzy(goalsV, xGPerMatchV, shotsPerMatchV, onTargetPerMatchV):
onTargetPerMatch_level_md = fuzz.interp_membership(onTargetPerMatch, onTargetPerMatch_md, onTargetPerMatch_value)
onTargetPerMatch_level_hi = fuzz.interp_membership(onTargetPerMatch, onTargetPerMatch_hi, onTargetPerMatch_value)
#fmax OR
#fmin AND
active_rule1 = np.fmax(goals_level_hi, xGPerMatch_level_hi)
active_rule2 = np.fmax(active_rule1, onTargetPerMatch_level_hi)
ocena_activation_hi = np.fmin(active_rule2, ocena_hi) # removed entirely to 0
active_rule3 = np.fmax(np.fmin(goals_level_lo, xGPerMatch_level_hi),
np.fmin(goals_level_lo, shotsPerMatch_level_hi))
active_rule4=np.fmax(np.fmin(goals_level_md, xGPerMatch_level_md), np.fmin(goals_level_md, shotsPerMatch_level_md))
active_rule3=np.fmin(onTargetPerMatch_level_md,goals_level_md)
active_rule4=np.fmin(xGPerMatch_level_hi,goals_level_md)
active_rule5=np.fmax(active_rule3,active_rule4)
ocena_activation_md = np.fmin(active_rule5, ocena_md)
active_rule6=np.fmin(onTargetPerMatch_level_hi,goals_level_lo)
active_rule7=np.fmax(active_rule5,active_rule6)
ocena_activation_md = np.fmin(active_rule7, ocena_md)
ocena_activation_lo = np.fmin(goals_level_lo, ocena_lo)
active_rule8=np.fmin(shotsPerMatch_level_hi,onTargetPerMatch_level_lo)
active_rule9=np.fmin(xGPerMatch_level_hi,goals_level_md)
active_rule10=np.fmax(active_rule8,active_rule9)
active_rule11=np.fmax(active_rule10,goals_level_lo)
ocena_activation_lo = np.fmin(active_rule11, ocena_lo)
ocena0 = np.zeros_like(ocena)
#
@ -153,6 +160,160 @@ def fuzzy(goalsV, xGPerMatchV, shotsPerMatchV, onTargetPerMatchV):
return ocena_output
def fuzzy2(season_rateV, ageV, market_valueV):
season_rate = np.arange(0, 101, 1)
age = np.arange(15, 50, 1)
market_value = np.arange(0, 200, 0.5)
transfer_rate = np.arange(0, 101, 1)
season_rate_lo = fuzz.trapmf(season_rate, [0, 0, 40, 50])
season_rate_md = fuzz.trapmf(season_rate, [40, 50, 60,80])
season_rate_hi = fuzz.trapmf(season_rate, [70, 80, 100, 100])
age_lo = fuzz.trapmf(age, [15, 15, 20, 25])
age_md = fuzz.trapmf(age, [20, 25, 28, 30])
age_hi = fuzz.trapmf(age, [28, 30, 40, 100])
market_value_lo = fuzz.trapmf(market_value, [0, 0, 15, 40])
market_value_md = fuzz.trimf(market_value, [30, 50, 80])
market_value_hi = fuzz.trapmf(market_value, [70, 80, 180, 1000])
transfer_rate_lo = fuzz.trapmf(transfer_rate, [0, 0, 40, 50])
transfer_rate_md = fuzz.trapmf(transfer_rate, [40, 50, 60, 80])
transfer_rate_hi = fuzz.trapmf(transfer_rate, [70, 80, 100, 100])
#
# fig, (ax0, ax1, ax2, ax3, ax4) = plt.subplots(nrows=5, figsize=(8, 9))
#
# ax0.plot(season_rate, season_rate_lo, 'b', linewidth=1.5, label='Mało')
# ax0.plot(season_rate, season_rate_md, 'g', linewidth=1.5, label='Średnio')
# ax0.plot(season_rate, season_rate_hi, 'r', linewidth=1.5, label='Dużo')
# ax0.set_title('Liczba bramek')
# ax0.legend()
#
# ax1.plot(age, age_lo, 'b', linewidth=1.5, label='Mało')
# ax1.plot(age, age_md, 'g', linewidth=1.5, label='Średno')
# ax1.plot(age, age_hi, 'r', linewidth=1.5, label='Dużo')
# ax1.set_title('Service quality')
# ax1.legend()
#
# ax2.plot(market_value, market_value_lo, 'b', linewidth=1.5, label='Mało')
# ax2.plot(market_value, market_value_md, 'g', linewidth=1.5, label='Średnio')
# ax2.plot(market_value, market_value_hi, 'r', linewidth=1.5, label='Dużo')
# ax2.set_title('Strzały na mecz')
# ax2.legend()
#
# ax3.plot(onTargetPerMatch, onTargetPerMatch_lo, 'b', linewidth=1.5, label='Mało')
# ax3.plot(onTargetPerMatch, onTargetPerMatch_md, 'g', linewidth=1.5, label='Średnio')
# ax3.plot(onTargetPerMatch, onTargetPerMatch_hi, 'r', linewidth=1.5, label='Dużo')
# ax3.set_title('Strzały w światlo bramki na mecz')
# ax3.legend()
#
# ax4.plot(transfer_rate, transfer_rate_lo, 'b', linewidth=1.5, label='Niska')
# ax4.plot(transfer_rate, transfer_rate_md, 'g', linewidth=1.5, label='Średnia')
# ax4.plot(transfer_rate, transfer_rate_hi, 'r', linewidth=1.5, label='Wysoka')
# ax4.set_title('Ocena')
# ax4.legend()
#
# # Turn off top/right axes
# for ax in (ax0, ax1, ax2, ax3, ax4):
# ax.spines['top'].set_visible(False)
# ax.spines['right'].set_visible(False)
# ax.get_xaxis().tick_bottom()
# ax.get_yaxis().tick_left()
#
# plt.tight_layout()
season_rate_value = season_rateV
age_value = ageV
market_value_value = market_valueV
season_rate_level_lo = fuzz.interp_membership(season_rate, season_rate_lo, season_rate_value)
season_rate_level_md = fuzz.interp_membership(season_rate, season_rate_md, season_rate_value)
season_rate_level_hi = fuzz.interp_membership(season_rate, season_rate_hi, season_rate_value)
age_level_lo = fuzz.interp_membership(age, age_lo, age_value)
age_level_md = fuzz.interp_membership(age, age_md, age_value)
age_level_hi = fuzz.interp_membership(age, age_hi, age_value)
market_value_level_lo = fuzz.interp_membership(market_value, market_value_lo, market_value_value)
market_value_level_md = fuzz.interp_membership(market_value, market_value_md, market_value_value)
market_value_level_hi = fuzz.interp_membership(market_value, market_value_hi, market_value_value)
#fmax OR
#fmin AND
active_rule1=np.fmin(season_rate_level_hi, age_level_lo)
active_rule2=np.fmin(season_rate_level_hi, market_value_level_md)
active_rule3=np.fmin(season_rate_level_hi, age_level_md)
active_rule4=np.fmax(active_rule1,active_rule2)
active_rule5=np.fmax(active_rule3,active_rule4)
transfer_rate_activation_hi = np.fmin(active_rule5, transfer_rate_hi) # removed entirely to 0
active_rule6=np.fmin(season_rate_level_md,age_level_lo)
active_rule7=np.fmin(season_rate_level_md, market_value_level_lo)
active_rule8=np.fmin(market_value_level_lo, age_level_lo)
active_rule9=np.fmin(age_level_hi,market_value_level_lo)
active_rule10=np.fmax(active_rule6,active_rule7)
active_rule11=np.fmax(active_rule8,active_rule9)
active_rule12=np.fmax(active_rule10,active_rule11)
transfer_rate_activation_md = np.fmin(active_rule12, transfer_rate_md)
active_rule13=np.fmin(age_level_hi, market_value_level_hi)
active_rule14=np.fmin(age_level_md,season_rate_md)
active_rule15=np.fmax(active_rule13,season_rate_level_lo)
active_rule16=np.fmax(active_rule14,active_rule15)
transfer_rate_activation_lo = np.fmin(active_rule16, transfer_rate_lo)
transfer_rate0 = np.zeros_like(transfer_rate)
#
# fig, ax0 = plt.subplots(figsize=(8, 3))
#
# ax0.fill_between(transfer_rate, transfer_rate0, transfer_rate_activation_lo, facecolor='b', alpha=0.7)
# ax0.plot(transfer_rate, transfer_rate_lo, 'b', linewidth=0.5, linestyle='--', )
# ax0.fill_between(transfer_rate, transfer_rate0, transfer_rate_activation_md, facecolor='g', alpha=0.7)
# ax0.plot(transfer_rate, transfer_rate_md, 'g', linewidth=0.5, linestyle='--')
# ax0.fill_between(transfer_rate, transfer_rate0, transfer_rate_activation_hi, facecolor='r', alpha=0.7)
# ax0.plot(transfer_rate, transfer_rate_hi, 'r', linewidth=0.5, linestyle='--')
# ax0.set_title('Output membership activity')
#
# # Turn off top/right axes
# for ax in (ax0,):
# ax.spines['top'].set_visible(False)
# ax.spines['right'].set_visible(False)
# ax.get_xaxis().tick_bottom()
# ax.get_yaxis().tick_left()
#
# plt.tight_layout()
aggregated = np.fmax(transfer_rate_activation_lo,
np.fmax(transfer_rate_activation_md, transfer_rate_activation_hi))
# Calculate defuzzified result
transfer_rate_output = fuzz.defuzz(transfer_rate, aggregated, 'centroid')
Transfer_rate_activation = fuzz.interp_membership(transfer_rate, aggregated, transfer_rate_output) # for plot
# # Visualize this
# fig, ax0 = plt.subplots(figsize=(8, 3))
#
# ax0.plot(transfer_rate, transfer_rate_lo, 'b', linewidth=0.5, linestyle='--', )
# ax0.plot(transfer_rate, transfer_rate_md, 'g', linewidth=0.5, linestyle='--')
# ax0.plot(transfer_rate, transfer_rate_hi, 'r', linewidth=0.5, linestyle='--')
# ax0.fill_between(transfer_rate, transfer_rate0, aggregated, facecolor='Orange', alpha=0.7)
# ax0.plot([transfer_rate_output, transfer_rate_output], [0, Transfer_rate_activation], 'k', linewidth=1.5, alpha=0.9)
# ax0.set_title('Aggregated membership and result (line)')
#
# # Turn off top/right axes
# for ax in (ax0,):
# ax.spines['top'].set_visible(False)
# ax.spines['right'].set_visible(False)
# ax.get_xaxis().tick_bottom()
# ax.get_yaxis().tick_left()
#
# plt.tight_layout()
return transfer_rate_output
def main():
data = pd.read_csv("resources/Data.csv")
@ -164,7 +325,8 @@ def main():
#print(filtered_df)
results = []
results_rate = []
results_transfer_rate = []
for item in filtered_df.iterrows():
print(item)
@ -173,10 +335,16 @@ def main():
shotsPerMatch=item[1]["Shots Per Avg Match"]
onTargetPerMatch=item[1]["On Target Per Avg Match"]
rate = fuzzy(goals,xGPerMatch,shotsPerMatch,onTargetPerMatch)
results.append(rate)
filtered_df['Rate'] = results
print(rate)
results_rate.append(rate)
age=item[1]["Age"]
market_value=item[1]["Value (in millions)"]
transfer_rate=fuzzy2(rate,age,market_value)
print(transfer_rate)
results_transfer_rate.append(transfer_rate)
filtered_df['Rate'] = results_rate
filtered_df['Transfer rate']=results_transfer_rate
filtered_df.to_csv('resources/out.csv')