Skip to content

Instantly share code, notes, and snippets.

@housemeow
Created July 30, 2015 07:45
Show Gist options
  • Save housemeow/da6d39413f979580fc16 to your computer and use it in GitHub Desktop.
Save housemeow/da6d39413f979580fc16 to your computer and use it in GitHub Desktop.
# coding:utf8
import numpy as np
import matplotlib.pyplot as plt
# Feature Envy Factor
def FEF(m,n,w,x):
return w*m/n + (1-w) * (1-x**m)
# 建立w,x軸的0~1切割點陣列
w_list = []
x_list = []
# np.arange超好用!除了以往range之外,這可以小數點切割!
for zero_to_one in np.arange(0, 1.01, 0.01):
w_list.append(zero_to_one)
x_list.append(zero_to_one)
# 利用w陣列配上固定的x來生成FEF陣列
def FEF_w_list(m, n, x):
fef_list = []
for w in w_list:
fef_list.append(FEF(m, n, w, x))
return fef_list
# 依照m, n把FEF畫出來
def plot_FEF_w(m, n, x):
plt.figure(figsize=(12,5))
# for w in w_list:
# plt.plot(x_list, y_list)
# x_list & y_list是一組(x,y)配對的點,會再figure上畫出來
# label是這個圖的名字
# color是線條顏色
# linewidth是線條寬度
plt.plot(w_list, FEF_w_list(m, n, x),label="FEF(m,n,x)=FEF(%d,%d,%.1f)" %(m,n,x) ,color="red",linewidth=2)
# x-legend的名稱
plt.xlabel("w")
# y-legend的名稱
plt.ylabel("FEF(m,n,x)")
# x軸要顯示的範圍
plt.xlim(0,1.3)
# y軸要顯示的範圍
plt.ylim(-0.05,1)
# 圖例
plt.legend(bbox_to_anchor=(1, 0.5), loc=5, borderaxespad=0.)
# 畫圖
plt.show()
plot_FEF_w(3, 6, 0.5)
plot_FEF_w(0, 6, 0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment