Skip to content

Commit

Permalink
20230106
Browse files Browse the repository at this point in the history
  • Loading branch information
zzb1185 committed Jan 6, 2023
0 parents commit 22ed4d0
Show file tree
Hide file tree
Showing 436 changed files with 3,341 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/T-GCN-85f7ed89ffa3fe165bc53deec723ed13c469383a.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions .idea/csv-plugin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions DTW_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import math
import numpy as np
import pandas as pd

def dtw(file, num1):
num = num1
distmatrix = np.zeros((num, num)) #生成一个零矩阵,大小为num*num,方便填数据
for i in range(num):
t = file.iloc[:, i] #取出第i个位置的值
for j in range(i + 1, num):
r = file.iloc[:, j] #去除第i+1位置的值
if len(r) == 0:
print("Notdata:", file[j])
distmatrix[i, j] = mydtw_function2(t, r) #调用计算函数,计算井i与井j的相似度
distmatrix[j, i] = distmatrix[i, j] #(i,j)==(j,i)
distmatrix[i, i] = 1 #(i,i)==1
# print("NO.{0}finish!".format(i))
return distmatrix

def mydtw_function2(t, r):
n = len(t)
m = len(r)
t = np.array(t)
r = np.array(r)
d = np.zeros((n, m))
for i in range(n):
for j in range(m):
d[i, j] = np.sum((t[i] - r[j]) ** 2)
# 累积距离 Cumulative distance
D = np.ones((n, m)) * np.inf
D[0, 0] = d[0, 0]
# 动态规划 dynamic programming
for i in range(1, n):
for j in range(m):
D1 = D[i - 1, j]
if j > 0:
D2 = D[i - 1, j - 1]
D3 = D[i, j - 1]
else:
D2 = np.inf
D3 = np.inf
D[i, j] = d[i, j] + min([D1, D2, D3])
dist = D[n - 1, m - 1]
# 对结果进行处理
dist = math.exp(-dist)
return dist


# 描述:使用DTW计算地址相似度的主程序
# 输入:数据集名称(dataname)
def dtw_adj(dataname):
"""
函数介绍(中文版)
描述:根据数据集名称读取对应地质特征文件,并在此基础上调用DTW函数计算地址相似性矩阵
输入:数据集名称(dataname)
输出:地质相似度矩阵,该矩阵经过了np.mat()转换
Function introduction (English version)
Description: Read the corresponding geological feature file according to the dataset name, and call the DTW function to calculate the address similarity matrix
Input: dataset name (dataname)
Output: geological similarity matrix, which is transformed by np.mat()
"""

# 01 读取数据 load_data
dfall = pd.read_csv(r'data/testdata/'+dataname+'_Details.csv')
num = dfall.shape[0]

# 02 归一化 normalization
dfmean = pd.DataFrame() # 归一化之后的df
for i in range(3, dfall.shape[1]): #取出相关的参数,准备处理
data1 = dfall.iloc[:, i]
max_value = np.max(data1)
min_value = np.min(data1)
range_value = max_value - min_value
mean_value = np.mean(data1)
data1 = (data1 - min_value) / range_value
dfmean = pd.concat([dfmean, data1], axis=1) # 参数归一化之后的df

# 03 计算 calculation
dfmeant = pd.DataFrame(dfmean.T) #转置,便于计算
num1 = dfmeant.shape[1] #获得行数
distmatrix = dtw(dfmeant, num1) #dtw计算主函数
dfmat = pd.DataFrame(distmatrix) #输出结果转为DataFrame,便于后续计算

return dfmat


21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 zzb1185

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions Spatial_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import math
import numpy as np
import pandas as pd

def spa_adj(dataname):
dfall = pd.read_csv(r'data/testdata/'+dataname+'_Details.csv')
dfxy = dfall.iloc[:, 1:3] # 取出经纬度计算
# 01 计算邻近关系
num = dfxy.shape[0] # 多少口井
dfnear = pd.DataFrame(columns=['a', 'b']) # 临近矩阵
for i in range(num):
x1 = dfxy.iloc[i, 0]
y1 = dfxy.iloc[i, 1]
for j in range(num):
x2 = dfxy.iloc[j, 0]
y2 = dfxy.iloc[j, 1]
dis = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** (0.5)
if dis <= 350: #350m
dfnear = dfnear.append(pd.DataFrame({'a': [i], 'b': [j]})) # 临近矩阵
print("邻近关系计算完成")

# 02 组合
num_finished = 1
oh432 = np.zeros((num, num))
for row in range(dfnear.shape[0]):
input = dfnear.iloc[(row, 0)]
near = dfnear.iloc[(row, 1)]
oh432[input][near] = 1
print(row)

dfoh1 = pd.DataFrame(oh432) # 完全体权重邻接矩阵
dfoh1.to_csv(r"data\testdata\test_Spamatrix.csv",index=False,header=None)
print("矩阵组装完成,保存在data中")
return dfoh1
Binary file added __pycache__/gru.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/input_data.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/input_data.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/load.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/tgcn.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/tgcn.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/utils.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/utils.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/visualization.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/visualization.cpython-37.pyc
Binary file not shown.
Loading

0 comments on commit 22ed4d0

Please sign in to comment.