Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //window.cpp
- #include "window.h"
- window::window()
- {
- setupUi(this);
- //alle möglichen slider
- connect(kopplung_x_slider, SIGNAL(valueChanged(int)),
- this, SLOT(scale_slider_kopplung_x(int)));
- connect(kopplung_y_slider, SIGNAL(valueChanged(int)),
- this, SLOT(scale_slider_kopplung_y(int)));
- connect(noise_x_slider, SIGNAL(valueChanged(int)),
- this, SLOT(scale_slider_noise_x(int)));
- connect(noise_y_slider, SIGNAL(valueChanged(int)),
- this, SLOT(scale_slider_noise_y(int)));
- connect(slider_length_timeseries, SIGNAL(valueChanged(int)),
- this, SLOT(scale_slider_length_timeseries(int)));
- connect(timelag_x_slider, SIGNAL(valueChanged(int)),
- this, SLOT(scale_slider_timelag_x(int)));
- connect(timelag_y_slider, SIGNAL(valueChanged(int)),
- this, SLOT(scale_slider_timelag_y(int)));
- connect(varianz_slider, SIGNAL(valueChanged(int)),
- this, SLOT(scale_slider_varianz(int)));
- connect(int_size_slider, SIGNAL(valueChanged(int)),
- this, SLOT(scale_slider_int_size(int)));
- //Auswahl Kernschätzer
- connect(actionGauss, SIGNAL(triggered()),
- this, SLOT(check_kernel_gauss()));
- connect(actionEpanechnikov, SIGNAL(triggered()),
- this, SLOT(check_kernel_epanechnikov()));
- this, SLOT(check_auto());
- //Beenden
- connect(actionBeenden, SIGNAL (triggered()),
- qApp, SLOT(quit()));
- //Berechnen
- connect(actionBerechnen, SIGNAL (triggered()),
- this, SLOT(read_var()));
- //Exportieren
- connect(actionExport, SIGNAL(triggered()),
- this, SLOT(exportDocument()));
- // Set axes
- plot_x -> setAxisTitle(xBottom, "t");
- plot_x -> setAxisScale(xBottom, 1.0, (length_timeseries_text -> text()).toDouble());
- plot_x -> setAxisTitle(yLeft, "x");
- plot_x -> setAxisScale(yLeft, 0, 1.0);
- plot_y -> setAxisTitle(xBottom, "t");
- plot_y -> setAxisScale(xBottom, 1.0, (length_timeseries_text -> text()).toDouble());
- plot_y -> setAxisTitle(yLeft, "y");
- plot_y -> setAxisScale(yLeft, 0, 1.0);
- QString tau = 0x03C4; //Falls es individueller sein soll
- QwtText title_ordinate(tau);
- title_ordinate.setFont(QFont("MS Shell Dlg", 14));
- plot_mutualinf -> setAxisTitle(xBottom, title_ordinate);
- plot_mutualinf -> setAxisScale(xBottom, -20, 20);
- // plot_mutualinf -> setAxisScale(xBottom, -(length_timeseries_text -> text()).toDouble(), (length_timeseries_text -> text()).toDouble());
- plot_mutualinf -> setAxisTitle(yLeft, "I / bit");
- plot_mutualinf -> setAxisScale(yLeft, 0, 1.0);
- //Statusbar
- statusBar()->showMessage("Bereit");
- }
- //Die slider mappen für die gewünschten Bereiche
- void window::scale_slider_kopplung_x(int _scale)
- {
- double _scale_label=0;
- _scale_label = (double)_scale/1000;
- kopplung_x_text -> setNum(_scale_label);
- label_11 -> setNum(_scale_label);
- label_15 -> setNum(1-_scale_label);
- }
- void window::scale_slider_kopplung_y(int _scale)
- {
- double _scale_label=0;
- _scale_label = (double)_scale/1000;
- kopplung_y_text -> setNum(_scale_label);
- label_20 -> setNum(_scale_label);
- label_24 -> setNum(1-_scale_label);
- }
- void window::scale_slider_noise_x(int _scale)
- {
- double _scale_label=0;
- _scale_label = (double)_scale/1000;
- noise_x_text -> setNum(_scale_label);
- label_17 -> setNum(_scale_label);
- }
- void window::scale_slider_noise_y(int _scale)
- {
- double _scale_label=0;
- _scale_label = (double)_scale/1000;
- noise_y_text -> setNum(_scale_label);
- label_26 -> setNum(_scale_label);
- }
- void window::scale_slider_length_timeseries(int _scale)
- {
- int _scale_label=10;
- if (_scale <= 10) _scale_label = 10*_scale;
- else if (_scale > 10 && _scale <= 19) _scale_label=100*((_scale - 10)+1);
- else _scale_label=1000*((_scale - 19)+1);
- length_timeseries_text -> setNum(_scale_label);
- timelag_x_slider -> setMaximum(_scale_label-1);
- timelag_y_slider -> setMaximum(_scale_label-1);
- plot_x -> setAxisScale(xBottom, 1.0, (length_timeseries_text -> text()).toDouble());
- plot_y -> setAxisScale(xBottom, 1.0, (length_timeseries_text -> text()).toDouble());
- // plot_mutualinf -> setAxisScale(xBottom, -(length_timeseries_text -> text()).toDouble(), (length_timeseries_text -> text()).toDouble());
- plot_x -> replot();
- plot_y -> replot();
- // plot_mutualinf -> replot();
- }
- void window::scale_slider_timelag_x(int _scale)
- {
- label_13 -> setNum(_scale);
- }
- void window::scale_slider_timelag_y(int _scale)
- {
- label_22 -> setNum(_scale);
- }
- void window::scale_slider_varianz(int _scale)
- {
- //varianz_text -> setNum((double)(_scale)/(double)(length_timeseries_text -> text()).toDouble());
- varianz_text -> setNum(_scale);
- }
- void window::scale_slider_int_size(int _scale)
- {
- int _scale_label=pow(2., (int)_scale);
- int_size_text -> setNum(_scale_label);
- }
- //Auswahl Kernschätzer (Funktion)
- void window::check_kernel_gauss()
- {
- actionGauss -> setChecked(true);
- actionEpanechnikov -> setChecked(false);
- QString dot = 0x22C5;
- QString sigma = 0x03C3;
- label_9 -> setText(QString("Varianz T%1%2%3").arg(dot).arg(sigma).arg("²"));
- // label_9 -> setText(QString("Varianz %1").arg(sigma));
- }
- void window::check_kernel_epanechnikov()
- {
- actionGauss -> setChecked(false);
- actionEpanechnikov -> setChecked(true);
- QString dot = 0x22C5;
- QString alpha = 0x03B1;
- label_9 -> setText(QString("Steuerparameter 5%1%2%3%4").arg(dot).arg("T").arg(dot).arg(alpha));
- // label_9 -> setText(QString("Steuerparameter %1").arg(alpha));
- }
- //Variablen auslesen und übergeben und anschließend Graphen plotten
- QVector<QPointF> window::read_var()
- //void window::read_var()
- {
- statusBar()->showMessage("Berechnen");
- kopplung_x = (kopplung_x_text -> text()).toDouble();
- kopplung_y = (kopplung_y_text -> text()).toDouble();
- timelag_x = (timelag_x_slider -> text()).toDouble();
- timelag_y = (timelag_y_slider -> text()).toDouble();
- noise_x = (noise_x_text -> text()).toDouble();
- noise_y = (noise_y_text -> text()).toDouble();
- length = (length_timeseries_text -> text()).toDouble();
- varianz = (varianz_text -> text()).toDouble();
- field_size = (int_size_text -> text()).toDouble();
- if (actionGauss->isChecked() == true) kernel = gauss;
- else kernel = epa;
- if (action_auto->isChecked() == true) auto_mi = true;
- else auto_mi = false;
- mut_inf.set_timeseries(kopplung_x, kopplung_y, timelag_x, timelag_y, noise_x, noise_y, length, varianz, kernel, auto_mi, field_size);
- TimeSeries timeseries;
- timeseries = mut_inf.generate_timeseries();
- //Zeitreihen unverändert ausgeben
- QFile writeFile2("Zeitreihen.txt");
- writeFile2.open(QIODevice::WriteOnly | QIODevice::Text);
- QTextStream out2(&writeFile2);
- out2 << "Index\tx\ty" << endl;
- for (int i=0; i<timeseries.x.size(); ++i) out2 << i << "\t" << timeseries.x.at(i) << "\t" << timeseries.y.at(i) <<endl;
- writeFile2.close();
- //Zeitreihen zeichnen
- QVector<QPointF> data_x, data_y;
- for (int i=1; i<=timeseries.x.size(); ++i)
- {
- data_x.append(QPointF(i , timeseries.x.at(i)));
- data_y.append(QPointF(i , timeseries.y.at(i)));
- }
- QwtPlotCurve curve_x, curve_y;
- curve_x.setSamples(data_x);
- curve_x.attach(plot_x);
- curve_y.setSamples(data_y);
- curve_y.attach(plot_y);
- plot_x -> replot();
- plot_y -> replot();
- //relative Rangzahlen berechnen und daraus die Transinformation
- QVector<double> final(40+1);
- clock_t start=0, stop=0;
- start = clock();
- final = mut_inf.calculate_rang(timeseries);
- stop = clock();
- //Transinformation zeichnen
- double maximum=0;
- for (int i=0; i<(2*20); ++i) if (maximum < std::max(final.at(i), final.at(i+1))) maximum = std::max(final.at(i), final.at(i+1));
- plot_mutualinf -> setAxisScale(yLeft, 0, (ceil(maximum*10))/10. );
- QFile writeFile1("mutual_inf.tex");
- writeFile1.open(QIODevice::WriteOnly | QIODevice::Text);
- QTextStream out1(&writeFile1);
- out1 << "\\beginpicture" << endl;
- out1 << "\\setcoordinatesystem units <.02\\textwidth," << 3.5/((double)(ceil(maximum*10))/10.+.1)-1.25 << "cm> point at 0 0" << endl;
- out1 << "\\setplotarea x from -20 to 20, y from 0 to "<< (double)(ceil(maximum*10))/10.+.1 << endl;
- out1 << "\\axis bottom label {$\\tau$}" << endl;
- out1 << "ticks numbered from -20 to 20 by 5" << endl;
- out1 << "unlabeled short from -20 to 20 by 1 /" << endl;
- out1 << "\\axis left label {\\begin{turn}{90}$\\nicefrac{I^{\\mathrm{MI}}}{\\mathrm{bit}}$\\end{turn}}" << endl;
- out1 << "ticks numbered from 0 to " << (double)(ceil(maximum*10))/10.+0.1 << " by .2" << endl;
- out1 << "unlabeled short from 0 to " << (double)(ceil(maximum*10))/10. << " by .1 /" << endl;
- out1 << "\\setlinear" << endl;
- out1 << "\\setplotsymbol ({\\circle*{.25}} [Bl])" << endl;
- out1 << "\\plot ";
- for (int i=0; i<final.size(); ++i) out1 << i-20 << " " << final[i] << "\t";
- out1 <<" /" << endl;
- out1 << "\\endpicture" << endl;
- // out1 << "tau\tI^MI / bit" << endl;
- // for (int i=0; i<final.size(); ++i) out1 << i-20 << "\t " << final[i] << endl;
- out1 << "%Dauer in ms: " << stop-start ;
- writeFile1.close();
- QVector<QPointF> data_mut;
- for (int i=0; i<final.size(); ++i) data_mut.append(QPointF(i-20 , final.at(i)));
- QwtPlotCurve curve_mut;
- curve_mut.setSamples(data_mut);
- curve_mut.attach(plot_mutualinf);
- plot_mutualinf -> replot();
- statusBar()->showMessage("Fertig");
- return data_mut;
- }
- void window::exportDocument()
- {
- QwtPlotCurve curve_mut;
- curve_mut.setSamples(data_mut);
- curve_mut.attach(plot_mutualinf);
- #ifndef QT_NO_PRINTER
- QString fileName = "mutual_inf.pdf";
- #else
- QString fileName = "mutual_inf.png";
- #endif
- #ifndef QT_NO_FILEDIALOG
- const QList<QByteArray> imageFormats =
- QImageWriter::supportedImageFormats();
- QStringList filter;
- filter += "PDF Documents (*.pdf)";
- #ifndef QWT_NO_SVG
- filter += "SVG Documents (*.svg)";
- #endif
- filter += "Postscript Documents (*.ps)";
- if ( imageFormats.size() > 0 )
- {
- QString imageFilter("Images (");
- for ( int i = 0; i < imageFormats.size(); i++ )
- {
- if ( i > 0 )
- imageFilter += " ";
- imageFilter += "*.";
- imageFilter += imageFormats[i];
- }
- imageFilter += ")";
- filter += imageFilter;
- }
- fileName = QFileDialog::getSaveFileName(
- this, "Export File Name", fileName,
- filter.join(";;"), NULL, QFileDialog::DontConfirmOverwrite);
- #endif
- if ( !fileName.isEmpty() )
- {
- QwtPlotRenderer renderer;
- #if 0
- // flags to make the document look like the widget
- renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
- renderer.setLayoutFlag(QwtPlotRenderer::KeepMargins, true);
- renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
- #endif
- renderer.renderDocument(plot_mutualinf, fileName, QSizeF(300, 200), 85);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement