Example #1
0
functions_name = ['BETA', 'NM', 'SMLA', 'SMLB']

if __name__ == '__main__':
    for s in size:
        for i, fun in enumerate(functions):
            for j, tau in enumerate(taus):
                generator = LSW(pdf=fun, sample_size=s, seed=123)
                results = {'selected_param': [], 'oracle_param': [], 'oracle_loss': [], 'loss': [], 'solution': [],
                           'oracle_solution': []}
                for _ in range(replications):
                    try:
                        spectrum = LordWillisSpektor(transformed_measure=True)
                        obs = generator.generate()
                        tsvd = TSVD(kernel=kernel, singular_values=spectrum.singular_values,
                                    left_singular_functions=spectrum.left_functions,
                                    right_singular_functions=spectrum.right_functions,
                                    observations=obs, sample_size=s, transformed_measure=True,
                                    max_size=max_size, njobs=-1, tau=tau)
                        tsvd.estimate()
                        tsvd.oracle(fun)
                        solution = list(tsvd.solution(np.linspace(0, 1, 10000)))
                        results['selected_param'].append(tsvd.regularization_param)
                        results['oracle_param'].append(tsvd.oracle_param)
                        results['oracle_loss'].append(tsvd.oracle_loss)
                        results['loss'].append(tsvd.residual)
                        results['solution'].append(solution)
                        results['oracle_solution'].append(list(tsvd.oracle_solution))
                        tsvd.client.close()
                    except:
                        pass
                pd.DataFrame(results).to_csv('TSVD_{}_{}.csv'.format(functions_name[i], taus_name[j]))
Example #2
0
     'oracle_param': [],
     'oracle_loss': [],
     'loss': [],
     'solution': [],
     'oracle_solution': []
 }
 for _ in range(replications):
     try:
         spectrum = LordWillisSpektor(transformed_measure=True)
         obs = generator.generate()
         landweber = TSVD(
             kernel=kernel_transformed,
             singular_values=spectrum.singular_values,
             left_singular_functions=spectrum.left_functions,
             right_singular_functions=spectrum.right_functions,
             observations=obs,
             sample_size=s,
             max_size=max_size,
             tau=tau,
             transformed_measure=True,
             njobs=-1)
         landweber.estimate()
         landweber.oracle(fun, patience=10)
         solution = list(
             landweber.solution(np.linspace(0, 1, 10000)))
         results['selected_param'].append(
             landweber.regularization_param)
         results['oracle_param'].append(landweber.oracle_param)
         results['oracle_loss'].append(landweber.oracle_loss)
         results['loss'].append(landweber.residual)
         results['solution'].append(solution)