├── DDDA ├── DDDA │ ├── .ipynb_checkpoints │ │ ├── 3Dv0.0.1-kdTreeO-checkpoint.ipynb │ │ ├── Debug-checkpoint.ipynb │ │ ├── START-checkpoint.ipynb │ │ └── packageTest-checkpoint.ipynb │ ├── DDDA.egg-info │ │ ├── PKG-INFO │ │ ├── SOURCES.txt │ │ ├── dependency_links.txt │ │ └── top_level.txt │ ├── DDDAGO.py │ └── setup.py └── __init__.py ├── Example ├── Case_2D │ ├── .ipynb_checkpoints │ │ └── 2D_TubeFlow-checkpoint.ipynb │ ├── 2D_TubeFlow.ipynb │ ├── OriginData.mat │ ├── OriginX.mat │ ├── OriginY.mat │ ├── PollutedData.mat │ ├── PollutedPositionX.mat │ └── PollutedPositionY.mat ├── Case_3D_1 │ ├── .ipynb_checkpoints │ │ └── 3Dv0.0.1-kdTree-checkpoint.ipynb │ ├── 3Dv1.4.1-kdTree.ipynb │ ├── Data_3D.mat │ ├── PositionX_3D.mat │ ├── PositionY_3D.mat │ └── PositionZ_3D.mat ├── Case_3D_2 │ ├── .ipynb_checkpoints │ │ └── 3Dv0.0.1-kdTreeO-checkpoint.ipynb │ ├── 3Dv1.4.1-kdTreeO.ipynb │ ├── Data_3D.mat │ ├── EigenRegionA.csv │ ├── EigenRegionB.csv │ ├── Eigenvector.csv │ ├── GoodU.csv │ ├── PollutedData_3D.mat │ ├── PollutedPositionX_3D.mat │ ├── PollutedPositionY_3D.mat │ ├── PollutedPositionZ_3D.mat │ ├── PositionX_3D.mat │ ├── PositionY_3D.mat │ └── PositionZ_3D.mat ├── Matlab_DDDA for the 2D case (pressure drops in pipe flows) │ ├── F_step2 │ │ ├── formuladata_diff │ │ │ └── fomular.m │ │ ├── linearinter_diff │ │ │ └── liner_inter.m │ │ ├── ml_diff │ │ │ └── ml_inter.m │ │ └── smooth_diff │ │ │ ├── DrawCircle.m │ │ │ ├── GauQuiry2D.m │ │ │ ├── GauQuiry2DFixedh.m │ │ │ ├── GetPointsFromPlot.m │ │ │ ├── Main.m │ │ │ ├── Prove1.m │ │ │ ├── VoronoiLimit.m │ │ │ ├── VoronoiLimit │ │ │ ├── VoronoiLimit.m │ │ │ └── license.txt │ │ │ ├── findPointsInH.m │ │ │ └── smooth_inter.m │ ├── F_step4 │ │ ├── cluster.m │ │ ├── cluster_f.m │ │ ├── cluster_myfcm.m │ │ ├── cluster_myfcm_f.m │ │ ├── myfcm.m │ │ ├── new_var.m │ │ └── stepfcm.m │ ├── f_h.m │ ├── f_l.m │ ├── readme.m │ ├── step0_research_boundary.m │ ├── step1_initial_data_boundary.m │ ├── step2_interpolation_data.m │ ├── step3_run_differential.m │ ├── step4_run_clust.m │ └── step5_run_fit.m └── Matlab_DDDA for the 3D case │ ├── A_Help_documentation.m │ ├── A_Step1_originaldata_smooth_differential.m │ ├── A_Step2_cutsapce_newvariables.m │ ├── F_clustering │ ├── cluster_myfcm.m │ └── new_var.m │ ├── F_differential │ ├── BB.m │ ├── DrawCircle3D.m │ ├── DrawQHull.m │ ├── DrawQHull3D.m │ ├── GauQuiry3D.m │ ├── GauQuiry3D_FixedH.m │ ├── VoronoiLimit.m │ └── findPointsInH.m │ ├── f1.m │ └── f2.m ├── Log ├── README.md └── docs ├── Paper&Talks ├── LMFS-安翼-适用于复杂力学问题的分区数据驱动量纲分析方法-221223更新.pdf └── readme.md └── figures ├── 0and1Moment.png ├── 0thConverge.png ├── 1n2Converge.png ├── 1stMoment.png ├── ClusterDemo.png ├── ClusterDemo2.png ├── Combined.png ├── Converge2.png ├── DataDense.png ├── Densied.png ├── Origin.png └── TubeFlow2D ├── AdaptiveSmooth.png ├── ClusterTubeFlow.png ├── ConvergingBenchmark.png ├── DDDA_FrameFlow.png ├── EigenVector.png ├── PartialD.png ├── SmoothInter.png ├── TubeData.png ├── TubePosition.png └── Voronoi.png /DDDA/DDDA/.ipynb_checkpoints/START-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "id": "84db8ed1", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "# Input a 2D pollutied data set within normal distributed noise.\n", 11 | "\n" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "ac0bc958", 17 | "metadata": {}, 18 | "source": [ 19 | "# Dataset pre-treatment\n", 20 | "## Import and draw\n", 21 | "(The data has polluted in three parts: background, position(x and y coordinate) and value noise(the dependent number))" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "id": "7383f087", 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "\u001b[H\u001b[2J" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "%reset -f\n", 40 | "%clear\n", 41 | "import numpy as np\n", 42 | "import copy\n", 43 | "import matplotlib.pyplot as plt \n", 44 | "plt.close('all')\n", 45 | "import scipy.io as scio\n", 46 | "from mpl_toolkits.mplot3d import axes3d\n", 47 | "import pandas as pd\n", 48 | "import scipy.stats as stats\n", 49 | "import math\n", 50 | "from numba import jit # Accelerator\n", 51 | "from scipy.spatial import Voronoi, ConvexHull\n", 52 | "from sklearn.neighbors import KDTree, KernelDensity\n", 53 | "from sklearn.model_selection import GridSearchCV\n", 54 | "import platform\n", 55 | "import time\n", 56 | "import seaborn as sns\n", 57 | "\n", 58 | "# DataX = scio.loadmat('PollutedPositionX_3D.mat')\n", 59 | "# DataX = DataX['PositionXP']\n", 60 | "# DataY = scio.loadmat('PollutedPositionY_3D.mat')\n", 61 | "# DataY = DataY['PositionYP']\n", 62 | "# DataZ = scio.loadmat('PollutedPositionZ_3D.mat')\n", 63 | "# DataZ = DataZ['PositionZP']\n", 64 | "# DataF = scio.loadmat('PollutedData_3D.mat')\n", 65 | "# DataF = DataF['DataOutP']\n", 66 | "\n", 67 | "DataX = scio.loadmat('PositionX_3D.mat')\n", 68 | "DataX = DataX['N1']\n", 69 | "DataY = scio.loadmat('PositionY_3D.mat')\n", 70 | "DataY = DataY['N2']\n", 71 | "DataZ = scio.loadmat('PositionZ_3D.mat')\n", 72 | "DataZ = DataZ['N3']\n", 73 | "DataF = scio.loadmat('Data_3D.mat')\n", 74 | "DataF = DataF['DataOut']\n", 75 | "\n", 76 | "InterLength = 40\n", 77 | "InterShift = 0.3\n", 78 | "r0 = 3\n", 79 | "rn = 10\n", 80 | "Claster = 2\n", 81 | "# NoPs = 40 * 40 # Points in one outend surface\n", 82 | "# print(NoPs)\n", 83 | "\n", 84 | "# Import data and draw.\n", 85 | "# Inter_Left_x = 0.3\n", 86 | "# Inter_Right_x = 2.7\n", 87 | "# Inter_Left_y = 0.3\n", 88 | "# Inter_Right_y = 2.7\n", 89 | "# Inter_Left_z = -1.2\n", 90 | "# Inter_Right_z = 1.2\n", 91 | "\n", 92 | "# n = 40\n", 93 | "\n", 94 | "# NoPin1D = 40\n", 95 | "# RoughMinAxis = min([Inter_Right_x - Inter_Left_x, \\\n", 96 | "# Inter_Right_y - Inter_Left_y, \\\n", 97 | "# Inter_Right_z - Inter_Left_z])\n", 98 | "\n", 99 | "# RoughMindis = RoughMinAxis / NoPin1D\n", 100 | "\n", 101 | "# Truncation paremeter\n", 102 | "# Trunc_r_0 = RoughMindis * 3\n", 103 | "# Trunc_r_1 = Trunc_r_0 * 1.5\n", 104 | "# Trunc_rn = 10\n", 105 | "\n", 106 | "# # Support domain paremeter\n", 107 | "# h_0 = RoughMindis * 1.2\n", 108 | "# h_1 = h_0 * 2\n", 109 | "# hn = 10\n", 110 | "\n", 111 | "\n", 112 | "# ClusterRegion = 2" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 2, 118 | "id": "a1ce6e23", 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stderr", 123 | "output_type": "stream", 124 | "text": [ 125 | "/home/kukup/MachineScientist/v0.0.3/DDDA/packageTest.py:46: RuntimeWarning: divide by zero encountered in divide\n", 126 | " RoughMindis = RoughMinAxis / NoPin1D\n" 127 | ] 128 | }, 129 | { 130 | "ename": "UnboundLocalError", 131 | "evalue": "local variable 'np' referenced before assignment", 132 | "output_type": "error", 133 | "traceback": [ 134 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 135 | "\u001b[0;31mUnboundLocalError\u001b[0m Traceback (most recent call last)", 136 | "Cell \u001b[0;32mIn [2], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpackageTest\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m DDDA\n\u001b[1;32m 2\u001b[0m my_work \u001b[38;5;241m=\u001b[39m DDDA(DataX, DataY, DataZ, DataF, InterLength, InterShift, \\\n\u001b[1;32m 3\u001b[0m r0, rn, Claster)\n\u001b[0;32m----> 4\u001b[0m \u001b[43mmy_work\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mDDDARun\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", 137 | "File \u001b[0;32m~/MachineScientist/v0.0.3/DDDA/packageTest.py:71\u001b[0m, in \u001b[0;36mDDDA.DDDARun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 68\u001b[0m DataZ_Xmin_Ori \u001b[38;5;241m=\u001b[39m copy\u001b[38;5;241m.\u001b[39mdeepcopy(DataZ)\n\u001b[1;32m 69\u001b[0m DataF_Xmin_Ori \u001b[38;5;241m=\u001b[39m copy\u001b[38;5;241m.\u001b[39mdeepcopy(DataF)\n\u001b[0;32m---> 71\u001b[0m XMinx_Frame \u001b[38;5;241m=\u001b[39m \u001b[43mnp\u001b[49m\u001b[38;5;241m.\u001b[39mzeros((NoPs,\u001b[38;5;241m1\u001b[39m))\n\u001b[1;32m 72\u001b[0m XMiny_Frame \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mzeros((NoPs,\u001b[38;5;241m1\u001b[39m))\n\u001b[1;32m 73\u001b[0m XMinz_Frame \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mzeros((NoPs,\u001b[38;5;241m1\u001b[39m))\n", 138 | "\u001b[0;31mUnboundLocalError\u001b[0m: local variable 'np' referenced before assignment" 139 | ] 140 | } 141 | ], 142 | "source": [ 143 | "\n", 144 | "from packageTest import DDDA\n", 145 | "my_work = DDDA(DataX, DataY, DataZ, DataF, InterLength, InterShift, \\\n", 146 | " r0, rn, Claster)\n", 147 | "my_work.DDDARun()" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "id": "be2b5d9c", 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [] 157 | } 158 | ], 159 | "metadata": { 160 | "kernelspec": { 161 | "display_name": "Python 3 (ipykernel)", 162 | "language": "python", 163 | "name": "python3" 164 | }, 165 | "language_info": { 166 | "codemirror_mode": { 167 | "name": "ipython", 168 | "version": 3 169 | }, 170 | "file_extension": ".py", 171 | "mimetype": "text/x-python", 172 | "name": "python", 173 | "nbconvert_exporter": "python", 174 | "pygments_lexer": "ipython3", 175 | "version": "3.8.13" 176 | }, 177 | "toc": { 178 | "base_numbering": 1, 179 | "nav_menu": {}, 180 | "number_sections": true, 181 | "sideBar": true, 182 | "skip_h1_title": false, 183 | "title_cell": "Table of Contents", 184 | "title_sidebar": "Contents", 185 | "toc_cell": false, 186 | "toc_position": {}, 187 | "toc_section_display": true, 188 | "toc_window_display": false 189 | }, 190 | "varInspector": { 191 | "cols": { 192 | "lenName": 16, 193 | "lenType": 16, 194 | "lenVar": 40 195 | }, 196 | "kernels_config": { 197 | "python": { 198 | "delete_cmd_postfix": "", 199 | "delete_cmd_prefix": "del ", 200 | "library": "var_list.py", 201 | "varRefreshCmd": "print(var_dic_list())" 202 | }, 203 | "r": { 204 | "delete_cmd_postfix": ") ", 205 | "delete_cmd_prefix": "rm(", 206 | "library": "var_list.r", 207 | "varRefreshCmd": "cat(var_dic_list()) " 208 | } 209 | }, 210 | "position": { 211 | "height": "400.844px", 212 | "left": "958.328px", 213 | "right": "20px", 214 | "top": "121px", 215 | "width": "660px" 216 | }, 217 | "types_to_exclude": [ 218 | "module", 219 | "function", 220 | "builtin_function_or_method", 221 | "instance", 222 | "_Feature" 223 | ], 224 | "window_display": false 225 | } 226 | }, 227 | "nbformat": 4, 228 | "nbformat_minor": 5 229 | } 230 | -------------------------------------------------------------------------------- /DDDA/DDDA/DDDA.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: DDDA 3 | Version: 0.0.3 4 | Author: Jiashun Pang 5 | -------------------------------------------------------------------------------- /DDDA/DDDA/DDDA.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | setup.py 2 | DDDA.egg-info/PKG-INFO 3 | DDDA.egg-info/SOURCES.txt 4 | DDDA.egg-info/dependency_links.txt 5 | DDDA.egg-info/top_level.txt -------------------------------------------------------------------------------- /DDDA/DDDA/DDDA.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /DDDA/DDDA/DDDA.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /DDDA/DDDA/DDDAGO.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | class DDDA: 8 | def __init__(self, *args, **kwargs): 9 | if len(args) == 0: 10 | print('No data') 11 | else: 12 | try: 13 | self.Dataf = args[0] 14 | except: 15 | print('0') 16 | else: 17 | self.Dataf = args[0] 18 | 19 | try: 20 | self.DataX = args[1] 21 | except: 22 | print('1') 23 | else: 24 | self.DataX = args[1] 25 | 26 | try: 27 | self.DataY = args[2] 28 | except: 29 | print('2') 30 | else: 31 | self.DataY = args[2] 32 | 33 | try: 34 | self.DataZ = args[3] 35 | except: 36 | print('3') 37 | else: 38 | self.DataZ = args[3] 39 | # Dict 40 | try: 41 | self.InterLength = kwargs['InterLength'] 42 | except: 43 | print('default interLength') 44 | self.InterLength = round(len(args[0]) ** (1 / (len(args) - 1))) 45 | else: 46 | self.InterLength = round(\ 47 | kwargs['InterLength'] * \ 48 | len(args[0]) ** (1 / (len(args) - 1))) 49 | 50 | try: 51 | self.r0 = kwargs['r0'] 52 | except: 53 | print('default r0 is 3') 54 | self.r0 = 3 55 | else: 56 | self.r0 = kwargs['r0'] 57 | 58 | try: 59 | self.rn = kwargs['rn'] 60 | except: 61 | print('default rn is 10') 62 | self.rn = 10 63 | else: 64 | self.rn = kwargs['rn'] 65 | 66 | try: 67 | self.Claster = kwargs['Claster'] 68 | except: 69 | print('default Cluster is 2') 70 | self.Claster = 2 71 | else: 72 | self.Claster = kwargs['Claster'] 73 | 74 | try: 75 | self.InterShift = kwargs['InterShift'] 76 | except: 77 | print('default InterShift') 78 | self.InterShift = (max(args[1]) - min(args[1])) * 0.1 79 | else: 80 | self.InterShift = kwargs['InterShift'] * \ 81 | (max(args[1]) - min(args[1])) 82 | 83 | def DDDARun(self): 84 | import numpy as np 85 | import copy 86 | import matplotlib.pyplot as plt 87 | import scipy.io as scio 88 | from mpl_toolkits.mplot3d import axes3d 89 | import pandas as pd 90 | import scipy.stats as stats 91 | import math 92 | from numba import jit # Accelerator 93 | from scipy.spatial import Voronoi, ConvexHull 94 | from sklearn.neighbors import KDTree, KernelDensity 95 | from sklearn.model_selection import GridSearchCV 96 | import platform 97 | import seaborn as sns 98 | DataX = self.DataX 99 | DataY = self.DataY 100 | DataZ = self.DataZ 101 | DataF = self.Dataf 102 | 103 | DataX = DataX.reshape((np.size(DataX), 1)) 104 | DataY = DataY.reshape((np.size(DataY), 1)) 105 | DataZ = DataZ.reshape((np.size(DataZ), 1)) 106 | DataF = DataF.reshape((np.size(DataF), 1)) 107 | 108 | DataLength = int(len(DataX) ** (1/3)) 109 | NoPin1D = DataLength 110 | 111 | 112 | 113 | NoPs = int(NoPin1D ** 2) 114 | 115 | n = self.InterLength 116 | InterShift = self.InterShift 117 | 118 | Inter_Left_x = min(DataX) + InterShift 119 | Inter_Right_x = max(DataX) - InterShift 120 | Inter_Left_y = min(DataY) + InterShift 121 | Inter_Right_y = max(DataY) - InterShift 122 | Inter_Left_z = min(DataZ) + InterShift 123 | Inter_Right_z = max(DataZ) - InterShift 124 | 125 | RoughMinAxis = min([Inter_Right_x - Inter_Left_x, \ 126 | Inter_Right_y - Inter_Left_y, \ 127 | Inter_Right_z - Inter_Left_z]) 128 | 129 | RoughMindis = RoughMinAxis / NoPin1D 130 | 131 | r1 = self.r0 132 | rn = self.rn 133 | Trunc_r_0 = RoughMindis * r1 134 | Trunc_r_1 = Trunc_r_0 * 1.5 135 | Trunc_rn = rn 136 | 137 | h_0 = Trunc_r_0 / 2.5 138 | h_1 = h_0 * 2 139 | hn = rn 140 | 141 | ClusterRegion = self.Claster 142 | 143 | # Temporary parameter for boundary reflection 144 | X_mid = (max(DataX) - min(DataX))/2 + min(DataX) 145 | Y_mid = (max(DataY) - min(DataY))/2 + min(DataY) 146 | Z_mid = (max(DataZ) - min(DataZ))/2 + min(DataZ) 147 | 148 | #Xmin Y-Z plane 149 | DataX_Xmin_Ori = copy.deepcopy(DataX) 150 | DataY_Xmin_Ori = copy.deepcopy(DataY) 151 | DataZ_Xmin_Ori = copy.deepcopy(DataZ) 152 | DataF_Xmin_Ori = copy.deepcopy(DataF) 153 | 154 | XMinx_Frame = np.zeros((NoPs,1)) 155 | XMiny_Frame = np.zeros((NoPs,1)) 156 | XMinz_Frame = np.zeros((NoPs,1)) 157 | XMinx_M1 = np.zeros((NoPs,1)) 158 | XMiny_M1 = np.zeros((NoPs,1)) 159 | XMinz_M1 = np.zeros((NoPs,1)) 160 | 161 | #Frame - The reference line 162 | for PtN in range(NoPs): 163 | PT_temp = DataX_Xmin_Ori.argmin() 164 | XMinx_Frame[PtN] = DataX_Xmin_Ori[PT_temp] 165 | XMiny_Frame[PtN] = DataY_Xmin_Ori[PT_temp] 166 | XMinz_Frame[PtN] = DataZ_Xmin_Ori[PT_temp] 167 | 168 | DataX_Xmin_Ori[PT_temp] = X_mid 169 | DataY_Xmin_Ori[PT_temp] = Y_mid 170 | DataZ_Xmin_Ori[PT_temp] = Z_mid 171 | 172 | # M1 & M1m Line 173 | for PtN in range(NoPs): 174 | PT_temp = DataX_Xmin_Ori.argmin() 175 | XMinx_M1[PtN] = DataX_Xmin_Ori[PT_temp] 176 | XMiny_M1[PtN] = DataY_Xmin_Ori[PT_temp] 177 | XMinz_M1[PtN] = DataZ_Xmin_Ori[PT_temp] 178 | 179 | # Cutting Reflection 180 | XMinx_FrameR = -1 * XMinx_Frame 181 | Xmin_Offset = np.abs(np.mean(XMinx_Frame - XMinx_M1)) 182 | Xmin_GAP = np.abs(np.mean(XMinx_Frame - XMinx_FrameR)) 183 | XMinx_CR = XMinx_FrameR + Xmin_GAP - Xmin_Offset 184 | 185 | DataX_xmin_DONE = np.vstack((DataX, XMinx_CR)) 186 | DataY_xmin_DONE = np.vstack((DataY, XMiny_Frame)) 187 | DataZ_xmin_DONE = np.vstack((DataZ, XMinz_Frame)) 188 | 189 | # Left boundary reflection 190 | # Yellow reflected points, Red Reference points 191 | 192 | #Zmin X-Y plane 193 | NoPs = 1640 194 | DataX_Zmin_Ori = copy.deepcopy(DataX_xmin_DONE) 195 | DataY_Zmin_Ori = copy.deepcopy(DataY_xmin_DONE) 196 | DataZ_Zmin_Ori = copy.deepcopy(DataZ_xmin_DONE) 197 | 198 | ZMinx_Frame = np.zeros((NoPs,1)) 199 | ZMiny_Frame = np.zeros((NoPs,1)) 200 | ZMinz_Frame = np.zeros((NoPs,1)) 201 | ZMinx_M1 = np.zeros((NoPs,1)) 202 | ZMiny_M1 = np.zeros((NoPs,1)) 203 | ZMinz_M1 = np.zeros((NoPs,1)) 204 | 205 | #Frame - The reference line 206 | for PtN in range(NoPs): 207 | PT_temp = DataZ_Zmin_Ori.argmin() 208 | ZMinx_Frame[PtN] = DataX_Zmin_Ori[PT_temp] 209 | ZMiny_Frame[PtN] = DataY_Zmin_Ori[PT_temp] 210 | ZMinz_Frame[PtN] = DataZ_Zmin_Ori[PT_temp] 211 | 212 | DataX_Zmin_Ori[PT_temp] = X_mid 213 | DataY_Zmin_Ori[PT_temp] = Y_mid 214 | DataZ_Zmin_Ori[PT_temp] = Z_mid 215 | 216 | 217 | # M1 & M1m Line 218 | for PtN in range(NoPs): 219 | PT_temp = DataZ_Zmin_Ori.argmin() 220 | ZMinx_M1[PtN] = DataX_Zmin_Ori[PT_temp] 221 | ZMiny_M1[PtN] = DataY_Zmin_Ori[PT_temp] 222 | ZMinz_M1[PtN] = DataZ_Zmin_Ori[PT_temp] 223 | 224 | # Cutting Reflection 225 | ZMinz_FrameR = -1 * ZMinz_Frame 226 | Zmin_Offset = np.abs(np.mean(ZMinz_Frame - ZMinz_M1)) 227 | Zmin_GAP = np.abs(np.mean(ZMinz_Frame - ZMinz_FrameR)) 228 | ZMinz_CR = ZMinz_FrameR - Zmin_GAP - Zmin_Offset 229 | 230 | DataX_Zmin_DONE = np.vstack((DataX_xmin_DONE, ZMinx_Frame)) 231 | DataY_Zmin_DONE = np.vstack((DataY_xmin_DONE, ZMiny_Frame)) 232 | DataZ_Zmin_DONE = np.vstack((DataZ_xmin_DONE, ZMinz_CR)) 233 | 234 | # Left boundary reflection 235 | # Yellow reflected points, Red Reference points 236 | 237 | #Ymin X-Z plane 238 | NoPs = 1681 239 | DataX_Ymin_Ori = copy.deepcopy(DataX_Zmin_DONE) 240 | DataY_Ymin_Ori = copy.deepcopy(DataY_Zmin_DONE) 241 | DataZ_Ymin_Ori = copy.deepcopy(DataZ_Zmin_DONE) 242 | 243 | YMinx_Frame = np.zeros((NoPs,1)) 244 | YMiny_Frame = np.zeros((NoPs,1)) 245 | YMinz_Frame = np.zeros((NoPs,1)) 246 | YMinx_M1 = np.zeros((NoPs,1)) 247 | YMiny_M1 = np.zeros((NoPs,1)) 248 | YMinz_M1 = np.zeros((NoPs,1)) 249 | 250 | #Frame - The reference line 251 | for PtN in range(NoPs): 252 | PT_temp = DataY_Ymin_Ori.argmin() 253 | YMinx_Frame[PtN] = DataX_Ymin_Ori[PT_temp] 254 | YMiny_Frame[PtN] = DataY_Ymin_Ori[PT_temp] 255 | YMinz_Frame[PtN] = DataZ_Ymin_Ori[PT_temp] 256 | 257 | DataX_Ymin_Ori[PT_temp] = X_mid 258 | DataY_Ymin_Ori[PT_temp] = Y_mid 259 | DataZ_Ymin_Ori[PT_temp] = Z_mid 260 | 261 | # M1 & M1m Line 262 | for PtN in range(NoPs): 263 | PT_temp = DataY_Ymin_Ori.argmin() 264 | YMinx_M1[PtN] = DataX_Ymin_Ori[PT_temp] 265 | YMiny_M1[PtN] = DataY_Ymin_Ori[PT_temp] 266 | YMinz_M1[PtN] = DataZ_Ymin_Ori[PT_temp] 267 | 268 | # Cutting Reflection 269 | YMiny_FrameR = -1 * YMiny_Frame 270 | Ymin_Offset = np.abs(np.mean(YMiny_Frame - YMiny_M1)) 271 | Ymin_GAP = np.abs(np.mean(YMiny_Frame - YMiny_FrameR)) 272 | YMiny_CR = YMiny_FrameR + Ymin_GAP - Ymin_Offset 273 | 274 | DataX_Ymin_DONE = np.vstack((DataX_Zmin_DONE, YMinx_Frame)) 275 | DataY_Ymin_DONE = np.vstack((DataY_Zmin_DONE, YMiny_CR)) 276 | DataZ_Ymin_DONE = np.vstack((DataZ_Zmin_DONE, YMinz_Frame)) 277 | 278 | # Left boundary reflection 279 | # Yellow reflected points, Red Reference points 280 | 281 | #Xmax Y-Z plane 282 | NoPs = 1681 283 | DataX_Xmax_Ori = copy.deepcopy(DataX_Ymin_DONE) 284 | DataY_Xmax_Ori = copy.deepcopy(DataY_Ymin_DONE) 285 | DataZ_Xmax_Ori = copy.deepcopy(DataZ_Ymin_DONE) 286 | 287 | XMaxx_Frame = np.zeros((NoPs,1)) 288 | XMaxy_Frame = np.zeros((NoPs,1)) 289 | XMaxz_Frame = np.zeros((NoPs,1)) 290 | XMaxx_M1 = np.zeros((NoPs,1)) 291 | XMaxy_M1 = np.zeros((NoPs,1)) 292 | XMaxz_M1 = np.zeros((NoPs,1)) 293 | 294 | #Frame - The reference line 295 | for PtN in range(NoPs): 296 | PT_temp = DataX_Xmax_Ori.argmax() 297 | XMaxx_Frame[PtN] = DataX_Xmax_Ori[PT_temp] 298 | XMaxy_Frame[PtN] = DataY_Xmax_Ori[PT_temp] 299 | XMaxz_Frame[PtN] = DataZ_Xmax_Ori[PT_temp] 300 | 301 | DataX_Xmax_Ori[PT_temp] = X_mid 302 | DataY_Xmax_Ori[PT_temp] = Y_mid 303 | DataZ_Xmax_Ori[PT_temp] = Z_mid 304 | 305 | 306 | # M1 & M1m Line 307 | for PtN in range(NoPs): 308 | PT_temp = DataX_Xmax_Ori.argmax() 309 | XMaxx_M1[PtN] = DataX_Xmax_Ori[PT_temp] 310 | XMaxy_M1[PtN] = DataY_Xmax_Ori[PT_temp] 311 | XMaxz_M1[PtN] = DataZ_Xmax_Ori[PT_temp] 312 | 313 | # Cutting Reflection 314 | XMaxx_FrameR = -1 * XMaxx_Frame 315 | Xmax_Offset = np.abs(np.mean(XMaxx_Frame - XMaxx_M1)) 316 | Xmax_GAP = np.abs(np.mean(XMaxx_Frame - XMaxx_FrameR)) 317 | XMaxx_CR = XMaxx_FrameR + Xmax_GAP + Xmax_Offset 318 | 319 | DataX_Xmax_DONE = np.vstack((DataX_Ymin_DONE, XMaxx_CR)) 320 | DataY_Xmax_DONE = np.vstack((DataY_Ymin_DONE, XMaxy_Frame)) 321 | DataZ_Xmax_DONE = np.vstack((DataZ_Ymin_DONE, XMaxz_Frame)) 322 | 323 | # Left boundary reflection 324 | # Yellow reflected points, Red Reference points 325 | 326 | #Ymax X-Z plane 327 | NoPs = 1722 328 | DataX_Ymax_Ori = copy.deepcopy(DataX_Xmax_DONE) 329 | DataY_Ymax_Ori = copy.deepcopy(DataY_Xmax_DONE) 330 | DataZ_Ymax_Ori = copy.deepcopy(DataZ_Xmax_DONE) 331 | 332 | YMaxx_Frame = np.zeros((NoPs,1)) 333 | YMaxy_Frame = np.zeros((NoPs,1)) 334 | YMaxz_Frame = np.zeros((NoPs,1)) 335 | YMaxx_M1 = np.zeros((NoPs,1)) 336 | YMaxy_M1 = np.zeros((NoPs,1)) 337 | YMaxz_M1 = np.zeros((NoPs,1)) 338 | 339 | #Frame - The reference line 340 | for PtN in range(NoPs): 341 | PT_temp = DataY_Ymax_Ori.argmax() 342 | YMaxx_Frame[PtN] = DataX_Ymax_Ori[PT_temp] 343 | YMaxy_Frame[PtN] = DataY_Ymax_Ori[PT_temp] 344 | YMaxz_Frame[PtN] = DataZ_Ymax_Ori[PT_temp] 345 | 346 | DataX_Ymax_Ori[PT_temp] = X_mid 347 | DataY_Ymax_Ori[PT_temp] = Y_mid 348 | DataZ_Ymax_Ori[PT_temp] = Z_mid 349 | 350 | 351 | # M1 & M1m Line 352 | for PtN in range(NoPs): 353 | PT_temp = DataY_Ymax_Ori.argmax() 354 | YMaxx_M1[PtN] = DataX_Ymax_Ori[PT_temp] 355 | YMaxy_M1[PtN] = DataY_Ymax_Ori[PT_temp] 356 | YMaxz_M1[PtN] = DataZ_Ymax_Ori[PT_temp] 357 | 358 | # Cutting Reflection 359 | YMaxy_FrameR = -1 * YMaxy_Frame 360 | Ymax_Offset = np.abs(np.mean(YMaxy_Frame - YMaxy_M1)) 361 | Ymax_GAP = np.abs(np.mean(YMaxy_Frame - YMaxy_FrameR)) 362 | YMaxy_CR = YMaxy_FrameR + Ymax_GAP + Ymax_Offset 363 | 364 | DataX_Ymax_DONE = np.vstack((DataX_Xmax_DONE, YMaxx_Frame)) 365 | DataY_Ymax_DONE = np.vstack((DataY_Xmax_DONE, YMaxy_CR)) 366 | DataZ_Ymax_DONE = np.vstack((DataZ_Xmax_DONE, YMaxz_Frame)) 367 | 368 | # Left boundary reflection 369 | # Yellow reflected points, Red Reference points 370 | 371 | #Zmax X-Y plane 372 | NoPs = 1764 373 | DataX_Zmax_Ori = copy.deepcopy(DataX_Ymax_DONE) 374 | DataY_Zmax_Ori = copy.deepcopy(DataY_Ymax_DONE) 375 | DataZ_Zmax_Ori = copy.deepcopy(DataZ_Ymax_DONE) 376 | 377 | ZMaxx_Frame = np.zeros((NoPs,1)) 378 | ZMaxy_Frame = np.zeros((NoPs,1)) 379 | ZMaxz_Frame = np.zeros((NoPs,1)) 380 | ZMaxx_M1 = np.zeros((NoPs,1)) 381 | ZMaxy_M1 = np.zeros((NoPs,1)) 382 | ZMaxz_M1 = np.zeros((NoPs,1)) 383 | 384 | #Frame - The reference line 385 | for PtN in range(NoPs): 386 | PT_temp = DataZ_Zmax_Ori.argmax() 387 | ZMaxx_Frame[PtN] = DataX_Zmax_Ori[PT_temp] 388 | ZMaxy_Frame[PtN] = DataY_Zmax_Ori[PT_temp] 389 | ZMaxz_Frame[PtN] = DataZ_Zmax_Ori[PT_temp] 390 | 391 | DataX_Zmax_Ori[PT_temp] = X_mid 392 | DataY_Zmax_Ori[PT_temp] = Y_mid 393 | DataZ_Zmax_Ori[PT_temp] = Z_mid 394 | 395 | # M1 & M1m Line 396 | for PtN in range(NoPs): 397 | PT_temp = DataZ_Zmax_Ori.argmax() 398 | ZMaxx_M1[PtN] = DataX_Zmax_Ori[PT_temp] 399 | ZMaxy_M1[PtN] = DataY_Zmax_Ori[PT_temp] 400 | ZMaxz_M1[PtN] = DataZ_Zmax_Ori[PT_temp] 401 | 402 | # Cutting Reflection 403 | ZMaxz_FrameR = -1 * ZMaxz_Frame 404 | Zmax_Offset = np.abs(np.mean(ZMaxz_Frame - ZMaxz_M1)) 405 | Zmax_GAP = np.abs(np.mean(ZMaxz_Frame - ZMaxz_FrameR)) 406 | ZMaxz_CR = ZMaxz_FrameR + Zmax_GAP + Zmax_Offset 407 | 408 | DataX_Zmax_DONE = np.vstack((DataX_Ymax_DONE, ZMaxx_Frame)) 409 | DataY_Zmax_DONE = np.vstack((DataY_Ymax_DONE, ZMaxy_Frame)) 410 | DataZ_Zmax_DONE = np.vstack((DataZ_Ymax_DONE, ZMaxz_CR)) 411 | 412 | # Left boundary reflection 413 | # Yellow reflected points, Red Reference points 414 | 415 | # Show points cloud and reflected boundary 416 | Data3D_x = copy.deepcopy(DataX_Zmax_DONE) 417 | Data3D_y = copy.deepcopy(DataY_Zmax_DONE) 418 | Data3D_z = copy.deepcopy(DataZ_Zmax_DONE) 419 | Data3D = np.hstack((Data3D_x, Data3D_y, Data3D_z)) 420 | 421 | vor = Voronoi(Data3D) 422 | vor_vertices = copy.deepcopy(vor.vertices) 423 | vor_regions = copy.deepcopy(vor.regions) 424 | 425 | # The crude votonoi cell, the boundary was tend to infinity 426 | 427 | OriginNoCell = len(vor_regions) 428 | 429 | NoVoronoiCell = len(vor.regions) 430 | V_vertices_x = copy.deepcopy(vor.vertices[:, 0]) 431 | V_vertices_y = copy.deepcopy(vor.vertices[:, 1]) 432 | V_vertices_z = copy.deepcopy(vor.vertices[:, 2]) 433 | 434 | V_coord_x = [ [] for _ in range(NoVoronoiCell) ] 435 | V_coord_y = [ [] for _ in range(NoVoronoiCell) ] 436 | V_coord_z = [ [] for _ in range(NoVoronoiCell) ] 437 | 438 | XMax = np.max(XMaxx_CR - 0.3 * Xmax_Offset) 439 | YMax = np.max(YMaxy_CR - 0.3 * Ymax_Offset) 440 | ZMax = np.max(ZMaxz_CR - 0.3 * Zmax_Offset) 441 | XMin = np.max(XMinx_CR - 0.3 * Xmin_Offset) 442 | YMin = np.max(YMiny_CR - 0.3 * Ymin_Offset) 443 | ZMin = np.max(ZMinz_CR - 0.3 * Zmax_Offset) 444 | 445 | # Delete the exceed points which behind or wothin 'The frame' in 446 | # section 1.2 boundary secure 447 | NoPs = 42 448 | XGrid_ST = (XMax - XMin)/NoPs 449 | YGrid_ST = (YMax - YMin)/NoPs 450 | ZGrid_ST = (ZMax - ZMin)/NoPs 451 | 452 | 453 | VEmptyCount = 0 454 | Cell_STD_x = np.zeros(NoVoronoiCell) 455 | Cell_STD_y = np.zeros(NoVoronoiCell) 456 | Cell_STD_z = np.zeros(NoVoronoiCell) 457 | 458 | for i in range(NoVoronoiCell): 459 | 460 | DeleteHint = 0; 461 | VL_Temp = len(vor.regions[i]) 462 | 463 | if VL_Temp == 0: 464 | continue 465 | 466 | V_coord_x[i] = np.zeros(VL_Temp) 467 | V_coord_y[i] = np.zeros(VL_Temp) 468 | V_coord_z[i] = np.zeros(VL_Temp) 469 | Ori_Check_x = np.zeros(VL_Temp) 470 | Ori_Check_y = np.zeros(VL_Temp) 471 | Ori_Check_z = np.zeros(VL_Temp) 472 | 473 | for j in range(VL_Temp): 474 | NoC = vor.regions[i][j] 475 | V_coord_x[i][j] = V_vertices_x[NoC] 476 | V_coord_y[i][j] = V_vertices_y[NoC] 477 | V_coord_z[i][j] = V_vertices_z[NoC] 478 | Ori_Check_x[j] = V_vertices_x[NoC] 479 | Ori_Check_y[j] = V_vertices_y[NoC] 480 | Ori_Check_z[j] = V_vertices_z[NoC] 481 | 482 | if V_coord_x[i][j] < XMin and np.std(V_coord_x[i]) > XGrid_ST * 0.6: 483 | 484 | V_coord_x[i] = [] 485 | V_coord_y[i] = [] 486 | V_coord_z[i] = [] 487 | VEmptyCount = VEmptyCount + 1 488 | DeleteHint = 1 489 | break 490 | elif V_coord_x[i][j] > XMax and np.std(V_coord_x[i]) > XGrid_ST * 0.6: 491 | V_coord_x[i] = [] 492 | V_coord_y[i] = [] 493 | V_coord_z[i] = [] 494 | VEmptyCount = VEmptyCount + 1 495 | DeleteHint = 1 496 | break 497 | elif V_coord_y[i][j] > YMax and np.std(V_coord_y[i]) > XGrid_ST * 0.6: 498 | V_coord_x[i] = [] 499 | V_coord_y[i] = [] 500 | V_coord_z[i] = [] 501 | VEmptyCount = VEmptyCount + 1 502 | DeleteHint = 1 503 | break 504 | elif V_coord_y[i][j] < YMin and np.std(V_coord_y[i]) > XGrid_ST * 0.6: 505 | V_coord_x[i] = [] 506 | V_coord_y[i] = [] 507 | V_coord_z[i] = [] 508 | VEmptyCount = VEmptyCount + 1 509 | DeleteHint = 1 510 | break 511 | elif V_coord_z[i][j] > ZMax and np.std(V_coord_z[i]) > XGrid_ST * 0.6: 512 | V_coord_x[i] = [] 513 | V_coord_y[i] = [] 514 | V_coord_z[i] = [] 515 | VEmptyCount = VEmptyCount + 1 516 | DeleteHint = 1 517 | break 518 | elif V_coord_z[i][j] < ZMin and np.std(V_coord_z[i]) > XGrid_ST * 0.6: 519 | V_coord_x[i] = [] 520 | V_coord_y[i] = [] 521 | V_coord_z[i] = [] 522 | VEmptyCount = VEmptyCount + 1 523 | DeleteHint = 1 524 | break 525 | 526 | if DeleteHint == 0: 527 | V_coord_x[i] = np.append(V_coord_x[i], V_coord_x[i][0]) 528 | V_coord_y[i] = np.append(V_coord_y[i], V_coord_y[i][0]) 529 | V_coord_z[i] = np.append(V_coord_z[i], V_coord_z[i][0]) 530 | 531 | 532 | NewNoPCell = len(V_coord_x) 533 | 534 | 535 | NewIndex = 0 536 | NewV_coord_x = list() 537 | NewV_coord_y = list() 538 | NewV_coord_z = list() 539 | 540 | for NoC in range(len(vor.regions)): 541 | if len(V_coord_x[NoC]) == 0: 542 | continue 543 | elif len(V_coord_x[NoC]) != 0 and NewIndex == 0: 544 | NewV_coord_x.append(V_coord_x[NoC]) 545 | NewV_coord_y.append(V_coord_y[NoC]) 546 | NewV_coord_z.append(V_coord_z[NoC]) 547 | NewIndex = NewIndex + 1 548 | else: 549 | NewV_coord_x.append(V_coord_x[NoC]) 550 | NewV_coord_y.append(V_coord_y[NoC]) 551 | NewV_coord_z.append(V_coord_z[NoC]) 552 | NewIndex = NewIndex + 1 553 | 554 | VolVoeSubj = np.zeros(NewIndex) 555 | OutBoundaryCount = 0 556 | 557 | for i in range(NewIndex): 558 | CellL = len(NewV_coord_x[i]) 559 | xxx = np.zeros((CellL, 3)) 560 | WrongCell = 0 561 | 562 | for j in range(CellL): 563 | 564 | xxx[j][0] = NewV_coord_x[i][j] 565 | xxx[j][1] = NewV_coord_y[i][j] 566 | xxx[j][2] = NewV_coord_z[i][j] 567 | try: 568 | vvvv = ConvexHull(xxx) 569 | except: 570 | VolVoeSubj[i] = 0 571 | OutBoundaryCount = OutBoundaryCount + 1 572 | else: 573 | VolVoeSubj[i] = vvvv.volume 574 | 575 | NewNoPCell = len(VolVoeSubj) 576 | 577 | 578 | for i in range(NewNoPCell): 579 | if VolVoeSubj[i] > 0.001: 580 | VolVoeSubj[i] = 0 581 | 582 | 583 | 584 | Inter_Data_x = np.linspace(Inter_Left_x, Inter_Right_x, num = n) 585 | Inter_Data_y = np.linspace(Inter_Left_y, Inter_Right_y, num = n) 586 | Inter_Data_z = np.linspace(Inter_Left_z, Inter_Right_z, num = n) 587 | 588 | x_Inter = np.zeros(pow(n, 3)) 589 | y_Inter = np.zeros(pow(n, 3)) 590 | z_Inter = np.zeros(pow(n, 3)) 591 | 592 | for xIndex in range(n): 593 | for yIndex in range(n): 594 | for zIndex in range(n): 595 | 596 | x_Inter[xIndex * n * n + yIndex * n + zIndex] = \ 597 | Inter_Data_x[xIndex] 598 | y_Inter[xIndex * n * n + yIndex * n + zIndex] = \ 599 | Inter_Data_y[yIndex] 600 | z_Inter[xIndex * n * n + yIndex * n + zIndex] = \ 601 | Inter_Data_z[zIndex] 602 | 603 | x_Inter = np.reshape(x_Inter, (len(x_Inter), 1)) 604 | y_Inter = np.reshape(y_Inter, (len(y_Inter), 1)) 605 | z_Inter = np.reshape(z_Inter, (len(z_Inter), 1)) 606 | 607 | 608 | 609 | DataSet_3D = np.hstack((DataX, DataY, DataZ)) 610 | InterSet_3D = np.hstack((x_Inter, y_Inter, z_Inter)) 611 | 612 | 613 | Trunc_r_range = np.linspace(Trunc_r_0, Trunc_r_1, Trunc_rn) 614 | 615 | def DomainCutoff(DataSet, Interpoints, r_range, rn): 616 | PoinsInd = [] 617 | distance = [] 618 | 619 | tree = KDTree(DataSet) # Assign K-D tree 620 | for i in range(rn): 621 | 622 | PoinsInd_one, distance_one = tree.query_radius(Interpoints, \ 623 | r = r_range[i], \ 624 | return_distance=True) 625 | PoinsInd.append(PoinsInd_one) 626 | distance.append(distance_one) 627 | return PoinsInd, distance 628 | 629 | PoinsInd, distance, = DomainCutoff(DataSet_3D, InterSet_3D, \ 630 | Trunc_r_range, Trunc_rn) 631 | 632 | 633 | h_range = np.linspace(h_0, h_1, hn) 634 | 635 | # Gaussion constant coordinate 636 | aGau = list(map(lambda x: 1 / (pow(math.pi, 1.5) * pow(x, 3)), h_range)) 637 | aGau = np.array(aGau) 638 | 639 | # Gaussian kernel with varis support domain & truncate domain 640 | @jit(nopython=True) 641 | def DistanceAll(distance, PoinsIndNP, VolVoeSubj, aGau, h): 642 | 643 | N_Data = int(len(distance)) 644 | W_Gau_0th = 0 645 | W_Gau_1st = 0 646 | 647 | for j in range(N_Data): 648 | 649 | q = distance[j] / h 650 | W_GauN = aGau * (2.7128 ** ( -1 * (q ** 2))) 651 | # 0th moment 652 | W_Gau_0th = W_Gau_0th + W_GauN * VolVoeSubj[PoinsIndNP[j]] 653 | # 1st moment 654 | W_Gau_1st = W_Gau_1st + \ 655 | W_GauN * VolVoeSubj[PoinsIndNP[j]] * distance[j] 656 | 657 | return(W_Gau_0th, W_Gau_1st, N_Data) 658 | 659 | Q_length = len(distance[0]) 660 | W_Gau_0th_vari = np.zeros((Trunc_rn, hn, Q_length)) 661 | W_Gau_1st_vari = np.zeros((Trunc_rn, hn, Q_length)) 662 | N_Data = np.zeros((Trunc_rn, Q_length)) 663 | for k in range(Trunc_rn): 664 | distanceNP = np.array(distance[k][0:]) 665 | PoinsIndNP = np.array(PoinsInd[k]) 666 | 667 | for j in range(hn): 668 | aGauNP = aGau[j] 669 | h = h_range[j] 670 | for i in range(Q_length) : 671 | W_Gau_0th_vari[k, j, i], W_Gau_1st_vari[k, j, i], N_Data[k, i]= \ 672 | DistanceAll(distanceNP[i], PoinsIndNP[i], VolVoeSubj, \ 673 | aGauNP[0], h[0]) 674 | 675 | 676 | # # Distance of 0th moment to its target value 1 677 | # W0th_abs = np.reshape(abs(W_Gau_0th_vari[:, :, 10000] - 1), Trunc_rn * hn) 678 | # # 1st moment 679 | # W1st = np.reshape(W_Gau_1st_vari[:, :, 10000], Trunc_rn * hn) 680 | 681 | # orderr = np.linspace(0, Trunc_rn * hn - 1, Trunc_rn * hn) 682 | 683 | 684 | # # The distance between 2 moment to target value(0 and 1) 685 | # Choice = W0th_abs + W1st 686 | 687 | # Chioce the 0th and 1st moment parameter that are the most close to the 688 | # target value 689 | 690 | W_Gau_0th_fix = np.zeros(Q_length) 691 | W_Gau_1st_fix = np.zeros(Q_length) 692 | Trunc_r_fix = np.zeros(Q_length) 693 | Distance_r_fix_index = np.zeros(Q_length) 694 | h_fix = np.zeros(Q_length) 695 | 696 | for j in range(Q_length): 697 | 698 | W0th_abs = np.reshape(abs(W_Gau_0th_vari[:, :, j] - 1), Trunc_rn * hn) 699 | W1st = np.reshape(W_Gau_1st_vari[:, :, j], Trunc_rn * hn) 700 | Choice = W0th_abs + W1st 701 | 702 | MCT = np.zeros((3, 2)) 703 | MCT_Weighted = np.zeros((3, 1)) 704 | for i in range(3): 705 | MCT[i, 0] = min(Choice) 706 | MCT[i, 1] = Choice.argmin() 707 | Choice[int(MCT[i, 1])] = Choice[int(MCT[0, 1])] + 1 708 | 709 | for i in range(3): 710 | MCT_Weighted[i, 0] = MCT[i, 0] * (MCT[i, 1] / 100) 711 | 712 | MCT_0 = min(MCT_Weighted[:, 0]) 713 | MCT_Weighted_index = MCT_Weighted[:, 0].argmin() 714 | 715 | MCT_0_index = MCT[MCT_Weighted_index, 1] 716 | 717 | MCT_index_row = int(MCT_0_index // 10) 718 | MCT_index_column = int(MCT_0_index % 10) 719 | 720 | # Randomly pick a point and see its PDF for a slance check. 721 | # W_Gau_0th_fix[j] = W_Gau_0th_vari[MCT_index_row, MCT_index_column, 1000] 722 | # W_Gau_1st_fix[j] = W_Gau_1st_vari[MCT_index_row, MCT_index_column, 1000] 723 | # Trunc_r_fix[j] = Trunc_r_range[MCT_index_row] 724 | 725 | # Two key paremeters, will use in kernel derivateve 726 | Distance_r_fix_index[j] = MCT_index_row 727 | h_fix[j] = h_range[MCT_index_column] 728 | 729 | # Show how well the origin data out of by our smooth algorithm with choice 730 | # parameter. 731 | 732 | W_GauProve = np.zeros((Q_length, 1)) 733 | 734 | @jit(nopython=True) 735 | def DistanceAllP(distance, PoinsIndex, VolVoeSubj, h, DataF): 736 | 737 | W_Gauij = 0 738 | N_Data = len(distance) 739 | aGau = 1 / (pow(math.pi, 1.5) * pow(h, 3)) 740 | for j in range(N_Data): 741 | 742 | q = distance[j] / h 743 | W_GauN = aGau * (2.7128 ** ( -1 * (q ** 2))) 744 | W_Gauij = W_Gauij + W_GauN * VolVoeSubj[PoinsIndex[j]] * \ 745 | DataF[PoinsIndex[j]][0] 746 | 747 | return(W_Gauij) 748 | 749 | for i in range(Q_length) : 750 | r_index = int(Distance_r_fix_index[i]) 751 | 752 | W_GauProve[i] = DistanceAllP(distance[r_index][i], \ 753 | PoinsInd[r_index][i], \ 754 | VolVoeSubj, \ 755 | h_fix[i], DataF) 756 | 757 | Inter_Plot = np.linspace(0, 100, len(W_GauProve)) 758 | Data_Plot = np.linspace(0, 100, len(DataF)) 759 | 760 | # Determine the partial derivative along each dimension 761 | 762 | W_GauProvePD = np.zeros((Q_length, 1)) 763 | Gauij_dev_x = np.zeros((Q_length, 1)) 764 | Gauij_dev_y = np.zeros((Q_length, 1)) 765 | Gauij_dev_z = np.zeros((Q_length, 1)) 766 | Gx = np.zeros((Q_length, 1)) 767 | 768 | @jit(nopython=True) 769 | def PD_fix(distance, PoinsIndex, VolVoeSubj, h, DataF, DataX, DataY, \ 770 | DataZ, x_Inter, y_Inter, z_Inter): 771 | W_Gauij = 0 772 | Gauij_dev_x = 0 773 | Gauij_dev_y = 0 774 | Gauij_dev_z = 0 775 | 776 | N_Data = len(distance) 777 | aGau = 1 / (pow(math.pi, 1.5) * (h ** 3)) 778 | for j in range(N_Data): 779 | 780 | q = distance[j] / h 781 | W_GauN = aGau * (2.7128 ** ( -1 * (q ** 2))) 782 | W_Gauij = W_Gauij + W_GauN * VolVoeSubj[PoinsIndex[j]] * \ 783 | DataF[PoinsIndex[j]][0] 784 | 785 | dx = (x_Inter - DataX[PoinsIndex[j]]) / distance[j] 786 | dy = (y_Inter - DataY[PoinsIndex[j]]) / distance[j] 787 | dz = (z_Inter - DataZ[PoinsIndex[j]]) / distance[j] 788 | 789 | Gau_dev_x = dx * aGau * \ 790 | math.exp(-1 * q * q) * (-2 * distance[j] / (h * h)) 791 | 792 | Gauij_dev_x = Gauij_dev_x + Gau_dev_x[0] * \ 793 | VolVoeSubj[PoinsIndex[j]] * DataF[PoinsIndex[j]][0] 794 | 795 | Gau_dev_y = dy * aGau * \ 796 | math.exp(-1 * q * q) * (-2 * distance[j] / (h * h)) 797 | 798 | Gauij_dev_y = Gauij_dev_y + Gau_dev_y[0] * \ 799 | VolVoeSubj[PoinsIndex[j]] * DataF[PoinsIndex[j]][0] 800 | 801 | Gau_dev_z = dz * aGau * \ 802 | math.exp( -1 * q * q) * (-2 * distance[j] / (h * h)) 803 | 804 | Gauij_dev_z = Gauij_dev_z + Gau_dev_z[0] * \ 805 | VolVoeSubj[PoinsIndex[j]] * DataF[PoinsIndex[j]][0] 806 | 807 | return(W_Gauij, Gauij_dev_x, Gauij_dev_y, Gauij_dev_z) 808 | 809 | 810 | for i in range(Q_length) : 811 | r_index = int(Distance_r_fix_index[i]) 812 | 813 | W_GauProvePD[i], Gauij_dev_x[i], Gauij_dev_y[i], Gauij_dev_z[i] = \ 814 | PD_fix(distance[r_index][i], PoinsInd[r_index][i], \ 815 | VolVoeSubj, h_fix[i], DataF, DataX, DataY, \ 816 | DataZ, x_Inter[i], y_Inter[i], z_Inter[i]) 817 | 818 | 819 | import copy 820 | lenDD = len(Gauij_dev_x) 821 | 822 | DD1 = copy.deepcopy(Gauij_dev_x) 823 | DD2 = copy.deepcopy(Gauij_dev_y) 824 | DD3 = copy.deepcopy(Gauij_dev_z) 825 | 826 | LastEigenvector = np.zeros((lenDD, 3)) 827 | LastEigenvectorABS = np.zeros((lenDD, 3)) 828 | for i in range(lenDD): 829 | # for i in range(1): 830 | pFpi = np.vstack((DD1[i], DD2[i], DD3[i])) 831 | #print(pFpi)#1*3 832 | # WW = np.outer(pFpi, pFpi.transpose()) 833 | WW = np.dot(pFpi, pFpi.transpose()) 834 | #print(WW) 835 | Eigenvalues, Eigenvectors = np.linalg.eig(WW) 836 | # print(Eigenvalues) 837 | # print(Eigenvectors) 838 | EigneValue_MaxIndex = Eigenvalues.argmax() 839 | # print('Max index is: ', EigneValue_MaxIndex) 840 | vesSwitch = Eigenvectors[:, EigneValue_MaxIndex] 841 | # print(vesSwitch) 842 | 843 | LastEigenvectorABS[i, 0] = abs(vesSwitch[0]) 844 | LastEigenvectorABS[i, 1] = abs(vesSwitch[1]) 845 | LastEigenvectorABS[i, 2] = abs(vesSwitch[2]) 846 | # print(LastEigenvectorABS) 847 | 848 | EigenFrame = pd.DataFrame({'Ev_x':LastEigenvectorABS[:, 0], \ 849 | 'Ev_y':LastEigenvectorABS[:, 1], \ 850 | 'Ev_z':LastEigenvectorABS[:, 2]}) 851 | EigenFrame.to_csv("Eigenvector.csv", index = False, sep = ',') 852 | 853 | PD_data = np.vstack((LastEigenvectorABS[:, 0].transpose(), \ 854 | LastEigenvectorABS[:, 1].transpose(), \ 855 | LastEigenvectorABS[:, 2].transpose())) 856 | 857 | import numpy as np 858 | from sklearn.cluster import KMeans 859 | 860 | class FuzzyKMeans3D: 861 | 862 | def __init__(self, n_clusters=8, m=2, max_iter=100, tol=1e-4): 863 | self.n_clusters = n_clusters 864 | self.m = m 865 | self.max_iter = max_iter 866 | self.tol = tol 867 | 868 | def fit(self, X): 869 | # Clusting center points 870 | kmeans = KMeans(n_clusters=self.n_clusters, max_iter=self.max_iter, tol=self.tol) 871 | kmeans.fit(X) 872 | centers = kmeans.cluster_centers_ 873 | 874 | # Initialise belonging metrix 875 | n_samples = X.shape[0] 876 | U = np.random.rand(n_samples, self.n_clusters) 877 | U /= np.sum(U, axis=1)[:, None] 878 | 879 | # Iterate belonging metrix and center points 880 | for i in range(self.max_iter): 881 | # Update Belongingbility 882 | distances = np.linalg.norm(X[:, None, :] - centers[None, :, :], axis=2) 883 | distances[distances == 0] = 1e-10 884 | U_new = 1 / distances ** (2 / (self.m - 1)) 885 | U_new /= np.sum(U_new, axis=1)[:, None] 886 | 887 | # Check if converge 888 | if np.allclose(U, U_new, rtol=self.tol): 889 | break 890 | 891 | U = U_new 892 | 893 | # Update centers 894 | centers = np.dot(U.T, X) / np.sum(U, axis=0)[:, None] 895 | 896 | # Return 897 | labels = np.argmax(U, axis=1) 898 | return centers, labels, U 899 | 900 | 901 | from mpl_toolkits.mplot3d import Axes3D 902 | import matplotlib.pyplot as plt 903 | 904 | PD_data = PD_data.transpose() 905 | 906 | fkm = FuzzyKMeans3D(n_clusters = ClusterRegion) 907 | centers, labels, U = fkm.fit(PD_data) 908 | 909 | 910 | RegionA_dev_x = copy.deepcopy(PD_data[labels == 0, 0]) 911 | RegionA_dev_y = copy.deepcopy(PD_data[labels == 0, 1]) 912 | RegionA_dev_z = copy.deepcopy(PD_data[labels == 0, 2]) 913 | 914 | RegionB_dev_x = copy.deepcopy(PD_data[labels == 1, 0]) 915 | RegionB_dev_y = copy.deepcopy(PD_data[labels == 1, 1]) 916 | RegionB_dev_z = copy.deepcopy(PD_data[labels == 1, 2]) 917 | 918 | EigenRegionA = pd.DataFrame({'Ev_x':RegionA_dev_x, \ 919 | 'Ev_y':RegionA_dev_y, \ 920 | 'Ev_z':RegionA_dev_z}) 921 | EigenRegionA.to_csv("EigenRegionA.csv", index = False, sep = ',') 922 | 923 | EigenRegionB = pd.DataFrame({'Ev_x':RegionB_dev_x, \ 924 | 'Ev_y':RegionB_dev_y, \ 925 | 'Ev_z':RegionB_dev_z}) 926 | EigenRegionB.to_csv("EigenRegionB.csv", index = False, sep = ',') 927 | 928 | RegionA_len = len(RegionA_dev_x) 929 | RegionB_len = len(RegionB_dev_x) 930 | 931 | Sum_RegionA = np.zeros((3, 3)) 932 | Sum_RegionB = np.zeros((3, 3)) 933 | 934 | for i in range(RegionA_len): 935 | 936 | pFpi_RegionA = np.vstack((RegionA_dev_x[i], RegionA_dev_y[i], \ 937 | RegionA_dev_z[i])) 938 | WW_RegionA = np.dot(pFpi_RegionA, pFpi_RegionA.transpose()) 939 | Sum_RegionA = Sum_RegionA + WW_RegionA 940 | 941 | Eigenvalues_RegionA, Eigenvectors_RegionA = np.linalg.eig(Sum_RegionA) 942 | EigneValue_MaxIndex_RegionA = Eigenvalues_RegionA.argmax() 943 | vesSwitch_RegionA = Eigenvectors_RegionA[:, EigneValue_MaxIndex_RegionA] 944 | Coord_RegionA = abs(vesSwitch_RegionA) 945 | 946 | for i in range(RegionB_len): 947 | 948 | pFpi_RegionB = np.vstack((RegionB_dev_x[i], RegionB_dev_y[i], \ 949 | RegionB_dev_z[i])) 950 | WW_RegionB = np.dot(pFpi_RegionB, pFpi_RegionB.transpose()) 951 | Sum_RegionB = Sum_RegionB + WW_RegionB 952 | 953 | Eigenvalues_RegionB, Eigenvectors_RegionB = np.linalg.eig(Sum_RegionB) 954 | EigneValue_MaxIndex_RegionB = Eigenvalues_RegionB.argmax() 955 | vesSwitch_RegionB = Eigenvectors_RegionB[:, EigneValue_MaxIndex_RegionB] 956 | Coord_RegionB = abs(vesSwitch_RegionB) 957 | 958 | print('Ra: ', Coord_RegionA, '\n', 'Rb: ', Coord_RegionB) 959 | 960 | # print(EigneValue_MaxIndex_RegionA) 961 | # print(Eigenvectors_RegionA) 962 | # print(EigneValue_MaxIndex_RegionB) 963 | # print(Eigenvectors_RegionB) 964 | -------------------------------------------------------------------------------- /DDDA/DDDA/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | from setuptools import setup, find_packages 8 | 9 | setup( 10 | name="DDDA", 11 | version="0.0.3", 12 | author="Jiashun Pang", 13 | packages=find_packages(), 14 | ) 15 | 16 | 17 | # In[ ]: 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /DDDA/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[ ]: 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Case_2D/OriginData.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_2D/OriginData.mat -------------------------------------------------------------------------------- /Example/Case_2D/OriginX.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_2D/OriginX.mat -------------------------------------------------------------------------------- /Example/Case_2D/OriginY.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_2D/OriginY.mat -------------------------------------------------------------------------------- /Example/Case_2D/PollutedData.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_2D/PollutedData.mat -------------------------------------------------------------------------------- /Example/Case_2D/PollutedPositionX.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_2D/PollutedPositionX.mat -------------------------------------------------------------------------------- /Example/Case_2D/PollutedPositionY.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_2D/PollutedPositionY.mat -------------------------------------------------------------------------------- /Example/Case_3D_1/Data_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_1/Data_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_1/PositionX_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_1/PositionX_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_1/PositionY_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_1/PositionY_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_1/PositionZ_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_1/PositionZ_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_2/Data_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_2/Data_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_2/PollutedData_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_2/PollutedData_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_2/PollutedPositionX_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_2/PollutedPositionX_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_2/PollutedPositionY_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_2/PollutedPositionY_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_2/PollutedPositionZ_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_2/PollutedPositionZ_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_2/PositionX_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_2/PositionX_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_2/PositionY_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_2/PositionY_3D.mat -------------------------------------------------------------------------------- /Example/Case_3D_2/PositionZ_3D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/Example/Case_3D_2/PositionZ_3D.mat -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/F_step2/formuladata_diff/fomular.m: -------------------------------------------------------------------------------- 1 | function [pFpX,pFpY]=fomular(f_dep,h,Num_x,Num_y,in_in) 2 | 3 | 4 | f_dep_martix=reshape(f_dep,Num_y,Num_x); 5 | 6 | 7 | 8 | 9 | for i=1:Num_x 10 | if i0.98&norm_v<1.02)); 138 | 139 | x=x_dep((norm_v>0.98&norm_v<1.02)); 140 | y=y_dep((norm_v>0.98&norm_v<1.02)); 141 | 142 | pFpX=D1_Gauij_x_fixH((norm_v>0.98&norm_v<1.02)); 143 | pFpY=D1_Gauij_y_fixH((norm_v>0.98&norm_v<1.02)); 144 | end 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/F_step4/cluster.m: -------------------------------------------------------------------------------- 1 | function [D,F]=cluster(x,y,f,pFpX,pFpY,M,sub_param,n,f_dep) 2 | 3 | %% local dominated eigenvector 4 | 5 | D_d.N=length(pFpY);% data number 6 | 7 | for i=1:D_d.N 8 | 9 | D_d.d(i).pFp_i=[pFpX(i);pFpY(i)]; 10 | 11 | D_d.d(i).W=D_d.d(i).pFp_i*D_d.d(i).pFp_i'; 12 | 13 | [D_d.d(i).ve,D_d.d(i).va]=eig(D_d.d(i).W,'nobalance'); 14 | 15 | [D_d.d(i).d,D_d.d(i).ind] = sort(diag(D_d.d(i).va)); 16 | D_d.d(i).vas = D_d.d(i).va(D_d.d(i).ind,D_d.d(i).ind); 17 | 18 | D_d.d(i).ves = D_d.d(i).ve(:,D_d.d(i).ind); % the position of the max eigenvalue corresponding to the dominated eigenvector 19 | 20 | end 21 | 22 | s=zeros(length(pFpY),n); 23 | for i=1:D_d.N 24 | for j=1:n 25 | s(i,j)=D_d.d(i).ves(j,n); 26 | end 27 | end 28 | 29 | %% estimating the number of the clusting center 30 | 31 | [F,S] = subclust(s,sub_param); 32 | 33 | %% FCM clusting 34 | 35 | 36 | options = [M NaN NaN 0]; 37 | [centers,U] = fcm(s,length(F),options); 38 | maxU = max(U); 39 | for i=1:length(F)+1 40 | if i<=length(F) 41 | D.sub(i).index=find(U(i,:)==maxU); 42 | else 43 | D.sub(i).index=find(maxU<0.6); 44 | end 45 | D.sub(i).x=x(D.sub(i).index); 46 | D.sub(i).y=y(D.sub(i).index); 47 | D.sub(i).f=f(D.sub(i).index); 48 | D.sub(i).fo=f_dep(D.sub(i).index); 49 | D.sub(i).pFpX=pFpX(D.sub(i).index); 50 | D.sub(i).pFpY=pFpY(D.sub(i).index); 51 | 52 | 53 | end 54 | 55 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/F_step4/cluster_f.m: -------------------------------------------------------------------------------- 1 | function [D,F]=cluster_f(x,y,f,pFpX,pFpY,M,sub_param,n,f_dep) 2 | 3 | %% local dominated eigenvector 4 | D_d.N=length(pFpY); 5 | 6 | for i=1:D_d.N 7 | 8 | D_d.d(i).pFp_i=[pFpX(i);pFpY(i)]; 9 | 10 | D_d.d(i).W=D_d.d(i).pFp_i*D_d.d(i).pFp_i'; 11 | 12 | [D_d.d(i).ve,D_d.d(i).va]=eig(D_d.d(i).W,'nobalance'); 13 | 14 | [D_d.d(i).d,D_d.d(i).ind] = sort(diag(D_d.d(i).va)); 15 | D_d.d(i).vas = D_d.d(i).va(D_d.d(i).ind,D_d.d(i).ind); 16 | 17 | D_d.d(i).ves = D_d.d(i).ve(:,D_d.d(i).ind);% the position of the max eigenvalue corresponding to the dominated eigenvector 18 | 19 | end 20 | 21 | s=zeros(length(pFpY),n); 22 | for i=1:D_d.N 23 | for j=1:n 24 | s(i,j)=abs(D_d.d(i).ves(j,n)); 25 | end 26 | end 27 | 28 | %% estimating the number of the clusting center 29 | 30 | [F,S] = subclust(s,sub_param);% C是中心点矩阵;S是 Cluster Influence Range for Each Data Dimension 31 | 32 | %% FCM clusting 33 | 34 | 35 | options = [M NaN NaN 0]; 36 | [centers,U] = fcm(s,length(F),options); 37 | maxU = max(U); 38 | for i=1:length(F)+1 39 | if i<=length(F) 40 | D.sub(i).index=find(U(i,:)==maxU); 41 | else 42 | D.sub(i).index=find(maxU<0.6); 43 | end 44 | D.sub(i).x=x(D.sub(i).index); 45 | D.sub(i).y=y(D.sub(i).index); 46 | D.sub(i).f=f(D.sub(i).index); 47 | D.sub(i).fo=f_dep(D.sub(i).index); 48 | D.sub(i).pFpX=pFpX(D.sub(i).index); 49 | D.sub(i).pFpY=pFpY(D.sub(i).index); 50 | 51 | 52 | end 53 | 54 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/F_step4/cluster_myfcm.m: -------------------------------------------------------------------------------- 1 | function [D,F]=cluster_myfcm(x,y,f,pFpX,pFpY,M,sub_p,n,f_dep) 2 | 3 | %% local dominated eigenvector 4 | D_d.N=length(pFpY); 5 | 6 | for i=1:D_d.N 7 | 8 | D_d.d(i).pFp_i=[pFpX(i);pFpY(i)]; 9 | 10 | D_d.d(i).W=D_d.d(i).pFp_i*D_d.d(i).pFp_i'; 11 | 12 | [D_d.d(i).ve,D_d.d(i).va]=eig(D_d.d(i).W,'nobalance'); 13 | 14 | [D_d.d(i).d,D_d.d(i).ind] = sort(diag(D_d.d(i).va)); 15 | D_d.d(i).vas = D_d.d(i).va(D_d.d(i).ind,D_d.d(i).ind); 16 | 17 | D_d.d(i).ves = D_d.d(i).ve(:,D_d.d(i).ind); % the position of the max eigenvalue corresponding to the dominated eigenvector 18 | 19 | end 20 | 21 | s=zeros(length(pFpY),n); 22 | for i=1:D_d.N 23 | for j=1:n 24 | s(i,j)=D_d.d(i).ves(j,n); 25 | end 26 | end 27 | 28 | %% estimating the number of the clusting center 29 | 30 | [F,S] = subclust(s,sub_p);% C是中心点矩阵;S是 Cluster Influence Range for Each Data Dimension 31 | 32 | %% FCM clusting 33 | 34 | 35 | % options = [M NaN NaN 0]; 36 | % [centers,U] = myfcm(s,length(F),F,options); 37 | 38 | dist_initi=distfcm(F+0.1.*ones(length(F),n),s); 39 | tmp_initi=dist_initi.^(-2/(M-1)); 40 | U = tmp_initi./(ones(length(F), 1)*sum(tmp_initi)); 41 | max_iter=100; 42 | min_impro=1e-5; 43 | for i = 1:max_iter 44 | [U, center, obj_fcn(i)] = stepfcm(s, U, length(F), M); 45 | 46 | % check termination condition 47 | if i>1 48 | 49 | if abs(obj_fcn(i) - obj_fcn(i-1)) < min_impro, break; end 50 | 51 | end 52 | end 53 | 54 | % iter_n = i; % Actual number of iterations 55 | % obj_fcn(iter_n+1:max_iter) = []; 56 | 57 | maxU = max(U); 58 | for i=1:length(F)+1 59 | if i<=length(F) 60 | D.sub(i).index=find(U(i,:)==maxU&U(i,:)>=0.6); 61 | else 62 | D.sub(i).index=find(maxU<0.6); 63 | end 64 | D.sub(i).x=x(D.sub(i).index); 65 | D.sub(i).y=y(D.sub(i).index); 66 | D.sub(i).f=f(D.sub(i).index); 67 | D.sub(i).fo=f_dep(D.sub(i).index); 68 | D.sub(i).pFpX=pFpX(D.sub(i).index); 69 | D.sub(i).pFpY=pFpY(D.sub(i).index); 70 | 71 | 72 | end 73 | 74 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/F_step4/cluster_myfcm_f.m: -------------------------------------------------------------------------------- 1 | function [D,F]=cluster_myfcm_f(x,y,f,pFpX,pFpY,M,sub_p,n,f_dep) 2 | 3 | %% local dominated eigenvector 4 | D_d.N=length(pFpY); 5 | 6 | for i=1:D_d.N 7 | 8 | D_d.d(i).pFp_i=[pFpX(i);pFpY(i)]; 9 | 10 | D_d.d(i).W=D_d.d(i).pFp_i*D_d.d(i).pFp_i'; 11 | 12 | [D_d.d(i).ve,D_d.d(i).va]=eig(D_d.d(i).W,'nobalance'); 13 | 14 | [D_d.d(i).d,D_d.d(i).ind] = sort(diag(D_d.d(i).va)); 15 | D_d.d(i).vas = D_d.d(i).va(D_d.d(i).ind,D_d.d(i).ind); 16 | 17 | D_d.d(i).ves = D_d.d(i).ve(:,D_d.d(i).ind);% the position of the max eigenvalue corresponding to the dominated eigenvector 18 | 19 | end 20 | 21 | s=zeros(length(pFpY),n); 22 | for i=1:D_d.N 23 | for j=1:n 24 | s(i,j)=abs(D_d.d(i).ves(j,n)); 25 | end 26 | end 27 | 28 | %% estimating the number of the clusting center 29 | 30 | [F,S] = subclust(s,sub_p);% C是中心点矩阵;S是 Cluster Influence Range for Each Data Dimension 31 | 32 | %% FCM clusting 33 | 34 | % options = [M NaN NaN 0]; 35 | % [centers,U] = myfcm(s,length(F),F,options); 36 | 37 | dist_initi=distfcm(F+0.1.*ones(length(F),n),s); 38 | tmp_initi=dist_initi.^(-2/(M-1)); 39 | U = tmp_initi./(ones(length(F), 1)*sum(tmp_initi)); 40 | max_iter=100; 41 | min_impro=1e-5; 42 | for i = 1:max_iter 43 | [U, center, obj_fcn(i)] = stepfcm(s, U, length(F), M); 44 | 45 | % check termination condition 46 | if i>1 47 | if abs(obj_fcn(i) - obj_fcn(i-1)) < min_impro, break; end 48 | end 49 | end 50 | 51 | % iter_n = i; % Actual number of iterations 52 | % obj_fcn(iter_n+1:max_iter) = []; 53 | 54 | maxU = max(U); 55 | for i=1:length(F)+1 56 | if i<=length(F) 57 | D.sub(i).index=find(U(i,:)==maxU&U(i,:)>=0.6); 58 | else 59 | D.sub(i).index=find(maxU<0.6); 60 | end 61 | 62 | D.sub(i).x=x(D.sub(i).index); 63 | D.sub(i).y=y(D.sub(i).index); 64 | D.sub(i).f=f(D.sub(i).index); 65 | D.sub(i).fo=f_dep(D.sub(i).index); 66 | D.sub(i).pFpX=pFpX(D.sub(i).index); 67 | D.sub(i).pFpY=pFpY(D.sub(i).index); 68 | 69 | 70 | end 71 | 72 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/F_step4/myfcm.m: -------------------------------------------------------------------------------- 1 | function [center, U, obj_fcn] = myfcm(data, cluster_n, center_initi, options) 2 | % center_initi is estimated by the function "subclust" 3 | %FCM Data set clustering using fuzzy c-means clustering. 4 | % 5 | % [CENTER, U, OBJ_FCN] = FCM(DATA, N_CLUSTER) finds N_CLUSTER number of 6 | % clusters in the data set DATA. DATA is size M-by-N, where M is the number of 7 | % data points and N is the number of coordinates for each data point. The 8 | % coordinates for each cluster center are returned in the rows of the matrix 9 | % CENTER. The membership function matrix U contains the grade of membership of 10 | % each DATA point in each cluster. The values 0 and 1 indicate no membership 11 | % and full membership respectively. Grades between 0 and 1 indicate that the 12 | % data point has partial membership in a cluster. At each iteration, an 13 | % objective function is minimized to find the best location for the clusters 14 | % and its values are returned in OBJ_FCN. 15 | % 16 | % [CENTER, ...] = FCM(DATA,N_CLUSTER,OPTIONS) specifies a vector of options 17 | % for the clustering process: 18 | % OPTIONS(1): exponent for the matrix U (default: 2.0) 19 | % OPTIONS(2): maximum number of iterations (default: 100) 20 | % OPTIONS(3): minimum amount of improvement (default: 1e-5) 21 | % OPTIONS(4): info display during iteration (default: 1) 22 | % The clustering process stops when the maximum number of iterations 23 | % is reached, or when the objective function improvement between two 24 | % consecutive iterations is less than the minimum amount of improvement 25 | % specified. Use NaN to select the default value. 26 | % 27 | % Example 28 | % data = rand(100,2); 29 | % [center,U,obj_fcn] = fcm(data,2); 30 | % plot(data(:,1), data(:,2),'o'); 31 | % hold on; 32 | % maxU = max(U); 33 | % % Find the data points with highest grade of membership in cluster 1 34 | % index1 = find(U(1,:) == maxU); 35 | % % Find the data points with highest grade of membership in cluster 2 36 | % index2 = find(U(2,:) == maxU); 37 | % line(data(index1,1),data(index1,2),'marker','*','color','g'); 38 | % line(data(index2,1),data(index2,2),'marker','*','color','r'); 39 | % % Plot the cluster centers 40 | % plot([center([1 2],1)],[center([1 2],2)],'*','color','k') 41 | % hold off; 42 | % 43 | % See also FCMDEMO, INITFCM, IRISFCM, DISTFCM, STEPFCM. 44 | 45 | % Roger Jang, 12-13-94, N. Hickey 04-16-01 46 | % Copyright 1994-2018 The MathWorks, Inc. 47 | 48 | if nargin ~= 3 && nargin ~= 4 49 | error(message("fuzzy:general:errFLT_incorrectNumInputArguments")) 50 | end 51 | 52 | 53 | 54 | % Change the following to set default options 55 | default_options = [2; % exponent for the partition matrix U 56 | 100; % max. number of iteration 57 | 1e-5; % min. amount of improvement 58 | 1]; % info display during iteration 59 | 60 | if nargin == 3 61 | options = default_options; 62 | else 63 | % If "options" is not fully specified, pad it with default values. 64 | if length(options) < 4 65 | tmp = default_options; 66 | tmp(1:length(options)) = options; 67 | options = tmp; 68 | end 69 | % If some entries of "options" are nan's, replace them with defaults. 70 | nan_index = find(isnan(options)==1); 71 | options(nan_index) = default_options(nan_index); 72 | if options(1) <= 1 73 | error(message("fuzzy:general:errFcm_expMustBeGtOne")) 74 | end 75 | end 76 | 77 | expo = options(1); % Exponent for U 78 | max_iter = options(2); % Max. iteration 79 | min_impro = options(3); % Min. improvement 80 | display = options(4); % Display info or not 81 | 82 | obj_fcn = zeros(max_iter, 1); % Array for objective function 83 | 84 | % the initial matrix is constructed by the center_initi 85 | dist_initi=distfcm(center_initi,data); 86 | tmp_initi=dist_initi.^(-2/(expo-1)); 87 | U = tmp_initi./(ones(cluster_n, 1)*sum(tmp_initi)); 88 | 89 | % U = initfcm(cluster_n, data_n); % Initial fuzzy partition 90 | % Main loop 91 | for i = 1:max_iter 92 | [U, center, obj_fcn(i)] = stepfcm(data, U, cluster_n, expo); 93 | if display 94 | fprintf('Iteration count = %d, obj. fcn = %f\n', i, obj_fcn(i)); 95 | end 96 | % check termination condition 97 | if i > 1 98 | if abs(obj_fcn(i) - obj_fcn(i-1)) < min_impro, break; end 99 | end 100 | end 101 | 102 | iter_n = i; % Actual number of iterations 103 | obj_fcn(iter_n+1:max_iter) = []; 104 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/F_step4/new_var.m: -------------------------------------------------------------------------------- 1 | 2 | function D=new_var(D,n,F) 3 | 4 | for i=1:length(F) 5 | 6 | D.sub(i).pFpX; 7 | D.sub(i).pFpY; 8 | D.sub(i).dx_dy=[D.sub(i).pFpX,D.sub(i).pFpY]; 9 | 10 | for j=1:length(D.sub(i).pFpX) 11 | 12 | D.sub(i).c(j).points=D.sub(i).dx_dy(j,:)'*D.sub(i).dx_dy(j,:); 13 | 14 | end 15 | end 16 | 17 | for i=1:length(F) 18 | 19 | D.sub(i).C=zeros(n,n); 20 | 21 | end 22 | 23 | for i=1:length(F) 24 | for j=1:length(D.sub(i).pFpX) 25 | 26 | D.sub(i).C= D.sub(i).C+D.sub(i).c(j).points; 27 | 28 | end 29 | end 30 | 31 | 32 | 33 | for i=1:length(F) 34 | D.sub(i).C1=D.sub(i).C.*length(D.sub(i).pFpX); 35 | 36 | [D.sub(i).ve,D.sub(i).va]=eig(D.sub(i).C1,'nobalance'); 37 | 38 | [D.sub(i).d,D.sub(i).ind] = sort(diag(D.sub(i).va)); 39 | 40 | D.sub(i).ves = D.sub(i).ve(:,D.sub(i).ind); 41 | 42 | % D.sub(i).Z=W* D.sub(i).ves; 43 | 44 | D.sub(i).x_y=[D.sub(i).x D.sub(i).y]; 45 | 46 | D.sub(i).lx_y_new=D.sub(i).x_y* D.sub(i).ves; 47 | 48 | D.sub(i).x_y_new=exp(D.sub(i).lx_y_new); 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/F_step4/stepfcm.m: -------------------------------------------------------------------------------- 1 | function [U_new, center, obj_fcn] = stepfcm(data, U, cluster_n, expo) 2 | %STEPFCM One step in fuzzy c-mean clustering. 3 | % [U_NEW, CENTER, ERR] = STEPFCM(DATA, U, CLUSTER_N, EXPO) 4 | % performs one iteration of fuzzy c-mean clustering, where 5 | % 6 | % DATA: matrix of data to be clustered. (Each row is a data point.) 7 | % U: partition matrix. (U(i,j) is the MF value of data j in cluster j.) 8 | % CLUSTER_N: number of clusters. 9 | % EXPO: exponent (> 1) for the partition matrix. 10 | % U_NEW: new partition matrix. 11 | % CENTER: center of clusters. (Each row is a center.) 12 | % ERR: objective function for partition U. 13 | % 14 | % Note that the situation of "singularity" (one of the data points is 15 | % exactly the same as one of the cluster centers) is not checked. 16 | % However, it hardly occurs in practice. 17 | % 18 | % See also DISTFCM, INITFCM, IRISFCM, FCMDEMO, FCM. 19 | 20 | % Copyright 1994-2014 The MathWorks, Inc. 21 | 22 | mf = U.^expo; % MF matrix after exponential modification 23 | center = mf*data./(sum(mf,2)*ones(1,size(data,2))); %new center 24 | dist = distfcm(center, data); % fill the distance matrix 25 | obj_fcn = sum(sum((dist.^2).*mf)); % objective function 26 | tmp = dist.^(-2/(expo-1)); % calculate new U, suppose expo != 1 27 | U_new = tmp./(ones(cluster_n, 1)*sum(tmp)); 28 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/f_h.m: -------------------------------------------------------------------------------- 1 | function f_h=f_h(X,Y) 2 | % Cd formula when Re>3000 3 | 4 | S = exp(Y)./3.7; 5 | T= 2.51./exp(X); 6 | fun = @(x) x + 2*log10( S + T.*x ); 7 | dfun = @(x) 1 + 2*( T ./ ( log(10) * (S + T.*x) ) ); 8 | x0=(exp(X).^0.5)./8; 9 | d = 1e9; tol = 1e-9; nx0 = norm(x0); 10 | count = 1; 11 | while d > tol 12 | 13 | x1 = x0 - fun(x0) ./ dfun(x0); 14 | d = norm(x1 - x0); 15 | fprintf('\tIter %d: step size = %6.4e\n', count, d); 16 | 17 | x0= x1; 18 | count = count + 1; 19 | 20 | end 21 | f_h=1./(x0.^2); 22 | end -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/f_l.m: -------------------------------------------------------------------------------- 1 | function f_l=f_l(X,Y) 2 | % Cd formula when Re<=3000 3 | f_l=64*exp(-X); 4 | end -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/readme.m: -------------------------------------------------------------------------------- 1 | 2 | % You can use the scripts to perform the data-driven dimensional analysis for 2D 3 | % system "pressure drops in pipe flows". Runing the scripts 0-5, you can 4 | % get the results 5 | 6 | %% Note!! 7 | 8 | % 1. Three methods for the gradient calculation are utilized, which are, smoothed gradient calculation; 9 | % liner interpolation + Finite Difference gradient calcualtion; interpolation with ML + fFinite Difference gradient calculation 10 | 11 | 12 | % 2. Different noise grades are considered; 13 | 14 | % 3. Different clustering parameters are applied and discussed. 15 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/step0_research_boundary.m: -------------------------------------------------------------------------------- 1 | clear 2 | % the merging papameter space of the 'pressure drops in the pipe flows' case 3 | 4 | %liminar 5 | x1_l=log(125); 6 | x1_h=log(3360); 7 | y1_l=log(3.75e-6); 8 | y1_h=log(1.6e-4); 9 | x1=linspace(x1_l,x1_h,10); 10 | y1=linspace(y1_l,y1_h,10); 11 | [X1,Y1]=meshgrid(x1,y1); 12 | %middle 13 | x2_l=log(1e+4); 14 | x2_h=log(5.6e+5); 15 | y2_l=log(5e-4); 16 | y2_h=log(4e-3); 17 | x2=linspace(x2_l,x2_h,10); 18 | y2=linspace(y2_l,y2_h,10); 19 | [X2,Y2]=meshgrid(x2,y2); 20 | %turbulent 21 | x3_l=log(2.5e+6); 22 | x3_h=log(9.8e+7); 23 | y3_l=log(0.01); 24 | y3_h=log(0.08); 25 | x3=linspace(x3_l,x3_h,10); 26 | y3=linspace(y3_l,y3_h,10); 27 | [X3,Y3]=meshgrid(x3,y3); 28 | 29 | %total 30 | x1=4.8283; 31 | x2=18.4005; 32 | y1=-12.4938; 33 | y2=-2.5257; -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/step1_initial_data_boundary.m: -------------------------------------------------------------------------------- 1 | clear 2 | %% making original random data points 3 | 4 | h1=0.1; 5 | 6 | xLim_L=4.8283-15*h1; 7 | xLim_H=18.4005+15*h1; 8 | yLim_L=-12.4938-15*h1; 9 | yLim_H= -2.5257+15*h1; 10 | 11 | 12 | 13 | Num_x1=round((xLim_H-xLim_L)/h1); 14 | Num_y1=round((yLim_H-yLim_L)/h1); 15 | x=linspace(xLim_L,xLim_H,Num_x1); 16 | y=linspace(yLim_L,yLim_H,Num_y1); 17 | [X,Y]=meshgrid(x,y); 18 | 19 | 20 | % Random sampling 21 | xArray=X(:); 22 | yArray=Y(:); 23 | LLength=length(xArray); 24 | PPoint1=0.92; % the percentage of the deleted points 25 | P_deletes1=round(LLength*PPoint1); 26 | 27 | PP1=sort(randperm(LLength,P_deletes1),'descend'); 28 | 29 | for i=1:P_deletes1 30 | 31 | j=PP1(i); 32 | xArray(j)=[]; 33 | yArray(j)=[]; 34 | end 35 | save xArray.mat xArray 36 | save yArray.mat yArray 37 | 38 | 39 | 40 | 41 | % determining the data boundary 42 | 43 | xv1=[4.8283;18.4005;18.4005;4.8283]; 44 | yv1=[-12.4938;-12.4938;-2.5257;-2.5257]; 45 | in1=inpolygon(xArray,yArray,xv1,yv1); 46 | xArray_in=xArray(in1); 47 | yArray_in=yArray(in1); 48 | 49 | DT = delaunayTriangulation(xArray_in,yArray_in); 50 | C_b = convexHull(DT); 51 | xv=DT.Points(C_b,1); 52 | yv=DT.Points(C_b,2); 53 | 54 | save xv.mat xv 55 | save yv.mat yv 56 | 57 | 58 | % otaining the formula value of the data point 59 | X_smooth_min=8.1197; 60 | X_smooth_max=8.1197; 61 | 62 | f_turb=f_h(xArray,yArray);% Re>3000 63 | f_lam=f_l(xArray,yArray);% Re<=3000 64 | 65 | f=f_turb; 66 | 67 | % smoothing the formula value of the point in the junction area of the 68 | % formula 69 | f(xArrayX_smooth_min) & (xArrayX_smooth_min) & (x_dep0.98&Da.s_noise(i).norm_v<1.02); 53 | Da.initial.s(i).y=Da.initial.y(Da.s_noise(i).norm_v>0.98&Da.s_noise(i).norm_v<1.02); 54 | Da.initial.s(i).f=Da.initial.f(Da.s_noise(i).norm_v>0.98&Da.s_noise(i).norm_v<1.02); 55 | Da.initial.s(i).pFpX=Da.initial.pFpX(Da.s_noise(i).norm_v>0.98&Da.s_noise(i).norm_v<1.02); 56 | Da.initial.s(i).pFpY=Da.initial.pFpY(Da.s_noise(i).norm_v>0.98&Da.s_noise(i).norm_v<1.02); 57 | end 58 | 59 | %% Machine learning 60 | 61 | for i=1:length(noise) 62 | for j=1:length(smooth) 63 | 64 | % calculating interpolation and partial differential 65 | [Da.m_noise(i).smooth(j).x,Da.m_noise(i).smooth(j).y,Da.m_noise(i).smooth(j).f,Da.m_noise(i).smooth(j).pFpX,Da.m_noise(i).smooth(j).pFpY]=ml_inter(xArray,yArray,fArray,noise(i),smooth(j),x_dep,y_dep,in_in,Num_x,Num_y,h); 66 | %[x,y,f,pFpX,pFpY]=ml_inter(xArray,yArray,fArray,noise,smooth,x_dep,y_dep,in_in,Num_x,Num_y,h) 67 | 68 | Da.m_noise(i).sd=[ num2str(0.05*noise(i)) 'f'];% marking the noise level 69 | 70 | Da.m_noise(i).smooth(j).sigma=smooth(j);% marking the smoothing level 71 | 72 | end 73 | end 74 | 75 | %% linear interpolation 76 | 77 | for i=1:length(noise) 78 | for j=1:length(smooth) 79 | 80 | 81 | [Da.l_noise(i).smooth(j).x,Da.l_noise(i).smooth(j).y,Da.l_noise(i).smooth(j).f,Da.l_noise(i).smooth(j).pFpX,Da.l_noise(i).smooth(j).pFpY]=liner_inter(xArray,yArray,fArray,noise(i),smooth(j),x_dep,y_dep,in_in,Num_x,Num_y,h); 82 | %[x,y,f,pFpX,pFpY]=ml_inter(xArray,yArray,fArray,noise,smooth,x_dep,y_dep,in_in,Num_x,Num_y,h) 83 | 84 | Da.l_noise(i).sd=[ num2str(0.05*noise(i)) 'f']; 85 | 86 | Da.l_noise(i).smooth(j).sigma=smooth(j); 87 | 88 | end 89 | end 90 | 91 | 92 | 93 | save Da.mat Da 94 | 95 | 96 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 2D case (pressure drops in pipe flows)/step4_run_clust.m: -------------------------------------------------------------------------------- 1 | 2 | clear 3 | %% cutting the parameter space using subculst-FCM algorithm 4 | 5 | %% loading the partial different 6 | 7 | load Da.mat 8 | 9 | noise=linspace(0,16,5)'; 10 | smooth=linspace(1,9,3)'; 11 | 12 | M=[1.1; 2; 3; 4];% M=m 13 | 14 | sub_param=0.1.*linspace(1,9,3)';% sub_param=ra 15 | 16 | % case dimensions 17 | n=2; 18 | %% formula values clustering 19 | 20 | % clusering for the comparison with linear interpolation and machine 21 | % learning since no points are deleted 22 | 23 | Da.initial.sub_inf=['M' num2str(M(2)), '_ra' num2str(sub_param(3))];% marking clustering parameters 24 | 25 | [Da.initial.sub,Da.initial.C]=cluster_myfcm_f(Da.initial.x,Da.initial.y,Da.initial.f,Da.initial.pFpX,Da.initial.pFpY,M(2),sub_param(3),n,Da.initial.f); 26 | %[D,F]=cluster(x,y,f,pFpX,pFpY,M,sub_param,n,f_dep), subclust-FCM 27 | %clustering 28 | 29 | Da.initial.sub= new_var(Da.initial.sub,n,Da.initial.C); 30 | %D=new_var(D,n,F), obtaining unique dimensionless group 31 | 32 | 33 | 34 | % clusering for the comparison with smooth interpolation since no points are deleted 35 | 36 | for i=1:length(noise) 37 | for k=1:length(sub_param) 38 | 39 | Da.initial.s(i).sub_param(k).sub_inf=['M' num2str(M(2)), '_ra' num2str(sub_param(k))]; 40 | 41 | [Da.initial.s(i).sub_param(k).sub,Da.initial.s(i).sub_param(k).C]=cluster_myfcm_f(Da.initial.s(i).x,Da.initial.s(i).y,Da.initial.s(i).f,Da.initial.s(i).pFpX,Da.initial.s(i).pFpY,M(2),sub_param(k),n,Da.initial.f); 42 | 43 | Da.initial.s(i).sub_param(k).sub= new_var(Da.initial.s(i).sub_param(k).sub,n,Da.initial.s(i).sub_param(k).C); 44 | 45 | end 46 | end 47 | 48 | for i=1:length(noise) 49 | for k=1:length(M) 50 | 51 | Da.initial.s(i).M(k).sub_inf=['M' num2str(M(k)), '_ra' num2str(sub_param(2))];% 标注overlap ra 52 | 53 | [Da.initial.s(i).M(k).sub,Da.initial.s(i).M(k).C]=cluster_myfcm_f(Da.initial.s(i).x,Da.initial.s(i).y,Da.initial.s(i).f,Da.initial.s(i).pFpX,Da.initial.s(i).pFpY,M(k),sub_param(2),n,Da.initial.f); 54 | 55 | Da.initial.s(i).M(k).sub= new_var(Da.initial.s(i).M(k).sub,n,Da.initial.s(i).M(k).C); 56 | 57 | end 58 | end 59 | 60 | %% smooth differential clustring 61 | 62 | % ra 63 | for i=1:length(noise) 64 | for k=1:length(sub_param) 65 | 66 | Da.s_noise(i).sub_param(k).sub_inf=['M' num2str(M(2)), '_ra' num2str(sub_param(k))];% 标注overlap ra 67 | 68 | [Da.s_noise(i).sub_param(k).sub,Da.s_noise(i).sub_param(k).C]=cluster_myfcm(Da.s_noise(i).x,Da.s_noise(i).y,Da.s_noise(i).f,Da.s_noise(i).pFpX,Da.s_noise(i).pFpY,M(2),sub_param(k),n,Da.initial.f); 69 | 70 | Da.s_noise(i).sub_param(k).sub= new_var(Da.s_noise(i).sub_param(k).sub,n,Da.s_noise(i).sub_param(k).C); 71 | 72 | end 73 | end 74 | 75 | % m 76 | for i=1:length(noise) 77 | for k=1:length(M) 78 | 79 | Da.s_noise(i).M(k).sub_inf=['M' num2str(M(k)), '_ra' num2str(sub_param(2))];% 标注overlap ra 80 | 81 | [Da.s_noise(i).M(k).sub,Da.s_noise(i).M(k).C]=cluster_myfcm(Da.s_noise(i).x,Da.s_noise(i).y,Da.s_noise(i).f,Da.s_noise(i).pFpX,Da.s_noise(i).pFpY,M(k),sub_param(2),n,Da.initial.f); 82 | 83 | Da.s_noise(i).M(k).sub= new_var(Da.s_noise(i).M(k).sub,n,Da.s_noise(i).M(k).C); 84 | 85 | end 86 | end 87 | 88 | 89 | %% machine learning clustering 90 | 91 | % clustering under M=2;sub_param=0.9 92 | 93 | for i=1:length(noise) 94 | for j=1:length(smooth) 95 | 96 | Da.m_noise(i).smooth(j).sub_inf=['M' num2str(M(2)), '_ra' num2str(sub_param(3))];% 标注overlap ra 97 | 98 | [Da.m_noise(i).smooth(j).sub,Da.m_noise(i).smooth(j).C]=cluster_myfcm(Da.m_noise(i).smooth(j).x,Da.m_noise(i).smooth(j).y,Da.m_noise(i).smooth(j).f,Da.m_noise(i).smooth(j).pFpX,Da.m_noise(i).smooth(j).pFpY,M(2),sub_param(3),n,Da.initial.f); 99 | 100 | Da.m_noise(i).smooth(j).sub= new_var(Da.m_noise(i).smooth(j).sub,n,Da.m_noise(i).smooth(j).C); 101 | 102 | end 103 | end 104 | 105 | 106 | %% linear interpolation clustering 107 | 108 | % clustering under M=2;sub_param=0.9 109 | 110 | for i=1:length(noise) 111 | for j=1:length(smooth) 112 | 113 | Da.l_noise(i).smooth(j).sub_inf=['M' num2str(M(2)), '_ra' num2str(sub_param(3))];% 标注overlap ra 114 | 115 | [Da.l_noise(i).smooth(j).sub,Da.l_noise(i).smooth(j).C]=cluster_myfcm(Da.l_noise(i).smooth(j).x,Da.l_noise(i).smooth(j).y,Da.l_noise(i).smooth(j).f,Da.l_noise(i).smooth(j).pFpX,Da.l_noise(i).smooth(j).pFpY,M(2),sub_param(3),n,Da.initial.f); 116 | 117 | Da.l_noise(i).smooth(j).sub= new_var(Da.l_noise(i).smooth(j).sub,n,Da.l_noise(i).smooth(j).C); 118 | 119 | end 120 | end 121 | 122 | 123 | save Da_clust.mat Da -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/A_Help_documentation.m: -------------------------------------------------------------------------------- 1 | % performing 3-D case in the paper. 2 | % /A_Step1_originaldata_smooth_differential/ 3 | % /A_Step2_cutsapce_newvariables/ 4 | % Runing the above scripts in sequence, you can get the results -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/A_Step1_originaldata_smooth_differential.m: -------------------------------------------------------------------------------- 1 | clear 2 | clc 3 | %% setting a cube parameters space 4 | 5 | Lim.x0 = 0; Lim.x1 = 3; 6 | Lim.y0 = 0; Lim.y1 = 3; 7 | Lim.z0 = -1.5; Lim.z1 = 1.5; 8 | 9 | num = 15; 10 | n_Quiry = num^3; % 3D DATA 11 | 12 | dxArray = (Lim.x1-Lim.x0)/num; 13 | dyArray = (Lim.y1-Lim.y0)/num; 14 | dzArray = (Lim.z1-Lim.z0)/num; 15 | 16 | xfp = linspace(Lim.x0,Lim.x1,num); 17 | yfp = linspace(Lim.y0,Lim.y1,num); 18 | zfp = linspace(Lim.z0,Lim.z1,num); 19 | 20 | Arrayx = zeros(n_Quiry,1); 21 | Arrayy = zeros(n_Quiry,1); 22 | Arrayz = zeros(n_Quiry,1); 23 | Arrayf = zeros(n_Quiry,1); 24 | 25 | for i = 1:num 26 | for j = 1:num 27 | for k = 1:num 28 | 29 | Arrayx((i-1)*num*num+(j-1)*num+k) = xfp(k); 30 | Arrayy((i-1)*num*num+(j-1)*num+k) = yfp(j); 31 | Arrayz((i-1)*num*num+(j-1)*num+k) = zfp(i); 32 | 33 | if Arrayz((i-1)*num*num+(j-1)*num+k) <= 0 34 | 35 | Arrayf((i-1)*num*num+(j-1)*num+k) = f1(Arrayx((i-1)*num*num+(j-1)*num+k),Arrayy((i-1)*num*num+(j-1)*num+k),Arrayz((i-1)*num*num+(j-1)*num+k)); 36 | 37 | elseif Arrayz((i-1)*num*num+(j-1)*num+k) > 0 38 | 39 | Arrayf((i-1)*num*num+(j-1)*num+k) = f2(Arrayx((i-1)*num*num+(j-1)*num+k),Arrayy((i-1)*num*num+(j-1)*num+k),Arrayz((i-1)*num*num+(j-1)*num+k)); 40 | 41 | end 42 | end 43 | end 44 | end 45 | 46 | %figure() 47 | %scatter3(Arrayx,Arrayy,Arrayz,'.'); 48 | 49 | %axis equal 50 | 51 | %% adding noise 52 | 53 | 54 | for i = 1:num 55 | for j = 1:num 56 | for k = 1:num 57 | 58 | Exyz = rand(1)*0.05; 59 | Arrayx((i-1)*num*num+(j-1)*num+k) = Arrayx((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayx((i-1)*num*num+(j-1)*num+k); 60 | Arrayy((i-1)*num*num+(j-1)*num+k) = Arrayy((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayy((i-1)*num*num+(j-1)*num+k); 61 | Arrayz((i-1)*num*num+(j-1)*num+k) = Arrayz((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayz((i-1)*num*num+(j-1)*num+k); 62 | 63 | end 64 | end 65 | end 66 | Arrayf_color = Arrayf; 67 | 68 | % figure() 69 | % scatter3(Arrayx,Arrayy,Arrayz,'.'); 70 | % 71 | % axis equal 72 | % 73 | % figure() 74 | % scatter3(Arrayx,Arrayy,Arrayz,80,Arrayf_color,'.'); 75 | % 76 | % axis equal 77 | 78 | 79 | 80 | Arrayf_Pert = Arrayf; 81 | for i = 1:num 82 | for j = 1:num 83 | for k = 1:num 84 | 85 | Exyz = rand(1)*0.05; 86 | Arrayf_Pert((i-1)*num*num+(j-1)*num+k) = Arrayf_Pert((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayf_Pert((i-1)*num*num+(j-1)*num+k); 87 | 88 | end 89 | end 90 | end 91 | Arrayf_Pert_color = Arrayf_Pert; 92 | 93 | % figure() 94 | % scatter3(Arrayx,Arrayy,Arrayz,80,Arrayf_Pert_color,'.'); 95 | % 96 | % axis equal 97 | 98 | save ox.mat Arrayx; 99 | save oy.mat Arrayy; 100 | save oz.mat Arrayz; 101 | save of.mat Arrayf_Pert_color; 102 | 103 | %% Voronoi_limit cell 104 | 105 | % Mirroring of boundaries 106 | 107 | reflectB = zeros(num*6,1); 108 | xmin = zeros(num*num,1); 109 | ymin = zeros(num*num,1); 110 | zmin = zeros(num*num,1); 111 | xmax = zeros(num*num,1); 112 | ymax = zeros(num*num,1); 113 | zmax = zeros(num*num,1); 114 | 115 | ArrayyJ = Arrayy; 116 | ArrayzJ = Arrayz; 117 | xmaxB = cell(100,1); 118 | xminB = cell(100,1); 119 | ymaxB = cell(100,1); 120 | yminB = cell(100,1); 121 | zmaxB = cell(100,1); 122 | zminB = cell(100,1); 123 | 124 | 125 | % xMin 126 | ArrayxJ_xMin = Arrayx; 127 | ArrayxB_xMin = Arrayx; 128 | ArrayyB_xMin = Arrayy; 129 | ArrayzB_xMin = Arrayz; 130 | 131 | for i = 1:num*num 132 | 133 | [rBxl,rBxil] = min(ArrayxJ_xMin); 134 | xmin(i) = rBxil; 135 | ArrayxJ_xMin(rBxil) = (Lim.x1-Lim.x0)/2; 136 | xminB{i} = [-1*ArrayxB_xMin(xmin(i))-dxArray+ArrayxB_xMin(xmin(i)),ArrayyB_xMin(xmin(i)),ArrayzB_xMin(xmin(i))]; 137 | 138 | ArrayxB_xMin = [ArrayxB_xMin;xminB{i}(1)]; 139 | ArrayyB_xMin = [ArrayyB_xMin;xminB{i}(2)]; 140 | ArrayzB_xMin = [ArrayzB_xMin;xminB{i}(3)]; 141 | Arrayf = [Arrayf;0]; 142 | 143 | end 144 | 145 | % yMin 146 | ArrayyJ_yMin = ArrayyB_xMin; 147 | ArrayxB_yMin = ArrayxB_xMin; 148 | ArrayyB_yMin = ArrayyB_xMin; 149 | ArrayzB_yMin = ArrayzB_xMin; 150 | 151 | for i = 1:num*num+10 152 | 153 | [rByl,rByil] = min(ArrayyJ_yMin); 154 | ymin(i) = rByil; 155 | ArrayyJ_yMin(rByil) = (Lim.y1-Lim.y0)/2; 156 | yminB{i} = [ArrayxB_yMin(ymin(i)),-1*ArrayyB_yMin(ymin(i))-dyArray+ArrayyB_yMin(ymin(i)),ArrayzB_yMin(ymin(i))]; 157 | ArrayxB_yMin = [ArrayxB_yMin;yminB{i}(1)]; 158 | ArrayyB_yMin = [ArrayyB_yMin;yminB{i}(2)]; 159 | ArrayzB_yMin = [ArrayzB_yMin;yminB{i}(3)]; 160 | Arrayf = [Arrayf;0]; 161 | 162 | end 163 | 164 | % xMax 165 | ArrayxJ_xMax = ArrayxB_yMin; 166 | ArrayxB_xMax = ArrayxB_yMin; 167 | ArrayyB_xMax = ArrayyB_yMin; 168 | ArrayzB_xMax = ArrayzB_yMin; 169 | 170 | for i = 1:num*num+20 171 | 172 | [rBxr,rBxir] = max(ArrayxJ_xMax); 173 | xmax(i) = rBxir; 174 | ArrayxJ_xMax(rBxir) = (Lim.x1-Lim.x0)/2; 175 | xmaxB{i} = [-1*ArrayxB_xMax(xmax(i))+ArrayxB_xMax(xmax(i))*2+dxArray,ArrayyB_xMax(xmax(i)),ArrayzB_xMax(xmax(i))]; 176 | ArrayxB_xMax = [ArrayxB_xMax;xmaxB{i}(1)]; 177 | ArrayyB_xMax = [ArrayyB_xMax;xmaxB{i}(2)]; 178 | ArrayzB_xMax = [ArrayzB_xMax;xmaxB{i}(3)]; 179 | Arrayf = [Arrayf;0]; 180 | 181 | end 182 | 183 | % yMax 184 | ArrayyJ_yMax = ArrayyB_xMax; 185 | ArrayxB_yMax = ArrayxB_xMax; 186 | ArrayyB_yMax = ArrayyB_xMax; 187 | ArrayzB_yMax = ArrayzB_xMax; 188 | 189 | for i = 1:num*num+40 190 | 191 | [rByr,rByir] = max(ArrayyJ_yMax); 192 | ymax(i) = rByir; 193 | ArrayyJ_yMax(rByir) = (Lim.y1-Lim.y0)/2; 194 | ymaxB{i} = [ArrayxB_yMax(ymax(i)),-1*ArrayyB_yMax(ymax(i))+dyArray+ArrayyB_yMax(ymax(i))*2,ArrayzB_yMax(ymax(i))]; 195 | ArrayxB_yMax = [ArrayxB_yMax;ymaxB{i}(1)]; 196 | ArrayyB_yMax = [ArrayyB_yMax;ymaxB{i}(2)]; 197 | ArrayzB_yMax = [ArrayzB_yMax;ymaxB{i}(3)]; 198 | Arrayf = [Arrayf;0]; 199 | 200 | end 201 | 202 | % zMax 203 | ArrayzJ_zMax = ArrayzB_yMax; 204 | ArrayxB_zMax = ArrayxB_yMax; 205 | ArrayyB_zMax = ArrayyB_yMax; 206 | ArrayzB_zMax = ArrayzB_yMax; 207 | 208 | for i = 1:num*num+44 209 | 210 | [rBzr,rBzir] = max(ArrayzJ_zMax); 211 | zmax(i) = rBzir; 212 | ArrayzJ_zMax(rBzir) = 0; 213 | zmaxB{i} = [ArrayxB_zMax(zmax(i)),ArrayyB_zMax(zmax(i)),-1*ArrayzB_zMax(zmax(i))+dzArray+ArrayzB_zMax(zmax(i))*2]; 214 | ArrayxB_zMax = [ArrayxB_zMax;zmaxB{i}(1)]; 215 | ArrayyB_zMax = [ArrayyB_zMax;zmaxB{i}(2)]; 216 | ArrayzB_zMax = [ArrayzB_zMax;zmaxB{i}(3)]; 217 | Arrayf = [Arrayf;0]; 218 | 219 | end 220 | 221 | % zMin 222 | ArrayzJ_zMin = ArrayzB_zMax; 223 | ArrayxB_zMin = ArrayxB_zMax; 224 | ArrayyB_zMin = ArrayyB_zMax; 225 | ArrayzB_zMin = ArrayzB_zMax; 226 | 227 | for i = 1:num*num+44 228 | 229 | [rBzl,rBzil] = min(ArrayzJ_zMin); 230 | zmin(i) = rBzil; 231 | ArrayzJ_zMin(rBzil) = 0; 232 | zminB{i} = [ArrayxB_zMin(zmin(i)),ArrayyB_zMin(zmin(i)),-1*ArrayzB_zMin(zmin(i))-dzArray+ArrayzB_zMin(zmin(i))*2]; 233 | ArrayxB_zMin = [ArrayxB_zMin;zminB{i}(1)]; 234 | ArrayyB_zMin = [ArrayyB_zMin;zminB{i}(2)]; 235 | ArrayzB_zMin = [ArrayzB_zMin;zminB{i}(3)]; 236 | Arrayf = [Arrayf;0]; 237 | 238 | end 239 | 240 | 241 | figure() 242 | plot3(Arrayx,Arrayy,Arrayz,'.') 243 | hold on 244 | plot3(Arrayx(xmin),Arrayy(xmin),Arrayz((xmin)),'.r'); 245 | hold on 246 | for i = 1:num*num 247 | plot3(xminB{i}(1),xminB{i}(2),xminB{i}(3),'.g'); 248 | end 249 | 250 | hold on 251 | plot3(ArrayxB_yMin(ymin),ArrayyB_yMin(ymin),ArrayzB_yMin((ymin)),'.r'); 252 | hold on 253 | for i = 1:num*num+10 254 | plot3(yminB{i}(1),yminB{i}(2),yminB{i}(3),'.g'); 255 | end 256 | 257 | hold on 258 | plot3(ArrayxB_xMax(xmax),ArrayyB_xMax(xmax),ArrayzB_xMax((xmax)),'.r'); 259 | hold on 260 | for i = 1:num*num+20 261 | plot3(xmaxB{i}(1),xmaxB{i}(2),xmaxB{i}(3),'.g'); 262 | end 263 | 264 | hold on 265 | plot3(ArrayxB_yMax(ymax),ArrayyB_yMax(ymax),ArrayzB_yMax((ymax)),'.r'); 266 | hold on 267 | for i = 1:num*num+40 268 | plot3(ymaxB{i}(1),ymaxB{i}(2),ymaxB{i}(3),'.g'); 269 | end 270 | 271 | hold on 272 | plot3(ArrayxB_zMax(zmax),ArrayyB_zMax(zmax),ArrayzB_zMax((zmax)),'.r'); 273 | hold on 274 | for i = 1:num*num+44 275 | plot3(zmaxB{i}(1),zmaxB{i}(2),zmaxB{i}(3),'.g'); 276 | end 277 | 278 | hold on 279 | plot3(ArrayxB_zMin(zmin),ArrayyB_zMin(zmin),ArrayzB_zMin((zmin)),'.r'); 280 | hold on 281 | for i = 1:num*num+44 282 | plot3(zminB{i}(1),zminB{i}(2),zminB{i}(3),'.g'); 283 | end 284 | title('Mirroring of boundaries') 285 | 286 | 287 | 288 | % figure() 289 | % plot3(ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin,'.b') 290 | 291 | 292 | % setting points for smooth differential calculation 293 | 294 | 295 | Qp = 20; 296 | n_Quiry = Qp^3; 297 | ax = zeros(n_Quiry,1); 298 | ay = zeros(n_Quiry,1); 299 | az = zeros(n_Quiry,1); 300 | 301 | xp = linspace(0.3,2.7,Qp); 302 | yp = linspace(0.3,2.7,Qp); 303 | zp = linspace(-1.2,1.2,Qp); 304 | 305 | for i = 1:Qp 306 | for j = 1:Qp 307 | for k = 1:Qp 308 | 309 | ax((i-1)*Qp*Qp+(j-1)*Qp+k) = xp(k); 310 | ay((i-1)*Qp*Qp+(j-1)*Qp+k) = yp(j); 311 | az((i-1)*Qp*Qp+(j-1)*Qp+k) = zp(i); 312 | 313 | end 314 | end 315 | end 316 | 317 | figure() 318 | scatter3(ax,ay,az,'.b'); 319 | hold on 320 | scatter3(ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin,'.r'); 321 | axis equal 322 | title('points for differential calculatio and original points') 323 | 324 | % Voronoi cell original 325 | 326 | 327 | DataMetrix = [ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin]; 328 | DataMetrix = unique(DataMetrix,'rows'); 329 | [v,c] = voronoin(DataMetrix); 330 | 331 | C_region = length(c); 332 | C_Vertex = cell(C_region,1); 333 | 334 | for i=1:C_region 335 | 336 | C_Vertex{i}=v(c{i},:); 337 | 338 | end 339 | 340 | % Counting of the points out of the boundary 341 | 342 | 343 | C_Vertex_judge = zeros(C_region,1); 344 | for j = 1:C_region 345 | 346 | Lc = size(C_Vertex{j},1); 347 | 348 | for k = 1:Lc 349 | 350 | for m = 1:3 351 | 352 | switch m 353 | 354 | case 1 355 | 356 | if C_Vertex{j}(k,m) <= Lim.x0-dxArray 357 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 358 | elseif C_Vertex{j}(k,m) >= Lim.x1+dxArray 359 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 360 | end 361 | 362 | case 2 363 | 364 | if C_Vertex{j}(k,m) <= Lim.y0-dyArray 365 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 366 | elseif C_Vertex{j}(k,m) >= Lim.y1+dyArray 367 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 368 | end 369 | 370 | case 3 371 | 372 | if C_Vertex{j}(k,m) <= Lim.z0-dzArray 373 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 374 | elseif C_Vertex{j}(k,m) >= Lim.z1+dzArray 375 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 376 | end 377 | end 378 | end 379 | end 380 | end 381 | 382 | % calculating the Voronoi cell volume 383 | 384 | 385 | VolForOne = zeros(C_region,1); 386 | k_vertexs = cell(C_region,1); 387 | for i = 1:C_region 388 | 389 | if isinf(C_Vertex{i}(1,:)) 390 | 391 | continue 392 | 393 | elseif C_Vertex_judge(i) < 1 394 | 395 | VertexsForOne = C_Vertex{i}; 396 | [k_vertexs{i},VolForOne(i)] = convhulln(VertexsForOne); 397 | 398 | end 399 | end 400 | 401 | 402 | sum(VolForOne) 403 | 404 | 405 | 406 | n_Quiry = length(ax); 407 | CircleC = 2; 408 | dh = mean((dxArray+dyArray+dzArray)./3); 409 | 410 | 411 | h0=0.3; 412 | hn=30; 413 | h1=1; 414 | hdn=(h1-h0)/hn; 415 | 416 | 417 | [W_Gauij,rij,xij,yij,zij]=GauQuiry3D(ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin,ax,ay,az,h0,h1,hn,VolForOne,Arrayf); 418 | 419 | 420 | 421 | figure() 422 | xlim([Lim.x0,Lim.x1]); 423 | ylim([Lim.y0,Lim.y1]); 424 | zlim([Lim.z0,Lim.z1]); 425 | scatter3(ax,ay,az,'.'); 426 | axis equal 427 | hold on 428 | 429 | 430 | h_Quiry = zeros(1,hn); 431 | h_r1 = zeros(1,n_Quiry); 432 | for i = 1:n_Quiry 433 | 434 | for j = 1:hn 435 | 436 | h_Quiry(j) = abs(W_Gauij(i,j)-1); 437 | [qq,hQT] = min(h_Quiry); 438 | h_r = find(h_Quiry==qq)*hdn; 439 | 440 | end 441 | 442 | h_r2 = hQT*hdn+h0; 443 | 444 | for k = 1:CircleC 445 | h_r1(i) = h_r+h0; 446 | [xunit,yunit,zunit] = DrawCircle3D(ax(i),ay(i),az(i),h_r1(i)); 447 | plot3(xunit(k,:),yunit(k,:),zunit(k,:)); 448 | xlim([Lim.x0,Lim.x1]); 449 | ylim([Lim.y0,Lim.y1]); 450 | zlim([Lim.z0,Lim.z1]); 451 | hold on 452 | end 453 | end 454 | 455 | ppp=cell(n_Quiry,1); 456 | for i=1:n_Quiry 457 | 458 | [rn]=findPointsInH(rij(i,:),h_r1(i)); 459 | ppp{i}=rn; 460 | 461 | end 462 | 463 | 464 | xij = abs(xij); 465 | Dminx = min(xij,[],2); 466 | yij = abs(yij); 467 | Dminy = min(yij,[],2); 468 | zij = abs(zij); 469 | Dminz = min(zij,[],2); 470 | 471 | 472 | Dh_r1_x = zeros(n_Quiry,1); 473 | Dh_r1_y = zeros(n_Quiry,1); 474 | Dh_r1_z = zeros(n_Quiry,1); 475 | Dh_r1 = zeros(n_Quiry,1); 476 | for i=1:n_Quiry 477 | 478 | Dh_r1_x(i) = h_r1(i)/Dminx(i); 479 | Dh_r1_y(i) = h_r1(i)/Dminy(i); 480 | Dh_r1_z(i) = h_r1(i)/Dminz(i); 481 | Dh_r1(i) = sqrt(Dh_r1_x(i)*Dh_r1_x(i)+Dh_r1_y(i)*Dh_r1_y(i)+Dh_r1_z(i)*Dh_r1_z(i)); 482 | 483 | end 484 | 485 | 486 | 487 | % for i = n_Quiry:-1:1 488 | % 489 | % if ppp{i} == 0 490 | % Arrayzf(i) = 0; 491 | % end 492 | % 493 | % end 494 | 495 | 496 | 497 | % for i = 1:n_Quiry 498 | % for j = 1:length(ppp{i}) 499 | % 500 | % VolForOneq{i}(j) = VolForOne(ppp{i}(j)); 501 | % 502 | % end 503 | % end 504 | % 505 | % for i = 1:n_Quiry 506 | % for j = 1:length(ppp{i}) 507 | % 508 | % fArrayq{i}(j) = Arrayf(ppp{i}(j)); 509 | % Datax{i}(j) = ArrayxB_zMin((ppp{i}(j))); 510 | % Datay{i}(j) = ArrayyB_zMin((ppp{i}(j))); 511 | % Dataz{i}(j) = ArrayzB_zMin((ppp{i}(j))); 512 | % 513 | % end 514 | % end 515 | % 516 | % W_Gauij_fix = zeros(n_Quiry,1); 517 | % W_Gauij1_fix = zeros(n_Quiry,1); 518 | % Wx = zeros(n_Quiry,1); 519 | % Wy = zeros(n_Quiry,1); 520 | % Wz = zeros(n_Quiry,1); 521 | % for i = 1:n_Quiry 522 | % [W_Gauij_fix(i),W_Gauij1_fix(i),Wx(i),Wy(i),Wz(i)]=GauQuiry3D_FixedH(Datax{i},Datay{i},Dataz{i},ax(i),ay(i),az(i),h_r1(i),VolForOneq{i},fArrayq{i}); 523 | % end 524 | 525 | 526 | %% smooth differential calculation 527 | 528 | W_Gauij_fix = zeros(n_Quiry,1); 529 | W_Gauij1_fix = zeros(n_Quiry,1); 530 | Wx = zeros(n_Quiry,1); 531 | Wy = zeros(n_Quiry,1); 532 | Wz = zeros(n_Quiry,1); 533 | for i = 1:n_Quiry 534 | [W_Gauij_fix(i),W_Gauij1_fix(i),Wx(i),Wy(i),Wz(i)]=GauQuiry3D_FixedH(ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin,ax(i),ay(i),az(i),h_r1(i),VolForOne,Arrayf); 535 | end 536 | 537 | %% data output 538 | 539 | save Arrayx.mat ax 540 | save Arrayy.mat ay 541 | save Arrayz.mat az 542 | 543 | save W_Gauij1_fix.mat W_Gauij1_fix 544 | save Wx.mat Wx 545 | save Wy.mat Wy 546 | save Wz.mat Wz 547 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/A_Step2_cutsapce_newvariables.m: -------------------------------------------------------------------------------- 1 | clear 2 | %% cutting parameter space and obtaining unique dimensionless group. 3 | % containing three steps:1 loading differnetial data; 2 cutting space 4 | % using function 5 | % [D,F,U,D_d]=cluster_myfcm(x,y,z,f,pFpX,pFpY,pFpZ,M,sub_p,n); 3 obtaining 6 | % unique dimensionless group using function D=new_var(D,n,F) 7 | 8 | %% loading differential data 9 | % points coordinate 10 | load Arrayx.mat 11 | load Arrayy.mat 12 | load Arrayz.mat 13 | 14 | 15 | % points interpolation 16 | load W_Gauij1_fix.mat 17 | 18 | % partial differential 19 | load Wx.mat 20 | load Wy.mat 21 | load Wz.mat 22 | 23 | %% cutting parameter space 24 | 25 | M=4; % m=4 26 | 27 | sub_p=0.9; % ra=0.9 28 | 29 | n=3; % dimensions=3 30 | 31 | [D.sub,D.C,U,D_d]=cluster_myfcm(ax,ay,az,W_Gauij1_fix,Wx,Wy,Wz,M,sub_p,n);%这里的f_inter只是方便每一个分区数值的对比 32 | 33 | %% obtaining unique dimensionless group 34 | 35 | D.sub=new_var(D.sub,n,D.C); 36 | 37 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/F_clustering/cluster_myfcm.m: -------------------------------------------------------------------------------- 1 | function [D,F,U,D_d]=cluster_myfcm(x,y,z,f,pFpX,pFpY,pFpZ,M,sub_p,n) 2 | 3 | % obtaining local features, cutting parameter space. F is the cluster 4 | % center matrix; U is the membership matrix. x,y,z,f,pFpX,pFpY,pFpZ are the 5 | % interpolation data; M is m; Sub_p is ra; n is the problem dimension. 6 | 7 | %% obtaining local dominated eigenvectors 8 | D_d.N=length(pFpY);% number of data points 9 | 10 | for i=1:D_d.N 11 | 12 | D_d.d(i).pFp_i=[pFpX(i);pFpY(i);pFpZ(i)]; 13 | 14 | D_d.d(i).W=D_d.d(i).pFp_i*D_d.d(i).pFp_i';% local feature matrix of each point 15 | 16 | [D_d.d(i).ve,D_d.d(i).va]=eig(D_d.d(i).W,'nobalance'); 17 | 18 | [D_d.d(i).d,D_d.d(i).ind] = sort(diag(D_d.d(i).va)); 19 | 20 | D_d.d(i).vas = D_d.d(i).va(D_d.d(i).ind,D_d.d(i).ind); % sorting eigenvalues 21 | 22 | D_d.d(i).ves = D_d.d(i).ve(:,D_d.d(i).ind);% sorting eigenvector matrix's column 23 | 24 | end 25 | 26 | s=zeros(length(pFpY),n);% obtain local features 27 | for i=1:D_d.N 28 | for j=1:n 29 | s(i,j)=abs(D_d.d(i).ves(j,n)); 30 | end 31 | end 32 | 33 | %% preforming subclust algorithm 34 | 35 | [F,S] = subclust(s,sub_p);% F is the estimating cluster center matrix ;S is Cluster Influence Range for Each Data Dimension 36 | % sub_p=ra 37 | %% performing FCM algorithm 38 | 39 | options = [M NaN NaN 0]; 40 | % M=m 41 | 42 | [centers,U] = fcm(s,length(F(:,1)),options); 43 | 44 | maxU = max(U); 45 | for i=1:length(F(:,1))+1 46 | if i<=length(F(:,1)) 47 | D.sub(i).index=find(U(i,:)==maxU&U(i,:)>=0.6); 48 | else 49 | D.sub(i).index=find(maxU<0.6); 50 | end 51 | D.sub(i).x=x(D.sub(i).index); 52 | D.sub(i).y=y(D.sub(i).index); 53 | D.sub(i).z=z(D.sub(i).index); 54 | D.sub(i).f=f(D.sub(i).index); 55 | D.sub(i).pFpX=pFpX(D.sub(i).index); 56 | D.sub(i).pFpY=pFpY(D.sub(i).index); 57 | D.sub(i).pFpZ=pFpZ(D.sub(i).index); 58 | end 59 | end 60 | 61 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/F_clustering/new_var.m: -------------------------------------------------------------------------------- 1 | 2 | function D=new_var(D,n,F) 3 | 4 | % sub-domains global feature matrix is established, and the unique 5 | % dimensionless group is obtained by matrix's eigenvector. F is the cluster 6 | % center matrix, n is the dimensions of the problem 7 | 8 | for i=1:length(F(:,1)) 9 | 10 | 11 | D.sub(i).dx_dy_dz=[D.sub(i).pFpX,D.sub(i).pFpY,D.sub(i).pFpZ]; 12 | 13 | for j=1:length(D.sub(i).pFpX) 14 | 15 | D.sub(i).c(j).points=D.sub(i).dx_dy_dz(j,:)'*D.sub(i).dx_dy_dz(j,:); 16 | 17 | end 18 | end 19 | 20 | for i=1:length(F(:,1)) 21 | 22 | D.sub(i).C=zeros(n,n); 23 | 24 | end 25 | 26 | for i=1:length(F(:,1)) 27 | for j=1:length(D.sub(i).pFpX) 28 | 29 | D.sub(i).C= D.sub(i).C+D.sub(i).c(j).points; 30 | 31 | end 32 | end 33 | 34 | 35 | 36 | for i=1:length(F(:,1)) 37 | D.sub(i).C1=D.sub(i).C.*length(D.sub(i).pFpX); % obtaining global feature matrix 38 | 39 | [D.sub(i).ve,D.sub(i).va]=eig(D.sub(i).C1,'nobalance'); 40 | 41 | [D.sub(i).d,D.sub(i).ind] = sort(diag(D.sub(i).va));% sorting eigenvalues 42 | 43 | D.sub(i).ves = D.sub(i).ve(:,D.sub(i).ind);% sorting eigenvector matrix's column 44 | 45 | D.sub(i).x_y_z=[D.sub(i).x D.sub(i).y D.sub(i).z]; 46 | 47 | D.sub(i).lx_y_z_new=D.sub(i).x_y_z* D.sub(i).ves; 48 | 49 | D.sub(i).x_y_z_new=exp(D.sub(i).lx_y_z_new); % obating the unique dimensionless group 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/F_differential/BB.m: -------------------------------------------------------------------------------- 1 | clear 2 | clc 3 | 4 | %% 正方体标准值测试 5 | 6 | %% 设置数据点及数据点数据 7 | % 本程序块首先定义了数值(实验)点域,再结合王驰提供的两个分段函数对每个数值点的位置和数值大小进行定义 8 | % lim为数据点的范围 9 | Lim.x0 = 0; Lim.x1 = 3; 10 | Lim.y0 = 0; Lim.y1 = 3; 11 | Lim.z0 = -1.5; Lim.z1 = 1.5; 12 | 13 | num = 20; % 设置数值点在每一个维度上的数量 14 | n_Quiry = num^3; % 数值点的总数(3维) 15 | 16 | dxArray = (Lim.x1-Lim.x0)/num; % 步长 17 | dyArray = (Lim.y1-Lim.y0)/num; 18 | dzArray = (Lim.z1-Lim.z0)/num; 19 | 20 | xfp = linspace(Lim.x0,Lim.x1,num); % 按照数值点的数量平均分布间距 21 | yfp = linspace(Lim.y0,Lim.y1,num); 22 | zfp = linspace(Lim.z0,Lim.z1,num); 23 | 24 | Arrayx = zeros(n_Quiry,1); 25 | Arrayy = zeros(n_Quiry,1); 26 | Arrayz = zeros(n_Quiry,1); 27 | Arrayf = zeros(n_Quiry,1); 28 | 29 | for i = 1:num 30 | for j = 1:num 31 | for k = 1:num 32 | 33 | Arrayx((i-1)*num*num+(j-1)*num+k) = xfp(k); % 定义点坐标, x为一步一变 34 | Arrayy((i-1)*num*num+(j-1)*num+k) = yfp(j); % y为n步一变(n为一个维度上点的数量) 35 | Arrayz((i-1)*num*num+(j-1)*num+k) = zfp(i); % z为n^2步一变 36 | 37 | if Arrayz((i-1)*num*num+(j-1)*num+k) <= 0 % 调用王驰的分段函数为数据点赋值 38 | 39 | Arrayf((i-1)*num*num+(j-1)*num+k) = f1(Arrayx((i-1)*num*num+(j-1)*num+k),Arrayy((i-1)*num*num+(j-1)*num+k),Arrayz((i-1)*num*num+(j-1)*num+k)); 40 | 41 | elseif Arrayz((i-1)*num*num+(j-1)*num+k) > 0 42 | 43 | Arrayf((i-1)*num*num+(j-1)*num+k) = f2(Arrayx((i-1)*num*num+(j-1)*num+k),Arrayy((i-1)*num*num+(j-1)*num+k),Arrayz((i-1)*num*num+(j-1)*num+k)); 44 | 45 | end 46 | end 47 | end 48 | end 49 | 50 | figure() 51 | scatter3(Arrayx,Arrayy,Arrayz,'.'); 52 | title('未扰动的数据点') 53 | axis equal 54 | 55 | %% 给数据点加上位置扰动 56 | % 反应实验中的问题,在xyz坐标上加入有正负值的扰动 57 | 58 | for i = 1:num 59 | for j = 1:num 60 | for k = 1:num 61 | 62 | Exyz = rand(1)*0.05; % 正负百分之十以内的随机误差 63 | Arrayx((i-1)*num*num+(j-1)*num+k) = Arrayx((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayx((i-1)*num*num+(j-1)*num+k); 64 | Arrayy((i-1)*num*num+(j-1)*num+k) = Arrayy((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayy((i-1)*num*num+(j-1)*num+k); 65 | Arrayz((i-1)*num*num+(j-1)*num+k) = Arrayz((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayz((i-1)*num*num+(j-1)*num+k); 66 | 67 | end 68 | end 69 | end 70 | Arrayf_color = Arrayf; 71 | 72 | figure() 73 | scatter3(Arrayx,Arrayy,Arrayz,'.'); 74 | title('加入扰动后的原数据') 75 | axis equal 76 | 77 | figure() 78 | scatter3(Arrayx,Arrayy,Arrayz,80,Arrayf_color,'.'); 79 | title('数值f扰动前') 80 | axis equal 81 | 82 | %% 给数值点加上数值扰动 83 | 84 | Arrayf_Pert = Arrayf; 85 | for i = 1:num 86 | for j = 1:num 87 | for k = 1:num 88 | 89 | Exyz = rand(1)*0.05; % 正负百分之十以内的随机误差 90 | Arrayf_Pert((i-1)*num*num+(j-1)*num+k) = Arrayf_Pert((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayf_Pert((i-1)*num*num+(j-1)*num+k); 91 | 92 | end 93 | end 94 | end 95 | Arrayf_Pert_color = Arrayf_Pert; 96 | 97 | figure() 98 | scatter3(Arrayx,Arrayy,Arrayz,80,Arrayf_Pert_color,'.'); 99 | title('数值f扰动后') 100 | axis equal 101 | 102 | %% 数值点边界处理 镜像(对称) 其中R为旋转矩阵,针对存在非垂直坐标轴的情况 103 | % MATLAB中自带的voronoi算法不会对外边界进行特殊处理,所以当对最外层数据点画网格时会导致许多的顶点超出我们定义的 104 | % 数据域,甚至会有距离无限远的顶点,从而导致原先的边界模糊且无法计算。 105 | % 在外边界倾斜时我们可以引入旋转矩阵来辅助镜像,在本例子中由于所有外边界都为垂直,所以没有使用此功能 106 | % 整体镜像偏移过程像是叠箱子,在过程中数组是增大的 107 | % 为了对齐数列的长度,方便计算,镜像后的数据点的数值f定为0 108 | 109 | reflectB = zeros(num*6,1); 110 | xmin = zeros(num*num,1); 111 | ymin = zeros(num*num,1); 112 | zmin = zeros(num*num,1); 113 | xmax = zeros(num*num,1); 114 | ymax = zeros(num*num,1); 115 | zmax = zeros(num*num,1); 116 | 117 | ArrayyJ = Arrayy; 118 | ArrayzJ = Arrayz; 119 | xmaxB = cell(100,1); 120 | xminB = cell(100,1); 121 | ymaxB = cell(100,1); 122 | yminB = cell(100,1); 123 | zmaxB = cell(100,1); 124 | zminB = cell(100,1); 125 | 126 | % 以下是按顺序对每个面进行重复 先识别出最外侧面的所有点,再对垂直坐标轴进行偏移镜像 127 | % xMin 128 | ArrayxJ_xMin = Arrayx; 129 | ArrayxB_xMin = Arrayx; 130 | ArrayyB_xMin = Arrayy; 131 | ArrayzB_xMin = Arrayz; 132 | 133 | for i = 1:num*num 134 | 135 | [rBxl,rBxil] = min(ArrayxJ_xMin); % 识别面上的极端点(在这里是最小点) 136 | xmin(i) = rBxil; % 储存极端点的位置 137 | ArrayxJ_xMin(rBxil) = (Lim.x1-Lim.x0)/2; % 使用中位点替代极端点,使得程序可以识别下一个极端点 138 | xminB{i} = [-1*ArrayxB_xMin(xmin(i))-dxArray+ArrayxB_xMin(xmin(i)),ArrayyB_xMin(xmin(i)),ArrayzB_xMin(xmin(i))]; 139 | % 上式为镜像及偏移过程 140 | ArrayxB_xMin = [ArrayxB_xMin;xminB{i}(1)]; % 将镜像后的点组合到原数据中 141 | ArrayyB_xMin = [ArrayyB_xMin;xminB{i}(2)]; 142 | ArrayzB_xMin = [ArrayzB_xMin;xminB{i}(3)]; 143 | Arrayf = [Arrayf;0]; 144 | 145 | end 146 | 147 | % yMin 148 | ArrayyJ_yMin = ArrayyB_xMin; 149 | ArrayxB_yMin = ArrayxB_xMin; 150 | ArrayyB_yMin = ArrayyB_xMin; 151 | ArrayzB_yMin = ArrayzB_xMin; 152 | 153 | for i = 1:num*num+10 154 | 155 | [rByl,rByil] = min(ArrayyJ_yMin); 156 | ymin(i) = rByil; 157 | ArrayyJ_yMin(rByil) = (Lim.y1-Lim.y0)/2; 158 | yminB{i} = [ArrayxB_yMin(ymin(i)),-1*ArrayyB_yMin(ymin(i))-dyArray+ArrayyB_yMin(ymin(i)),ArrayzB_yMin(ymin(i))]; 159 | ArrayxB_yMin = [ArrayxB_yMin;yminB{i}(1)]; 160 | ArrayyB_yMin = [ArrayyB_yMin;yminB{i}(2)]; 161 | ArrayzB_yMin = [ArrayzB_yMin;yminB{i}(3)]; 162 | Arrayf = [Arrayf;0]; 163 | 164 | end 165 | 166 | % xMax 167 | ArrayxJ_xMax = ArrayxB_yMin; 168 | ArrayxB_xMax = ArrayxB_yMin; 169 | ArrayyB_xMax = ArrayyB_yMin; 170 | ArrayzB_xMax = ArrayzB_yMin; 171 | 172 | for i = 1:num*num+20 173 | 174 | [rBxr,rBxir] = max(ArrayxJ_xMax); 175 | xmax(i) = rBxir; 176 | ArrayxJ_xMax(rBxir) = (Lim.x1-Lim.x0)/2; 177 | xmaxB{i} = [-1*ArrayxB_xMax(xmax(i))+ArrayxB_xMax(xmax(i))*2+dxArray,ArrayyB_xMax(xmax(i)),ArrayzB_xMax(xmax(i))]; 178 | ArrayxB_xMax = [ArrayxB_xMax;xmaxB{i}(1)]; 179 | ArrayyB_xMax = [ArrayyB_xMax;xmaxB{i}(2)]; 180 | ArrayzB_xMax = [ArrayzB_xMax;xmaxB{i}(3)]; 181 | Arrayf = [Arrayf;0]; 182 | 183 | end 184 | 185 | % yMax 186 | ArrayyJ_yMax = ArrayyB_xMax; 187 | ArrayxB_yMax = ArrayxB_xMax; 188 | ArrayyB_yMax = ArrayyB_xMax; 189 | ArrayzB_yMax = ArrayzB_xMax; 190 | 191 | for i = 1:num*num+40 192 | 193 | [rByr,rByir] = max(ArrayyJ_yMax); 194 | ymax(i) = rByir; 195 | ArrayyJ_yMax(rByir) = (Lim.y1-Lim.y0)/2; 196 | ymaxB{i} = [ArrayxB_yMax(ymax(i)),-1*ArrayyB_yMax(ymax(i))+dyArray+ArrayyB_yMax(ymax(i))*2,ArrayzB_yMax(ymax(i))]; 197 | ArrayxB_yMax = [ArrayxB_yMax;ymaxB{i}(1)]; 198 | ArrayyB_yMax = [ArrayyB_yMax;ymaxB{i}(2)]; 199 | ArrayzB_yMax = [ArrayzB_yMax;ymaxB{i}(3)]; 200 | Arrayf = [Arrayf;0]; 201 | 202 | end 203 | 204 | % zMax 205 | ArrayzJ_zMax = ArrayzB_yMax; 206 | ArrayxB_zMax = ArrayxB_yMax; 207 | ArrayyB_zMax = ArrayyB_yMax; 208 | ArrayzB_zMax = ArrayzB_yMax; 209 | 210 | for i = 1:num*num+44 211 | 212 | [rBzr,rBzir] = max(ArrayzJ_zMax); 213 | zmax(i) = rBzir; 214 | ArrayzJ_zMax(rBzir) = 0; 215 | zmaxB{i} = [ArrayxB_zMax(zmax(i)),ArrayyB_zMax(zmax(i)),-1*ArrayzB_zMax(zmax(i))+dzArray+ArrayzB_zMax(zmax(i))*2]; 216 | ArrayxB_zMax = [ArrayxB_zMax;zmaxB{i}(1)]; 217 | ArrayyB_zMax = [ArrayyB_zMax;zmaxB{i}(2)]; 218 | ArrayzB_zMax = [ArrayzB_zMax;zmaxB{i}(3)]; 219 | Arrayf = [Arrayf;0]; 220 | 221 | end 222 | 223 | % zMin 224 | ArrayzJ_zMin = ArrayzB_zMax; 225 | ArrayxB_zMin = ArrayxB_zMax; 226 | ArrayyB_zMin = ArrayyB_zMax; 227 | ArrayzB_zMin = ArrayzB_zMax; 228 | 229 | for i = 1:num*num+44 230 | 231 | [rBzl,rBzil] = min(ArrayzJ_zMin); 232 | zmin(i) = rBzil; 233 | ArrayzJ_zMin(rBzil) = 0; 234 | zminB{i} = [ArrayxB_zMin(zmin(i)),ArrayyB_zMin(zmin(i)),-1*ArrayzB_zMin(zmin(i))-dzArray+ArrayzB_zMin(zmin(i))*2]; 235 | ArrayxB_zMin = [ArrayxB_zMin;zminB{i}(1)]; 236 | ArrayyB_zMin = [ArrayyB_zMin;zminB{i}(2)]; 237 | ArrayzB_zMin = [ArrayzB_zMin;zminB{i}(3)]; 238 | Arrayf = [Arrayf;0]; 239 | 240 | end 241 | 242 | 243 | figure() 244 | plot3(Arrayx,Arrayy,Arrayz,'.') 245 | hold on 246 | plot3(Arrayx(xmin),Arrayy(xmin),Arrayz((xmin)),'.r'); 247 | hold on 248 | for i = 1:num*num 249 | plot3(xminB{i}(1),xminB{i}(2),xminB{i}(3),'.g'); 250 | end 251 | 252 | hold on 253 | plot3(ArrayxB_yMin(ymin),ArrayyB_yMin(ymin),ArrayzB_yMin((ymin)),'.r'); 254 | hold on 255 | for i = 1:num*num+10 256 | plot3(yminB{i}(1),yminB{i}(2),yminB{i}(3),'.g'); 257 | end 258 | 259 | hold on 260 | plot3(ArrayxB_xMax(xmax),ArrayyB_xMax(xmax),ArrayzB_xMax((xmax)),'.r'); 261 | hold on 262 | for i = 1:num*num+20 263 | plot3(xmaxB{i}(1),xmaxB{i}(2),xmaxB{i}(3),'.g'); 264 | end 265 | 266 | hold on 267 | plot3(ArrayxB_yMax(ymax),ArrayyB_yMax(ymax),ArrayzB_yMax((ymax)),'.r'); 268 | hold on 269 | for i = 1:num*num+40 270 | plot3(ymaxB{i}(1),ymaxB{i}(2),ymaxB{i}(3),'.g'); 271 | end 272 | 273 | hold on 274 | plot3(ArrayxB_zMax(zmax),ArrayyB_zMax(zmax),ArrayzB_zMax((zmax)),'.r'); 275 | hold on 276 | for i = 1:num*num+44 277 | plot3(zmaxB{i}(1),zmaxB{i}(2),zmaxB{i}(3),'.g'); 278 | end 279 | 280 | hold on 281 | plot3(ArrayxB_zMin(zmin),ArrayyB_zMin(zmin),ArrayzB_zMin((zmin)),'.r'); 282 | hold on 283 | for i = 1:num*num+44 284 | plot3(zminB{i}(1),zminB{i}(2),zminB{i}(3),'.g'); 285 | end 286 | title('镜像边界示例,红色点阵为识别到的边界,绿色点阵为镜像边界') 287 | 288 | % 旋转矩阵 289 | % hold on 290 | % for i = 1:num*num % 镜像中加入旋转角度 291 | % 292 | % Rx = rotx(0); 293 | % Ry = roty(0); 294 | % Rz = rotz(0); 295 | % 296 | % xminB{i} = Rz*[Arrayx(xmin(i));Arrayy(xmin(i));Arrayz(xmin(i))]; 297 | % plot3(xminB{i}(1),xminB{i}(2)+3.5,xminB{i}(3),'.g'); 298 | % hold on 299 | % 300 | % yminB{i} = Rz*[Arrayx(ymin(i));Arrayy(ymin(i));Arrayz(ymin(i))]; 301 | % plot3(yminB{i}(1),yminB{i}(2),yminB{i}(3),'.g'); 302 | % hold on 303 | % 304 | % zminB{i} = Rz*[Arrayx(zmin(i));Arrayy(zmin(i));Arrayz(zmin(i))]+Arrayz(zmin(i)); 305 | % plot3(zminB{i}(1),zminB{i}(2),zminB{i}(3),'.g'); 306 | % hold on 307 | % 308 | % end 309 | 310 | figure() 311 | plot3(ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin,'.b') 312 | title('加入镜像边界后'); 313 | 314 | %% 设置差值点 315 | % 要插值的点 316 | 317 | Qp = 10; % 每个维度设置10个差值点 318 | n_Quiry = Qp^3; 319 | ax = zeros(n_Quiry,1); 320 | ay = zeros(n_Quiry,1); 321 | az = zeros(n_Quiry,1); 322 | 323 | xp = linspace(0.2,2.8,Qp); 324 | yp = linspace(0.2,2.8,Qp); 325 | zp = linspace(-1.3,1.3,Qp); 326 | 327 | for i = 1:Qp 328 | for j = 1:Qp 329 | for k = 1:Qp 330 | 331 | ax((i-1)*Qp*Qp+(j-1)*Qp+k) = xp(k); 332 | ay((i-1)*Qp*Qp+(j-1)*Qp+k) = yp(j); 333 | az((i-1)*Qp*Qp+(j-1)*Qp+k) = zp(i); 334 | 335 | end 336 | end 337 | end 338 | 339 | figure() 340 | scatter3(ax,ay,az,'.b'); 341 | hold on 342 | scatter3(ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin,'.r'); 343 | axis equal 344 | title('差值点与数据点') 345 | 346 | %% 画Voronoi网格 347 | % 直接引用MATLAB中的程序 348 | 349 | DataMetrix = [ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin]; % 画Voronoi所需的坐标 350 | DataMetrix = unique(DataMetrix,'rows'); % 删除重复的点 351 | [v,c] = voronoin(DataMetrix); % 画Voronoi网格 得到顶点在数组中的位置和坐标 352 | 353 | C_region = length(c); 354 | C_Vertex = cell(C_region,1); 355 | 356 | for i=1:C_region % 获得每个Voronoi网格中每一点的坐标值 357 | 358 | C_Vertex{i}=v(c{i},:); 359 | 360 | end 361 | 362 | %% 统计超出边界的多边体 363 | % 在原边界(lim)上增加一层缓冲(dx,dy,dz),而后统计所有存在顶点超过边界的Voronoi网格 364 | % 这里有一个容忍度的功能,C_Vertex_judge是用来判断的变量,每当一个顶点的一个坐标点超过边界限制, 365 | % C_Vertex_judge就会加一。此功能遍历所有Voronoi网格。 366 | 367 | C_Vertex_judge = zeros(C_region,1); 368 | for j = 1:C_region % 遍历每一个多面体,每一个多边体的顶点坐标 C_region 369 | 370 | Lc = size(C_Vertex{j},1); 371 | 372 | for k = 1:Lc % 多边体的边数 Lc 373 | 374 | for m = 1:3 % 三个方向共六个最大/最小边界 找出点超出哪个边界 Dimensions 375 | 376 | switch m 377 | 378 | case 1 % 第一个维度(x) 379 | 380 | if C_Vertex{j}(k,m) <= Lim.x0-dxArray 381 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 382 | elseif C_Vertex{j}(k,m) >= Lim.x1+dxArray 383 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 384 | end 385 | 386 | case 2 % 第二个维度(y) 387 | 388 | if C_Vertex{j}(k,m) <= Lim.y0-dyArray 389 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 390 | elseif C_Vertex{j}(k,m) >= Lim.y1+dyArray 391 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 392 | end 393 | 394 | case 3 % 第三个维度(z) 395 | 396 | if C_Vertex{j}(k,m) <= Lim.z0-dzArray 397 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 398 | elseif C_Vertex{j}(k,m) >= Lim.z1+dzArray 399 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 400 | end 401 | end 402 | end 403 | end 404 | end 405 | 406 | %% 计算体积 407 | % 直接引用程序包QHull来计算体积,这是本套代码对于高维度数组计算的唯一限制,维度N被限制小于9。 408 | 409 | VolForOne = zeros(C_region,1); 410 | k_vertexs = cell(C_region,1); 411 | figure() 412 | for i = 1:C_region % 遍历 C_region 413 | 414 | if isinf(C_Vertex{i}(1,:)) % 当Voronoi cell存在一无限远的顶点时,跳过这一Voronoi cell 415 | 416 | continue 417 | 418 | elseif C_Vertex_judge(i) < 1 % 这一步可设置容忍度C_Vertex_judge,本程序中容忍度为零 419 | 420 | VertexsForOne = C_Vertex{i}; 421 | [k_vertexs{i},VolForOne(i)] = convhulln(VertexsForOne); 422 | trisurf(k_vertexs{i},VertexsForOne(:,1),VertexsForOne(:,2),VertexsForOne(:,3),'FaceColor','cyan') 423 | hold on 424 | end 425 | 426 | 427 | end 428 | title('画出Voronoi凸域'); 429 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/F_differential/DrawCircle3D.m: -------------------------------------------------------------------------------- 1 | function [xunit,yunit,zunit] = DrawCircle3D(x,y,z,r) 2 | 3 | th = 0:pi/50:2*pi; 4 | 5 | xunit(1,:) = r * cos(th) + x; 6 | yunit(1,:) = r * sin(th) + y; 7 | zunit(1,:) = r * cos(th) + z; 8 | 9 | xunit(2,:) = r * cos(th) + x; 10 | yunit(2,:) = r * sin(th) + y; 11 | zunit(2,:) = r * -cos(th) + z; 12 | 13 | 14 | xunit(3,:) = r * -cos(th) + x; 15 | yunit(3,:) = r * -sin(th) + y; 16 | zunit(3,:) = 0 * cos(th) + z; -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/F_differential/DrawQHull.m: -------------------------------------------------------------------------------- 1 | clear 2 | clc 3 | 4 | %% 正方体标准值测试 5 | 6 | clear 7 | clc 8 | 9 | %% 设置数据点及数据点数据 10 | % 本程序块首先定义了数值(实验)点域,再结合王驰提供的两个分段函数对每个数值点的位置和数值大小进行定义 11 | % lim为数据点的范围 12 | Lim.x0 = 0; Lim.x1 = 3; 13 | Lim.y0 = 0; Lim.y1 = 3; 14 | Lim.z0 = -1.5; Lim.z1 = 1.5; 15 | 16 | num = 5; % 设置数值点在每一个维度上的数量 17 | n_Quiry = num^3; % 数值点的总数(3维) 18 | 19 | dxArray = (Lim.x1-Lim.x0)/num; % 步长 20 | dyArray = (Lim.y1-Lim.y0)/num; 21 | dzArray = (Lim.z1-Lim.z0)/num; 22 | 23 | xfp = linspace(Lim.x0,Lim.x1,num); % 按照数值点的数量平均分布间距 24 | yfp = linspace(Lim.y0,Lim.y1,num); 25 | zfp = linspace(Lim.z0,Lim.z1,num); 26 | 27 | Arrayx = zeros(n_Quiry,1); 28 | Arrayy = zeros(n_Quiry,1); 29 | Arrayz = zeros(n_Quiry,1); 30 | Arrayf = zeros(n_Quiry,1); 31 | 32 | for i = 1:num 33 | for j = 1:num 34 | for k = 1:num 35 | 36 | Arrayx((i-1)*num*num+(j-1)*num+k) = xfp(k); % 定义点坐标, x为一步一变 37 | Arrayy((i-1)*num*num+(j-1)*num+k) = yfp(j); % y为n步一变(n为一个维度上点的数量) 38 | Arrayz((i-1)*num*num+(j-1)*num+k) = zfp(i); % z为n^2步一变 39 | 40 | if Arrayz((i-1)*num*num+(j-1)*num+k) <= 0 % 调用王驰的分段函数为数据点赋值 41 | 42 | Arrayf((i-1)*num*num+(j-1)*num+k) = f1(Arrayx((i-1)*num*num+(j-1)*num+k),Arrayy((i-1)*num*num+(j-1)*num+k),Arrayz((i-1)*num*num+(j-1)*num+k)); 43 | 44 | elseif Arrayz((i-1)*num*num+(j-1)*num+k) > 0 45 | 46 | Arrayf((i-1)*num*num+(j-1)*num+k) = f2(Arrayx((i-1)*num*num+(j-1)*num+k),Arrayy((i-1)*num*num+(j-1)*num+k),Arrayz((i-1)*num*num+(j-1)*num+k)); 47 | 48 | end 49 | end 50 | end 51 | end 52 | 53 | figure() 54 | scatter3(Arrayx,Arrayy,Arrayz,'.'); 55 | title('未扰动的数据点') 56 | axis equal 57 | 58 | %% 给数据点加上位置扰动 59 | % 反应实验中的问题,在xyz坐标上加入有正负值的扰动 60 | 61 | for i = 1:num 62 | for j = 1:num 63 | for k = 1:num 64 | 65 | Exyz = rand(1)*0.05; % 正负百分之十以内的随机误差 66 | Arrayx((i-1)*num*num+(j-1)*num+k) = Arrayx((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayx((i-1)*num*num+(j-1)*num+k); 67 | Arrayy((i-1)*num*num+(j-1)*num+k) = Arrayy((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayy((i-1)*num*num+(j-1)*num+k); 68 | Arrayz((i-1)*num*num+(j-1)*num+k) = Arrayz((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayz((i-1)*num*num+(j-1)*num+k); 69 | 70 | end 71 | end 72 | end 73 | Arrayf_color = Arrayf; 74 | 75 | figure() 76 | scatter3(Arrayx,Arrayy,Arrayz,'.'); 77 | title('加入扰动后的原数据') 78 | axis equal 79 | 80 | figure() 81 | scatter3(Arrayx,Arrayy,Arrayz,80,Arrayf_color,'.'); 82 | title('数值f扰动前') 83 | axis equal 84 | 85 | %% 给数值点加上数值扰动 86 | 87 | Arrayf_Pert = Arrayf; 88 | for i = 1:num 89 | for j = 1:num 90 | for k = 1:num 91 | 92 | Exyz = rand(1)*0.05; % 正负百分之十以内的随机误差 93 | Arrayf_Pert((i-1)*num*num+(j-1)*num+k) = Arrayf_Pert((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayf_Pert((i-1)*num*num+(j-1)*num+k); 94 | 95 | end 96 | end 97 | end 98 | Arrayf_Pert_color = Arrayf_Pert; 99 | 100 | figure() 101 | scatter3(Arrayx,Arrayy,Arrayz,80,Arrayf_Pert_color,'.'); 102 | title('数值f扰动后') 103 | axis equal 104 | 105 | voronoi(Arrayx,Arrayz); -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/F_differential/DrawQHull3D.m: -------------------------------------------------------------------------------- 1 | clear 2 | clc 3 | 4 | %% 正方体标准值测试 5 | 6 | %% 设置数据点及数据点数据 7 | % 本程序块首先定义了数值(实验)点域,再结合王驰提供的两个分段函数对每个数值点的位置和数值大小进行定义 8 | % lim为数据点的范围 9 | Lim.x0 = 0; Lim.x1 = 3; 10 | Lim.y0 = 0; Lim.y1 = 3; 11 | Lim.z0 = -1.5; Lim.z1 = 1.5; 12 | 13 | num = 20; % 设置数值点在每一个维度上的数量 14 | n_Quiry = num^3; % 数值点的总数(3维) 15 | 16 | dxArray = (Lim.x1-Lim.x0)/num; % 步长 17 | dyArray = (Lim.y1-Lim.y0)/num; 18 | dzArray = (Lim.z1-Lim.z0)/num; 19 | 20 | xfp = linspace(Lim.x0,Lim.x1,num); % 按照数值点的数量平均分布间距 21 | yfp = linspace(Lim.y0,Lim.y1,num); 22 | zfp = linspace(Lim.z0,Lim.z1,num); 23 | 24 | Arrayx = zeros(n_Quiry,1); 25 | Arrayy = zeros(n_Quiry,1); 26 | Arrayz = zeros(n_Quiry,1); 27 | Arrayf = zeros(n_Quiry,1); 28 | 29 | for i = 1:num 30 | for j = 1:num 31 | for k = 1:num 32 | 33 | Arrayx((i-1)*num*num+(j-1)*num+k) = xfp(k); % 定义点坐标, x为一步一变 34 | Arrayy((i-1)*num*num+(j-1)*num+k) = yfp(j); % y为n步一变(n为一个维度上点的数量) 35 | Arrayz((i-1)*num*num+(j-1)*num+k) = zfp(i); % z为n^2步一变 36 | 37 | if Arrayz((i-1)*num*num+(j-1)*num+k) <= 0 % 调用王驰的分段函数为数据点赋值 38 | 39 | Arrayf((i-1)*num*num+(j-1)*num+k) = f1(Arrayx((i-1)*num*num+(j-1)*num+k),Arrayy((i-1)*num*num+(j-1)*num+k),Arrayz((i-1)*num*num+(j-1)*num+k)); 40 | 41 | elseif Arrayz((i-1)*num*num+(j-1)*num+k) > 0 42 | 43 | Arrayf((i-1)*num*num+(j-1)*num+k) = f2(Arrayx((i-1)*num*num+(j-1)*num+k),Arrayy((i-1)*num*num+(j-1)*num+k),Arrayz((i-1)*num*num+(j-1)*num+k)); 44 | 45 | end 46 | end 47 | end 48 | end 49 | 50 | figure() 51 | scatter3(Arrayx,Arrayy,Arrayz,'.'); 52 | title('未扰动的数据点') 53 | axis equal 54 | 55 | %% 给数据点加上位置扰动 56 | % 反应实验中的问题,在xyz坐标上加入有正负值的扰动 57 | 58 | for i = 1:num 59 | for j = 1:num 60 | for k = 1:num 61 | 62 | Exyz = rand(1)*0.05; % 正负百分之十以内的随机误差 63 | Arrayx((i-1)*num*num+(j-1)*num+k) = Arrayx((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayx((i-1)*num*num+(j-1)*num+k); 64 | Arrayy((i-1)*num*num+(j-1)*num+k) = Arrayy((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayy((i-1)*num*num+(j-1)*num+k); 65 | Arrayz((i-1)*num*num+(j-1)*num+k) = Arrayz((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayz((i-1)*num*num+(j-1)*num+k); 66 | 67 | end 68 | end 69 | end 70 | Arrayf_color = Arrayf; 71 | 72 | figure() 73 | scatter3(Arrayx,Arrayy,Arrayz,'.'); 74 | title('加入扰动后的原数据') 75 | axis equal 76 | 77 | figure() 78 | scatter3(Arrayx,Arrayy,Arrayz,80,Arrayf_color,'.'); 79 | title('数值f扰动前') 80 | axis equal 81 | 82 | %% 给数值点加上数值扰动 83 | 84 | Arrayf_Pert = Arrayf; 85 | for i = 1:num 86 | for j = 1:num 87 | for k = 1:num 88 | 89 | Exyz = rand(1)*0.05; % 正负百分之十以内的随机误差 90 | Arrayf_Pert((i-1)*num*num+(j-1)*num+k) = Arrayf_Pert((i-1)*num*num+(j-1)*num+k) + ((-1)^round(Exyz))*Exyz*Arrayf_Pert((i-1)*num*num+(j-1)*num+k); 91 | 92 | end 93 | end 94 | end 95 | Arrayf_Pert_color = Arrayf_Pert; 96 | 97 | figure() 98 | scatter3(Arrayx,Arrayy,Arrayz,80,Arrayf_Pert_color,'.'); 99 | title('数值f扰动后') 100 | axis equal 101 | 102 | %% 数值点边界处理 镜像(对称) 其中R为旋转矩阵,针对存在非垂直坐标轴的情况 103 | % MATLAB中自带的voronoi算法不会对外边界进行特殊处理,所以当对最外层数据点画网格时会导致许多的顶点超出我们定义的 104 | % 数据域,甚至会有距离无限远的顶点,从而导致原先的边界模糊且无法计算。 105 | % 在外边界倾斜时我们可以引入旋转矩阵来辅助镜像,在本例子中由于所有外边界都为垂直,所以没有使用此功能 106 | % 整体镜像偏移过程像是叠箱子,在过程中数组是增大的 107 | % 为了对齐数列的长度,方便计算,镜像后的数据点的数值f定为0 108 | 109 | reflectB = zeros(num*6,1); 110 | xmin = zeros(num*num,1); 111 | ymin = zeros(num*num,1); 112 | zmin = zeros(num*num,1); 113 | xmax = zeros(num*num,1); 114 | ymax = zeros(num*num,1); 115 | zmax = zeros(num*num,1); 116 | 117 | ArrayyJ = Arrayy; 118 | ArrayzJ = Arrayz; 119 | xmaxB = cell(100,1); 120 | xminB = cell(100,1); 121 | ymaxB = cell(100,1); 122 | yminB = cell(100,1); 123 | zmaxB = cell(100,1); 124 | zminB = cell(100,1); 125 | 126 | % 以下是按顺序对每个面进行重复 先识别出最外侧面的所有点,再对垂直坐标轴进行偏移镜像 127 | % xMin 128 | ArrayxJ_xMin = Arrayx; 129 | ArrayxB_xMin = Arrayx; 130 | ArrayyB_xMin = Arrayy; 131 | ArrayzB_xMin = Arrayz; 132 | 133 | for i = 1:num*num 134 | 135 | [rBxl,rBxil] = min(ArrayxJ_xMin); % 识别面上的极端点(在这里是最小点) 136 | xmin(i) = rBxil; % 储存极端点的位置 137 | ArrayxJ_xMin(rBxil) = (Lim.x1-Lim.x0)/2; % 使用中位点替代极端点,使得程序可以识别下一个极端点 138 | xminB{i} = [-1*ArrayxB_xMin(xmin(i))-dxArray+ArrayxB_xMin(xmin(i)),ArrayyB_xMin(xmin(i)),ArrayzB_xMin(xmin(i))]; 139 | % 上式为镜像及偏移过程 140 | ArrayxB_xMin = [ArrayxB_xMin;xminB{i}(1)]; % 将镜像后的点组合到原数据中 141 | ArrayyB_xMin = [ArrayyB_xMin;xminB{i}(2)]; 142 | ArrayzB_xMin = [ArrayzB_xMin;xminB{i}(3)]; 143 | Arrayf = [Arrayf;0]; 144 | 145 | end 146 | 147 | % yMin 148 | ArrayyJ_yMin = ArrayyB_xMin; 149 | ArrayxB_yMin = ArrayxB_xMin; 150 | ArrayyB_yMin = ArrayyB_xMin; 151 | ArrayzB_yMin = ArrayzB_xMin; 152 | 153 | for i = 1:num*num+10 154 | 155 | [rByl,rByil] = min(ArrayyJ_yMin); 156 | ymin(i) = rByil; 157 | ArrayyJ_yMin(rByil) = (Lim.y1-Lim.y0)/2; 158 | yminB{i} = [ArrayxB_yMin(ymin(i)),-1*ArrayyB_yMin(ymin(i))-dyArray+ArrayyB_yMin(ymin(i)),ArrayzB_yMin(ymin(i))]; 159 | ArrayxB_yMin = [ArrayxB_yMin;yminB{i}(1)]; 160 | ArrayyB_yMin = [ArrayyB_yMin;yminB{i}(2)]; 161 | ArrayzB_yMin = [ArrayzB_yMin;yminB{i}(3)]; 162 | Arrayf = [Arrayf;0]; 163 | 164 | end 165 | 166 | % xMax 167 | ArrayxJ_xMax = ArrayxB_yMin; 168 | ArrayxB_xMax = ArrayxB_yMin; 169 | ArrayyB_xMax = ArrayyB_yMin; 170 | ArrayzB_xMax = ArrayzB_yMin; 171 | 172 | for i = 1:num*num+20 173 | 174 | [rBxr,rBxir] = max(ArrayxJ_xMax); 175 | xmax(i) = rBxir; 176 | ArrayxJ_xMax(rBxir) = (Lim.x1-Lim.x0)/2; 177 | xmaxB{i} = [-1*ArrayxB_xMax(xmax(i))+ArrayxB_xMax(xmax(i))*2+dxArray,ArrayyB_xMax(xmax(i)),ArrayzB_xMax(xmax(i))]; 178 | ArrayxB_xMax = [ArrayxB_xMax;xmaxB{i}(1)]; 179 | ArrayyB_xMax = [ArrayyB_xMax;xmaxB{i}(2)]; 180 | ArrayzB_xMax = [ArrayzB_xMax;xmaxB{i}(3)]; 181 | Arrayf = [Arrayf;0]; 182 | 183 | end 184 | 185 | % yMax 186 | ArrayyJ_yMax = ArrayyB_xMax; 187 | ArrayxB_yMax = ArrayxB_xMax; 188 | ArrayyB_yMax = ArrayyB_xMax; 189 | ArrayzB_yMax = ArrayzB_xMax; 190 | 191 | for i = 1:num*num+40 192 | 193 | [rByr,rByir] = max(ArrayyJ_yMax); 194 | ymax(i) = rByir; 195 | ArrayyJ_yMax(rByir) = (Lim.y1-Lim.y0)/2; 196 | ymaxB{i} = [ArrayxB_yMax(ymax(i)),-1*ArrayyB_yMax(ymax(i))+dyArray+ArrayyB_yMax(ymax(i))*2,ArrayzB_yMax(ymax(i))]; 197 | ArrayxB_yMax = [ArrayxB_yMax;ymaxB{i}(1)]; 198 | ArrayyB_yMax = [ArrayyB_yMax;ymaxB{i}(2)]; 199 | ArrayzB_yMax = [ArrayzB_yMax;ymaxB{i}(3)]; 200 | Arrayf = [Arrayf;0]; 201 | 202 | end 203 | 204 | % zMax 205 | ArrayzJ_zMax = ArrayzB_yMax; 206 | ArrayxB_zMax = ArrayxB_yMax; 207 | ArrayyB_zMax = ArrayyB_yMax; 208 | ArrayzB_zMax = ArrayzB_yMax; 209 | 210 | for i = 1:num*num+44 211 | 212 | [rBzr,rBzir] = max(ArrayzJ_zMax); 213 | zmax(i) = rBzir; 214 | ArrayzJ_zMax(rBzir) = 0; 215 | zmaxB{i} = [ArrayxB_zMax(zmax(i)),ArrayyB_zMax(zmax(i)),-1*ArrayzB_zMax(zmax(i))+dzArray+ArrayzB_zMax(zmax(i))*2]; 216 | ArrayxB_zMax = [ArrayxB_zMax;zmaxB{i}(1)]; 217 | ArrayyB_zMax = [ArrayyB_zMax;zmaxB{i}(2)]; 218 | ArrayzB_zMax = [ArrayzB_zMax;zmaxB{i}(3)]; 219 | Arrayf = [Arrayf;0]; 220 | 221 | end 222 | 223 | % zMin 224 | ArrayzJ_zMin = ArrayzB_zMax; 225 | ArrayxB_zMin = ArrayxB_zMax; 226 | ArrayyB_zMin = ArrayyB_zMax; 227 | ArrayzB_zMin = ArrayzB_zMax; 228 | 229 | for i = 1:num*num+44 230 | 231 | [rBzl,rBzil] = min(ArrayzJ_zMin); 232 | zmin(i) = rBzil; 233 | ArrayzJ_zMin(rBzil) = 0; 234 | zminB{i} = [ArrayxB_zMin(zmin(i)),ArrayyB_zMin(zmin(i)),-1*ArrayzB_zMin(zmin(i))-dzArray+ArrayzB_zMin(zmin(i))*2]; 235 | ArrayxB_zMin = [ArrayxB_zMin;zminB{i}(1)]; 236 | ArrayyB_zMin = [ArrayyB_zMin;zminB{i}(2)]; 237 | ArrayzB_zMin = [ArrayzB_zMin;zminB{i}(3)]; 238 | Arrayf = [Arrayf;0]; 239 | 240 | end 241 | 242 | 243 | figure() 244 | plot3(Arrayx,Arrayy,Arrayz,'.') 245 | hold on 246 | plot3(Arrayx(xmin),Arrayy(xmin),Arrayz((xmin)),'.r'); 247 | hold on 248 | for i = 1:num*num 249 | plot3(xminB{i}(1),xminB{i}(2),xminB{i}(3),'.g'); 250 | end 251 | 252 | hold on 253 | plot3(ArrayxB_yMin(ymin),ArrayyB_yMin(ymin),ArrayzB_yMin((ymin)),'.r'); 254 | hold on 255 | for i = 1:num*num+10 256 | plot3(yminB{i}(1),yminB{i}(2),yminB{i}(3),'.g'); 257 | end 258 | 259 | hold on 260 | plot3(ArrayxB_xMax(xmax),ArrayyB_xMax(xmax),ArrayzB_xMax((xmax)),'.r'); 261 | hold on 262 | for i = 1:num*num+20 263 | plot3(xmaxB{i}(1),xmaxB{i}(2),xmaxB{i}(3),'.g'); 264 | end 265 | 266 | hold on 267 | plot3(ArrayxB_yMax(ymax),ArrayyB_yMax(ymax),ArrayzB_yMax((ymax)),'.r'); 268 | hold on 269 | for i = 1:num*num+40 270 | plot3(ymaxB{i}(1),ymaxB{i}(2),ymaxB{i}(3),'.g'); 271 | end 272 | 273 | hold on 274 | plot3(ArrayxB_zMax(zmax),ArrayyB_zMax(zmax),ArrayzB_zMax((zmax)),'.r'); 275 | hold on 276 | for i = 1:num*num+44 277 | plot3(zmaxB{i}(1),zmaxB{i}(2),zmaxB{i}(3),'.g'); 278 | end 279 | 280 | hold on 281 | plot3(ArrayxB_zMin(zmin),ArrayyB_zMin(zmin),ArrayzB_zMin((zmin)),'.r'); 282 | hold on 283 | for i = 1:num*num+44 284 | plot3(zminB{i}(1),zminB{i}(2),zminB{i}(3),'.g'); 285 | end 286 | title('镜像边界示例,红色点阵为识别到的边界,绿色点阵为镜像边界') 287 | 288 | % 旋转矩阵 289 | % hold on 290 | % for i = 1:num*num % 镜像中加入旋转角度 291 | % 292 | % Rx = rotx(0); 293 | % Ry = roty(0); 294 | % Rz = rotz(0); 295 | % 296 | % xminB{i} = Rz*[Arrayx(xmin(i));Arrayy(xmin(i));Arrayz(xmin(i))]; 297 | % plot3(xminB{i}(1),xminB{i}(2)+3.5,xminB{i}(3),'.g'); 298 | % hold on 299 | % 300 | % yminB{i} = Rz*[Arrayx(ymin(i));Arrayy(ymin(i));Arrayz(ymin(i))]; 301 | % plot3(yminB{i}(1),yminB{i}(2),yminB{i}(3),'.g'); 302 | % hold on 303 | % 304 | % zminB{i} = Rz*[Arrayx(zmin(i));Arrayy(zmin(i));Arrayz(zmin(i))]+Arrayz(zmin(i)); 305 | % plot3(zminB{i}(1),zminB{i}(2),zminB{i}(3),'.g'); 306 | % hold on 307 | % 308 | % end 309 | 310 | figure() 311 | plot3(ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin,'.b') 312 | title('加入镜像边界后'); 313 | 314 | %% 设置差值点 315 | % 要插值的点 316 | 317 | Qp = 10; % 每个维度设置10个差值点 318 | n_Quiry = Qp^3; 319 | ax = zeros(n_Quiry,1); 320 | ay = zeros(n_Quiry,1); 321 | az = zeros(n_Quiry,1); 322 | 323 | xp = linspace(0.2,2.8,Qp); 324 | yp = linspace(0.2,2.8,Qp); 325 | zp = linspace(-1.3,1.3,Qp); 326 | 327 | for i = 1:Qp 328 | for j = 1:Qp 329 | for k = 1:Qp 330 | 331 | ax((i-1)*Qp*Qp+(j-1)*Qp+k) = xp(k); 332 | ay((i-1)*Qp*Qp+(j-1)*Qp+k) = yp(j); 333 | az((i-1)*Qp*Qp+(j-1)*Qp+k) = zp(i); 334 | 335 | end 336 | end 337 | end 338 | 339 | figure() 340 | scatter3(ax,ay,az,'.b'); 341 | hold on 342 | scatter3(ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin,'.r'); 343 | axis equal 344 | title('差值点与数据点') 345 | 346 | %% 画Voronoi网格 347 | % 直接引用MATLAB中的程序 348 | 349 | DataMetrix = [ArrayxB_zMin,ArrayyB_zMin,ArrayzB_zMin]; % 画Voronoi所需的坐标 350 | DataMetrix = unique(DataMetrix,'rows'); % 删除重复的点 351 | [v,c] = voronoin(DataMetrix); % 画Voronoi网格 得到顶点在数组中的位置和坐标 352 | 353 | C_region = length(c); 354 | C_Vertex = cell(C_region,1); 355 | 356 | for i=1:C_region % 获得每个Voronoi网格中每一点的坐标值 357 | 358 | C_Vertex{i}=v(c{i},:); 359 | 360 | end 361 | 362 | %% 统计超出边界的多边体 363 | % 在原边界(lim)上增加一层缓冲(dx,dy,dz),而后统计所有存在顶点超过边界的Voronoi网格 364 | % 这里有一个容忍度的功能,C_Vertex_judge是用来判断的变量,每当一个顶点的一个坐标点超过边界限制, 365 | % C_Vertex_judge就会加一。此功能遍历所有Voronoi网格。 366 | 367 | C_Vertex_judge = zeros(C_region,1); 368 | for j = 1:C_region % 遍历每一个多面体,每一个多边体的顶点坐标 C_region 369 | 370 | Lc = size(C_Vertex{j},1); 371 | 372 | for k = 1:Lc % 多边体的边数 Lc 373 | 374 | for m = 1:3 % 三个方向共六个最大/最小边界 找出点超出哪个边界 Dimensions 375 | 376 | switch m 377 | 378 | case 1 % 第一个维度(x) 379 | 380 | if C_Vertex{j}(k,m) <= Lim.x0-dxArray 381 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 382 | elseif C_Vertex{j}(k,m) >= Lim.x1+dxArray 383 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 384 | end 385 | 386 | case 2 % 第二个维度(y) 387 | 388 | if C_Vertex{j}(k,m) <= Lim.y0-dyArray 389 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 390 | elseif C_Vertex{j}(k,m) >= Lim.y1+dyArray 391 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 392 | end 393 | 394 | case 3 % 第三个维度(z) 395 | 396 | if C_Vertex{j}(k,m) <= Lim.z0-dzArray 397 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 398 | elseif C_Vertex{j}(k,m) >= Lim.z1+dzArray 399 | C_Vertex_judge(j) = C_Vertex_judge(j)+1; 400 | end 401 | end 402 | end 403 | end 404 | end 405 | 406 | %% 计算体积 407 | % 直接引用程序包QHull来计算体积,这是本套代码对于高维度数组计算的唯一限制,维度N被限制小于9。 408 | 409 | VolForOne = zeros(C_region,1); 410 | k_vertexs = cell(C_region,1); 411 | figure() 412 | for i = 1:C_region % 遍历 C_region 413 | 414 | if isinf(C_Vertex{i}(1,:)) % 当Voronoi cell存在一无限远的顶点时,跳过这一Voronoi cell 415 | 416 | continue 417 | 418 | elseif C_Vertex_judge(i) < 1 % 这一步可设置容忍度C_Vertex_judge,本程序中容忍度为零 419 | 420 | VertexsForOne = C_Vertex{i}; 421 | [k_vertexs{i},VolForOne(i)] = convhulln(VertexsForOne); 422 | trisurf(k_vertexs{i},VertexsForOne(:,1),VertexsForOne(:,2),VertexsForOne(:,3),'FaceColor','cyan') 423 | hold on 424 | end 425 | 426 | 427 | end 428 | title('画出Voronoi凸域'); 429 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/F_differential/GauQuiry3D.m: -------------------------------------------------------------------------------- 1 | function [W_Gauij,rij,xij,yij,zij] = GauQuiry3D(x,y,z,x_Q,y_Q,z_Q,h0,h1,hn,Area,d_var) 2 | 3 | xarray = x; %输入3D坐标点 4 | yarray = y; 5 | zarray = z; 6 | N = length(xarray); 7 | 8 | N_Q = length(x_Q); 9 | 10 | 11 | 12 | xij = zeros(N_Q,N_Q); 13 | yij = zeros(N_Q,N_Q); 14 | zij = zeros(N_Q,N_Q); 15 | rij = zeros(N_Q,N); 16 | xDx = zeros(N_Q,N_Q); 17 | yDy = zeros(N_Q,N_Q); 18 | zDz = zeros(N_Q,N_Q); 19 | 20 | for i = 1:N_Q 21 | for j = 1:N 22 | 23 | 24 | xij(i,j) = x_Q(i) - xarray(j); % x distances 25 | yij(i,j) = y_Q(i) - yarray(j); % y distances 26 | zij(i,j) = z_Q(i) - zarray(j); % y distances 27 | 28 | rij(i,j) = sqrt(xij(i,j)*xij(i,j) + yij(i,j)*yij(i,j) + zij(i,j)*zij(i,j)); 29 | 30 | xDx(i,j) = xij(i,j)/rij(i,j); 31 | yDy(i,j) = yij(i,j)/rij(i,j); 32 | zDz(i,j) = zij(i,j)/rij(i,j); 33 | 34 | if isnan(xDx(i,j)) 35 | xDx(i,j) = 0; 36 | end 37 | if isnan(yDy(i,j)) 38 | yDy(i,j) = 0; 39 | end 40 | if isnan(zDz(i,j)) 41 | zDz(i,j) = 0; 42 | end 43 | end 44 | 45 | end 46 | 47 | % % ConfidenceRange=0.99; 48 | % % Vol=dp*dp; % the volume in 2-D is simply dx*dx 49 | % % SmoothLength_Coefficient=1.5; %平滑系数 50 | % 51 | W_Gauij = zeros(N_Q,hn); 52 | W_Gauij1 = zeros(N_Q,hn); 53 | 54 | for k = 1:hn 55 | 56 | h = (((h1-h0)/hn))*k+h0; 57 | aGau = 1/((pi^(3/2))*(h*h*h)); 58 | 59 | q = rij./h; 60 | 61 | D1_Gauij_x = zeros(N_Q,1); 62 | D1_Gauij_y = zeros(N_Q,1); 63 | D1_Gauij_z = zeros(N_Q,1); 64 | 65 | for i = 1:N_Q 66 | W_Gauij(i,k) = 0; 67 | W_Gauij1(i,k) = 0; 68 | for j = 1:N 69 | q(i,j) = rij(i,j)/h; 70 | 71 | % 高斯核函数计算 72 | W_Gau_neigh = aGau*exp(-q(i,j)^2); 73 | W_Gauij1(i,k) = W_Gauij1(i,k) + d_var(j)*W_Gau_neigh*Area(j); 74 | W_Gauij(i,k) = W_Gauij(i,k) + W_Gau_neigh*Area(j); 75 | 76 | % % 高斯核函数计算 x方向导数 77 | W1_Gau_neigh_x = xDx(i,j)*(-2*rij(i,j)/(h^2))*aGau*exp(-q(i,j)^2); 78 | D1_Gauij_x(i) = D1_Gauij_x(i) + d_var(j)*W1_Gau_neigh_x*Area(j); 79 | % 80 | % % 高斯核函数计算 y方向导数 81 | W1_Gau_neigh_y = yDy(i,j)*(-2*rij(i,j)/(h^2))*aGau*exp(-q(i,j)^2); 82 | D1_Gauij_y(i) = D1_Gauij_y(i) + d_var(j)*W1_Gau_neigh_y*Area(j); 83 | 84 | % % 高斯核函数计算 z方向导数 85 | W1_Gau_neigh_z = zDz(i,j)*(-2*rij(i,j)/(h^2))*aGau*exp(-q(i,j)^2); 86 | D1_Gauij_z(i) = D1_Gauij_z(i) + d_var(j)*W1_Gau_neigh_z*Area(j); 87 | end 88 | end 89 | end 90 | 91 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/F_differential/GauQuiry3D_FixedH.m: -------------------------------------------------------------------------------- 1 | function [W_Gauij,W_Gauij1,D1_Gauij_x,D1_Gauij_y,D1_Gauij_z] = GauQuiry3D_FixedH(x,y,z,x_Q,y_Q,z_Q,h,Area,d_var) 2 | 3 | xarray = x; %输入3D坐标点 4 | yarray = y; 5 | zarray = z; 6 | N = length(xarray); 7 | 8 | aGau = 1/((pi^(3/2))*(h*h*h)); 9 | 10 | D1_Gauij_x = 0; 11 | D1_Gauij_y = 0; 12 | D1_Gauij_z = 0; 13 | W_Gauij = 0; 14 | W_Gauij1 = 0; 15 | 16 | 17 | for j = 1:N 18 | 19 | xij = x_Q - xarray(j); % x distances 20 | yij = y_Q - yarray(j); % y distances 21 | zij = z_Q - zarray(j); % y distances 22 | 23 | rij = sqrt(xij*xij + yij*yij + zij*zij); 24 | 25 | xDr = xij/rij; 26 | yDr = yij/rij; 27 | zDr = zij/rij; 28 | 29 | if isnan(xDr) 30 | xDr = 0; 31 | end 32 | if isnan(yDr) 33 | yDr = 0; 34 | end 35 | if isnan(zDr) 36 | zDr = 0; 37 | end 38 | 39 | q(j) = rij/h; 40 | 41 | % 高斯核函数计算 42 | if q(j) <= 3 43 | W_Gau_neigh = aGau*exp(-q(j)^2); 44 | else 45 | W_Gau_neigh = 0; 46 | end 47 | 48 | W_Gauij1 = W_Gauij1 + d_var(j)*W_Gau_neigh*Area(j); 49 | W_Gauij = W_Gauij + W_Gau_neigh*Area(j); 50 | 51 | % % 高斯核函数计算 x方向导数 52 | 53 | 54 | W1_Gau_neigh_x = xDr*(-2.*rij/(h^2))*W_Gau_neigh; 55 | D1_Gauij_x = D1_Gauij_x + d_var(j)*W1_Gau_neigh_x*Area(j); 56 | 57 | % % 高斯核函数计算 y方向导数 58 | 59 | W1_Gau_neigh_y = yDr*(-2.*rij/(h^2))*W_Gau_neigh; 60 | D1_Gauij_y = D1_Gauij_y + d_var(j)*W1_Gau_neigh_y*Area(j); 61 | 62 | % % 高斯核函数计算 z方向导数 63 | 64 | W1_Gau_neigh_z = zDr*(-2.*rij/(h^2))*W_Gau_neigh; 65 | D1_Gauij_z = D1_Gauij_z + d_var(j)*W1_Gau_neigh_z*Area(j); 66 | end 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/F_differential/findPointsInH.m: -------------------------------------------------------------------------------- 1 | function [rn] = findPointsInH(rij_one,h) 2 | 3 | n = length(rij_one); 4 | j = 1; 5 | for i=1:n 6 | 7 | if rij_one(i) <= h 8 | rn(j) = i; 9 | j = j+1; 10 | end 11 | 12 | end 13 | 14 | if j == 1 15 | rn = 0; 16 | end 17 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/f1.m: -------------------------------------------------------------------------------- 1 | function f1=f1(X,Y,Z) 2 | f1=exp(0.45.*X+0.225.*Y); 3 | end 4 | -------------------------------------------------------------------------------- /Example/Matlab_DDDA for the 3D case/f2.m: -------------------------------------------------------------------------------- 1 | function f2=f2(X,Y,Z) 2 | f2=exp(Z+0.1.*X+0.05.*Y); 3 | end 4 | -------------------------------------------------------------------------------- /Log: -------------------------------------------------------------------------------- 1 | Version 0.0.0 2023/2/6 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DDDA (Data Driven Dimensional Analysis) v1.6.1 2 | # 数据驱动量纲分析 v1.6.1 3 | 4 | DDDA(Data Driven Dimensional Analysis), when applied to a set of real-world data, can extract the unique and dominating dimensionless number from the data based on Buckingham Pi Theorem. It will help human or robot scientists to compress the data and convert the hidden knowledge into a simple and clear empirical law of one or two (novel) combined dimensionless numbers. The whole process is automatic and involves very few artificial parameters. 5 | 6 | DDDA-数据驱动量纲分析,是一套**用于从数据中自动提取主控(新)无量纲数的开源代码**。代码可以在几乎不需要人工参与的条件下,从高维(多个参数或无量纲数控制)的数据集中,自动找到主导的(组合)无量纲数(供您命名),并按照无量纲数的形式分割整个数据区域,并在每个区域给出最优的经验公式。在常见力学问题中,方法可以将高至9维的数据集压缩为分段的一至二维显式函数表达,从而为人类和机器科学家提供探索规律的基本工具。 7 | 8 | ## 目录 :point_down: 9 | 10 | - [特点](#特点) 11 | - [入门指南](#入门指南) 12 | - [安装DDDA](#安装) 13 | - [如何使用DDDA代码包](#如何使用代码包) 14 | - [DDDA的示例](#示例) 15 | - [关于本程序包](#关于本程序包) 16 | - [工作流程图](#工作流程图) 17 | - [部分算法解释](#部分算法解释) 18 | - [DDDA工作流程概览](#流程概览) 19 | - [FAQ](#faq) 20 | - [正在开发中](#ongoing) 21 | - [重要版本更新](#version-update) 22 | 23 | ## 特点 24 | 25 | 🔐 Robust 26 | - 强噪声抑制 —— 在数据预处理截断我们开发并在全局上使用了高阶的自适应收敛算法,至少在2阶精度上使每一数据点做到了最佳收敛。 27 | 28 | 🏄 Researcher friendly 29 | - 可以根据使用者所处环境内的噪声情况对结果的不确定性进行定量化。 30 | - 我们尽最大程度减少了自定义参数。 31 | 32 | 📊 Good visualisation 33 | - 所有的数据都可以方便的以图表方式呈现。 34 | 35 | 🚀 Fast (and light) All algorithms work within optimised data structure: 36 | - 针对高维度大数据量计算进行了数据结构优化,随着数据维度(k)增加,主要代码的时间复杂度由O(n^k)降低为O(kN^(1-1/k)). 37 | 38 | ## 入门指南 39 | 40 | ### 使用选项 41 | 42 | 1. 直接使用Matlab代码,示例与论文一致,相关代码和示例见(Matlab版本可以作为快速学习之用,当前仅有2D和3D版本): 43 | 2D case: https://github.com/whoseboy/DDDA/tree/989c8f1f55662becfd0f7311ec50d1b553e48806/Example/Matlab_DDDA%20for%20the%202D%20case%20(pressure%20drops%20in%20pipe%20flows) 44 | 3D case: https://github.com/whoseboy/DDDA/tree/989c8f1f55662becfd0f7311ec50d1b553e48806/Example/Matlab_DDDA%20for%20the%203D%20case 45 | 46 | 2. 使用Jupyter NoteBook快速试用并学习DDDA方法(iPython版本可以作为快速学习之用,当前仅有2D和3D版本): 47 | 2D case: 48 | https://github.com/whoseboy/DDDA/tree/989c8f1f55662becfd0f7311ec50d1b553e48806/Example/Case_2D 49 | 3D case: 50 | https://github.com/whoseboy/DDDA/tree/989c8f1f55662becfd0f7311ec50d1b553e48806/Example/Case_3D_1 51 | https://github.com/whoseboy/DDDA/tree/989c8f1f55662becfd0f7311ec50d1b553e48806/Example/Case_3D_2 52 | 53 | 54 | 3. **使用标准Python包,用于高效运行DDDA算法: 55 | Use standard Python packages for efficiently running the DDDA algorithm:** 56 | https://github.com/whoseboy/DDDA/tree/989c8f1f55662becfd0f7311ec50d1b553e48806/DDDA 57 | 具体安装方式如下。 58 | 59 | 60 | ### 安装 61 | 62 | #### conda 63 | 64 | 使用 Anaconda Prompt: 65 | 66 | 1. 下载代码包至本地 67 | 68 | Shell: (https) & (ssh) 69 | 70 | Shell: https 71 | ``` 72 | git clone https://github.com/whoseboy/DDDA.git 73 | ``` 74 | Shell: ssh 75 | ``` 76 | git clone git@github.com:whoseboy/DDDA.git 77 | ``` 78 | 79 | 80 | 2. 创建 Python 3.8 或以上更新环境. 81 | 82 | ``` 83 | conda create -n your_env_name python=3.8 84 | conda activate your_env_name 85 | ``` 86 | 87 | *需要安装的代码包:* 88 | 89 | ``` 90 | conda install numpy pandas scipy numba scikit-learn 91 | ``` 92 | *可以选装的代码包 —— 用于可视化和计时:* 93 | 94 | ``` 95 | conda install matplotlib seaborn time 96 | ``` 97 | 3. 安装DDDA 98 | 99 | ``` 100 | pip install DDDA 101 | ``` 102 | 103 | #### Core Code 104 | 105 | DDDAGO.py v1.6 106 | https://github.com/whoseboy/DDDA/blob/main/DDDA/DDDA/DDDAGO.py 107 | 108 | 109 | 110 | 111 | ### 如何使用代码包 112 | 113 | 114 | ## 示例 115 | ### 如何使用 116 | 这里我们提供了DDDA()函数负责传输数据,参数。DDDARun()函数负责开始运算。 117 | 118 | *三维且默认参数的示例, 其中DataF为数据,DataX, DataY, DataZ 为三维坐标点集* 119 | 120 | ``` 121 | from DDDAGO import DDDA 122 | my_work = DDDA(DataF, DataX, DataY, DataZ) 123 | my_work.DDDARun() 124 | ``` 125 | 126 | 我们提供了5个可以自定义的参数 127 | 128 | *其中InterLength代表差值点与数据点的比例关系(例如1.1为加密,0.9为稀疏),InterShift为边界处理算法的参数[0-1]默认为0.1, 129 | r0为自适应光滑算法计算域的尺寸参数,rn为自适应光滑算法计算域的尺寸参数,增大rn会带来更高的精度但计算速度会显著降低。Claster为聚类的分类数量。* 130 | 131 | ``` 132 | from DDDAGO import DDDA 133 | my_work = DDDA(DataF, DataX, DataY, DataZ, InterLength = 1, \ 134 | InterShift = 0.1, r0 = 3, rn = 10, Claster = 2) 135 | my_work.DDDARun() 136 | ``` 137 | 138 | ### 算例 139 | 我们在jupyter notebook中提供了简洁易读的测试算例: 140 | 141 | - [2D Tubeflow](https://github.com/whoseboy/DDDA/tree/main/Examples/TubeFlow%202D) 142 | - [3D Random Designed Case](https://github.com/whoseboy/DDDA/tree/main/Examples/Selfdefined%203Dcase) 143 | 144 | 测试算例的Matlab版本: 145 | - [2D Tubeflow](https://github.com/whoseboy/DDDA/tree/989c8f1f55662becfd0f7311ec50d1b553e48806/Example/Matlab_DDDA%20for%20the%203D%20case) 146 | - [3D Random Designed Case](https://github.com/whoseboy/DDDA/tree/989c8f1f55662becfd0f7311ec50d1b553e48806/Example/Matlab_DDDA%20for%20the%202D%20case%20(pressure%20drops%20in%20pipe%20flows)) 147 | 148 | ☝️ *上述算例的详细信息可以看链接内文件夹中的readme文档* 149 | 150 | ## 关于本程序包 151 | 152 | ### 工作流程图 153 |

154 | 155 |

156 | This package can evaluate the rest of work automatically if the reasearcher gets the data from experiment or simulation. The datasets could be acquired from varies sources, and of course in varies noise distribution and confidence interval. 157 | 158 | 159 | ### 部分算法解释 160 | 161 | #### 自适应收敛光滑 162 | 基于径向基函数的原理,为了抑制数据的噪声,我们将每一个数据点都做了局部最佳优化。 163 | 164 | 上图是我们示例数据中某一数据点的收敛判定。 165 | 图中,x轴代表光滑长度,其随x轴的增加而增大,y轴为抽象出来的收敛参数以0为判定基准。 166 | 左图中,红色的点为以欧式距离为标准,运用在本算法中得到的0阶距,其随光滑长度的增大而收敛。绿色点为1阶距的结果,其随光滑长度的增加而愈加远离判定基准。 167 | 这种交叉的趋势提供了最优收敛点,如右图所见,我们将两组数据组合后,选择了最小的计算域为此数据点的最佳收敛位置。 168 | 169 | 170 | 上图为加入噪声后整场的收敛后数值的密度分布图。 171 | 左图为0阶距的整场密度分布,其标准值为1,可以看做光滑后数据与原数据的差异大小。右图为0阶距的密度分布,其标准值为0,代表了数据分布的混乱程度。 172 | 可见加入噪声后,本算法的自适应属性可以将每一个数据点赋予不同的收敛参数,以获得最佳效果。 173 | 174 | 175 | 我们可以使用本算法对数据点进行加密操作,上图中,左侧为原数据点,右侧为加密后的数据点。 176 | 177 |

178 | 179 |

180 | 上图为2维例子中,我们随机抽取6个差值点来展示算法结果。其中图例为当前位置对中心差值点的影响大小,可看做一个高斯分布。 181 | 可见,不同位置的差值点会随着其周围数值点(蓝色)的数量,分布情况来调整不同的计算域。 182 | 183 | ### 基于位置噪声的权重分配 184 | 我们根据数据点的位置噪声,使用voronoi图的方式为每一数据点分配了权重。并在n维度数据点的voronoi cell边缘切割上提供了创新可靠的算法。 185 |

186 | 187 |

188 | 189 | ## 流程概览 190 | 我们以2维与3维算例为基础,按流程图的顺序向您展示我们代码中每一步骤的实现方法和巧思。 191 | 192 | ### 输入的数据结构 193 | 194 | 195 | ## FAQ 196 | 197 | ## 问题和支持 198 | 使用微信的朋友可以关注我们的微信公众号(智能科力实验室),将会有不定期的使用经验推送,以及加入微信群的方式,结识一起使用的好友;遇到问题也可以发送到公众号,我们在后台看到后会回复。 199 | ![扫码_搜索联合传播样式-白色版](https://github.com/whoseboy/DDDA/assets/34500062/26f30452-ea24-4bc9-b754-0efa98d7a193) 200 | 201 | 其他途径(包括并不限于论坛、微信群)还在建设中,请耐心等候。 202 | 203 | 204 | 205 | 206 | 207 | ## 正在开发中 208 | v2.0.0 - 对噪声的传播进行定量化。 209 | 210 | ## 重要版本更新 211 | 212 | **v1.6.0** 补充了Matlab代码,并更新了使用和安装说明。 213 | 214 | **v1.5.0** 现在可以使用任意数量的数组参数了。除此之外还优化了用户自定义系数。 215 | 216 | **v1.4.0** 确定了参数之间的相关性,减少了用户自定义参数,提高易用性 217 | 218 | **v1.3.0** 重写了聚类算法,提升了聚类精度。提升了数据可视化程度 219 | 220 | **v1.2.0** 更新收敛算法,从单一的0阶距提升到了高阶距 221 | 222 | **v1.1.0** 数据结构优化 223 | 224 | **v1.0.0** 改写MATLAB代码到Python 225 | 226 | **v0.4.2** 完整的MATLAB下的三维代码实现 227 | 228 | **v0.3.1** 截止到分区的MATLAB下的三维代码实现 229 | 230 | **v0.2.0** 截止到分区的MATLAB下的二维代码实现 231 | 232 | 233 | -------------------------------------------------------------------------------- /docs/Paper&Talks/LMFS-安翼-适用于复杂力学问题的分区数据驱动量纲分析方法-221223更新.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/Paper&Talks/LMFS-安翼-适用于复杂力学问题的分区数据驱动量纲分析方法-221223更新.pdf -------------------------------------------------------------------------------- /docs/Paper&Talks/readme.md: -------------------------------------------------------------------------------- 1 | # Papers and talks 2 | Here are all related papers and presentations, see current list below: 3 | 1. 安翼,王驰,庞嘉顺,适用于复杂力学问题的分区数据驱动量纲分析方法及应用,第十七届全国环境力学学术会议——2022.12.24 4 | 2. 5 | -------------------------------------------------------------------------------- /docs/figures/0and1Moment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/0and1Moment.png -------------------------------------------------------------------------------- /docs/figures/0thConverge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/0thConverge.png -------------------------------------------------------------------------------- /docs/figures/1n2Converge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/1n2Converge.png -------------------------------------------------------------------------------- /docs/figures/1stMoment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/1stMoment.png -------------------------------------------------------------------------------- /docs/figures/ClusterDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/ClusterDemo.png -------------------------------------------------------------------------------- /docs/figures/ClusterDemo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/ClusterDemo2.png -------------------------------------------------------------------------------- /docs/figures/Combined.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/Combined.png -------------------------------------------------------------------------------- /docs/figures/Converge2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/Converge2.png -------------------------------------------------------------------------------- /docs/figures/DataDense.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/DataDense.png -------------------------------------------------------------------------------- /docs/figures/Densied.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/Densied.png -------------------------------------------------------------------------------- /docs/figures/Origin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/Origin.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/AdaptiveSmooth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/AdaptiveSmooth.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/ClusterTubeFlow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/ClusterTubeFlow.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/ConvergingBenchmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/ConvergingBenchmark.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/DDDA_FrameFlow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/DDDA_FrameFlow.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/EigenVector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/EigenVector.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/PartialD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/PartialD.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/SmoothInter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/SmoothInter.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/TubeData.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/TubeData.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/TubePosition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/TubePosition.png -------------------------------------------------------------------------------- /docs/figures/TubeFlow2D/Voronoi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoseboy/DDDA/fbb50236ced6bf73c09fdd5c74d4d1b27d8a8afc/docs/figures/TubeFlow2D/Voronoi.png --------------------------------------------------------------------------------