add: GaussianMixture

This commit is contained in:
liuyihui 2022-07-07 15:50:43 +08:00
parent b66e839b32
commit 3dafde3a67
4 changed files with 37 additions and 2 deletions

2
.gitignore vendored
View File

@ -3,8 +3,8 @@
*.log *.log
*.csv *.csv
*.json *.json
*.txt
2016Q3D/ 2016Q3D/
result/
# env # env
venv/ venv/

36
GaussianMixture.py Normal file
View File

@ -0,0 +1,36 @@
import os
import numpy as np
from tqdm import tqdm
from matplotlib import pyplot as plt
from sklearn.mixture import GaussianMixture
path = 'result/bind'
file_list = os.listdir(path)
pbar = tqdm(total=len(file_list))
for file in file_list:
name = file.split('.')[0]
file = os.path.join(path, file)
data = np.loadtxt(file, dtype=np.uint16)
x = data[:, 0]
y = data[:, 1]
model = GaussianMixture(n_components=2)
model.fit(data)
nx = np.array([])
ny = model.predict(data)
fig = plt.figure(figsize=(8, 8))
for cluster in np.unique(ny):
idx = np.where(ny == cluster)[0]
nx = idx if len(idx) > len(nx) else nx
plt.scatter(data[idx, 0], data[idx, 1], s=0.1)
fig.savefig('result/GMM/' + name + '.png')
plt.close()
np.savetxt('result/bind-GMM/' + name + '.txt', data[nx], fmt='%d')
pbar.update(1)
pbar.close()

View File

@ -5,7 +5,6 @@
#include "BindHandler.h" #include "BindHandler.h"
#include "FileHandler.h" #include "FileHandler.h"
#include "GaussFit.h"
class BlockHandler { class BlockHandler {
public: public:

BIN
requirements.txt Normal file

Binary file not shown.