save lm data for plots later

This commit is contained in:
Jonathan Bosson
2017-05-10 17:07:54 -06:00
parent 08e3ac8a6b
commit 9bc653ec01
5 changed files with 45 additions and 19 deletions

View File

@@ -30,7 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
// set parameters required by levmarq() to default values
void levmarq_init(LMstat *lmstat) {
lmstat->verbose = 0;
lmstat->verbose = true;
lmstat->max_it = 5000;
lmstat->init_lambda = 1e-6;
lmstat->up_factor = 10;
@@ -62,7 +62,9 @@ bool levmarq(int npar, double *par, int ny, double *dysq,
void (*grad)(double *, double *, int, void *),
void *fdata, LMstat *lmstat) {
int x, i, j, it, nit, ill, verbose;
int x, i, j, it, nit, ill;
bool verbose;
std::string data = "";
double lambda, up, down, mult, weight, err, newerr, derr, target_derr;
// allocate the arrays
@@ -86,6 +88,10 @@ bool levmarq(int npar, double *par, int ny, double *dysq,
weight = 1;
derr = newerr = 0; // to avoid compiler warnings
if (verbose) {
data = "it,err,derr,q,g,d\n";
}
// calculate the initial error ("chi-squared")
err = error_func(par, ny, dysq, func, fdata);
@@ -123,7 +129,27 @@ bool levmarq(int npar, double *par, int ny, double *dysq,
ill = (derr > 0);
}
if (verbose) {
printf("it = %4d, lambda = %10g, err = %10g, derr = %10g (%d)\n", it, lambda, err, derr, !(newerr > err));
/*printf("it = %4d, lambda = %10g, err = %10g, derr = %10g (%d)\n", it, lambda, err, derr, !(newerr > err));
for (int i = 0; i < npar; ++i) {
printf("g[%d] = %g, ", i, g[i]);
}
printf("\n");*/
//std::ostringstream gString;
std::ostringstream gString, qString, dString, os;
for (int i = 0; i < npar; ++i) {
gString << g[i];
qString << par[i];
dString << d[i];
if (i + 1 < npar) {
gString << " ";
qString << " ";
dString << " ";
}
}
os << it << "," << err << "," << derr << "," << qString.str() << "," << gString.str() << "," << dString.str() << "\n";
data.append(os.str());
// store iteration, error, gradient, step
}
if (ill) {
mult = (1 + lambda * up) / (1 + lambda);
@@ -143,13 +169,7 @@ bool levmarq(int npar, double *par, int ny, double *dysq,
lmstat->final_it = it;
lmstat->final_err = err;
lmstat->final_derr = derr;
if (verbose) {
for (int i = 0; i < npar; ++i) {
printf("g[%d] = %g, ", i, g[i]);
}
printf("\n");
}
lmstat->data = data;
// deallocate the arrays
for (int i = 0; i < npar; i++) {

View File

@@ -23,9 +23,12 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <sstream>
typedef struct {
int verbose;
bool verbose;
std::string data;
int max_it;
double init_lambda;
double up_factor;

View File

@@ -116,6 +116,7 @@ class TouchInteraction : public properties::PropertyOwner
// Property variables
properties::StringProperty _origin;
properties::BoolProperty _lmVerbose;
properties::IntProperty _maxTapTime;
properties::FloatProperty _touchScreenSize;
properties::FloatProperty _nodeRadiusThreshold;

View File

@@ -58,6 +58,7 @@ using namespace openspace;
TouchInteraction::TouchInteraction()
: properties::PropertyOwner("TouchInteraction"),
_origin("origin", "Origin", ""),
_lmVerbose("LM verbose", "Save data from LM algorithm", true),
_maxTapTime("Max Tap Time", "Max tap delay (in ms) for double tap", 300, 10, 1000),
_touchScreenSize("TouchScreenSize", "Touch Screen size in inches", 55.0f, 5.5f, 150.0f),
_nodeRadiusThreshold("Activate direct-manipulation", "Radius a planet has to have to activate direct-manipulation", 0.3f, 0.0f, 1.0f),
@@ -76,6 +77,7 @@ TouchInteraction::TouchInteraction()
_currentRadius{ 1.0 }, _slerpdT{ 1000 },
_directTouchMode{ false }, _tap{ false }, _doubleTap{ false }, _lmSuccess{ true }, _guiON{ false }
{
addProperty(_lmVerbose);
addProperty(_maxTapTime);
addProperty(_touchScreenSize);
addProperty(_nodeRadiusThreshold);
@@ -141,7 +143,7 @@ bool TouchInteraction::gui(const std::vector<TuioCursor>& list) {
glm::ivec2 res = wrapper.currentWindowSize();
glm::dvec2 pos = glm::vec2(list.at(0).getScreenX(res.x), list.at(0).getScreenY(res.y)); // mouse pixel position
_guiON = OnScreenGUIModule::gui.isEnabled();
_lmstat.verbose = _lmVerbose;
if (_tap && list.size() == 1 && pos.x < _guiButton.value().x && pos.y < _guiButton.value().y) { // pressed invisible button
_guiON = !_guiON;
OnScreenGUIModule::gui.setEnabled(_guiON);
@@ -302,11 +304,14 @@ void TouchInteraction::manipulate(const std::vector<TuioCursor>& list) {
}
// debugging
/*std::ostringstream os;
for (int i = 0; i < nDOF; ++i) {
os << par[i] << ", ";
if (_lmVerbose) {
/*std::ostringstream os;
for (int i = 0; i < nDOF; ++i) {
os << par[i] << ", ";
}
std::cout << "Levmarq success after " << _lmstat.final_it << " iterations. Values: " << os.str() << "\n";*/
std::cout << _lmstat.data;
}
std::cout << "Levmarq success after " << _lmstat.final_it << " iterations. Values: " << os.str() << "\n";*/
// cleanup
delete[] par;

View File

@@ -37,8 +37,6 @@
#include <sstream>
#include <string>
#include <iostream>
#include <thread> // std::this_thread::sleep_for
#include <chrono> // std::chrono::seconds
using namespace TUIO;
@@ -128,7 +126,6 @@ TouchModule::TouchModule()
if (gotNewInput() && OsEng.windowWrapper().isMaster()) {
touch->update(list, lastProcessed);
//std::this_thread::sleep_for(std::chrono::seconds(1)); // for debugging
}
else if (list.size() == 0) {
touch->clear();