feat: добавил генерацию данных: фактора (#20)

Co-authored-by: Maxim Slipenko <no-reply@maxim.slipenko.com>
This commit is contained in:
MisterMLiL 2023-09-27 13:05:41 +03:00 committed by GitHub
parent 6684b79931
commit 62d689eff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 394 additions and 6 deletions

42
poetry.lock generated
View File

@ -423,6 +423,48 @@ files = [
{file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"},
]
[[package]]
name = "scipy"
version = "1.11.2"
description = "Fundamental algorithms for scientific computing in Python"
optional = false
python-versions = "<3.13,>=3.9"
files = [
{file = "scipy-1.11.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2b997a5369e2d30c97995dcb29d638701f8000d04df01b8e947f206e5d0ac788"},
{file = "scipy-1.11.2-cp310-cp310-macosx_12_0_arm64.whl", hash = "sha256:95763fbda1206bec41157582bea482f50eb3702c85fffcf6d24394b071c0e87a"},
{file = "scipy-1.11.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e367904a0fec76433bf3fbf3e85bf60dae8e9e585ffd21898ab1085a29a04d16"},
{file = "scipy-1.11.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d690e1ca993c8f7ede6d22e5637541217fc6a4d3f78b3672a6fe454dbb7eb9a7"},
{file = "scipy-1.11.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:d2b813bfbe8dec6a75164523de650bad41f4405d35b0fa24c2c28ae07fcefb20"},
{file = "scipy-1.11.2-cp310-cp310-win_amd64.whl", hash = "sha256:afdb0d983f6135d50770dd979df50bf1c7f58b5b33e0eb8cf5c73c70600eae1d"},
{file = "scipy-1.11.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:8d9886f44ef8c9e776cb7527fb01455bf4f4a46c455c4682edc2c2cc8cd78562"},
{file = "scipy-1.11.2-cp311-cp311-macosx_12_0_arm64.whl", hash = "sha256:1342ca385c673208f32472830c10110a9dcd053cf0c4b7d4cd7026d0335a6c1d"},
{file = "scipy-1.11.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b133f237bd8ba73bad51bc12eb4f2d84cbec999753bf25ba58235e9fc2096d80"},
{file = "scipy-1.11.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3aeb87661de987f8ec56fa6950863994cd427209158255a389fc5aea51fa7055"},
{file = "scipy-1.11.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:90d3b1364e751d8214e325c371f0ee0dd38419268bf4888b2ae1040a6b266b2a"},
{file = "scipy-1.11.2-cp311-cp311-win_amd64.whl", hash = "sha256:f73102f769ee06041a3aa26b5841359b1a93cc364ce45609657751795e8f4a4a"},
{file = "scipy-1.11.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:fa4909c6c20c3d91480533cddbc0e7c6d849e7d9ded692918c76ce5964997898"},
{file = "scipy-1.11.2-cp312-cp312-macosx_12_0_arm64.whl", hash = "sha256:ac74b1512d38718fb6a491c439aa7b3605b96b1ed3be6599c17d49d6c60fca18"},
{file = "scipy-1.11.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b8425fa963a32936c9773ee3ce44a765d8ff67eed5f4ac81dc1e4a819a238ee9"},
{file = "scipy-1.11.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:542a757e2a6ec409e71df3d8fd20127afbbacb1c07990cb23c5870c13953d899"},
{file = "scipy-1.11.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:ea932570b1c2a30edafca922345854ff2cd20d43cd9123b6dacfdecebfc1a80b"},
{file = "scipy-1.11.2-cp312-cp312-win_amd64.whl", hash = "sha256:4447ad057d7597476f9862ecbd9285bbf13ba9d73ce25acfa4e4b11c6801b4c9"},
{file = "scipy-1.11.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:b0620240ef445b5ddde52460e6bc3483b7c9c750275369379e5f609a1050911c"},
{file = "scipy-1.11.2-cp39-cp39-macosx_12_0_arm64.whl", hash = "sha256:f28f1f6cfeb48339c192efc6275749b2a25a7e49c4d8369a28b6591da02fbc9a"},
{file = "scipy-1.11.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:214cdf04bbae7a54784f8431f976704ed607c4bc69ba0d5d5d6a9df84374df76"},
{file = "scipy-1.11.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:10eb6af2f751aa3424762948e5352f707b0dece77288206f227864ddf675aca0"},
{file = "scipy-1.11.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:0f3261f14b767b316d7137c66cc4f33a80ea05841b9c87ad83a726205b901423"},
{file = "scipy-1.11.2-cp39-cp39-win_amd64.whl", hash = "sha256:2c91cf049ffb5575917f2a01da1da082fd24ed48120d08a6e7297dfcac771dcd"},
{file = "scipy-1.11.2.tar.gz", hash = "sha256:b29318a5e39bd200ca4381d80b065cdf3076c7d7281c5e36569e99273867f61d"},
]
[package.dependencies]
numpy = ">=1.21.6,<1.28.0"
[package.extras]
dev = ["click", "cython-lint (>=0.12.2)", "doit (>=0.36.0)", "mypy", "pycodestyle", "pydevtool", "rich-click", "ruff", "types-psutil", "typing_extensions"]
doc = ["jupytext", "matplotlib (>2)", "myst-nb", "numpydoc", "pooch", "pydata-sphinx-theme (==0.9.0)", "sphinx (!=4.1.0)", "sphinx-design (>=0.2.0)"]
test = ["asv", "gmpy2", "mpmath", "pooch", "pytest", "pytest-cov", "pytest-timeout", "pytest-xdist", "scikit-umfpack", "threadpoolctl"]
[[package]]
name = "setuptools"
version = "68.2.2"

View File

@ -0,0 +1,35 @@
from PySide6.QtCore import Slot
from PySide6.QtGui import QIntValidator
from PySide6.QtWidgets import QDialog
from statapp.ui.ui_generate_factor_window import Ui_GenerateFactorWindow
from statapp.models.combobox_model import ComboBoxModel
DIRECT_LINK = 0
INDIRECT_LINK = 1
class GenerateFactorWindow(QDialog):
def __init__(self):
super().__init__()
self.deviation = None
self.mat = None
self.typeConnection = None
self._typeComboBox = ComboBoxModel([
[DIRECT_LINK, "прямая"],
[INDIRECT_LINK, "обратная"]
])
self.ui = Ui_GenerateFactorWindow()
self.ui.setupUi(self)
self.ui.typeComboBox.setModel(self._typeComboBox)
@Slot()
def on_generatePushButton_clicked(self):
self.typeConnection = self._typeComboBox.rawData(self.ui.typeComboBox.currentIndex())[0]
self.mat = self.ui.matSpinBox.value()
self.deviation = self.ui.deviationSpinBox.value()
self.accept()

View File

@ -2,6 +2,7 @@ import numpy as np
from PySide2.QtCore import Slot
from PySide2.QtWidgets import QMainWindow
from statapp.generate_factor_window import GenerateFactorWindow, INDIRECT_LINK
from statapp.models.data_model import DataModel
from statapp.generate_window import GenerateWindow
from statapp.about_window import AboutWindow
@ -25,6 +26,48 @@ class MainWindow(QMainWindow):
# self.model._data = y
self.model.updateAllData(y)
@Slot()
def on_generateXaction_triggered(self):
gfw = GenerateFactorWindow()
if gfw.exec():
y = self.model.getY()
yMat = np.mean(y)
x_arr = np.array([])
# y - 5 x1 - прямая 4 -> 6
# 7
#
#
dd = np.array([])
for cur_y in y:
k = np.abs(cur_y / yMat)
if gfw.typeConnection == INDIRECT_LINK:
k = 1 / k
# def f(x):
# x = np.abs(x)
# return 2.01375 - (1 / np.exp(x - 0.7))
# k = f(k)
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()
# self.model._data = 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)
@Slot()
def on_aboutmenuaction_triggered(self):
global about_window

View File

@ -0,0 +1,35 @@
from PySide6.QtCore import QAbstractListModel, Qt
class ComboBoxModel(QAbstractListModel):
def __init__(self, data):
super().__init__()
self._data = data
def updateAllData(self, data: list):
self.layoutAboutToBeChanged.emit()
self._data = data
self.layoutChanged.emit()
def rawData(self, index: int):
return self._data[index]
def findById(self, oid: int):
for i, x in enumerate(self._data):
if x[0] == oid:
return i
return -1
def data(self, index, role):
if role == Qt.DisplayRole:
return self._data[index.row()][1]
if role == Qt.UserRole:
return self._data[index.row()]
return None
def rowCount(self, index):
return len(self._data)

View File

@ -4,7 +4,7 @@ from PySide2.QtCore import Qt
class DataModel(QtCore.QAbstractTableModel):
def __init__(self, data=np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32)):
def __init__(self, data=np.array([[]], dtype=np.float32)):
super().__init__()
self._data = data
@ -22,7 +22,7 @@ class DataModel(QtCore.QAbstractTableModel):
def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...):
if role == Qt.DisplayRole:
if orientation == Qt.Orientation.Horizontal:
# if orientation == Qt.Orientation.Horizontal:
if section == 0:
return 'Y'
@ -44,9 +44,16 @@ class DataModel(QtCore.QAbstractTableModel):
return True
return False
def getData(self):
return self._data
def getY(self):
return self._data[:, 0]
def data(self, index, role):
if role == Qt.DisplayRole or role == Qt.EditRole:
# ?
return float(self._data[index.row(), index.column()])
return None
return None

View File

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GenerateFactorWindow</class>
<widget class="QDialog" name="GenerateFactorWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>503</width>
<height>193</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Тип связи</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Среднеквадратичное отклонение</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="generatePushButton">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Сгенерировать</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Математическое ожидание</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="matSpinBox">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="deviationSpinBox">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="typeComboBox">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="editable">
<bool>false</bool>
</property>
<property name="currentText">
<string/>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>503</width>
<height>381</height>
<height>182</height>
</rect>
</property>
<property name="font">
@ -43,7 +43,11 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="matSpinBox"/>
<widget class="QDoubleSpinBox" name="matSpinBox">
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
@ -57,10 +61,17 @@
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>500</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="deviationSpinBox"/>
<widget class="QDoubleSpinBox" name="deviationSpinBox">
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>

96
statapp/ui/ui_generate_factor_window.py generated Normal file
View File

@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'generate_factor_window.ui'
##
## Created by: Qt User Interface Compiler version 6.5.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QComboBox, QDialog, QDoubleSpinBox,
QGridLayout, QLabel, QPushButton, QSizePolicy,
QWidget)
class Ui_GenerateFactorWindow(object):
def setupUi(self, GenerateFactorWindow):
if not GenerateFactorWindow.objectName():
GenerateFactorWindow.setObjectName(u"GenerateFactorWindow")
GenerateFactorWindow.resize(503, 193)
self.gridLayout_2 = QGridLayout(GenerateFactorWindow)
self.gridLayout_2.setObjectName(u"gridLayout_2")
self.gridLayout = QGridLayout()
self.gridLayout.setObjectName(u"gridLayout")
self.label = QLabel(GenerateFactorWindow)
self.label.setObjectName(u"label")
font = QFont()
font.setPointSize(12)
self.label.setFont(font)
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.label_3 = QLabel(GenerateFactorWindow)
self.label_3.setObjectName(u"label_3")
self.label_3.setFont(font)
self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1)
self.generatePushButton = QPushButton(GenerateFactorWindow)
self.generatePushButton.setObjectName(u"generatePushButton")
self.generatePushButton.setFont(font)
self.gridLayout.addWidget(self.generatePushButton, 3, 0, 1, 2)
self.label_2 = QLabel(GenerateFactorWindow)
self.label_2.setObjectName(u"label_2")
self.label_2.setFont(font)
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
self.matSpinBox = QDoubleSpinBox(GenerateFactorWindow)
self.matSpinBox.setObjectName(u"matSpinBox")
self.matSpinBox.setFont(font)
self.matSpinBox.setMaximum(1000000.000000000000000)
self.gridLayout.addWidget(self.matSpinBox, 1, 1, 1, 1)
self.deviationSpinBox = QDoubleSpinBox(GenerateFactorWindow)
self.deviationSpinBox.setObjectName(u"deviationSpinBox")
self.deviationSpinBox.setFont(font)
self.deviationSpinBox.setMaximum(1000000.000000000000000)
self.gridLayout.addWidget(self.deviationSpinBox, 2, 1, 1, 1)
self.typeComboBox = QComboBox(GenerateFactorWindow)
self.typeComboBox.setObjectName(u"typeComboBox")
self.typeComboBox.setFont(font)
self.typeComboBox.setEditable(False)
self.gridLayout.addWidget(self.typeComboBox, 0, 1, 1, 1)
self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
self.retranslateUi(GenerateFactorWindow)
QMetaObject.connectSlotsByName(GenerateFactorWindow)
# setupUi
def retranslateUi(self, GenerateFactorWindow):
GenerateFactorWindow.setWindowTitle(QCoreApplication.translate("GenerateFactorWindow", u"Dialog", None))
self.label.setText(QCoreApplication.translate("GenerateFactorWindow", u"\u0422\u0438\u043f \u0441\u0432\u044f\u0437\u0438", None))
self.label_3.setText(QCoreApplication.translate("GenerateFactorWindow", u"\u0421\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435", None))
self.generatePushButton.setText(QCoreApplication.translate("GenerateFactorWindow", u"\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c", None))
self.label_2.setText(QCoreApplication.translate("GenerateFactorWindow", u"\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435", None))
self.typeComboBox.setCurrentText("")
self.typeComboBox.setPlaceholderText("")
# retranslateUi

View File

@ -42,6 +42,7 @@ class Ui_GenerateWindow(object):
self.matSpinBox = QDoubleSpinBox(GenerateWindow)
self.matSpinBox.setObjectName(u"matSpinBox")
self.matSpinBox.setMaximum(1000000.000000000000000)
self.gridLayout.addWidget(self.matSpinBox, 1, 1, 1, 1)
@ -53,11 +54,13 @@ class Ui_GenerateWindow(object):
self.countSpinBox = QSpinBox(GenerateWindow)
self.countSpinBox.setObjectName(u"countSpinBox")
self.countSpinBox.setMinimum(1)
self.countSpinBox.setMaximum(500)
self.gridLayout.addWidget(self.countSpinBox, 0, 1, 1, 1)
self.deviationSpinBox = QDoubleSpinBox(GenerateWindow)
self.deviationSpinBox.setObjectName(u"deviationSpinBox")
self.deviationSpinBox.setMaximum(1000000.000000000000000)
self.gridLayout.addWidget(self.deviationSpinBox, 2, 1, 1, 1)
@ -80,3 +83,4 @@ class Ui_GenerateWindow(object):
self.label_3.setText(QCoreApplication.translate("GenerateWindow", u"\u0421\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435", None))
self.label.setText(QCoreApplication.translate("GenerateWindow", u"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439", None))
# retranslateUi