# sop.SumOfProducts { #pompon.sop.SumOfProducts }```pythonsop.SumOfProducts(self input_size hidden_size basis_size output_size=1 w_scale=1.0 b_scale=1.0 w_dist='uniform' b_dist='linspace' x0=None activation='silu+moderate' key=None X_out=None fix_bias=False)```Function given by sum of products.. math:: f(x_1, x_2, \ldots, x_d) = \sum_{\rho} w_{\rho} \prod_{i=1}^{d} \phi_{\rho, i}(x_i)## Attributes| Name | Description || --- | --- || [q0](#pompon.sop.SumOfProducts.q0) | Get initial hidden coordinates $q_0=x_0U$ |## Methods| Name | Description || --- | --- || [export_h5](#pompon.sop.SumOfProducts.export_h5) | Export the model to a HDF5 file || [forward](#pompon.sop.SumOfProducts.forward) | Forward propagation || [grad](#pompon.sop.SumOfProducts.grad) | Gradient of loss function || [import_h5](#pompon.sop.SumOfProducts.import_h5) | Import the model from a HDF5 file || [mse](#pompon.sop.SumOfProducts.mse) | Mean squared error || [mse_force](#pompon.sop.SumOfProducts.mse_force) | Mean squared error with force || [plot_basis](#pompon.sop.SumOfProducts.plot_basis) | Plot distribution of $\phi$ || [show_onebody](#pompon.sop.SumOfProducts.show_onebody) | Visualize one-dimensional cut. || [to_nnmpo](#pompon.sop.SumOfProducts.to_nnmpo) | Convert to NNMPO model |### export_h5 { #pompon.sop.SumOfProducts.export_h5 }```pythonsop.SumOfProducts.export_h5(path)```Export the model to a HDF5 file#### Parameters {.doc-section .doc-section-parameters}| Name | Type | Description | Default ||--------|--------------|-----------------------|------------|| path | [str](`str`) | path to the HDF5 file | _required_ |#### Examples {.doc-section .doc-section-examples}```pythonimport pomponmodel = pompon.NNMPO(input_size=3, hidden_size=3, basis_size=5)model.export_h5("/path/to/model.h5")```#### See Also {.doc-section .doc-section-see-also}[import_h5()](#pompon.model.NNMPO.import_h5)### forward { #pompon.sop.SumOfProducts.forward }```pythonsop.SumOfProducts.forward(x)```Forward propagation#### Parameters {.doc-section .doc-section-parameters}| Name | Type | Description | Default ||--------|----------------------|------------------------------------------------------------------------------------------------------|------------|| x | [Array](`jax.Array`) | input tensor with shape $(D,n)$ where $D$ is the batch size and $n$ is the input size. | _required_ |#### Returns {.doc-section .doc-section-returns}| Name | Type | Description ||--------|----------------------|----------------------------------|| Array | [Array](`jax.Array`) | output tensor with shape $(D,1)$ |### grad { #pompon.sop.SumOfProducts.grad }```pythonsop.SumOfProducts.grad( x y* f=None basis_grad=True coordinator_grad=True lambda1=0.0 mu1=1.0 mu2=1.0 wf=1.0)```Gradient of loss function#### Parameters {.doc-section .doc-section-parameters}| Name | Type | Description | Default ||------------------|----------------------|------------------------------------------------------------------------------------------------------|------------|| x | [Array](`jax.Array`) | input tensor with shape $(D,n)$ where $D$ is the batch size and $n$ is the input size. | _required_ || y | [Array](`jax.Array`) | output tensor with shape $(D,1)$ | _required_ || f | [Array](`jax.Array`) | force tensor with shape $(D,n)$ | `None` || basis_grad | [bool](`bool`) | calculate $w,b$ grad | `True` || coordinator_grad | [bool](`bool`) | calculate $U$ grad | `True` || wf | [float](`float`) | Weight $w_f$ of force term in loss function. | `1.0` |#### Returns {.doc-section .doc-section-returns}| Name | Type | Description ||--------|---------------------------------------------------------------------|----------------------------------------------------|| | [list](`list`)\[[Parameter](`pompon.layers.parameters.Parameter`)\] | list[Parameter]: list of parameters with gradients |### import_h5 { #pompon.sop.SumOfProducts.import_h5 }```pythonsop.SumOfProducts.import_h5(path)```Import the model from a HDF5 file#### Parameters {.doc-section .doc-section-parameters}| Name | Type | Description | Default ||--------|--------------|-----------------------|------------|| path | [str](`str`) | path to the HDF5 file | _required_ |#### Returns {.doc-section .doc-section-returns}| Name | Type | Description ||--------|-------------------------------|----------------|| Model | [Model](`pompon.model.Model`) | model instance |#### Examples {.doc-section .doc-section-examples}```pythonimport pomponmodel = pompon.NNMPO.import_h5("/path/to/model.h5")```#### See Also {.doc-section .doc-section-see-also}[export_h5()](#pompon.model.NNMPO.export_h5)### mse { #pompon.sop.SumOfProducts.mse }```pythonsop.SumOfProducts.mse(x, y)```Mean squared error#### Parameters {.doc-section .doc-section-parameters}| Name | Type | Description | Default ||--------|----------------------|------------------------------------------------------------------------------------------------------|------------|| x | [Array](`jax.Array`) | input tensor with shape $(D,n)$ where $D$ is the batch size and $n$ is the input size. | _required_ || y | [Array](`jax.Array`) | output tensor with shape $(D,1)$ | _required_ |#### Returns {.doc-section .doc-section-returns}| Name | Type | Description ||--------|------------------|--------------------|| float | [float](`float`) | mean squared error |### mse_force { #pompon.sop.SumOfProducts.mse_force }```pythonsop.SumOfProducts.mse_force(x, f)```Mean squared error with force#### Parameters {.doc-section .doc-section-parameters}| Name | Type | Description | Default ||--------|----------------------|------------------------------------------------------------------------------------------------------|------------|| x | [Array](`jax.Array`) | input tensor with shape $(D,n)$ where $D$ is the batch size and $n$ is the input size. | _required_ || f | [Array](`jax.Array`) | force tensor with shape $(D,n)$ | _required_ |### plot_basis { #pompon.sop.SumOfProducts.plot_basis }```pythonsop.SumOfProducts.plot_basis(x)```Plot distribution of $\phi$#### Parameters {.doc-section .doc-section-parameters}| Name | Type | Description | Default ||--------|----------------------|------------------------------------------------------------------------------------------------------|------------|| x | [Array](`jax.Array`) | input tensor with shape $(D,n)$ where $D$ is the batch size and $n$ is the input size. | _required_ |#### Examples {.doc-section .doc-section-examples}```{python}import numpy as npimport pomponx = np.random.rand(10, 3)model = pompon.NNMPO(input_size=3, hidden_size=3, basis_size=5, activation="gauss", b_scale=1.0, w_scale=1.0)model.plot_basis(x)```### show_onebody { #pompon.sop.SumOfProducts.show_onebody }```pythonsop.SumOfProducts.show_onebody()```Visualize one-dimensional cut.#### Examples {.doc-section .doc-section-examples}```{python}import pomponmodel = pompon.NNMPO(input_size=3, hidden_size=3, basis_size=5)model.show_onebody()```### to_nnmpo { #pompon.sop.SumOfProducts.to_nnmpo }```pythonsop.SumOfProducts.to_nnmpo()```Convert to NNMPO model