pymks/mks_localization_model.py
def fit(self, X, y, size=None):
        """
        Fits the data by calculating a set of influence coefficients.

        Args:
            X (ND array): The microstructure, an `(n_samples, n_x, ...)`
                shaped array where `n_samples` is the number of samples and
                `n_x` is the spatial discretization.
            y (ND array): The response field, same shape as `X`.
            size (tuple, optional): Alters the shape of X and y during the
                calibration of the influence coefficients. If None, the size
                of the influence coefficients is the same shape as `X` and `y`.

        Example

        >>> X = np.linspace(0, 1, 4).reshape((1, 2, 2))
        >>> y = X.swapaxes(1, 2)
        >>> from .bases import PrimitiveBasis
        >>> prim_basis = PrimitiveBasis(2, [0, 1])
        >>> model = MKSLocalizationModel(basis=prim_basis)
        >>> model.fit(X, y)
        >>> assert np.allclose(model._filter.Fkernel, [[[ 0.5,  0.5],
        ...                                             [  -2,    0]],
        ...                                            [[-0.5,  0  ],
        ...                                             [  -1,  0  ]]])
        """
        self.basis = self.basis.__class__(self.n_states, self.domain)
        if size is not None:
            y = self._reshape_feature(y, size)
            X = self._reshape_feature(X, size)
        if not len(y.shape) > 1:
            raise RuntimeError("The shape of y is incorrect.")
        if y.shape != X.shape:
            raise RuntimeError("X and y must be the same shape.")
        X_ = self.basis.discretize(X)
        axes = np.arange(X_.ndim)[1:-1]
        FX = np.fft.fftn(X_, axes=axes)
        Fy = np.fft.fftn(y, axes=axes)
        Fkernel = np.zeros(FX.shape[1:], dtype=np.complex)
        s0 = (slice(None),)
        for ijk in np.ndindex(X_.shape[1:-1]):
            s1 = self.basis._get_basis_slice(ijk, s0)
            Fkernel[ijk + s1] = lstsq(FX[s0 + ijk + s1], Fy[s0 + ijk])[0]
        self._filter = Filter(Fkernel[None])

        Fits the data by calculating a set of influence coefficients.

        Args:
            X (ND array): The microstructure, an `(n_samples, n_x, ...)`
                shaped array where `n_samples` is the number of samples and
                `n_x` is the spatial discretization.
            y (ND array): The response field, same shape as `X`.
            size (tuple, optional): Alters the shape of X and y during the
                calibration of the influence coefficients. If None, the size
                of the influence coefficients is the same shape as `X` and `y`.

        Example

        >>> X = np.linspace(0, 1, 4).reshape((1, 2, 2))
        >>> y = X.swapaxes(1, 2)
        >>> from .bases import PrimitiveBasis
        >>> prim_basis = PrimitiveBasis(2, [0, 1])
        >>> model = MKSLocalizationModel(basis=prim_basis)
        >>> model.fit(X, y)
        >>> assert np.allclose(model._filter.Fkernel, [[[ 0.5,  0.5],
        ...                                             [  -2,    0]],
        ...                                            [[-0.5,  0  ],
        ...                                             [  -1,  0  ]]])
        
Fits the data by calculating a set of influence coefficients.
Fits the data by calculating a set of influence coefficients .
def fit(self, X, y, size=None):
        self.basis = self.basis.__class__(self.n_states, self.domain)
        if size is not None:
            y = self._reshape_feature(y, size)
            X = self._reshape_feature(X, size)
        if not len(y.shape) > 1:
            raise RuntimeError("The shape of y is incorrect.")
        if y.shape != X.shape:
            raise RuntimeError("X and y must be the same shape.")
        X_ = self.basis.discretize(X)
        axes = np.arange(X_.ndim)[1:-1]
        FX = np.fft.fftn(X_, axes=axes)
        Fy = np.fft.fftn(y, axes=axes)
        Fkernel = np.zeros(FX.shape[1:], dtype=np.complex)
        s0 = (slice(None),)
        for ijk in np.ndindex(X_.shape[1:-1]):
            s1 = self.basis._get_basis_slice(ijk, s0)
            Fkernel[ijk + s1] = lstsq(FX[s0 + ijk + s1], Fy[s0 + ijk])[0]
        self._filter = Filter(Fkernel[None])
def fit ( self , X , y , size = None ) : self . basis = self . basis . __class__ ( self . n_states , self . domain ) if size is not None : y = self . _reshape_feature ( y , size ) X = self . _reshape_feature ( X , size ) if not len ( y . shape ) > 1 : raise RuntimeError ( "The shape of y is incorrect." ) if y . shape != X . shape : raise RuntimeError ( "X and y must be the same shape." ) X_ = self . basis . discretize ( X ) axes = np . arange ( X_ . ndim ) [ 1 : - 1 ] FX = np . fft . fftn ( X_ , axes = axes ) Fy = np . fft . fftn ( y , axes = axes ) Fkernel = np . zeros ( FX . shape [ 1 : ] , dtype = np . complex ) s0 = ( slice ( None ) , ) for ijk in np . ndindex ( X_ . shape [ 1 : - 1 ] ) : s1 = self . basis . _get_basis_slice ( ijk , s0 ) Fkernel [ ijk + s1 ] = lstsq ( FX [ s0 + ijk + s1 ] , Fy [ s0 + ijk ] ) [ 0 ] self . _filter = Filter ( Fkernel [ None ] )
Fits the data by calculating a set of influence coefficients.
Fits the data by calculating a set of influence coefficients .
"""
        Fits the data by calculating a set of influence coefficients.

        Args:
            X (ND array): The microstructure, an `(n_samples, n_x, ...)`
                shaped array where `n_samples` is the number of samples and
                `n_x` is the spatial discretization.
            y (ND array): The response field, same shape as `X`.
            size (tuple, optional): Alters the shape of X and y during the
                calibration of the influence coefficients. If None, the size
                of the influence coefficients is the same shape as `X` and `y`.

        Example

        >>> X = np.linspace(0, 1, 4).reshape((1, 2, 2))
        >>> y = X.swapaxes(1, 2)
        >>> from .bases import PrimitiveBasis
        >>> prim_basis = PrimitiveBasis(2, [0, 1])
        >>> model = MKSLocalizationModel(basis=prim_basis)
        >>> model.fit(X, y)
        >>> assert np.allclose(model._filter.Fkernel, [[[ 0.5,  0.5],
        ...                                             [  -2,    0]],
        ...                                            [[-0.5,  0  ],
        ...                                             [  -1,  0  ]]])
        """
self
X
The microstructure, an `(n_samples, n_x, ...)`
shaped array where `n_samples` is the number of samples and
`n_x` is the spatial discretization.
The microstructure an ` ( n_samples n_x ... ) ` shaped array where ` n_samples ` is the number of samples and ` n_x ` is the spatial discretization .
y
The response field, same shape as `X`.
The response field same shape as ` X ` .
size
Alters the shape of X and y during the
calibration of the influence coefficients. If None, the size
of the influence coefficients is the same shape as `X` and `y`.
Alters the shape of X and y during the calibration of the influence coefficients . If None the size of the influence coefficients is the same shape as ` X ` and ` y ` .