add: GaussianMixture
This commit is contained in:
parent
b66e839b32
commit
3dafde3a67
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,8 +3,8 @@
|
|||||||
*.log
|
*.log
|
||||||
*.csv
|
*.csv
|
||||||
*.json
|
*.json
|
||||||
*.txt
|
|
||||||
2016Q3D/
|
2016Q3D/
|
||||||
|
result/
|
||||||
|
|
||||||
# env
|
# env
|
||||||
venv/
|
venv/
|
||||||
|
36
GaussianMixture.py
Normal file
36
GaussianMixture.py
Normal 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()
|
@ -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
BIN
requirements.txt
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user