-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradientdescent.h
65 lines (53 loc) · 1.37 KB
/
gradientdescent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef WORKER_H
#define WORKER_H
#include "theoreticalmodelparameters.h"
#include "dropgenerator.h"
#include <QObject>
#include <QThread>
#include <QMutex>
#include <QQueue>
class GDWorker : public QThread
{
Q_OBJECT
public:
struct context
{
static constexpr double gdPrecision = 1e-3;
static const int tableSizeB = 100, tableSizeC = 15;
QMutex m1, m2, m3;
QQueue<QPair<double, double>> queue;
bool m_cancelled;
const QVector<QPointF> &experimental;
TheoreticalModelParameters::DropType dropType;
double precision;
int cutoffMoment;
double bestError;
TheoreticalModelParameters bestParameters;
};
GDWorker(context &context)
:m_ctx(context)
{}
void run() override;
signals:
void progressChanged(double progress);
private:
context &m_ctx;
};
class GradientDescent : public QObject
{
Q_OBJECT
public:
explicit GradientDescent(QObject *parent = nullptr)
: QObject(parent)
{}
public slots:
void doWork(const QVector<QPointF> &experimental, TheoreticalModelParameters::DropType dropType, double precision, int cutoffMoment);
void cancel();
signals:
void finished(TheoreticalModelParameters parameters);
void progressChanged(double progress);
void cancelled();
private:
GDWorker::context *m_ctx;
};
#endif // WORKER_H