Skip to content

Commit

Permalink
Remove optimization boundary parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Oct 17, 2021
1 parent 369158d commit c997ba6
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 492 deletions.
22 changes: 0 additions & 22 deletions src/model/CurveFittingOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class CurveFittingOptions {

CurveFittingOptions(AlgorithmType _algorithm_type, double* _frequency, double* _gain, int _count,
uint64_t _rng_seed, ProbDensityFunc _rng_density_dist,
DoubleRange _obc_freq, DoubleRange _obc_q, DoubleRange _obc_gain,
bool _force_oct_grid, unsigned int _iterations, unsigned int _iterations2, unsigned int _iterations3,
double _avgbw, double _pop_k, double _pop_n,
double _de_probibound,
Expand All @@ -38,9 +37,6 @@ class CurveFittingOptions {
count = _count;
rng_seed = _rng_seed;
rng_density_dist = _rng_density_dist;
obc_freq = _obc_freq;
obc_q = _obc_q;
obc_gain = _obc_gain;
force_oct_grid = _force_oct_grid;
iterations_count = _iterations;
iterations2_count = _iterations2;
Expand Down Expand Up @@ -105,9 +101,6 @@ class CurveFittingOptions {
uint64_t rng_seed;
ProbDensityFunc rng_density_dist;
AlgorithmType algorithm_type;
DoubleRange obc_freq;
DoubleRange obc_q;
DoubleRange obc_gain;
bool force_oct_grid;
unsigned int iterations_count;
unsigned int iterations2_count;
Expand Down Expand Up @@ -164,21 +157,6 @@ inline CurveFittingOptions::AlgorithmType CurveFittingOptions::algorithmType() c
return algorithm_type;
}

inline DoubleRange CurveFittingOptions::obcFrequencyRange() const
{
return obc_freq;
}

inline DoubleRange CurveFittingOptions::obcQRange() const
{
return obc_q;
}

inline DoubleRange CurveFittingOptions::obcGainRange() const
{
return obc_gain;
}

inline bool CurveFittingOptions::forceLogOctGrid() const
{
return force_oct_grid;
Expand Down
26 changes: 9 additions & 17 deletions src/utils/CurveFittingWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ CurveFittingWorker::CurveFittingWorker(const CurveFittingOptions& _options, QObj
rng_density_func = _options.probabilityDensityFunc();
array_size = _options.dataCount();
algorithm_type = _options.algorithmType();
obc_freq = _options.obcFrequencyRange();
obc_q = _options.obcQRange();
obc_gain = _options.obcGainRange();
force_to_oct_grid_conversion = _options.forceLogOctGrid();
avg_bw = _options.averageBandwidth();

Expand Down Expand Up @@ -367,27 +364,22 @@ void CurveFittingWorker::run()
preprocess(flt_freqList, targetList, array_size, fs, force_to_oct_grid_conversion, avg_bw, nullptr, options.invertGain());

// Bound constraints
double lowFc = obc_freq.first; // Hz
double upFc = obc_freq.second; // Hz
double lowQ = obc_q.first; // 0.01 - 1000, higher shaper the filter
double upQ = obc_q.second; // 0.01 - 1000, higher shaper the filter
double lowGain = obc_gain.first; // dB
double upGain = obc_gain.second; // dB

/* --- VVV This is already pre-calculated in GUI code
lowGain = targetList[0];
upGain = targetList[0];
double lowFc = 10; // Hz
double upFc = fs / 2 - 1; // Hz
double lowQ = 0.01; // 0.01 - 1000, higher == shaper the filter
double upQ = 512; // 0.01 - 1000, higher == shaper the filter
double lowGain = targetList[0]; // dB
double upGain = targetList[0]; // dB

for (i = 1; i < array_size; i++)
{
if (targetList[i] < lowGain)
lowGain = targetList[i];
if (targetList[i] > upGain)
upGain = targetList[i];
}
lowGain -= 5.0;
upGain += 5.0;
*/

lowGain -= 32.0;
upGain += 32.0;

// Parameter estimation
unsigned int numMaximas, numMinimas;
Expand Down
3 changes: 0 additions & 3 deletions src/utils/CurveFittingWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public slots:
uint64_t rng_seed;
CurveFittingOptions::ProbDensityFunc rng_density_func;
CurveFittingOptions::AlgorithmType algorithm_type;
DoubleRange obc_freq;
DoubleRange obc_q;
DoubleRange obc_gain;
bool force_to_oct_grid_conversion;
uint stage1Epk;
uint stage2Epk;
Expand Down
78 changes: 43 additions & 35 deletions src/widget/CurveFittingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ CurveFittingDialog::CurveFittingDialog(QWidget *parent) :
auto * rngLayout = new QVBoxLayout(this);
rngLayout->setContentsMargins(6, 0, 0, 0);
rngLayout->addWidget(ui->widget);
auto * optLayout = new QVBoxLayout(this);
optLayout->setContentsMargins(6, 0, 0, 0);
optLayout->addWidget(ui->obc_container);
auto * fgridLayout = new QVBoxLayout(this);
fgridLayout->setContentsMargins(6, 0, 0, 0);
fgridLayout->addWidget(ui->fgrid_container);
Expand All @@ -51,8 +48,6 @@ CurveFittingDialog::CurveFittingDialog(QWidget *parent) :
algo_chio->setContentLayout(*chioLayout);
algo_sgd = new Expander("SGD options", 300, ui->mainPane);
algo_sgd->setContentLayout(*sgdLayout);
opt_boundary_constraints = new Expander("Optimization boundary constraints", 300, ui->mainPane);
opt_boundary_constraints->setContentLayout(*optLayout);
fgrid = new Expander("Axis rebuilding", 300, ui->mainPane);
fgrid->setContentLayout(*fgridLayout);
advanced_rng = new Expander("Randomness options", 300, ui->mainPane);
Expand All @@ -61,13 +56,12 @@ CurveFittingDialog::CurveFittingDialog(QWidget *parent) :
ui->mainPane->layout()->addWidget(algo_sgd);
ui->mainPane->layout()->addWidget(algo_de);
ui->mainPane->layout()->addWidget(algo_chio);
ui->mainPane->layout()->addWidget(opt_boundary_constraints);
ui->mainPane->layout()->addWidget(fgrid);
ui->mainPane->layout()->addWidget(advanced_rng);
ui->mainPane->layout()->addWidget(ui->previewSwitchLayout);
ui->mainPane->layout()->addWidget(ui->footer);

QList<Expander*> _expanders(std::initializer_list<Expander*>({algo_de, algo_chio, algo_sgd, opt_boundary_constraints, fgrid, advanced_rng}));
QList<Expander*> _expanders(std::initializer_list<Expander*>({algo_de, algo_chio, algo_sgd, fgrid, advanced_rng}));
for(const auto& exp : qAsConst(_expanders)){
connect(exp, &Expander::stateChanged, this, [=](bool state){
if(state){
Expand All @@ -84,10 +78,6 @@ CurveFittingDialog::CurveFittingDialog(QWidget *parent) :
ui->adv_random_seed->setValidator(new QInt64Validator(0, UINT64_MAX, ui->adv_random_seed));
ui->adv_random_seed->setText(QString::number(((uint64_t)rand() << 32ull) | rand()));

/* Update optimization boundary freq */
const double fs = 44100; // <- Don't forget to update this
ui->obc_freq_max->setValue(fs / 2 - 1);

// Setup UI
ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setEnabled(false);
ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setText("Calculate");
Expand Down Expand Up @@ -254,21 +244,6 @@ void CurveFittingDialog::parseCsv(){
ui->fgrid_force_convert->setChecked(!is_nonuniform);
ui->fgrid_avgbw->setEnabled(!is_nonuniform);


double lowGain = targetList[0];
double upGain = targetList[0];
for (uint i = 1; i < size; i++)
{
if (targetList[i] < lowGain)
lowGain = targetList[i];
if (targetList[i] > upGain)
upGain = targetList[i];
}
lowGain -= 25.0;
upGain += 25.0;

ui->obc_gain_min->setValue(lowGain);
ui->obc_gain_max->setValue(upGain);
free(flt_freqList);
free(targetList);

Expand Down Expand Up @@ -296,11 +271,16 @@ QVector<DeflatedBiquad> CurveFittingDialog::getResults() const
return results;
}

void CurveFittingDialog::updatePreviewPlot(){
DoubleRange CurveFittingDialog::calculateYAxisRange(bool exportDataset, double** ret_freq, double** ret_gain){
uint size = freq.size();

if(size < 1){
return;
if(exportDataset)
{
ret_freq = nullptr;
ret_gain = nullptr;
}
return DoubleRange(-40, 40);
}

double* flt_freqList = (double*)malloc(size * sizeof(double));
Expand All @@ -326,12 +306,43 @@ void CurveFittingDialog::updatePreviewPlot(){
if (targetList[i] > upGain)
upGain = targetList[i];
}
lowGain -= 25.0;
upGain += 25.0;
lowGain -= 32.0;
upGain += 32.0;

if(exportDataset)
{
*ret_freq = flt_freqList;
*ret_gain = targetList;
}
else
{
free(flt_freqList);
free(targetList);
}

return DoubleRange(lowGain, upGain);
}

void CurveFittingDialog::updatePreviewPlot(){
uint size = freq.size();

if(size < 1){
return;
}

double* flt_freqList = nullptr;
double* targetList = nullptr;
DoubleRange range = calculateYAxisRange(true, &flt_freqList, &targetList);

ui->previewPlot->yAxis->setRange(lowGain, upGain);
ui->previewPlot->clearGraphs();

if(flt_freqList == nullptr || targetList == nullptr)
{
return;
}

ui->previewPlot->yAxis->setRange(range.first, range.second);

auto *pGraphOrig = ui->previewPlot->addGraph();
QPen graphPen;
graphPen.setColor(QColor(60, 60, 60));
Expand Down Expand Up @@ -377,9 +388,6 @@ void CurveFittingDialog::accept()
freq.count(),
ui->adv_random_seed->text().toLong(),
(CurveFittingOptions::ProbDensityFunc) ui->adv_prob_density_func->currentIndex(),
DoubleRange(ui->obc_freq_min->value(), ui->obc_freq_max->value()),
DoubleRange(ui->obc_q_min->value(), ui->obc_q_max->value()),
DoubleRange(ui->obc_gain_min->value(), ui->obc_gain_max->value()),
ui->fgrid_force_convert->isChecked(),
ui->iterations->value(),
ui->iterations_b->value(),
Expand All @@ -392,7 +400,7 @@ void CurveFittingDialog::accept()
ui->modelComplex->value(),
ui->sgd_lr_1->value(), ui->sgd_ldr_1->value(), ui->sgd_lr_2->value(), ui->sgd_ldr_2->value());

auto *worker = new CurveFittingWorkerDialog(options, this);
auto *worker = new CurveFittingWorkerDialog(options, calculateYAxisRange(false, NULL, NULL), this);

// Launch worker dialog and halt until finished or cancelled
if(!worker->exec()){
Expand Down
3 changes: 2 additions & 1 deletion src/widget/CurveFittingDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CURVEFITTINGDIALOG_H

#include "model/DeflatedBiquad.h"
#include "model/CurveFittingOptions.h"

#include <QDialog>

Expand Down Expand Up @@ -39,7 +40,6 @@ private slots:
void setStatus(bool success, const QString& text);

Ui::CurveFittingDialog *ui;
Expander* opt_boundary_constraints = nullptr;
Expander* advanced_rng = nullptr;
Expander* fgrid = nullptr;
Expander* algo_de = nullptr;
Expand All @@ -50,6 +50,7 @@ private slots:
QVector<double> gain;

QVector<DeflatedBiquad> results;
DoubleRange calculateYAxisRange(bool exportDataset, double** freq = nullptr, double** gain = nullptr);
};

#endif // CURVEFITTINGDIALOG_H
Loading

0 comments on commit c997ba6

Please sign in to comment.