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

Fixes issue #1888 #1896

Closed
wants to merge 1 commit into from
Closed

Fixes issue #1888 #1896

wants to merge 1 commit into from

Conversation

dhruv13J
Copy link
Contributor

Created a templated function CMath::fequals() in Math.h and called this function in TParameter::compare_ptype() for floating point types.

@dhruv13J dhruv13J mentioned this pull request Feb 27, 2014
@@ -187,7 +187,9 @@ class CMath : public CSGObject
else
return -a;
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the whitespace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was going to put the 'CMath::fequals(..)' function there, forgot to erase the whitespace...

@karlnapf
Copy link
Member

@dhruv13J This already looks good. Have a look at travis, one unit test fails, it is TParameter.equals_scalar_different2 and TParameter.equals_vector_different1

See https://travis-ci.org/shogun-toolbox/shogun/jobs/19696129

In fact, could you add all the unit tests in http://floating-point-gui.de/errors/NearlyEqualsTest.java This would be extremely helpful, and is only copy paste work and some minor adjustments

@karlnapf
Copy link
Member

good work btw :)

@dhruv13J
Copy link
Contributor Author

I'm working on it :-)

@@ -212,3 +213,53 @@
EXPECT_TRUE(CMath::strtold("1.234567890123", &long_double_result));
EXPECT_DOUBLE_EQ(1.234567890123, long_double_result);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all unit tests added yet; will add the rest soon

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice those strtold tests!

@pranet
Copy link

pranet commented Feb 28, 2014

Hi.
I tried creating all the unit tests listed here http://floating-point-gui.de/errors/NearlyEqualsTest.java ,
but a lot of them are failing even for an identical(I think so) implementation of the nearlyEqual() function. It is classifying practically half the false assertions as true, but the true ones are fine .

One possible mistake I came across was the representation of negative infinity (just added a '-' to positive infinity and that failed. According to the test, +inf==-inf is true).
Any suggestions as to what else I'm doing wrong?

https://gist.github.com/pranet/9267745

@dhruv13J
Copy link
Contributor Author

Travis fails because of JSON Serialization, weird...

@dhruv13J
Copy link
Contributor Author

@pranet: what is the value of epsilon you are using? some tests depend on it, use 0.00001f

@pranet
Copy link

pranet commented Feb 28, 2014

It is 0.00001l not 0.00001f. Will that make a difference?

@@ -3237,7 +3237,7 @@ bool TParameter::equals(TParameter* other, float64_t accuracy)

for (index_t i=0; i<length; ++i)
{
SG_SDEBUG("comparing element %d which is %d byes from start\n",
SG_SDEBUG("comparing element %d which is %d bytes from start\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha nice, thanks! :)

@karlnapf
Copy link
Member

Nice, these are already very helpful. However, the most interesting ones are the other ones from this website.

Travis:
The JSON serialisation failures in gcc are probably caused by the accuracy being too high (I think it only support 1e-6, play with that and test locally)
https://travis-ci.org/shogun-toolbox/shogun/jobs/19785263

The python tests fail here:
https://travis-ci.org/shogun-toolbox/shogun/jobs/19785267
[INFO] leaving TParameter::compare_ptype(): PT_FLOAT64: data1=-0.005844, data2=-0.005844
[INFO] Result of fequals -> 0
Again, run locally and try to find out whats wrong there

Your help is really appreciated. We also realise that this is a highly complicated task which touches lots of Shogun's internals. Keep on going! :)

@dhruv13J
Copy link
Contributor Author

dhruv13J commented Mar 1, 2014

Still working on the JSON tests... will try and finish soon!

@karlnapf
Copy link
Member

karlnapf commented Mar 1, 2014

looking forward! :)

@@ -3133,7 +3133,7 @@ void TParameter::copy_data(const TParameter* source)
SG_SDEBUG("leaving TParameter::copy_data for %s\n", m_name)
}

bool TParameter::equals(TParameter* other, float64_t accuracy)
bool TParameter::equals(TParameter* other, float64_t accuracy, bool tolerant)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tolerant parameter allows less strict check for equality, based on the epsilon value given to the function. it has been added to all methods which can call TParameter::equals.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about a default parameter value?

@@ -89,7 +89,7 @@ TEST(SerializationJSON,{{class}}_{{type}})

// check whether they are equal, up to accuracy since json is lossy
float64_t accuracy=1e-6;
ASSERT(object->equals(deserializedObject, accuracy));
ASSERT(object->equals(deserializedObject, accuracy, true));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know why this is assert ,but should be expect

@karlnapf
Copy link
Member

karlnapf commented Mar 3, 2014

ok, lets wait for travis, do all tests pass locally on your machine?

@dhruv13J
Copy link
Contributor Author

dhruv13J commented Mar 3, 2014

@karlnapf: yeah, all tests passed locally, before i added the last commit; made a stupid typo

@karlnapf
Copy link
Member

karlnapf commented Mar 5, 2014

any progress here? :)
its almost passing all tests so we should merge that one soon. Its very useful for us

@dhruv13J
Copy link
Contributor Author

dhruv13J commented Mar 5, 2014

@karlnapf: my latest pr should fix it; I'm having problems because I can't reproduce the build error locally...

@dhruv13J
Copy link
Contributor Author

dhruv13J commented Mar 5, 2014

@karlnapf: Ready for merge i think!

Conflicts:
	src/shogun/mathematics/Math.h
@dhruv13J dhruv13J closed this Mar 5, 2014
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling e1fbef4 on dhruv13J:develop into 9c67564 on shogun-toolbox:develop.

@besser82 besser82 mentioned this pull request Mar 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants