Compare commits
30 Commits
Author | SHA1 | Date |
---|---|---|
|
19fa153e5a | 7 months ago |
|
7c100f95fa | 7 months ago |
|
7a93f76da0 | 7 months ago |
|
5a9d5da45d | 7 months ago |
|
7f917cf9e6 | 7 months ago |
|
7c694554d4 | 7 months ago |
|
a1f852b393 | 7 months ago |
|
6059412e5a | 7 months ago |
|
e0d39ed553 | 7 months ago |
|
910206eb1b | 7 months ago |
|
f12366ca01 | 7 months ago |
|
b19bd9bef5 | 7 months ago |
|
7b70265a0d | 7 months ago |
|
ab8bd7dfae | 7 months ago |
|
22043cdac7 | 7 months ago |
|
0ec602fbc1 | 7 months ago |
|
b789574e3e | 7 months ago |
|
3d0453cf0b | 7 months ago |
|
aa9c8889bd | 7 months ago |
|
19262e6ef2 | 7 months ago |
|
7d1020b93a | 7 months ago |
|
cb4ffe074c | 7 months ago |
|
f5a4c8b16b | 7 months ago |
|
811bec3b62 | 7 months ago |
|
d032cbab43 | 7 months ago |
|
97a3f6598d | 7 months ago |
|
2237326033 | 7 months ago |
|
2a3a14b6d9 | 7 months ago |
|
95f484af5c | 7 months ago |
|
371c0c70c3 | 7 months ago |
@ -0,0 +1,3 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,12 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="INFORMATION" enabled_by_default="true">
|
||||
<option name="ignoredPackages">
|
||||
<value>
|
||||
<list size="0" />
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (mycode)" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/mycode.iml" filepath="$PROJECT_DIR$/.idea/mycode.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,2 @@
|
||||
a=[0]*int(2e4)
|
||||
print(len(a))
|
@ -0,0 +1,54 @@
|
||||
from functools import cmp_to_key
|
||||
c=[[],[]]
|
||||
string=[[],[]]
|
||||
for i in range(2):
|
||||
a = eval(input())
|
||||
while a>0:
|
||||
s=input().split()
|
||||
s[1],s[2]=eval(s[1]),eval(s[2])
|
||||
c[i].append(s)
|
||||
string[i].append(s[0])
|
||||
a-=1
|
||||
def cmp(a,b):
|
||||
if a[1]>b[1]:
|
||||
return -1
|
||||
elif a[1]==b[1]:
|
||||
if a[2]<b[2] :
|
||||
return -1
|
||||
else:
|
||||
return 1
|
||||
else :
|
||||
return 1
|
||||
c[0]=sorted(c[0],key=cmp_to_key(cmp))
|
||||
# print(c[0])
|
||||
c[1]=sorted(c[1],key=cmp_to_key(cmp))
|
||||
# print(c[1])
|
||||
# m='123'
|
||||
# n='123'
|
||||
# print(m==n)
|
||||
st="lzr010506"
|
||||
s=set(string[0])&set(string[1])
|
||||
# for i in c[0]:
|
||||
# for j in c[1]:
|
||||
# if i[0] == j[0] :
|
||||
# s.append(j[0])
|
||||
# print(s)
|
||||
ans1=0
|
||||
ans2=0
|
||||
i=0
|
||||
while c[0][i][0] != st:
|
||||
# print(c[0][i][0])
|
||||
if c[0][i][0] in s:
|
||||
ans1+=1
|
||||
i+=1
|
||||
ans1= i+1-ans1
|
||||
i=0
|
||||
while c[1][i][0]!=st:
|
||||
# print(c[1][i][0])
|
||||
if c[1][i][0] in s:
|
||||
ans2+=1
|
||||
i+=1
|
||||
ans2=i+1-ans2
|
||||
# print(ans1,ans2)
|
||||
print(min(ans1,ans2))
|
||||
# print(c[0],'\n',c[1])
|
@ -0,0 +1,18 @@
|
||||
import heapq
|
||||
import ctypes
|
||||
a=int(input())
|
||||
b=input().split()
|
||||
for i in range(len(b)):
|
||||
b[i]=int(b[i])
|
||||
heapq.heapify(b)
|
||||
# print(b)
|
||||
sum=0
|
||||
while len(b) != 1:
|
||||
c,d=heapq.nsmallest(2,b)
|
||||
# heapq.heappop(b)
|
||||
# heapq.heappop(b)
|
||||
b.remove(c)
|
||||
b.remove(d)
|
||||
sum+=c+d
|
||||
heapq.heappush(b,c+d)
|
||||
print(sum)
|
@ -0,0 +1,28 @@
|
||||
import functools
|
||||
a,b =map(int, input().split(' '))
|
||||
nums=[]
|
||||
for i in range(b):
|
||||
m,n=map(int,input().split(' '))
|
||||
if m>n:continue;
|
||||
nums.append([m,n])
|
||||
def cmp(a,b):#升序
|
||||
if(a[0]>b[0]):
|
||||
return 1
|
||||
else :
|
||||
return -1#不变
|
||||
nums=sorted(nums,key=functools.cmp_to_key(cmp))
|
||||
# for i in nums:
|
||||
# print(i)
|
||||
sum = 0
|
||||
start,end=nums[0][0],nums[0][1]
|
||||
count=1
|
||||
while count<len(nums):
|
||||
if nums[count][0]>=start and nums[count][0]<=end:
|
||||
if end<=nums[count][1]:
|
||||
end=nums[count][1]
|
||||
else :
|
||||
sum+=end-start+1
|
||||
start=nums[count][0];end=nums[count][1]
|
||||
count+=1
|
||||
sum+=end-start+1
|
||||
print(a-sum+1)
|
@ -0,0 +1,7 @@
|
||||
a,b =map(int, input().split(' '))
|
||||
nums=[]
|
||||
for i in range(b):
|
||||
m,n=map(int,input().split(' '))
|
||||
nums.extend(range(m,n+1))
|
||||
nums=set(nums)
|
||||
print(a+1-len(nums))
|
@ -0,0 +1,64 @@
|
||||
%AHP步骤
|
||||
|
||||
clc,clear,close all;
|
||||
A=[1,2,3,5
|
||||
1/2,1,1/2,2
|
||||
1/3,2,1,2
|
||||
1/5,1/2,1/2,1];
|
||||
[row,col]=size(A);
|
||||
|
||||
%判断矩阵一致性检验
|
||||
n=col;
|
||||
maxlam=max(eig(A));
|
||||
RI=[0 0 0.58 0.90 1.12 1.24 1.32 1.41 1.45];
|
||||
CI=(maxlam-n)/(n-1);
|
||||
CR=CI/RI(n);
|
||||
|
||||
%判断矩阵确定权重
|
||||
for i=1:col
|
||||
sumcol=sum(A(:,i));
|
||||
for j=1:row
|
||||
A(j,i)=A(j,i)/sumcol;
|
||||
end
|
||||
end
|
||||
|
||||
weig=zeros(row,1);
|
||||
for i=1:row
|
||||
sumrow=sum(A(i,:));
|
||||
weig(i)=sumrow/n;
|
||||
end
|
||||
|
||||
%各个指标归一化 按列单位化
|
||||
data= [1686.4 3183 12000 397
|
||||
903.6 1916.4 3439.6 43
|
||||
837.6 817.6 4748 1159
|
||||
824.9 1296.4 12000 442
|
||||
2110.2 1465.7 6199.5 228];
|
||||
[rowd,cold]=size(data);
|
||||
for i=1:cold
|
||||
sumcold=sum(data(:,i));
|
||||
for j=1:rowd
|
||||
data(j,i)=data(j,i)/sumcold;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
%按权重计算分数
|
||||
|
||||
score=data*weig;
|
||||
|
||||
|
||||
projectNames={'老番茄','何同学','木鱼水心','凉风','罗翔'};
|
||||
figure;
|
||||
bar(score);%条形图
|
||||
|
||||
set(gca, 'XTickLabel', projectNames); %每个条形图标签
|
||||
xlabel('博主');
|
||||
ylabel('加权总分');
|
||||
title('得分');
|
||||
|
||||
grid on; % 网格线
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
clc,clear,close all;
|
||||
|
||||
%相关系数矩阵
|
||||
r=[ 1.000,0.577,0.509,0.387,0.462
|
||||
0.577,1.000,1.599,0.389,0.322
|
||||
0.509,0.599,1.000,0.436,0.426
|
||||
0.387,0.389,0.436,1.000,0.523
|
||||
0.462,0.322,0.426,0.523,1.000];
|
||||
|
||||
[vec1,val,rate]=pcacov(r);%特征向量、特征值、贡献率
|
||||
f1=repmat(sign(sum(vec1)),size(vec1,1),1);%调整符号
|
||||
vec2=vec1.*f1;%是用 .*
|
||||
f2=repmat(sqrt(val)',size(vec2,1),1);
|
||||
a=vec2.*f2;%载荷矩阵
|
||||
a1=a(:,1);
|
||||
tcha1=diag(r-a1*a1');
|
||||
a2=a(:,[1,2]);
|
||||
tcha2=diag(r-a2*a2');
|
||||
ccha2=r-a2*a2'-diag(tcha2);
|
||||
con=cumsum(rate);
|
||||
|
||||
|
||||
|
||||
|
||||
clc,clear,close all;
|
||||
load data_mh.mat;
|
||||
[n,p]=size(x);
|
||||
%标准化
|
||||
X=zscore(x);
|
||||
|
||||
%相关系数矩阵
|
||||
r=cov(X);
|
||||
|
||||
[vec1,val,rate]=pcacov(r);%特征向量、特征值、贡献率
|
||||
f1=repmat(sign(sum(vec1)),size(vec1,1),1);%调整符号
|
||||
vec2=vec1.*f1;%是用 .*
|
||||
f2=repmat(sqrt(val)',size(vec2,1),1);
|
||||
a=vec2.*f2;%载荷矩阵
|
||||
a1=a(:,1);
|
||||
tcha1=diag(r-a1*a1');
|
||||
a2=a(:,[1,2]);
|
||||
tcha2=diag(r-a2*a2');
|
||||
ccha2=r-a2*a2'-diag(tcha2);
|
||||
con=cumsum(rate);
|
||||
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 824 KiB |
@ -0,0 +1,28 @@
|
||||
import networkx as nx
|
||||
import pylab as plt
|
||||
import numpy as np
|
||||
p=[25,26,28,31] ;a=[10,14,18,26] ; r=[20,16,13,11]
|
||||
b= np.zeros((5,5))
|
||||
|
||||
for i in range(5):
|
||||
for j in range(i+1,5):
|
||||
b[i,j]=p[i]+np.sum(a[0:j-i])-r[j-i-1]
|
||||
G=nx.DiGraph(b)
|
||||
print(G)
|
||||
p=nx.dijkstra_path(G,source=0,target=4,weight='weight')
|
||||
print("最短路径为:",np.array(p)+1)#下标从零开始
|
||||
d=nx.dijkstra_path_length(G,source=0,target=4,weight="weight")
|
||||
print("所求的费用最小值为:",d)
|
||||
s=dict(zip(range(5),range(1,6)))
|
||||
plt.rc("font",size=16)
|
||||
pos=nx.shell_layout((G))#设置布局
|
||||
print(type(pos),'\npos=',pos)
|
||||
w=nx.get_edge_attributes(G,"weight")
|
||||
print(type(w),'\nw=',w)
|
||||
nx.draw(G,pos,font_weight='bold',labels=s,node_color='r')#绘制点和边
|
||||
nx.draw_networkx_edge_labels(G,pos,edge_labels=w)#绘制标签
|
||||
#绘制最短路径
|
||||
path_edges=list(zip(p,p[1:]))
|
||||
print(type(path_edges),"\npath_edges=",path_edges)
|
||||
nx.draw_networkx_edges(G,pos,edgelist=path_edges,edge_color="r",width=1)
|
||||
plt.savefig("figure10_9.png",dpi=1000);plt.show()
|
After Width: | Height: | Size: 2.7 MiB |
@ -0,0 +1,70 @@
|
||||
import pandas as pd
|
||||
<<<<<<< HEAD
|
||||
import numpy as np
|
||||
from scipy.stats import zscore
|
||||
from sklearn.decomposition import PCA
|
||||
=======
|
||||
from scipy.stats import zscore
|
||||
>>>>>>> remotes/origin/盘荣博
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.pyplot import ylabel
|
||||
df = pd.read_excel("棉花产量论文作业的数据.xlsx")
|
||||
# plt.plot(df["年份"],df["单产"])
|
||||
plt.rcParams['font.sans-serif']="SimHei"
|
||||
# plt.rcParams['size'] =10
|
||||
# plt.ylabel('单产')
|
||||
# plt.xlabel('年份')
|
||||
|
||||
# print(df)
|
||||
d = df.to_numpy()[:,1:]
|
||||
print(d)
|
||||
plt.subplot(4,1,1)
|
||||
plt.scatter(d[:,:1],d[:,1:2],c='r')
|
||||
ylabel('原始数据'),plt.title("单产和种子费用的关系")
|
||||
#公式调用标准化,遵守标准正态分布
|
||||
data = zscore(d)
|
||||
print(data)
|
||||
plt.subplot(4,1,2)
|
||||
plt.scatter(data[:,:1],data[:,1:2],c='b',)
|
||||
ylabel('zscore')
|
||||
|
||||
print(d.max(axis=0))
|
||||
print(d.std(axis=0))
|
||||
print(d.mean(axis=0))
|
||||
#手写标准正态分布
|
||||
data1=(d-d.mean(axis=0))/d.std(axis=0)
|
||||
print(data1)
|
||||
plt.subplot(4,1,3)
|
||||
plt.scatter(data1[:,:1],data1[:,1:2],c='y')
|
||||
ylabel('手写标准正态分布')
|
||||
|
||||
data2=(d-d.min(axis=0))/(d.max(axis=0)-d.min(axis=0))
|
||||
plt.subplot(4,1,4)
|
||||
plt.scatter(data2[:,:1],data2[:,1:2],c='g')
|
||||
plt.xlabel('压缩到0~1')
|
||||
print(data==data1)
|
||||
|
||||
<<<<<<< HEAD
|
||||
# plt.savefig("shuju.jpg",dpi=2000)
|
||||
# plt.show()
|
||||
md= PCA().fit(data)
|
||||
cf = np.cov(data.T)#求协方差矩阵
|
||||
print(cf)
|
||||
c, d= np.linalg.eig(cf)
|
||||
print("特征值:\n",c)
|
||||
print(md.explained_variance_)
|
||||
e=c/c.sum()
|
||||
# for _ in range(len(e)):
|
||||
# if(_!=0):
|
||||
# e[_]+=e[_-1]
|
||||
print('贡献率:')
|
||||
print(e)
|
||||
print(md.explained_variance_ratio_)
|
||||
print('特征向量:')
|
||||
print(d.T)
|
||||
print(md.components_)
|
||||
print(md.components_-d.T<=0.1)
|
||||
=======
|
||||
plt.savefig("shuju.jpg",dpi=2000)
|
||||
plt.show()
|
||||
>>>>>>> remotes/origin/盘荣博
|
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
from matplotlib import pyplot as plt
|
||||
from numpy import ones , diag , c_ , zeros
|
||||
from scipy.optimize import linprog
|
||||
import time
|
||||
start = time.time()
|
||||
c=list( [-0.05,-0.27,-0.19,-0.185,-0.185])
|
||||
A=c_[zeros(4),diag([0.025,0.015,0.055,0.026])]
|
||||
Aeq = [[1,1.01,1.02,1.045,1.065]];beq=[[1]]
|
||||
a=0;aa=[];ss = []
|
||||
while a<=0.05:
|
||||
b=list(ones(4)*a)
|
||||
res= linprog(c,A,b,Aeq,beq)
|
||||
aa.append(a);ss.append(-res.fun)
|
||||
a=a+0.001
|
||||
end = time.time()
|
||||
print("花费时间:",end-start)
|
||||
plt.plot(aa,ss,"r*")
|
||||
plt.xlabel("$a$");plt.ylabel("$Q$",rotation=90)
|
||||
plt.savefig("figure5_1_1.png",dpi=500) ;plt.show()
|
@ -0,0 +1,26 @@
|
||||
import numpy as np
|
||||
from numpy import ones , zeros , c_,diag
|
||||
from scipy.optimize import linprog
|
||||
import matplotlib.pyplot as plt
|
||||
c = np.append(zeros(5).tolist(),[1]).tolist()
|
||||
print(c)
|
||||
A=np.append(zeros(4).reshape(4,1),diag([0.025,0.015,0.055,0.026]),axis=1)
|
||||
A=np.append(A,ones(4).reshape(4,1)*-1,axis=1).tolist()
|
||||
Aeq =[[1,1.01,1.02,1.045,1.065,0]] ;beq=[1]
|
||||
A.append([-0.05,-0.27,-0.19,0.185,-0.185,0])
|
||||
print(A)
|
||||
k=0.05;step = 0.005
|
||||
b=([0]*4);b.append(-k)
|
||||
print(b)
|
||||
kk=[];ss=[]
|
||||
while k<0.28:
|
||||
res= linprog(c,A,b,Aeq,beq)
|
||||
kk.append(k)
|
||||
ss.append(res.fun)
|
||||
print(res.fun)
|
||||
k+=step
|
||||
b[4]=-k
|
||||
plt.plot(kk,ss,'r*')
|
||||
plt.xlabel("$k$");plt.ylabel('$R$')
|
||||
plt.savefig("figures5_1_2.png",dpi=500);plt.show()
|
||||
|
After Width: | Height: | Size: 93 KiB |
After Width: | Height: | Size: 115 KiB |
@ -0,0 +1,23 @@
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
from scipy.optimize import linprog
|
||||
start = time.time()
|
||||
c = [-110,-120,-130,-110,-115,150]
|
||||
c = (-np.array(c)).tolist()
|
||||
A=[[1,1,0,0,0,0],
|
||||
[0,0,1,1,1,0],
|
||||
[8.8,6.1,2.0,4.2,5.0,-6],
|
||||
[8.8,6.1,2.0,4.2,5.0,-3]
|
||||
]
|
||||
A[3]=(-np.array(A[3])).tolist()
|
||||
b=[[200],[250],[0],[0]]
|
||||
Aeq =[[1,1,1,1,1,-1]]
|
||||
beq = [[0]]
|
||||
LB= [0]*len(c)
|
||||
UB= [None]*len(c)
|
||||
bounds= tuple(zip(LB,UB))
|
||||
res = linprog(c,A,b,Aeq,beq,bounds)
|
||||
end = time.time()
|
||||
print("最优解:\n",res.x)
|
||||
print("目标函数最小值:\n",-res.fun)
|
@ -0,0 +1,16 @@
|
||||
import numpy as np
|
||||
import pylab as pl
|
||||
from scipy import interpolate
|
||||
import matplotlib.pyplot as plt
|
||||
x = np.linspace(0,2*np.pi+np.pi/4,10)
|
||||
x1 = np.linspace(0,2*np.pi+np.pi/4,100)#num个0~2*Pi+Pi/4的范围的点
|
||||
y = np.sin(x)
|
||||
y1= np.sin(x1)
|
||||
plt.xlabel(f"安培/A")
|
||||
plt.ylabel(f'伏特/V')
|
||||
linear_ = interpolate.interp1d(x,y)
|
||||
print(linear_(x1))
|
||||
plt.rcParams['font.sans-serif'] = ['SimSun']#设置字体
|
||||
plt.plot(x,y,'o',label=f"原始数据")
|
||||
plt.plot(x1,linear_(x1),"*",label="线性插入")
|
||||
pl.show()
|
@ -0,0 +1,27 @@
|
||||
from scipy import optimize
|
||||
import numpy as np
|
||||
|
||||
c= np.array([-1,4])
|
||||
A=np.array([[-3,1],[1,2]])
|
||||
b=np.array([6,4])#小于关系
|
||||
Aeq=np.array([[1,1,1]])#相等
|
||||
beq = np.array([7])#
|
||||
bounds = ((None,None),(-3,None))
|
||||
res = optimize.linprog(c,A,b,None,None,bounds=bounds)
|
||||
print("目标函数最小值:",res.fun)#目标函数最优解
|
||||
print("最优解",res.x)#求得的最优解
|
||||
|
||||
|
||||
c = [-1,2,3]
|
||||
A=[[-2,1,1],[3,-1,-2]]
|
||||
b=[[9],[-4]]
|
||||
Aeq =[[4,-2,-1]]
|
||||
beq=[-6]
|
||||
LB=[-10,0,None]
|
||||
UB = [None]*len(c)
|
||||
print(UB)
|
||||
bound = tuple(zip(LB,UB))
|
||||
print(zip(LB,UB),'\n',bound)
|
||||
res = optimize.linprog(c,A,b,Aeq,beq,bounds=bound)
|
||||
print("函数的最小值为",res.fun)
|
||||
print("最优解为:",res.x)
|
Loading…
Reference in new issue