Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: добавлены "Распределения" #116

Merged
merged 5 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ dependencies:
- pyyaml==6.0.1
- setuptools-scm==8.0.4
- six==1.16.0
- statapp==0.10.2
- sympy==1.12
- tomli==2.0.1
- tomlkit==0.12.1
Expand Down
86 changes: 86 additions & 0 deletions statapp/distribution_window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import numpy as np
from PySide2.QtWidgets import QDialog, QVBoxLayout, QComboBox

from statapp.polynoms.polynom_window import MplCanvas
from statapp.utils import addIcon
from statapp.models.utils import yxHeader


class DistributionWindow(QDialog):
def __init__(self, title: str, data: np.ndarray):
super().__init__()
self.setWindowTitle(title)
addIcon(self)

self.layout = QVBoxLayout()
self.setLayout(self.layout)

self.data = data
self.values = yxHeader(data.shape[1])

self.comboBox = QComboBox()
self.comboBox.addItems(self.values)
self.comboBox.currentIndexChanged.connect(self.onChange)
self.sc = self.getSc(data[:, 0])
self.layout.addWidget(self.comboBox)

self.l = QVBoxLayout()
self.l.addWidget(self.sc)
self.layout.addLayout(self.l)


def onChange(self):
while ((child := self.l.takeAt(0)) != None):
child.widget().deleteLater()
self.sc = self.getSc(self.data[:, self.comboBox.currentIndex()])
self.l.addWidget(self.sc)


class UniformDistributionWindow(DistributionWindow):
def __init__(self, data: np.array):
super().__init__("Равномерное распределение", data)

def getSc(self, points):
sc = MplCanvas(self, width=5, height=4, dpi=100)
points = np.sort(points)
points = np.array(
[points[0]] +
[pt for pt, next_pt in zip(points[:-1], points[1:]) if pt != next_pt]
)
differences = np.diff(points)
inverseDifferences = 1 / differences
for i, (start, end) in enumerate(zip(points[:-1], points[1:])):
sc.axes.hlines(inverseDifferences[i], start, end, colors='r', linestyles='solid')
return sc


def normalDensity(x, mu, sigmaSquared):
return 1 / np.sqrt(2 * np.pi * sigmaSquared) * np.exp(-(x - mu) ** 2 / (2 * sigmaSquared))


class NormalDistributionWindow(DistributionWindow):
def __init__(self, data: np.array):
super().__init__("Нормальное распределение", data)

def getSc(self, points):
sc = MplCanvas(self, width=5, height=4, dpi=100)
points = np.sort(points)
mu = np.mean(points)
sigmaSquared = np.var(points)
yValues = normalDensity(points, mu, sigmaSquared)
sc.axes.plot(points, yValues)
return sc


class ExponentialDistributionWindow(DistributionWindow):
def __init__(self, data: np.array):
super().__init__("Экспоненциальное распределение", data)

def getSc(self, points):
sc = MplCanvas(self, width=5, height=4, dpi=100)
points = np.sort(points)
mu = np.mean(points)
lambdaParam = 1 / mu
yValues = lambdaParam * np.exp(-lambdaParam * points)
sc.axes.plot(points, yValues)
return sc
26 changes: 26 additions & 0 deletions statapp/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

from statapp.calculations import generateXValues, generateYValues
from statapp.constants import NUMBERS_PRECISION
from statapp.distribution_window import NormalDistributionWindow, UniformDistributionWindow, \
ExponentialDistributionWindow
from statapp.generate_factor_window import GenerateFactorWindow
from statapp.polynoms.linear_polynom_window import LinearPolynomWindow
from statapp.mathtex_header_view import MathTexHeaderView
Expand Down Expand Up @@ -257,6 +259,30 @@ def on_transformPolynomAction_triggered(self):
except Exception as error:
onError(error)

@Slot()
def on_uniformDistributionAction_triggered(self):
try:
dw = UniformDistributionWindow(self.model.getData())
dw.exec()
except Exception as error:
onError(error)

@Slot()
def on_normalDistributionAction_triggered(self):
try:
dw = NormalDistributionWindow(self.model.getData())
dw.exec()
except Exception as error:
onError(error)

@Slot()
def on_exponentialDistributionAction_triggered(self):
try:
dw = ExponentialDistributionWindow(self.model.getData())
dw.exec()
except Exception as error:
onError(error)

def closeEvent(self, event):
if self.isDataChanged:
file = ''
Expand Down
4 changes: 0 additions & 4 deletions statapp/polynoms/polynom_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ def __init__(self, data, result, windowTitle):
realY = predictionResult[:, 0]
calculatedY = predictionResult[:, 1]

print(xAxes)
print(realY)
print(calculatedY)

sc.axes.scatter(xAxes, realY)

# xnew = np.linspace(xAxes.min(), xAxes.max(), 300)
Expand Down
1 change: 0 additions & 1 deletion statapp/polynoms/transform_polynom_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def __init__(self, data):

def on_data_changed(self):
data = np.copy(self.data)
print(len(data[0:]))
for i in range(len(data[0:])):
for j in range(1, len(data[i])):
tr = self.model.data(self.model.createIndex(j, 0), Qt.DisplayRole)
Expand Down
9 changes: 0 additions & 9 deletions statapp/ui/generate_factor_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@
<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>
Expand Down
26 changes: 25 additions & 1 deletion statapp/ui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
<height>29</height>
</rect>
</property>
<widget class="QMenu" name="filemenu">
Expand Down Expand Up @@ -80,10 +80,19 @@
<addaction name="usageaction"/>
<addaction name="aboutmenuaction"/>
</widget>
<widget class="QMenu" name="menu">
<property name="title">
<string>Распределения</string>
</property>
<addaction name="uniformDistributionAction"/>
<addaction name="normalDistributionAction"/>
<addaction name="exponentialDistributionAction"/>
</widget>
<addaction name="filemenu"/>
<addaction name="generatemenu"/>
<addaction name="analyzemenu"/>
<addaction name="modelmenu"/>
<addaction name="menu"/>
<addaction name="helpmenu"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
Expand Down Expand Up @@ -147,6 +156,21 @@
<string>Использование</string>
</property>
</action>
<action name="uniformDistributionAction">
<property name="text">
<string>Равномерное</string>
</property>
</action>
<action name="normalDistributionAction">
<property name="text">
<string>Нормальное</string>
</property>
</action>
<action name="exponentialDistributionAction">
<property name="text">
<string>Экспоненциальное</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down
129 changes: 48 additions & 81 deletions statapp/ui/ui_generate_factor_window.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading