autograd.numpy.array - python examples

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

55 Examples 7

3 View Complete Implementation : frisk.py
Copyright MIT License
Author : andymiller
def process_dataset():
    data_dir = os.path.dirname(__file__)
    df = pd.read_csv(os.path.join(data_dir, 'data/frisk/frisk_with_noise.dat'), skiprows=6, delim_whitespace=True)

    # compute proportion black in precinct, black = 1
    # first aggregate by precinct/ethnicity, and sum over populations
    popdf = df[['pop', 'precinct', 'eth']]. \
                groupby(['precinct', 'eth'])['pop'].apply(sum)
    percent_black = np.array([ popdf[i][1] / float(popdf[i].sum())
                               for i in xrange(1, 76)] )
    precinct_type = pd.cut(percent_black, [0, .1, .4, 1.])  #
    df['precinct_type'] = precinct_type.codes[df.precinct.values-1]
    return df

3 View Complete Implementation : numpy_grads.py
Copyright MIT License
Author : BB-UCL
def forward_grad_np_var(g, ans, gvs, vs, x, axis=None, ddof=0, keepdims=False):
    if axis is None:
        if gvs.iscomplex:
            num_reps = gvs.size / 2
        else:
            num_reps = gvs.size
    elif isinstance(axis, int):
        num_reps = gvs.shape[axis]
    elif isinstance(axis, tuple):
        num_reps = anp.prod(anp.array(gvs.shape)[list(axis)])

    x_minus_mean = anp.conj(x - anp.mean(x, axis=axis, keepdims=True))
    return (2.0 * anp.sum(anp.real(g * x_minus_mean), axis=axis, keepdims=keepdims) /
            (num_reps - ddof))

3 View Complete Implementation : numpy_grads.py
Copyright MIT License
Author : BB-UCL
def forward_grad_np_std(g, ans, gvs, vs, x, axis=None, ddof=0, keepdims=False):
    if axis is None:
        if gvs.iscomplex:
            num_reps = gvs.size / 2
        else:
            num_reps = gvs.size
    elif isinstance(axis, int):
        num_reps = gvs.shape[axis]
    elif isinstance(axis, tuple):
        num_reps = anp.prod(anp.array(gvs.shape)[list(axis)])

    if num_reps <= 1:
        return vs.zeros()
    x_minus_mean = anp.conj(x - anp.mean(x, axis=axis, keepdims=True))
    return (anp.sum(anp.real(g * x_minus_mean), axis=axis, keepdims=keepdims) /
            ((num_reps - ddof) * ans))

3 View Complete Implementation : base.py
Copyright MIT License
Author : cryscan
def value(p, mu0, S0, dynmodel, policy, plant, cost, H):
    policy.p = rewrap(p, policy.p)

    M = mu0
    S = S0
    L = np.array([0])
    for t in range(H):
        M, S = plant.prop(M, S, plant, dynmodel, policy)
        L = L + cost.gamma**t * cost.fcn(M, S)
    return L

3 View Complete Implementation : ExperienceReplay.py
Copyright MIT License
Author : dtak
	def rand_unif_sample(self, n):
		"""Returns a random uniform sample of n experiences.
		
		Arguments:
		n -- number of transitions to sample
		"""
		indices = npr.choice(range(self.size), replace=False, size=n)
		exp_batch = np.array(self.exp_buffer)[indices]
		return np.reshape(exp_batch,(n, -1))

3 View Complete Implementation : test_likelihood.py
Copyright MIT License
Author : KeplerGO
@pytest.mark.parametrize("counts, ans, opt_kwargs",
        ([np.array([30, 30]), 0.5, {'optimizer': 'minimize', 'x0': 0.3, 'method': 'Nelder-Mead'}],
         [np.array([90, 10]), 0.9, {'optimizer': 'minimize', 'x0': 0.8, 'method': 'Nelder-Mead'}],
         [np.array([30, 30]), 0.5, {'optimizer': 'differential_evolution', 'bounds': [(0, 1)], 'tol': 1e-8}],
         [np.array([90, 10]), 0.9, {'optimizer': 'differential_evolution', 'bounds': [(0, 1)], 'tol': 1e-8}]))
def test_multinomial_likelihood(counts, ans, opt_kwargs):
    ber_pmf = lambda p: npa.array([p, 1 - p])
    logL = MultinomialLikelihood(data=counts, mean=ber_pmf)
    p_hat = logL.fit(**opt_kwargs)
    np.testing.astert_almost_equal(logL.uncertainties(p_hat.x),
                                   sqrt(p_hat.x[0] * (1 - p_hat.x[0]) / counts.sum()))
    astert abs(p_hat.x - ans) < 0.05
    # yyyytical jeffrey's prior
    neg_log_jeff_prior = 0.5 * (np.log(p_hat.x) + np.log(1 - p_hat.x) - np.log(counts.sum()))
    np.testing.astert_almost_equal(neg_log_jeff_prior, logL.jeffreys_prior(p_hat.x))
    np.testing.astert_almost_equal(logL.gradient(p_hat.x), 0., decimal=2)

3 View Complete Implementation : component.py
Copyright MIT License
Author : lanius
    def matrix(self, _):
        """Return translation matrix in hemogeneous coordinates."""
        x, y, z = self.coord
        return np.array([
            [1., 0., 0., x],
            [0., 1., 0., y],
            [0., 0., 1., z],
            [0., 0., 0., 1.]
        ])

3 View Complete Implementation : ilqr_policy.py
Copyright MIT License
Author : Lukeeeeee
    def forward(self, obs, **kwargs):
        obs = make_batch(obs, original_shape=self.env_spec.obs_shape).tolist()
        action = []
        if 'step' in kwargs:
            step = kwargs['step']
        else:
            step = None
        for obs_i in obs:
            action_i = self._forward(obs_i, step=step)
            action.append(action_i)
        return np.array(action)

3 View Complete Implementation : g.py
Copyright Apache License 2.0
Author : msu-coinlab
    def _calc_pareto_set(self):
        return anp.array(
            [3.16246061572185, 3.12833142812967, 3.09479212988791, 3.06145059523469, 3.02792915885555, 2.99382606701730,
             2.95866871765285, 2.92184227312450, 0.49482511456933, 0.48835711005490, 0.48231642711865, 0.47664475092742,
             0.47129550835493, 0.46623099264167, 0.46142004984199, 0.45683664767217, 0.45245876903267, 0.44826762241853,
             0.44424700958760, 0.44038285956317])

3 View Complete Implementation : g.py
Copyright Apache License 2.0
Author : msu-coinlab
    def __init__(self):
        self.n_var = 5
        self.n_constr = 6
        self.n_obj = 1
        self.func = self._evaluate
        self.xl = anp.array([78, 33, 27, 27, 27])
        self.xu = anp.array([102, 45, 45, 45, 45])
        super(G4, self).__init__(n_var=self.n_var, n_obj=self.n_obj, n_constr=self.n_constr, xl=self.xl, xu=self.xu,
                                 type_var=anp.double)