def load(cls, path):
        """
        Load a recursive SOM from a JSON file.

        You can use this function to load weights of other SOMs.
        If there are no context weights, they will be set to 0.

        Parameters
        ----------
        path : str
            The path to the JSON file.

        Returns
        -------
        s : cls
            A som of the specified class.

        """
        data = json.load(open(path))

        weights = data['weights']
        weights = np.asarray(weights, dtype=np.float64)

        try:
            context_weights = data['context_weights']
            context_weights = np.asarray(context_weights,
                                         dtype=np.float64)
        except KeyError:
            context_weights = np.zeros((len(weights), len(weights)))

        try:
            alpha = data['alpha']
            beta = data['beta']
        except KeyError:
            alpha = 1.0
            beta = 1.0

        s = cls(data['map_dimensions'],
                data['data_dimensionality'],
                data['params']['lr']['orig'],
                influence=data['params']['infl']['orig'],
                alpha=alpha,
                beta=beta,
                lr_lambda=data['params']['lr']['factor'],
                infl_lambda=data['params']['infl']['factor'])

        s.weights = weights
        s.context_weights = context_weights
        s.trained = True

        return s
def load ( cls , path ) : data = json . load ( open ( path ) ) weights = data [ 'weights' ] weights = np . asarray ( weights , dtype = np . float64 ) try : context_weights = data [ 'context_weights' ] context_weights = np . asarray ( context_weights , dtype = np . float64 ) except KeyError : context_weights = np . zeros ( ( len ( weights ) , len ( weights ) ) ) try : alpha = data [ 'alpha' ] beta = data [ 'beta' ] except KeyError : alpha = 1.0 beta = 1.0 s = cls ( data [ 'map_dimensions' ] , data [ 'data_dimensionality' ] , data [ 'params' ] [ 'lr' ] [ 'orig' ] , influence = data [ 'params' ] [ 'infl' ] [ 'orig' ] , alpha = alpha , beta = beta , lr_lambda = data [ 'params' ] [ 'lr' ] [ 'factor' ] , infl_lambda = data [ 'params' ] [ 'infl' ] [ 'factor' ] ) s . weights = weights s . context_weights = context_weights s . trained = True return s
Load a recursive SOM from a JSON file.

        You can use this function to load weights of other SOMs.
        If there are no context weights, they will be set to 0.

        Parameters
        ----------
        path : str
            The path to the JSON file.

        Returns
        -------
        s : cls
            A som of the specified class.