diff --git a/statapp/calculations.py b/statapp/calculations.py index 08ce6cd..d06abd1 100644 --- a/statapp/calculations.py +++ b/statapp/calculations.py @@ -1,5 +1,30 @@ import numpy as np +DIRECT_LINK = 0 +INDIRECT_LINK = 1 + +def generate_x_values(mean, std, typeConnection, y): + yMean = np.mean(y) + values = [] + for cur_y in y: + k = np.abs(cur_y / yMean) + if k > 1: + k = 2 - 1 / k + if typeConnection == INDIRECT_LINK: + k = 1 / k + if std == 0: + k = 1 + + x = np.random.normal(mean * (k ** 3), std * k) + values.append(x) + # if (x > gfw.mat and cur_y > yMat) or (x < gfw.mat and cur_y < yMat): + # dd = np.append(dd, 1) + # else: + # dd = np.append(dd, 0) + + # x_arr = x_arr.reshape(len(x_arr), 1) + + return np.array(values) def variance_analysis(data): return np.array([ diff --git a/statapp/main_window.py b/statapp/main_window.py index 38c0fa1..9a31bfb 100644 --- a/statapp/main_window.py +++ b/statapp/main_window.py @@ -3,6 +3,7 @@ from PySide2.QtCore import Slot, QLocale, QSize from PySide2.QtGui import QIcon from PySide2.QtWidgets import QMainWindow, QMessageBox, QApplication +from statapp.calculations import generate_x_values from statapp.generate_factor_window import GenerateFactorWindow, INDIRECT_LINK from statapp.models.input_values_model import InputValuesModel from statapp.generate_window import GenerateWindow @@ -81,36 +82,12 @@ class MainWindow(QMainWindow): def on_generateXaction_triggered(self): gfw = GenerateFactorWindow() - # dd = np.array([]) - if gfw.exec(): - y = self.model.getY() - yMat = np.mean(y) - - x_arr = np.array([]) - - for cur_y in y: - k = np.abs(cur_y / yMat) - if k > 1: - k = 2 - 1 / k - if gfw.typeConnection == INDIRECT_LINK: - k = 1 / k - if gfw.deviation == 0: - k = 1 - - x = np.random.normal(gfw.mat * (k ** 3), gfw.deviation * k, size=1) - x_arr = np.append(x_arr, x) - # if (x > gfw.mat and cur_y > yMat) or (x < gfw.mat and cur_y < yMat): - # dd = np.append(dd, 1) - # else: - # dd = np.append(dd, 0) - data = self.model.getData() - + y = self.model.getY() + x_arr = generate_x_values(gfw.mat, gfw.deviation, gfw.typeConnection, y) x_arr = x_arr.reshape(len(x_arr), 1) - # dd = dd.reshape(len(dd), 1) data = np.concatenate((data, x_arr), axis=1) - # data = np.concatenate((data, dd), axis=1) self.model.updateAllData(data) self.isDataChanged = True