robbert-harms / MOT

Multi-threaded Optimization Toolbox
Other
31 stars 8 forks source link

Add examples #1

Closed ktamiola closed 4 years ago

ktamiola commented 6 years ago

First all thank you for this amazing body of work! Could you point us to any existing examples of the usage of Monte Carlo routines from MOT?

robbert-harms commented 6 years ago

Hej Kamil,

Thank you for the compliment! It is appreciated.

My paper on parallel sampling of diffusion Magnetic Resonance Imaging (dMRI) models will be out on bioarxiv in the next few days. That one contains an illustration of parallel sampling. My paper about parallel optimization of dMRI models can be found here: https://www.sciencedirect.com/science/article/pii/S1053811917303178?via%3Dihub (as a sidenote, the software MDT mentioned in those papers is a dMRI package building on top of MOT, I developed both for my Phd).

I am currently refactoring the sampling routines as they are too tightly coupled with the model interface at the moment. The next version, v0.4 will be out in the next few days with a cleaner user interface to the sampling routines. Additionally, I will add some code examples of how to use the optimization and sampling routines to the documentation.

Might I ask to your interest? I am eager to learn if and how MOT is applicable to other areas beside MRI analysis.

Best regards,

Robbert

ktamiola commented 6 years ago

Fantastic news indeed!

Robert, we are in a desperate need for efficient and scalable stochastic optimization methods. Thus my interest in your work. Importantly, we want to employ them for automated protein design.

robbert-harms commented 6 years ago

Just to keep you up to date, version 0.4 is now out with a much improved API to the MCMC algorithms.

Example usage will follow shortly.

ktamiola commented 6 years ago

Fabulous! Thank you so much for the update @robbert-harms . We will wait for some tangible examples.

robbert-harms commented 6 years ago

Hej Kamil,

I took the liberty of cleaning up the API a bit such that it would present a more stable target for future use. The much needed examples are now in the repository, you can find them at: https://github.com/cbclab/MOT/tree/master/examples . Please let me know if those examples work out for you.

If you are interested in someone with experience in high-performance computing and a background in computer science, I am investigating entrepreneurship as a high-performance computing consultant.

Best,

Robbert

DMaterka commented 6 years ago

@robbert-harms I'm also thankful to you for your impressive work. I'm quite new to python and very new to the opencl but it seems perspective in my future research in quadrupolar nmr spectra analysis. In the meanwhile, I'm trying to do a simple curve fitting to the normal_pdf() function as a test before I develop more suited distribution to my research problem. But I cannot do the very basic fitting:

At the moment I've come over an issue with the error message: " passing 'local mot_float_type *' (aka 'local double *') to parameter of incompatible type 'double' "

that appears when calling mot.optimize.minimize(func, x0, kernel_data)

kernel_data = mot.lib.kernel_data.Array(spectrum, 'mot_float_type')

print(np.shape(spectrum)) (512, 2) print(spectrum.dtype) float64

x0 = spectrum[:,0]

func = normal_pdf()

Build on <pyopencl.Device 'pthread-Intel(R) Core(TM)2 Duo CPU E8600 @ 3.33GHz' on 'Portable Computing Language' at 0x2def900>

I tried to do assorted things, to enable or disable double precision, converting the dtype to ctype, but with no success. I would be glad if you could point me any direction to fix the error or provide any very basic example of such usage.

Thanks for the reply.

robbert-harms commented 6 years ago

@DMaterka, thank for the compliment, I hope my software can be of use to you.

To use MOT for your curve fitting, you will have to write an objective function in OpenCL and with using the MOT framework. The signature of such an objective function would be:

objective_func = SimpleCLFunction.from_string('''
    double my_objective(
            local const mot_float_type* const x,
            void* data, 
            local mot_float_type* objective_list){

        // ...
    }
''')

This is then the kind of objective functions you can give to MOT as:

minimize(objective_func, ...)

The normal_pdf() function in MOT is not a function to be directly used for model fitting, rather, it is an library function which you can use to generate your own objective function.

To help you get started, I added a quick gamma fitting example to MOT, please find it here: https://github.com/cbclab/MOT/blob/master/examples/fitting_gamma_distribution.py

Here, we generate the parameters of some Gamma distributions, simulate some data and fit it using MOT.

Do let me know if this works out for you.

Best,

Robbert