Skip to content

Conversation

@EnricoPaglia
Copy link
Contributor

Hi,
this is a first implementation of Python Mixing. As we discussed we made a branch from the hierarchy pr and added the needed files and changes to it to avoid losing all the things in common that we had. So here you will see a lot of changed files but the ones that are about the mixing are:

  • docs/examples/DP.py
  • docs/examples/test_run.py
  • pybmix/core/mixing.py
  • pybmix/core/mixture_model.py
  • pybmix/core/pybmixcpp/algorithm_wrapper.cpp
  • pybmix/core/pybmixcpp/algorithm_wrapper.hpp
  • pybmix/core/pybmixcpp/py_hier/CMakeLists.txt
  • pybmix/core/pybmixcpp/py_hier/includes.h
  • pybmix/core/pybmixcpp/py_hier/load_py_mixings.h
  • pybmix/core/pybmixcpp/py_hier/python_mixing.cc
  • pybmix/core/pybmixcpp/py_hier/python_mixing.h

We are aware of some problems and we will fix them as soon as possible (changing the parameters of the PythonMixing implemented in Python, avoiding having to write pass for unused functions as for the hierarchies, adding the documentation).

We have two questions:

  • PythonMixing class is inheriting from BaseMixing and not from Abstract, on the other hand PythonHierarchy must inherit from AbstractHierarchy, is it OK or it would be nicer to have them both inherit from the corresponding abstract class?
  • In AbstractHierarchy use the following structure:
namespace Python {
    struct State {
        std::vector<double> generic_state;
    };
}

And in MixingHierarchy we have (note the namespace is in capital letters):

namespace PYTHON {
    struct State {
        std::vector<double> generic_state;
    };
}

We did this to differentiate between the state of mixing and hierarchy. We think we could define only one structure in a different file and use the same for both Mixing and Hierarchy, what do you think is better?

@EnricoPaglia EnricoPaglia changed the title Python Mixing PR Python Mixing Implementation Jun 23, 2022
@taguhiM taguhiM requested review from brunoguindani and mberaha June 23, 2022 15:11
@mberaha
Copy link
Contributor

mberaha commented Jun 23, 2022

The namespaces could be called PyHier and PyMix, what do you think?

@mberaha
Copy link
Contributor

mberaha commented Jul 7, 2022

Please pull from master so that it shows the correct diffs


def __init__(self, mix_implementation):
self._build_prior_proto()
self.mix_implementation = mix_implementation
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if this file does not exist?

Also, I think both this class and PythonHierarchy need more docs, explaining in detail their use linking possibly to the example

Copy link
Collaborator

Choose a reason for hiding this comment

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

It gives a ModuleNotFoundError: No module named 'something'. It seemed to us quite self-explanatory error, do you think we need to add more logs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think it would be better to have a check raising a more detailed error. Everything is a "module" in python, I would just write "the mix_implementation file {0} does not exist".format(mix_implementation) or something along these lines

Copy link
Collaborator

Choose a reason for hiding this comment

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

We addressed this in the run_mcmc in the mixture_model.py since that's where the error actually raises. I just committed that, do you like this approach? The reason of using the old-fashioned style code was to avoid raising another ModuleNotFoundError and seeing the redundant traceback message like "During handling of the above exception, another exception occurred:" which would point to the same thing with a different message.
If there is a neater solution, we'd like to know :)

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me!

};
}; // namespace PyMix

class PythonMixing
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that a high-level documentation of the full class (also for the hierarchy) would be nice

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah sorry, we were focused on the presentation, we will add it soon!

self.mix_implementation = mix_implementation

def prior_cluster_distribution(self, grid, nsamples):
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather logging.error that this function cannot be implemented

@taguhiM
Copy link
Collaborator

taguhiM commented Sep 22, 2022

Hi all. The summer went by in exam sessions and vacations but we are willing to finish what we started :) I guess the main thing missing here was the documentation and the last remark about the logging.error, is that so?

@mberaha
Copy link
Contributor

mberaha commented Sep 25, 2022

Hi all. The summer went by in exam sessions and vacations but we are willing to finish what we started :) I guess the main thing missing here was the documentation and the last remark about the logging.error, is that so?

Great hearing from you :) Yes that sounds about right! For the documentation part, I would add also a page to the docs by creating a new "rst" fine in "docs/soruces/extending_pybmix.rst", where you try to summarise the needed steps for implementing a new hierarchy / mixing. Then add a notebook with the actual implementation

@taguhiM
Copy link
Collaborator

taguhiM commented Nov 12, 2022

Hi. We added the stuff you mentioned in the last comment. Except we didn't really understand if you wanted to put the python implementations in a .ipynb file, since it can't be imported and used from a .ipynb. If you just need it for the tutorial documentations, then we can add that too.

@mberaha
Copy link
Contributor

mberaha commented Nov 14, 2022

Hi. We added the stuff you mentioned in the last comment. Except we didn't really understand if you wanted to put the python implementations in a .ipynb file, since it can't be imported and used from a .ipynb. If you just need it for the tutorial documentations, then we can add that too.

My bad, I just meant that it would be nice to have a ipynb that puts everything together and shows how to actually implement such a model using the library!

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.

4 participants