april-tools / cirkit

a python framework to build, learn and reason about probabilistic circuits and tensor networks
https://cirkit-docs.readthedocs.io/en/latest/
GNU General Public License v3.0
80 stars 4 forks source link

Support for parameterization upper and lower bounds? #320

Open isurulucky opened 1 week ago

isurulucky commented 1 week ago

Hi,

Right now, the Parameterization class takes the arguments initialization, activation and dtype [1]. If there is a requirement to specify upper and/or lower limits to the circuit parameter values, is there a way of doing it? AFAIU, the Parameterization class should carry this additional arguments, or is there a better way?

Some symbolic level parameter classes (ex.: ClampParameter [2]) already exist for actual clamping, I think we only need to pass the additional information about min/max values from the definition of the symbolic circuit.

[1]. https://github.com/april-tools/cirkit/blob/main/cirkit/templates/circuit_templates/utils.py#L35-L44

[2]. https://github.com/april-tools/cirkit/blob/main/cirkit/symbolic/parameters.py#L563

Thanks, Isuru

loreloc commented 4 days ago

Hi Isuru, we already have a "positive-clamp" parameterization. You can see it here: https://github.com/april-tools/cirkit/blob/main/cirkit/templates/circuit_templates/utils.py#L169-L172 However, if you want to also specify min/max values, you would need to change the Parameterization class as to allow this extra parameters. For instance, we could have an activation_kwargs dictionary in Parameterization that takes the extra arguments, and are then passed to the chosen activation initialization.

If you want even more control on the parameterization, then I suggest using the Circuit.from_region_graph method to specify layer factories and sum weight factories. https://cirkit-docs.readthedocs.io/en/latest/api/cirkit/symbolic/circuit/?h=from_region_g#cirkit.symbolic.circuit.Circuit.from_region_graph

isurulucky commented 2 days ago

Hi @loreloc ,

Thank you for the reply and the info.

I will check out the Circuit.from_region_graph method.

we already have a "positive-clamp" parameterization. You can see it here: https://github.com/april-tools/cirkit/blob/main/cirkit/templates/circuit_templates/utils.py#L169-L172 However, if you want to also specify min/max values, you would need to change the Parameterization class as to allow this extra parameters. For instance, we could have an activation_kwargs dictionary in Parameterization that takes the extra arguments, and are then passed to the chosen activation initialization.

I actually tried out the same earlier. If you think this is something good to have in addition to capabilities of Circuit.from_region_graph, I can send a PR.

BR, Isuru