예제 #1
0
def compute_solutions(res):
    """ Compute solution from original and reconstructed parameters
    """
    # configure comparison
    omega = 0.5

    orig_conf = get_base_config(res.A.orig, res.B.orig, omega)
    rec_conf = get_base_config(res.A.rec, res.B.rec, omega)

    init = np.random.uniform(0, 2 * np.pi, size=orig_conf.o_vec.shape)

    # solve systems
    orig_sols, ots = solve_system(orig_conf, init=init)
    rec_sols, rts = solve_system(rec_conf, init=init)
    assert (ots == rts).all()

    # aggregate data
    df = pd.DataFrame()
    for orig_slice, rec_slice, t in zip(orig_sols.T, rec_sols.T, rts):
        for i, (orig_val, rec_val) in enumerate(zip(orig_slice, rec_slice)):
            df = df.append([{
                'time': t,
                'theta': orig_val,
                'oscillator': i,
                'source': 'orig'
            }, {
                'time': t,
                'theta': rec_val,
                'oscillator': i,
                'source': 'rec'
            }],
                           ignore_index=True)

    return df
예제 #2
0
def compute_solutions(res):
    """ Compute solution from original and reconstructed parameters
    """
    # configure comparison
    omega = 0.5

    orig_conf = get_base_config(res.A.orig, res.B.orig, omega)
    rec_conf = get_base_config(res.A.rec, res.B.rec, omega)

    init = np.random.uniform(0, 2*np.pi, size=orig_conf.o_vec.shape)

    # solve systems
    orig_sols, ots = solve_system(orig_conf, init=init)
    rec_sols, rts = solve_system(rec_conf, init=init)
    assert (ots == rts).all()

    # aggregate data
    df = pd.DataFrame()
    for orig_slice, rec_slice, t in zip(orig_sols.T, rec_sols.T, rts):
        for i, (orig_val, rec_val) in enumerate(zip(orig_slice, rec_slice)):
            df = df.append([
                {'time': t, 'theta': orig_val, 'oscillator': i, 'source': 'orig'},
                {'time': t, 'theta': rec_val, 'oscillator': i, 'source': 'rec'}
            ], ignore_index=True)

    return df
예제 #3
0
파일: main.py 프로젝트: kpj/OsciPy
def simulate_system(bundle, reps=10, check_laplacian=True):
    """ Generate data from system setup
    """
    # lonely investigation :'(
    if check_laplacian:
        investigate_laplacian(bundle.graph)

    # solve system on network
    corr_mats = []
    var_sers = []
    all_sols = []
    for _ in trange(reps):
        sols, ts = solve_system(bundle.system_config)

        cmat = compute_correlation_matrix(sols)
        vser = compute_cluster_num(sols, len(bundle.graph.nodes()))

        corr_mats.append(cmat)
        var_sers.append(vser)
        all_sols.append(sols)

    bundle['all_sols'] = all_sols
    bundle['corr_mats'] = np.array(corr_mats)
    bundle['var_sers'] = np.array(var_sers)
    bundle['ts'] = ts

    return bundle
예제 #4
0
def process(bundle_pack, reps=10, skipper=1):
    """ Solve system bundle and return data
    """
    # assemble final bundle from pack
    repr_bundle = bundle_pack[0]

    data = []
    for bundle in tqdm(bundle_pack):
        all_sols = []
        for _ in range(reps):
            sols, ts = solve_system(bundle.system_config, force_mod=False)
            sols, ts = reduce_information_content(sols, ts, step=skipper)

            all_sols.append(sols)
        data.append((bundle.system_config, all_sols))

    # reconstruct parameters
    rec_a, rec_b = reconstruct_coupling_params(
        DW({
            'A': repr_bundle.system_config.A,
            'B': repr_bundle.system_config.B,
            'Phi': repr_bundle.system_config.Phi,
            'dt': repr_bundle.system_config.dt,
            'ts': ts,
            'skip': skipper
        }), data, verbose=False)

    return DW({
        'A': DW({'orig': repr_bundle.system_config.A, 'rec': rec_a}),
        'B': DW({'orig': repr_bundle.system_config.B, 'rec': rec_b}),
    })
예제 #5
0
파일: main.py 프로젝트: kpj/OsciPy
def simulate_system(bundle, reps=10, check_laplacian=True):
    """ Generate data from system setup
    """
    # lonely investigation :'(
    if check_laplacian:
        investigate_laplacian(bundle.graph)

    # solve system on network
    corr_mats = []
    var_sers = []
    all_sols = []
    for _ in trange(reps):
        sols, ts = solve_system(bundle.system_config)

        cmat = compute_correlation_matrix(sols)
        vser = compute_cluster_num(sols, len(bundle.graph.nodes()))

        corr_mats.append(cmat)
        var_sers.append(vser)
        all_sols.append(sols)

    bundle['all_sols'] = all_sols
    bundle['corr_mats'] = np.array(corr_mats)
    bundle['var_sers'] = np.array(var_sers)
    bundle['ts'] = ts

    return bundle
예제 #6
0
def process(bundle_pack, reps=10, skipper=1):
    """ Solve system bundle and return data
    """
    # assemble final bundle from pack
    repr_bundle = bundle_pack[0]

    data = []
    for bundle in tqdm(bundle_pack):
        all_sols = []
        for _ in range(reps):
            sols, ts = solve_system(bundle.system_config, force_mod=False)
            sols, ts = reduce_information_content(sols, ts, step=skipper)

            all_sols.append(sols)
        data.append((bundle.system_config, all_sols))

    # reconstruct parameters
    rec_a, rec_b = reconstruct_coupling_params(DW({
        'A':
        repr_bundle.system_config.A,
        'B':
        repr_bundle.system_config.B,
        'Phi':
        repr_bundle.system_config.Phi,
        'dt':
        repr_bundle.system_config.dt,
        'ts':
        ts,
        'skip':
        skipper
    }),
                                               data,
                                               verbose=False)

    return DW({
        'A': DW({
            'orig': repr_bundle.system_config.A,
            'rec': rec_a
        }),
        'B': DW({
            'orig': repr_bundle.system_config.B,
            'rec': rec_b
        }),
    })
예제 #7
0
    def test_valid_input(self):
        variables = [
            [6, 4863, 8761, 654],
            [4863, 4521899, 8519938, 620707],
            [8761, 8519938, 21022091, 905925],
            [654, 620707, 905925, 137902]
        ]
        results = [714, 667832, 1265493, 100583]

        result = solve_system(variables, results)

        expected_result = [
            6.701336536389188,
            0.07836603673386534,
            0.015041331199344957,
            0.24605633258014775
        ]

        self.assertEqual(result, expected_result)
def recover_master(p, t, shadows, moduli):
    k0 = utils.solve_system(shadows, moduli)
    return k0 - t*p
def recover_master(p, t, shadows, moduli):
    k0 = utils.solve_system(shadows, moduli)
    return k0 - t * p