numpy.real - python examples

Here are the examples of the python api numpy.real taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

5 View Complete Implementation : local_energy_stats.py
Copyright MIT License
Author : HUJI-Deep
    def add_energy_stats_to_logs(self, logs, generator, prefix=""):
        logs['%senergy/energy' % prefix] = numpy.real(generator.current_energy)
        logs['%senergy/local_energy_variance' % prefix] = numpy.real(generator.current_local_energy_variance)
        if self.true_ground_state_energy is not None:
            logs['%senergy/relative_error' % prefix] = (self.true_ground_state_energy - numpy.real(
                generator.current_energy)) / self.true_ground_state_energy

5 View Complete Implementation : local_energy.py
Copyright MIT License
Author : HUJI-Deep
    def add_energy_to_logs(self, logs):
        logs['energy/energy'] = numpy.real(self.exact_variational.energy_observable.current_energy)
        logs['energy/local_energy_variance'] = numpy.real(self.exact_variational.energy_observable.current_local_energy_variance)
        if self.true_ground_state_energy is not None:
            logs['energy/relative_error'] = (self.true_ground_state_energy - numpy.real(self.exact_variational.energy_observable.current_energy)) \
                                            / self.true_ground_state_energy

3 View Complete Implementation : _ode.py
Copyright MIT License
Author : ktraunmueller
    def set_initial_value(self, y, t=0.0):
        """Set initial conditions y(t) = y."""
        y = asarray(y)
        self.tmp = zeros(y.size * 2, 'float')
        self.tmp[::2] = real(y)
        self.tmp[1::2] = imag(y)
        if self.cjac is not None:
            self.jac_tmp = zeros((y.size * 2, y.size * 2), 'float')
        return ode.set_initial_value(self, self.tmp, t)

3 View Complete Implementation : _ode.py
Copyright MIT License
Author : ktraunmueller
    def _wrap_jac(self, t, y, *jac_args):
        jac = self.cjac(*((t, y[::2] + 1j * y[1::2]) + jac_args))
        self.jac_tmp[1::2, 1::2] = self.jac_tmp[::2, ::2] = real(jac)
        self.jac_tmp[1::2, ::2] = imag(jac)
        self.jac_tmp[::2, 1::2] = -self.jac_tmp[1::2, ::2]
        return self.jac_tmp

3 View Complete Implementation : _ode.py
Copyright MIT License
Author : ktraunmueller
    def set_initial_value(self, y, t=0.0):
        """Set initial conditions y(t) = y."""
        y = asarray(y)
        self.tmp = zeros(y.size * 2, 'float')
        self.tmp[::2] = real(y)
        self.tmp[1::2] = imag(y)
        if self.cjac is not None:
            self.jac_tmp = zeros((y.size * 2, y.size * 2), 'float')
        return ode.set_initial_value(self, self.tmp, t)

3 View Complete Implementation : _ode.py
Copyright MIT License
Author : ktraunmueller
    def _wrap_jac(self, t, y, *jac_args):
        jac = self.cjac(*((t, y[::2] + 1j * y[1::2]) + jac_args))
        self.jac_tmp[1::2, 1::2] = self.jac_tmp[::2, ::2] = real(jac)
        self.jac_tmp[1::2, ::2] = imag(jac)
        self.jac_tmp[::2, 1::2] = -self.jac_tmp[1::2, ::2]
        return self.jac_tmp

3 View Complete Implementation : test_autoregressive.py
Copyright MIT License
Author : HUJI-Deep
@pytest.mark.parametrize('machine_input, machine_clast, machine_args', [
    (ONE_DIM_INPUT, SimpleConvNetAutoregressive1D, {'depth': 7, 'num_of_channels': 16, 'weights_normalization': False}),
    (TWO_DIM_INPUT, ConvNetAutoregressive2D, {'depth': 4, 'num_of_channels': 16, 'weights_normalization': False})
])
def test_autoregressive_have_normalize_distribution(machine_input, machine_clast, machine_args):
    with graph.as_default():
        machine = machine_clast(machine_input, **machine_args)
        model = Model(inputs=machine_input, outputs=machine.predictions)
        log_wave_function = to_log_wave_function_vector(model)
        log_distribution = numpy.real(2 * log_wave_function)
        log_distribution_sum = scipy.special.logsumexp(log_distribution)
        distribution_sum = numpy.exp(log_distribution_sum)
        astert distribution_sum == pytest.approx(1.0, 0.00001)

3 View Complete Implementation : _ode.py
Copyright Apache License 2.0
Author : dnanexus
    def _wrap_jac(self, t, y, *jac_args):
        jac = self.cjac(*((t, y[::2] + 1j * y[1::2]) + jac_args))
        self.jac_tmp[1::2, 1::2] = self.jac_tmp[::2, ::2] = real(jac)
        self.jac_tmp[1::2, ::2] = imag(jac)
        self.jac_tmp[::2, 1::2] = -self.jac_tmp[1::2, ::2]
        return self.jac_tmp

3 View Complete Implementation : mcmc_stats.py
Copyright MIT License
Author : HUJI-Deep
    def add_mcmc_logs(self, logs):
        r_hat, _, correlations_sum, effective_sample_size = self.generator.sampler.calc_r_hat_value(
            numpy.real(self.generator.current_local_energy))
        logs['mcmc/acceptance_ratio'] = self.generator.sampler.acceptance_ratio
        logs['mcmc/energy_r_hat'] = r_hat
        logs['mcmc/energy_effective_sample_size'] = effective_sample_size
        logs['mcmc/energy_correlations_sum'] = correlations_sum

3 View Complete Implementation : test_ltisys.py
Copyright MIT License
Author : luckystarufo
def _astert_poles_close(P1,P2, rtol=1e-8, atol=1e-8):
    """
    Check each pole in P1 is close to a pole in P2 with a 1e-8
    relative tolerance or 1e-8 absolute tolerance (useful for zero poles).
    These tolerances are very strict but the systems tested are known to
    accept these poles so we should not be far from what is requested.
    """
    P2 = P2.copy()
    for p1 in P1:
        found = False
        for p2_idx in range(P2.shape[0]):
            if np.allclose([np.real(p1), np.imag(p1)],
                           [np.real(P2[p2_idx]), np.imag(P2[p2_idx])],
                           rtol, atol):
                found = True
                np.delete(P2, p2_idx)
                break
        if not found:
            raise ValueError("Can't find pole " + str(p1) + " in " + str(P2))