#模糊粗糙集的属性约简
#参考github和matlab模糊粗糙集算法
import numpy as np
class RoughSetsReducer:
def __size(self, x):
return (1, x.shape[0]) if x.ndim == 1 else x.shape
'''
Calculates indiscernibility relation
'''
def indisc(self, a, x):
def codea(a, x, b):
yy = 0
for i in range(0, a):
yy += x[i] * b**(a-(i+1))
return yy
p, q = self.__size(x)
ap, aq = self.__size(a)
z = [e for e in xrange(1, q+1)]
tt = np.setdiff1d(z, a)
tt_ind = np.setdiff1d(z, tt)-1
if x.ndim == 1:
x = x[tt_ind]
else:
x = x[:, tt_ind]
y = x
v = [codea(aq, y, 10) for i in range(0, p)] if y.ndim == 1 \
else [codea(aq, y[i, :], 10) for i in range(0, p)]
y = np.transpose(v)
if y.shape[0] == 1 and len(y.shape) == 1:
I, yy = [1], [y]
y = np.hstack((y, I))
b, k, l = [y], [1], [1]
else:
ax = 1 if y.ndim > 1 else 0
yy = np.sort(y, axis=ax)
I = y.argsort(axis=ax)
y = np.hstack((yy, I))
b, k, l = np.unique(yy, return_index=True, return_inverse=True)
y = np.hstack((l, I))
m = np.max(l)
aa = np.zeros((m+1, p), dtype=int)
for ii in range(0, m+1):
for j in range(0, p):
if l[j] == ii:
aa[ii, j] = I[j]+1
return aa
'''
Calculates lower approximation set of y
'''
def rslower(self, y, a, T):
z = self.indisc(a, T)
w = []
p, q = self.__size(z)
for u in range(0, p):
zz = np.setdiff1d(z[u, :], 0)
if np.in1d(zz, y).all():
w = np.hstack((w, zz))
return w.astype(dtype=int)
'''
Calculates upper approximation set of y
'''
def rsupper(self, y, a, T):
z = self.indisc(a, T)
w = []
p, q = self.__size(z)
for u in range(0, p):
zz = np.setdiff1d(z[u, :], 0)
zzz = np.intersect1d(zz, y)
if len(zzz) > 0:
w = np.hstack((w, zz))
return w.astype(dtype=int)
def __pospq(self, p, q):
pm, pn = self.__size(p)
qm, qn = self.__size(q)
num = 0
pp, qq = [[]] * pm, [[]] * qm
for i in range(0, pm):
pp[i] = np.unique(p[i, :])
for j in range(0, qm):
qq[j] = np.unique(q[j, :])
b = []
for i in range(0, qm):
for j in range(0, pm):
if np.in1d(pp[j], qq[i]).all():
num += 1
b = np.hstack((b, pp[j]))
bb = np.unique(b)
if bb.size == 0:
dd = 1
else:
_, dd = self.__size(bb)
y = float(dd - 1)/pn if 0 in bb else float(dd)/pn
b = np.setdiff1d(bb, 0)
return y, b
'''
Extract core set from C to D
'''
def core(self, C, D):
x = np.hstack((C, D))
c = np.array(range(1, C.shape[1]+1))
d = np.array([C.shape[1]+1])
cp, cq = self.__size(c)
q = self.indisc(d, x)
pp = self.indisc(c, x)
b, w = self.__pospq(pp, q)
a, k, kk, p = ([[]] * cq for i in range(4))
y = []
for u in range(0, cq):
ind = u+1
a[u] = np.setdiff1d(c, ind)
p[u] = self.indisc(a[u], x)
k[u], kk[u] = self.__pospq(p[u], q)
if k[u] != b:
y = np.hstack((y, ind))
return np.array(y)
def __sgf(self, a, r, d, x):
pr = self.indisc(r, x)
q = self.indisc(d, x)
b = np.hstack((r, a))
pb = self.indisc(b, x)
p1, _ = self.__pospq(pb, q)
p2, _ = self.__pospq(pr, q)
return p1 - p2
'''
Return the set of irreducible attributes
'''
def reduce(self, C, D):
def redu2(i, re, c, d, x):
yre = re
re1, re2 = self.__size(re)
q = self.indisc(d, x)
p = self.indisc(c, x)
pos_cd, _ = self.__pospq(p, q)
y, j = None, None
for qi in range(i, re2):
re = np.setdiff1d(re, re[qi])
red = self.indisc(re, x)
pos_red, _ = self.__pospq(red, q)
if np.array_equal(pos_cd, pos_red):
y = re
j = i
break
else:
y = yre
j = i + 1
break
return y, j
x = np.hstack((C, D))
c = np.array(range(1, C.shape[1]+1))
d = np.array([C.shape[1]+1])
y = self.core(C, D)
q = self.indisc(d, x)
p = self.indisc(c, x)
pos_cd, _ = self.__pospq(p, q)
re = y
red = self.indisc(y, x)
pos_red, _ = self.__pospq(red, q)
while pos_cd != pos_red:
cc = np.setdiff1d(c, re)
c1, c2 = self.__size(cc)
yy = [0] * c2
for i in range(0, c2):
yy[i] = self.__sgf(cc[i], re, d, x)
cd = np.setdiff1d(c, y)
d1, d2 = self.__size(cd)
for i in range(d2, c2, -1):
yy[i] = []
ii = np.argsort(yy)
for v1 in range(c2-1, -1, -1):
v2 = ii[v1]
re = np.hstack((re, cc[v2]))
red = self.indisc(re, x)
pos_red, _ = self.__pospq(red, q)
re1, re2 = self.__size(re)
core = y
for qi in range(re2-1, -1, -1):
if re[qi] in core:
y = re
break
re = np.setdiff1d(re, re[qi])
red = self.indisc(re, x)
pos_red, _ = self.__pospq(red, q)
if np.array_equal(pos_cd, pos_red):
y = re
y1, y2 = self.__size(y)
j = 0
for i in range(0, y2):
y, j = redu2(j, y, c, d, x)
return y
#reduction属相约简
import numpy as np
from sklearn.base import BaseEstimator
from sklearn.feature_selection.base import SelectorMixin
from scikit_roughsets.roughsets import RoughSetsReducer
class RoughSetsSelector(BaseEstimator, SelectorMixin):
def _get_support_mask(self):
return self.mask_
def fit(self, X, y=None):
# Missing values are not supported yet!
if np.isnan(X).any():
raise ValueError("X must not contain any missing values")
if np.isnan(y).any():
raise ValueError("y must not contain any missing values")
# Check that X and Y contains only integer values
if not np.all(np.equal(np.mod(X, 1), 0)):
raise ValueError("X must contain only integer values")
if not np.all(np.equal(np.mod(y, 1), 0)):
raise ValueError("y must contain only integer values")
reducer = RoughSetsReducer()
selected_ = reducer.reduce(X, y)
B_unique_sorted, B_idx = np.unique(np.array(range(X.shape[1])), return_index=True)
B_unique_sorted = B_unique_sorted + 1 # Shift elements by one, as RS index array starts by one
self.mask_ = np.in1d(B_unique_sorted, selected_, assume_unique=True)
if self.mask_.size == 0:
raise ValueError("No features were selected by rough sets reducer")
return self
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于LSTM神经网络的风力发电风速预测 python源码+项目说明.zip 基于LSTM神经网络的风速预测 两层lstm神经网络的时间序列预测,利用lstm,避免传递过程中的梯度消失。 代码:lstm.py。使用keras搭建。 基于LSTM神经网络的风力发电风速预测 python源码+项目说明.zip 基于LSTM神经网络的风速预测 两层lstm神经网络的时间序列预测,利用lstm,避免传递过程中的梯度消失。 代码:lstm.py。使用keras搭建。 基于LSTM神经网络的风力发电风速预测 python源码+项目说明.zip 基于LSTM神经网络的风速预测 两层lstm神经网络的时间序列预测,利用lstm,避免传递过程中的梯度消失。 代码:lstm.py。使用keras搭建。 基于LSTM神经网络的风力发电风速预测 python源码+项目说明.zip 基于LSTM神经网络的风速预测 两层lstm神经网络的时间序列预测,利用lstm,避免传递过程中的梯度消失。 代码:lstm.py。使用keras搭建。
资源推荐
资源详情
资源评论
收起资源包目录
基于LSTM神经网络的风力发电风速预测 python源码+项目说明.zip (8个子文件)
frs.py 7KB
项目说明.md 951B
网络模型.JPG 69KB
预测模型.JPG 83KB
lstm.py 3KB
Clstm.py 1KB
预测结果.JPG 68KB
输入参数确定.JPG 60KB
共 8 条
- 1
资源评论
.whl
- 粉丝: 3960
- 资源: 4908
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- TRIZ矛盾矩阵表.pdf
- ssm基于SSM框架的购物商城系统+jsp.zip
- ssm基于SSM框架的个人博客网站的设计与实现+vue.zip
- ssm基于SSM框架的金鱼销售平台的开发和实现+jsp.zip
- ssm基于SSM框架的德云社票务系统的设计与实现+vue.zip
- ssm基于SSM框架的安全教育平台+vue.zip
- ssm基于ssm框架的大学生就业信息平台+jsp.zip
- ssm基于SSM的养老院老人健康监护平台设计与实现+vue.zip
- ssm基于ssm的疫情物质管理系统+jsp.zip
- ssm基于SSM的药房药品采购集中管理系统的设计与实现+vue.zip
- ssm基于SSM的乡镇篮球队管理系统+jsp.zip
- ssm基于ssm的新能源汽车在线租赁管理系统+vue.zip
- ssm基于SSM的校园二手物品交易平台+vue.zip
- ssm基于ssm的人才招聘网站+jsp.zip
- ssm基于SSM的高校疫情管理系统设计与实现+vue.zip
- ssm基于ssm的线上课程管理系统+jsp.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功