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

Created CUAIFile class (Issue #1913) to save and load file in UAI file format. #2019

Merged
merged 1 commit into from
Apr 13, 2014

Conversation

abinashpanda
Copy link
Contributor

No description provided.

@abinashpanda
Copy link
Contributor Author

CUAIFile implemented according to Issue #1913

* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2014 Abinash Panda (gsomix)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you want to name after gsomix :)

@hushell
Copy link
Contributor

hushell commented Mar 17, 2014

@abinashpanda Good job! There are several issues, you may try to resolve. Make sure that function tables in UAI format are actually energy tables in our case. Please add unit-tests for the new class.

@hushell
Copy link
Contributor

hushell commented Mar 18, 2014

Also, please git reset --soft to make only one commit for this PR.

#include <shogun/io/UAIFile.h>

#include <shogun/lib/SGVector.h>
#include <shogun/base/DynArray.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use shogun/lib/DynamicArray.h

@hushell
Copy link
Contributor

hushell commented Mar 18, 2014

parse() is great! But I think you missed how to construct a FactorGraph from the UAI file. Please think about how to do that. Something like SGVector::load(CFile*).


void CUAIFile::parse()
{

Copy link
Member

Choose a reason for hiding this comment

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

why new line?

@vigsterkr
Copy link
Member

any progress on this PR?

@abinashpanda
Copy link
Contributor Author

@vigsterkr I would be completing it by today. I was busy with my GSoC applications and class test.

@abinashpanda
Copy link
Contributor Author

@hushell @vigsterkr I have corrupted this PR with many commits and I have to still refactor it. So should I close this one and send a new PR?

@vigsterkr
Copy link
Member

@abinashpanda corrupted how?

m_tokenizer=NULL;
m_line_tokenizer=NULL;
m_parser=NULL;
m_line_reader=NULL;
Copy link
Member

Choose a reason for hiding this comment

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

SG_ADD is still missing... please check other shogun class implementation...

@abinashpanda
Copy link
Contributor Author

@vigsterkr by corrupted means, I have messed up the implementation. Regarding SG_ADD: I am trying to implement this class as CSVFile has been implemented. I didn't find any SG_ADD. I you could suggest me some other class.

@hushell
Copy link
Contributor

hushell commented Mar 21, 2014

@abinashpanda Please don't launch another PR, since we have already discussed a lot on this one. Try to git reset --soft. This way people knows better what's going on here.

virtual void get_vector(uint16_t*& vector, int32_t& len);
virtual void get_vector(int64_t*& vector, int32_t& len);
virtual void get_vector(uint64_t*& vector, int32_t& len);
//@}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we try to use function templates here? IMO it whould really reduce the amount of duplicated code.

Copy link
Member

Choose a reason for hiding this comment

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

@tklein23 see CFile.h

@tklein23
Copy link
Contributor

Code itself looks good to me. I'm happy to see unit-tests for that.

But I'm really confused about 1000 lines for reading one file format. (@abinashpanda - I know it's not completely your fault, but it's a good time to discuss this.)

The header file contains about 450 lines, the implementation 350. Seems to be 90% boiler-plate-code. Is this really necessary or did we just massively duplicate code? Any suggestions how to improve it?

Any objections against using function templates to reduce the size of the header file? Shouldn't be a big deal - let me know if you need any assistance (i.e. documentation/examples) for this.

@abinashpanda
Copy link
Contributor Author

@tklein23 By the function template implementation for get_vector, what I understood is template <class T> get_vector(T&* vector, int32_t& len) (correct me if I am wrong), but I think there are few problems associated with it:

  • First the vectors access functions as well as the matrix access functions are inherited from CFile, where they are not implemented using function templates, so I don't think they can be implemented here using function templates.
  • Secondly, the vector and matrix access functions cannot be implemented using function templates in CFile also as they must be virtual and I don't think C++ allows creation of virtual template function.
    Any suggestions?

@tklein23
Copy link
Contributor

I'm convinced that it requires bigger changes. I'd say it's beyond the scope of this issue.

@hushell - as you created the issue, finishing this issue is up to you. Please check if we're done here.

@hushell
Copy link
Contributor

hushell commented Mar 30, 2014

@tklein23 I think since most of file loaders in Shogun are implemented in this way, we can keep it as this temporally. My intuition was not to make so much effort to create a UAI file loader.

@abinashpanda The code for UAI format part is good. Please fix the Travis issues, try to avoid using add_vector() to register members. I mean you don't need to stick on SGVector. Once you make Travis happy, we could merge this PR for you.

However, it seems you only finished 50% of issue #1913, we would like to use these code to build factor graphs. Well, since this PR has lived for a long time, let's finish it soon and start a new one for the rest of the task.


/** Can only be enable after this issue is https://github.com/shogun-toolbox/shogun/issues/1972
* resolved
* SG_ADD(m_factors_table, "m_factors_table", "table of factors", MS_NOT_AVAILABLE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, in this way, it passed the clone tests. Use "factors_table" not "m_factors_table".

Copy link
Contributor

Choose a reason for hiding this comment

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

On Sunday 30 March 2014 00:52:18 Shell Hu wrote:

+}
+
+CUAIFile::~CUAIFile()
+{

  • SG_UNREF(m_tokenizer);
  • SG_UNREF(m_line_tokenizer);
  • SG_UNREF(m_parser);
  • SG_UNREF(m_line_reader);
    +}

+void CUAIFile::init()
+{
+

Interesting, in this way, it passed the clone tests. Use "factors_table" not
"m_factors_table".

No surprise: No registration takes place, so it's simply serializing an
object without members.

If we're only missing support for SGVector, can't we just enable all
other members and keep the affected ones disabled until #1972 is solved?

@hushell
Copy link
Contributor

hushell commented Mar 30, 2014

It seems Travis issues have been solved, I am not sure we still have problems related to #1972.
@abinashpanda Before merging the PR, please valgrind to make sure no memory leak in your unit-tests.

namespace shogun
{

/** @brief Class UAIFILE used to read data from comma-separated values (CSV)
Copy link
Member

Choose a reason for hiding this comment

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

this class description is not true at all..

@tklein23
Copy link
Contributor

@abinashpanda - welcome back. I hope you are fully recovered.

What's the status of this PR?

Last Travis built failed because SerializationXML.UAIFile is broken. Do you know what happened here?

@abinashpanda
Copy link
Contributor Author

@tklein23 - I am fully recovered now.
Regarding the PR, as per @karlnapf the SerializationXML.UAIFile breaking down might have to do with the generic type of the class or its members. It is set with the method
template<class T> void set_generic();
or unset with
void unset_generic();.
I tried to unset it using unset_generic() method, but still facing the same error. Any suggestions ?

@hushell
Copy link
Contributor

hushell commented Apr 12, 2014

@abinashpanda let's wrap this up. After getting over the serialization issue, you could choose to leave the 2nd half of the entrance task aside, i.e., no touching with factor graph stuffs. It will be nice to get familiar with SSVM solvers in Shogun in pre-GSoC period.

@karlnapf
Copy link
Member

I suggest you copy the unit test template and fill in your class that fails by hand, have this as a separate Shogun program and then debug to see whats wrong. Let me know if that helps, sometimes this stuff is tricky

@abinashpanda
Copy link
Contributor Author

@karlnapf Thanks for your suggestion. Finally I have modified the code and travis build passed. @tklein23 @hushell If you could review the code. Thanks in advance :)

SG_UNREF(m_parser);
SG_UNREF(m_line_reader);

delete [] m_factors_table;
Copy link
Contributor

Choose a reason for hiding this comment

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

SG_FREE is better. I mean use SG_ALLOC and SG_FREE.

@hushell
Copy link
Contributor

hushell commented Apr 13, 2014

@abinashpanda Almost here! Great job! Just two things: 1) merge all commits to a single one, by using git reset --soft; 2) Make sure valgrind reports no memory leaks: valgrind --leak-check=full ./shogun-unit-test --gtest_filter=UAIFileTest*

@abinashpanda
Copy link
Contributor Author

Ran valgrind test and no memory leaks found.
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0).

@tklein23
Copy link
Contributor

@abinashpanda - Congratulations.

Let's wait for Travis and @hushell to merge. ;)

@hushell
Copy link
Contributor

hushell commented Apr 13, 2014

@tklein23 It looks great for me! Please merge for Abinash.

tklein23 added a commit that referenced this pull request Apr 13, 2014
Created CUAIFile class (Issue #1913) to save and load file in UAI file format.
@tklein23 tklein23 merged commit 0ade087 into shogun-toolbox:develop Apr 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants