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

More Examples for Factor Graph #1913

Open
hushell opened this issue Mar 1, 2014 · 22 comments
Open

More Examples for Factor Graph #1913

hushell opened this issue Mar 1, 2014 · 22 comments

Comments

@hushell
Copy link
Contributor

hushell commented Mar 1, 2014

This is an entrance task for this project: http://www.shogun-toolbox.org/page/Events/gsoc2014_ideas#sosvmapprox

Currently, no approximate inference implemented with factor graph model in Shogun. This is what we are going to do this summer. In the first step, we could create graphs with loops for later use.

  • So try to get familiar with factor graph and create grid graphs with 4-connection and 8-connection as well as a full connected graph.
  • Implement loading/saving graphs in UAI format to save time for manually constructing factor graph. Specifically, implement an IO class to parse (save/load) UAI format (http://www.cs.huji.ac.il/project/PASCAL/fileFormat.php) CUAIFile. A reference of loading function is here: http://cs.nyu.edu/~dsontag/code/README_v2.html. Note that function tables can be computed by CFactorGraph::compute_energies(), and obtained by SGVector<float64_t> CFactor::get_energies() const. Add member functions CFactorGraph::save(CUAIFile*) and CFactorGraph::load(CUAIFile*), where CUAIFile should have interim variables to represent an UAI file (according to Viktor's suggestion). To support the loading function, you need to set energy table for each factor. Make sure that you really understand CFactor, CFactorType, CFactorGraph.
@karlnapf
Copy link
Member

karlnapf commented Mar 4, 2014

@hushell how should the loading/saving of graphs work, could you elaborate a bit?

@aroma123
Copy link

aroma123 commented Mar 5, 2014

Hi,
I have some experience with graphical models so I thought I would work on this issue.
I am finished with 4, 8 and fully connected graphs.
I am unsure what would be better in graph loading and saving. If we load/save graphs from sources like uai files, independent functions would be better. Serialization would limit the format of graphs we can load from. What do you think ?

@hushell
Copy link
Contributor Author

hushell commented Mar 5, 2014

@aroma123 and @karlnapf : I was thinking just save/load the CFactorGraph, but it will be nice if we are compatible with UAI format.
@aroma123 : try to reuse Sontag's MPLP code: http://cs.nyu.edu/~dsontag/code/README_v2.html if you decided to go with UAI format.

@hushell
Copy link
Contributor Author

hushell commented Mar 5, 2014

@aroma123 BTW, if you have time, you may also want to work on this: #1916, I think @tklein23 will be happy to be involved :)

@vigsterkr
Copy link
Member

@hushell i cannot agree with CFactorGraphFile. why dont we create an CUAIFile class that can handle UAI file in general, i.e. define all the right data structures and APIs and then when we have that ready, create maybe a CFactorGraphFile

UAI has the following syntax:

<Preamble>

<Function tables>

so in other words we need to define a function in CUAIFile that can parse any <Preamble> and then another function that can read the <Function tables> based on the preamble information.

and then of course define the API in CUAIFile that supports reading these information...

@vigsterkr
Copy link
Member

@hushell same goes for CFactorGraph::convert_to_UAI(CFactorGraphFile* file, CFactorGraphFile* uai_file)... why would you have a file formatting/conversion function in CFactorGraph?
it's purely IO related story.... it's like you would put csv to libsvm format conversion in LibSVM... why?

@abinashpanda
Copy link
Contributor

@vigsterkr and @hushell : What I understood from the discussion above that:

  • First I should create a IO class called CUAIFile. Once this class is ready with all its API, then CFactorGraphFile should be created that would inherit from CUAIFile. (correct me if I am going in wrong direction).
  • Secondly, I have a another implementation in mind (it might be very noobish but still I would propose). Instead of creating CFactorGraph::convert_to_UAI(CFactorGraphFile* file, CFactorGraphFile* uai_file), we could be overloading the CFactorGraph::save method. CFactorGraph::save(CUAIFile* file) would save the graph in UAI file format and CFactorGraph::save(CFactorGraph* file) would save the graph in FactorGraph file format.

@iglesias
Copy link
Collaborator

@abinashpanda, as I understood it, there would be no CFactorGraphFile, because you may want to read UAI files and not necessarily use them for factor graphs.

Have a look in the examples to how CSVFile is used. CUAIFile should be used in a similar manner, just parsing UAI files instead of CSV files.

@aroma123
Copy link

I have another idea. Why do we need to have different classes for different format. Can't we just have multiple functions for CFactorgraph class itself like CFactorgraph::load_from_uai , CFactorgraph::save_to_uai ? This way we can add support for other file formats later. What do you think ?

@vigsterkr
Copy link
Member

@aroma123 in short: not a good idea

@iglesias
Copy link
Collaborator

@aroma123, so say that tomorrow I make a Markov network class in Shogun and I want to be able to load Markov networks from UAI files. Then I should make CMarkovNetwork::load_from_uai, CMarkovNetwork::save_to_uai which are going to be pretty much the same as CFactorGraph::load_from_uai and its brother.

See the point?

@aroma123
Copy link

Okay. Also, I was looking at code @hushell pointed to reuse for uai for implementation. How should .evid files be handled ?

@vigsterkr
Copy link
Member

@aroma123 let's concentrate on UAI itself now... but either it'll have to be a part of CUAIFile or a separate class. although since they are related they should be somehow coupled.. same goes for result file...

@aroma123
Copy link

@vigsterkr So a virtual function for loading evidence should do for now ?

@vigsterkr
Copy link
Member

@aroma123 i'm not so sure if i understand the direct connection between a virtual function and an unimplemented functionality... as said earlier let's concentrate first on UAI itself.

@aroma123
Copy link

Understood. Working on it. Get back soon.

@hushell
Copy link
Contributor Author

hushell commented Mar 12, 2014

@aroma123 and @abinashpanda: Please read my updated description!

@vigsterkr
Copy link
Member

@hushell this design pattern is completely flawed

void CUAIFile::save(CFactorGraph* fg);

it should be CFactorGraph::save(CUAIFile*) and CUAIFile should have interim variables to represent an uai file...

@hushell
Copy link
Contributor Author

hushell commented Mar 21, 2014

@vigsterkr Thanks for pointing this out. I was not familiar with IO part at that time. Now I find the correct way, an example is void SGVector::save(CFile* saver). I'll update the description right away :)

tklein23 added a commit that referenced this issue Apr 13, 2014
Created CUAIFile class (Issue #1913) to save and load file in UAI file format.
@iglesias
Copy link
Collaborator

iglesias commented May 8, 2014

Hey @hushell, @abinashpanda , did the part CFactorGraph::save(CUAIFile*) finally happen? I see the CUAIFile implementation but no how it can be used from FactorGraph.

@hushell
Copy link
Contributor Author

hushell commented May 8, 2014

@iglesias Finally Throlf and I decided to let Abinash focus on multilabel classification. So this final step to make use of CUAIFile hasn't been done yet. Maybe @Jiaolong want to continue on this :)
Anyway, If he doesn't have time, I'll do it in June. Now I am overwhelmed by homeworks and projects.

@Jiaolong
Copy link
Contributor

Jiaolong commented May 8, 2014

@hushell I am currently focusing on MPLP and Graph cut. I will take a look at this issue. Also, I would like to compare it with OpenGM which employs HD5 for reading and saving graphical model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants