def initialize_with_standard_model(self, standard_model=None):
        """
        Initialize with a standard Hawkes model. Typically this will have
        been fit by gradient descent or BFGS, and we just want to copy
        over the parameters to get a good starting point for MCMC or VB.
        :param W:
        :param g:
        :return:
        """
        if standard_model is None:
            standard_model = DiscreteTimeStandardHawkesModel(
                K=self.K, dt=self.dt, dt_max=self.dt_max, B=self.B)

            for data in self.data_list:
                standard_model.add_data(data.S)

            standard_model.initialize_to_background_rate()
            standard_model.fit_with_bfgs()

        else:
            from pyhawkes.standard_models import StandardHawkesProcess
            assert isinstance(standard_model, StandardHawkesProcess)
            assert standard_model.K == self.K
            assert standard_model.B == self.B

        lambda0 = standard_model.bias

        # Get the connection weights
        # Wg = standard_model.weights[:,1:].reshape((self.K, self.K, self.B))
        # # Permute to out x in x basis
        # Wg = np.transpose(Wg, [1,0,2])
        # # Sum to get the total weight
        # W = Wg.sum(axis=2) + 1e-6
        W = standard_model.W + 1e-6

        # The impulse responses are normalized weights
        # g = Wg / W[:,:,None]
        # for k1 in xrange(self.K):
        #     for k2 in xrange(self.K):
        #         if g[k1,k2,:].sum() < 1e-2:
        #             g[k1,k2,:] = 1.0/self.B
        g = standard_model.G

        # Clip g to make sure it is stable for MF updates
        g = np.clip(g, 1e-2, np.inf)

        # Make sure g is normalized
        g = g / g.sum(axis=2)[:,:,None]


        # We need to decide how to set A.
        # The simplest is to initialize it to all ones, but
        # A = np.ones((self.K, self.K))
        # Alternatively, we can start with a sparse matrix
        # of only strong connections. What sparsity? How about the
        # mean under the network model
        # sparsity = self.network.tau1 / (self.network.tau0 + self.network.tau1)
        sparsity = self.network.p
        A = W > np.percentile(W, (1.0 - sparsity) * 100)

        # Set the model parameters
        self.bias_model.lambda0 = lambda0.copy('C')
        self.weight_model.A     = A.copy('C')
        self.weight_model.W     = W.copy('C')
        self.impulse_model.g    = g.copy('C')

        # if isinstance(self.network, StochasticBlockModel) and not self.network.fixed:
        #     # Cluster the standard model with kmeans in order to initialize the network
        #     from sklearn.cluster import KMeans
        #
        #     features = []
        #     for k in xrange(self.K):
        #         features.append(np.concatenate((W[:,k], W[k,:])))
        #
        #     self.network.c = KMeans(n_clusters=self.C).fit(np.array(features)).labels_
        #
        #     # print "DEBUG: Do not set p and v in init from standard model"
        #     self.network.resample_p(self.weight_model.A)
        #     self.network.resample_v(self.weight_model.A, self.weight_model.W)
        #     self.network.resample_m()
dataset/ETHPy150Open slinderman/pyhawkes/pyhawkes/models.py/_DiscreteTimeNetworkHawkesModelBase.initialize_with_standard_model/original