Exemple #1
0
def compare_ll(settings,noise_type, n_factors):
    '''
        for each setting and number pf factors, plot the LL against iterations
    '''
    lambdas, std = settings()

    fm = FactorModel(1000, lambdas, std, seed=10)
    fm.simulate()
    cyy = fm.cov()
    lambdas, taus = fm.get_pca_factors(n_factors)
    init_params = {"lambdas" : lambdas.T, "taus" : taus}
    # init_params = {}
    # init_params["lambdas"] = np.array([[0.7, 0.7, 0.3, 0.3, 0.6, 0.7, 0.6, 0.5, 0.4],
    #                                    [-0.5,-0.1,0.8, 0.7, 0.0, 0.0, 0.0, 0.6, 0.6],
    #                                    [0.1, 0.2, 0.3, 0.8, 0.0, 0.0, 0.0, 0.0, 0.0]])

    # init_params["taus"] = np.diag([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5])

    emmlfa = EMMlFactorAnalysis(n_factors,1000, init_params, plot=False)
    emmlfa.fit(cyy)
    print("EM lambdas shape: %d * %d" % (emmlfa.lambdas.shape[0], emmlfa.lambdas.shape[1]))

    mlfa = MlFactorAnalysis(n_factors,1000, init_params, plot=False)
    mlfa.fit(cyy)
    print("ML lambdas shape: %d * %d" % (emmlfa.lambdas.shape[0], emmlfa.lambdas.shape[1]))

    plot_comparison(mlfa.ll, emmlfa.ll, file_name="exp_%s_%d" % (noise_type, n_factors))
Exemple #2
0
def compare_iter(fm,n_factors):
    fm.simulate()
    cyy = fm.cov()
    lambdas, taus = fm.get_pca_factors(n_factors)
    init_params = {"lambdas" : lambdas.T, "taus" : taus}

    emmlfa = EMMlFactorAnalysis(n_factors,1000, init_params, plot=False)
    emmlfa.fit(cyy)

    mlfa = MlFactorAnalysis(n_factors,1000, init_params, plot=False)
    mlfa.fit(cyy)
    return mlfa.iterations, mlfa.lambdas, mlfa.taus, emmlfa.iterations, emmlfa.lambdas, emmlfa.taus, cyy[0][0]