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.
98 Examples
3
Source : tracking.py
with MIT License
from alan-turing-institute
with MIT License
from alan-turing-institute
def errors_update(self, i, y, T, n_pred, theta_true=None):
Y_pred = np.array([self._y_pred[k] for k in range(1, T + n_pred + 1)])
Y_true = np.array([y[k] for k in range(1, T + n_pred + 1)])
Y_pred = Y_pred.squeeze().T
Y_true = Y_true.squeeze().T
self._E_y[i] = np.linalg.norm(Y_pred - Y_true).item()
self._E_train[i] = np.linalg.norm(Y_pred[:, :T] - Y_true[:, :T]).item()
self._E_pred[i] = np.linalg.norm(Y_pred[:, T:] - Y_true[:, T:]).item()
if not theta_true is None:
self._E_theta[i] = np.linalg.norm(
self._theta[i] - theta_true
).item()
def figures_init(self, live_plot=False):
3
Source : lqr.py
with MIT License
from BlueRiverTech
with MIT License
from BlueRiverTech
def LQR_control():
# Cost matrices for LQR
Q = np.diag(np.array([1, 1, 1, 1])) # state_dimension = 4
R = np.eye(1) # control_dimension = 1
A, B = computeAB(np.array([0.0, 0.0, 0.0, 0.0]), np.array([0.0]))
# Use if discrete forward dynamics is used
X = sp_linalg.solve_discrete_are(A, B, Q, R)
K = np.dot(np.linalg.pinv(R + np.dot(B.T, np.dot(X, B))), np.dot(B.T, np.dot(X, A)))
# Use for continuous version of LQR
# X = sp_linalg.solve_continuous_are(A, B, Q, R)
# K = np.dot(np.linalg.pinv(R), np.dot(B.T, X))
return np.squeeze(K, 0)
def main():
3
Source : ilqr_policy.py
with MIT License
from cap-ntu
with MIT License
from cap-ntu
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)
def copy_from(self, obj) -> bool:
3
Source : lqr_policy.py
with MIT License
from cap-ntu
with MIT License
from cap-ntu
def _forward(self, obs, step: None):
self.Lqr_instance.backward(np.array([obs]), np.array([self.action_space.sample()]))
x = obs
u = self.Lqr_instance.get_action_one_step(x, t=step if step else 0)
return u
@property
3
Source : exponential.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def lambda_cb(self, x, failure_rate, cv_matrix, alpha_ci=0.05):
return failure_rate * np.exp(np.array([-1, 1]).reshape(2, 1) * (z(alpha_ci/2) *
np.sqrt(cv_matrix.item()) / failure_rate))
# def R_cb(self, x, failure_rate, cv_matrix, alpha_ci=0.05):
# return np.exp(-self.lambda_cb(x, failure_rate, cv_matrix, alpha_ci=alpha_ci) * x).T
Exponential = Exponential_('Exponential')
3
Source : gumbel.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def z_cb(self, x, mu, sigma, cv_matrix, alpha_ci=0.05):
z_hat = (x - mu)/sigma
var_z = self.var_z(x, mu, sigma, cv_matrix)
bounds = z_hat + np.array([1., -1.]).reshape(2, 1) * z(alpha_ci/2) * np.sqrt(var_z)
return bounds
# def R_cb(self, x, mu, sigma, cv_matrix, alpha_ci=0.05):
# return self.sf(self.z_cb(x, mu, sigma, cv_matrix, alpha_ci=alpha_ci), 0, 1).T
Gumbel = Gumbel_('Gumbel')
3
Source : lognormal.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def z_cb(self, x, mu, sigma, cv_matrix, alpha_ci=0.05):
z_hat = (x - mu)/sigma
var_z = self.var_z(x, mu, sigma, cv_matrix)
bounds = z_hat + np.array([1., -1.]).reshape(2, 1) * z(alpha_ci/2) * np.sqrt(var_z)
return bounds
# def R_cb(self, x, mu, sigma, cv_matrix, alpha_ci=0.05):
# t = np.log(x)
# return para.Normal.sf(self.z_cb(t, mu, sigma, cv_matrix, alpha_ci=alpha_ci), 0, 1).T
def _mom(self, x):
3
Source : normal.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def z_cb(self, x, mu, sigma, cv_matrix, alpha_ci=0.05):
z_hat = (x - mu)/sigma
var_z = self.var_z(x, mu, sigma, cv_matrix)
bounds = z_hat + np.array([1., -1.]).reshape(2, 1) * z(alpha_ci/2) * np.sqrt(var_z)
return bounds
# def R_cb(self, x, mu, sigma, cv_matrix, alpha_ci=0.05):
# return self.sf(self.z_cb(x, mu, sigma, cv_matrix, alpha_ci=alpha_ci), 0, 1).T
Normal = Normal_('Normal')
3
Source : parametric.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def _round_vals(x):
not_different = True
i = 1
while not_different:
x_ticks = np.array(round_sig(x, i))
not_different = (np.diff(x_ticks) == 0).any()
i += 1
return x_ticks
class Parametric():
3
Source : weibull.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def u_cb(self, x, alpha, beta, cv_matrix, alpha_ci, bound='two-sided'):
u = self.u(x, alpha, beta)
var_u = self.var_u(x, alpha, beta, cv_matrix)
if bound == 'two-sided':
diff = z(alpha_ci/2) * np.array([1., -1.]).reshape(2, 1)
elif bound == 'upper':
diff = z(alpha_ci)
else:
diff = -z(alpha_ci)
u_cb = u + (diff * np.sqrt(var_u))
return u_cb
def du(self, x, alpha, beta):
3
Source : accelerated_failure_time.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def Hf(self, x, X, *params):
dist_params = np.array(params[0:self.k_dist])
phi_params = np.array(params[self.k_dist:])
return self.Hf_dist(self.phi(X, *phi_params) * x, *dist_params)
def hf(self, x, X, *params):
3
Source : accelerated_failure_time.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def hf(self, x, X, *params):
dist_params = np.array(params[0:self.k_dist])
phi_params = np.array(params[self.k_dist:])
return self.hf_dist(self.phi(X, *phi_params) * x, *dist_params)
def df(self, x, X, *params):
3
Source : accelerated_failure_time.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def neg_ll(self, X, x, c, n, *params):
params = np.array(params)
like = np.zeros_like(x).astype(float)
like = np.where(c == 0, self.log_df(x, X, *params), like)
like = np.where(c == 1, self.log_sf(x, X, *params), like)
like = np.where(c == -1, self.log_ff(x, X, *params), like)
like = np.multiply(n, like)
return -np.sum(like)
def random(self, size, X, *params):
3
Source : accelerated_failure_time.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def random(self, size, X, *params):
dist_params = np.array(params[0:self.k_dist])
phi_params = np.array(params[self.k_dist:])
x = []
X_out = []
for stress in np.unique(X):
U = np.random.uniform(0, 1, size)
x.append(self.dist.qf(U, *dist_params)/self.phi(stress, *phi_params))
X_out.append(np.ones(size) * stress)
return np.concatenate(x), np.concatenate(X_out)
def fit(self, X, x, c=None, n=None, t=None, init=[], fixed={}):
3
Source : cox_ph.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def __init__(self):
self.name = 'CoxPH'
self.phi = lambda X, *params: np.exp(np.dot(X, np.array(params)))
self.phi_init = phi_init=lambda X: np.zeros(X.shape[1])
self.phi_bounds = lambda X: (((None, None),) * X.shape[1])
self.phi_param_map = lambda X: {'beta_' + str(i) : i for i in range(X.shape[1])}
def Hf(self, x, X, *params):
3
Source : cox_ph.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def neg_ll(self, X, x, c, n, *params):
params = np.array(params)
like = np.zeros_like(x).astype(float)
like = np.where(c == 0, self.log_df(x, X, *params), like)
# like = np.where(x == 0, 0, like)
like = np.where(c == 1, self.log_sf(x, X, *params), like)
like = np.where(c == -1, self.log_ff(x, X, *params), like)
like = np.multiply(n, like)
return -np.sum(like)
def neg_ll_breslow(self, X, x, c, n, *params):
3
Source : cox_ph.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def neg_ll_breslow(self, X, x, c, n, *params):
params = np.array(params)
like = np.dot(X, params)
theta = np.exp(like)
theta = theta.sum() - theta.cumsum() + theta[0]
like = n * (c == 0).astype(int) * (like - np.log(theta))
return -like.sum()
def neg_ll_breslow(self, X, x, c, n, *params):
3
Source : cox_ph.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def neg_ll_breslow(self, X, x, c, n, *params):
params = np.array(params)
like = np.dot(X, params)
theta = np.exp(like)
theta = theta.sum() - theta.cumsum() + theta[0]
like = n * (c == 0).astype(int) * (like - np.log(theta))
return -like.sum()
def fit(self, X, x, c=None, n=None, t=None, baseline='Fleming-Harrington', init=[]):
3
Source : parameter_substitution.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def df(self, x, X, *params):
x = np.array(x)
if np.isscalar(X):
X = np.ones_like(x) * X
else:
X = np.array(X)
return self.hf(x, X, *params) * np.exp(-self.Hf(x, X, *params))
def sf(self, x, X, *params):
3
Source : parameter_substitution.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def sf(self, x, X, *params):
x = np.array(x)
if np.isscalar(X):
X = np.ones_like(x) * X
else:
X = np.array(X)
return np.exp(-self.Hf(x, X, *params))
def ff(self, x, X, *params):
3
Source : parameter_substitution.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def ff(self, x, X, *params):
x = np.array(x)
if np.isscalar(X):
X = np.ones_like(x) * X
else:
X = np.array(X)
return 1 - np.exp(-self.Hf(x, X, *params))
def _parameter_initialiser_dist(self, x, c=None, n=None, t=None):
3
Source : proportional_hazards.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def Hf(self, x, X, *params):
dist_params = np.array(params[0:self.k_dist])
phi_params = np.array(params[self.k_dist:])
Hf_raw = self.Hf_dist(x, *dist_params)
return self.phi(X, *phi_params) * Hf_raw
def hf(self, x, X, *params):
3
Source : proportional_hazards.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def hf(self, x, X, *params):
dist_params = np.array(params[0:self.k_dist])
phi_params = np.array(params[self.k_dist:])
hf_raw = self.hf_dist(x, *dist_params)
return self.phi(X, *phi_params) * hf_raw
def df(self, x, X, *params):
3
Source : proportional_hazards.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def random(self, size, X, *params):
dist_params = np.array(params[0:self.k_dist])
phi_params = np.array(params[self.k_dist:])
random = []
U = np.random.uniform(0, 1, size)
x = self.dist.qf(U**(self.phi(X, *phi_params)), *dist_params)
X_out = np.ones_like(x) * X
return x.flatten(), X_out.flatten()
def neg_ll(self, X, x, c, n, *params):
3
Source : proportional_hazards.py
with MIT License
from derrynknife
with MIT License
from derrynknife
def neg_ll(self, X, x, c, n, *params):
params = np.array(params)
like = np.zeros_like(x).astype(float)
like = np.where(c == 0, self.log_df(x, X, *params), like)
like = np.where(c == 1, self.log_sf(x, X, *params), like)
like = np.where(c == -1, self.log_ff(x, X, *params), like)
like = np.multiply(n, like)
return -np.sum(like)
def fit(self, X, x, c=None, n=None, t=None, init=[], fixed={}):
3
Source : autograd_fft.py
with MIT License
from fancompute
with MIT License
from fancompute
def objective(eps_space):
F.eps_r *= eps_space
measured = []
for t_index in range(steps):
fields = F.forward(Jz=source(t_index))
measured.append(npa.sum(fields['Ez'] * measure_pos))
measured_f = my_fft(npa.array(measured))
spectral_power = npa.square(npa.abs(measured_f))
return spectral_power
eps_space = 1.0
3
Source : methods.py
with Apache License 2.0
from google
with Apache License 2.0
from google
def rosenbrock(x):
"""Rosenbrock function: test function for evaluating algorithms."""
x = np.array(x)
x_curr, x_next = x[..., :-1], x[..., 1:]
terms = 100 * np.square(x_next - np.square(x_curr)) + np.square(1 - x_curr)
return np.sum(terms, axis=-1)
def grid(num, ndim, large=False):
3
Source : eval_curvature.py
with MIT License
from IDEALLab
with MIT License
from IDEALLab
def eval_1st_derivative(t, P, W):
assert P.shape[0] == W.shape[0]
fun_x = lambda t: eval_bezier(t, P, W)[0]
fun_y = lambda t: eval_bezier(t, P, W)[1]
dx = grad(fun_x)(t)
dy = grad(fun_y)(t)
return np.array([dx, dy])
def eval_2nd_derivative(t, P, W):
3
Source : eval_curvature.py
with MIT License
from IDEALLab
with MIT License
from IDEALLab
def eval_2nd_derivative(t, P, W):
assert P.shape[0] == W.shape[0]
fun_x = lambda t: eval_1st_derivative(t, P, W)[0]
fun_y = lambda t: eval_1st_derivative(t, P, W)[1]
ddx = grad(fun_x)(t)
ddy = grad(fun_y)(t)
return np.array([ddx, ddy])
def compute_curvature(P, W, resolution=500):
3
Source : functions.py
with MIT License
from IDEALLab
with MIT License
from IDEALLab
def __call__(self, x):
x = np.array(x, ndmin=2)
y = np.apply_along_axis(lambda x: evaluate(self.synthesize(x), self.config_fname), 1, x)
self.y = np.squeeze(y)
return self.y
def is_feasible(self, x):
3
Source : functions.py
with MIT License
from IDEALLab
with MIT License
from IDEALLab
def is_feasible(self, x):
x = np.array(x, ndmin=2)
if self.y is None:
self.y = self.__call__(x)
feasibility = np.logical_not(np.isnan(self.y))
return feasibility
def synthesize(self, x):
3
Source : functions.py
with MIT License
from IDEALLab
with MIT License
from IDEALLab
def synthesize(self, alpha):
alpha = np.array(alpha, ndmin=2)
if (not self.full) and (self.latent is None):
noise = np.zeros((alpha.shape[0],self.noise_dim))
airfoils = self.gan.synthesize(alpha, noise)
else:
latent = alpha[:, :self.latent_dim]
noise = alpha[:, self.latent_dim:]
airfoils = self.gan.synthesize(latent, noise)
return airfoils
def fit(self, target_airfoil):
3
Source : functions.py
with MIT License
from IDEALLab
with MIT License
from IDEALLab
def synthesize(self, alpha):
alpha = np.array(alpha, ndmin=2).T # dim x n_samples
airfoils = self.u_truncated @ alpha # N x n_samples
airfoils = airfoils.reshape(2, -1, alpha.shape[1])
airfoils = np.transpose(airfoils, [2,1,0]) + self.airfoil0
# # Adjust trailing head
# ind = airfoils[:,0,1] < airfoils[:,-1,1]
# mean = .5*(airfoils[ind,0,1]+airfoils[ind,-1,1])
# airfoils[ind,0,1] = airfoils[ind,-1,1] = mean
return np.squeeze(airfoils)
def fit(self, target_airfoil):
3
Source : functions.py
with MIT License
from IDEALLab
with MIT License
from IDEALLab
def synthesize(self, alpha):
alpha = np.array(alpha, ndmin=2).T # dim x n_samples
alpha = alpha.reshape(self.dim//2, 2, -1) # dim/2 x 2 x n_samples
alpha = np.transpose(alpha, [1,0,2]) # 2 x dim/2 x n_samples
airfoils = self.v_truncated @ alpha # 2 x n_points x n_samples
airfoils = np.transpose(airfoils, [2,1,0]) # n_samples x n_points x 2
airfoils = np.concatenate((airfoils, airfoils[:,:1]), axis=1)
airfoils += self.airfoil0
return np.squeeze(airfoils)
def fit(self, target_airfoil):
3
Source : functions.py
with MIT License
from IDEALLab
with MIT License
from IDEALLab
def synthesize(self, alpha):
alpha = np.array(alpha, ndmin=2)
airfoils = np.apply_along_axis(lambda x: synthesize_ffd(x, self.airfoil0, self.m, self.n, self.Px), 1, alpha)
return np.squeeze(airfoils)
def fit(self, target_airfoil):
3
Source : test_gaussian.py
with MIT License
from jackyzyb
with MIT License
from jackyzyb
def input_validation_single(alg, anm):
fe1 = False
fe2 = False
try:
alg('fdas')
except:
fe1 = True
try:
alg(np.array(['fdsa', 'asdf']))
except:
fe2 = True
if not fe1 or not fe2:
assert False, anm + " failed: did not catch invalid input"
3
Source : component.py
with MIT License
from llSourcell
with MIT License
from llSourcell
def matrix(self, _):
"""Return translation matrix in homogeneous 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.]
])
class Joint(object):
3
Source : LogisticRegression.py
with MIT License
from mkuchnik
with MIT License
from mkuchnik
def W_b(self, value):
# TODO multinomial
if self.fit_intercept:
self.coef_ = np.array([value[:-1]])
self.intercept_ = value[-1:]
else:
self.coef_ = np.array([value])
@property
3
Source : LogisticRegression.py
with MIT License
from mkuchnik
with MIT License
from mkuchnik
def indices_to_one_hot(data, nb_classes):
"""
Convert an iterable of indices to one-hot encoded labels.
From: https://stackoverflow.com/questions/37292872/how-can-i-one-hot-encode-in-python
"""
targets = np.array(data).reshape(-1)
return np.eye(nb_classes)[targets]
3
Source : LinearSVM.py
with MIT License
from mkuchnik
with MIT License
from mkuchnik
def W_b(self):
"""
Gets the weights concatenated with the bias (bias trick)
"""
weights = np.array(self.coef_)
assert weights.shape == (1, self.X_.shape[1])
weights = weights[0, :] # Unpack the weights
if not self.fit_intercept:
return weights
else:
intercept = np.array(self.intercept_)
assert intercept.shape == (1,)
W_b = np.concatenate((weights, intercept), axis=0)
return W_b
@property
3
Source : LinearSVM.py
with MIT License
from mkuchnik
with MIT License
from mkuchnik
def W_b(self, value):
if self.fit_intercept:
self.coef_ = np.array([value[:-1]])
self.intercept_ = value[-1:]
else:
self.coef_ = np.array([value])
@property
3
Source : model_tests.py
with BSD 3-Clause "New" or "Revised" License
from RaulAstudillo06
with BSD 3-Clause "New" or "Revised" License
from RaulAstudillo06
def test_posterior_covariance(self):
k = GPy.kern.Poly(2, order=1)
X1 = np.array([
[-2, 2],
[-1, 1]
])
X2 = np.array([
[2, 3],
[-1, 3]
])
Y = np.array([[1], [2]])
m = GPy.models.GPRegression(X1, Y, kernel=k)
result = m.posterior_covariance_between_points(X1, X2)
expected = np.array([[0.4, 2.2], [1.0, 1.0]]) / 3.0
self.assertTrue(np.allclose(result, expected))
def test_posterior_covariance_missing_data(self):
3
Source : model_tests.py
with BSD 3-Clause "New" or "Revised" License
from RaulAstudillo06
with BSD 3-Clause "New" or "Revised" License
from RaulAstudillo06
def test_posterior_covariance_missing_data(self):
Q = 4
k = GPy.kern.Linear(Q, ARD=True)
m = _create_missing_data_model(k, Q)
with self.assertRaises(RuntimeError):
m.posterior_covariance_between_points(np.array([[1], [2]]), np.array([[3], [4]]))
def _create_missing_data_model(kernel, Q):
3
Source : pattern_containers.py
with Apache License 2.0
from rgiordan
with Apache License 2.0
from rgiordan
def unfreeing_jacobian(self, folded_val, sparse=True):
jacobians = []
for pattern_name, pattern in self.__pattern_dict.items():
jac = pattern.unfreeing_jacobian(
folded_val[pattern_name], sparse=True)
jacobians.append(jac)
sp_jac = block_diag(jacobians, format='coo')
if sparse:
return sp_jac
else:
return np.array(sp_jac.todense())
def freeing_jacobian(self, folded_val, sparse=True):
3
Source : pattern_containers.py
with Apache License 2.0
from rgiordan
with Apache License 2.0
from rgiordan
def freeing_jacobian(self, folded_val, sparse=True):
jacobians = []
for pattern_name, pattern in self.__pattern_dict.items():
jac = pattern.freeing_jacobian(
folded_val[pattern_name], sparse=True)
jacobians.append(jac)
sp_jac = block_diag(jacobians, format='coo')
if sparse:
return sp_jac
else:
return np.array(sp_jac.todense())
def log_abs_det_unfreeing_jacobian(self, folded_val):
3
Source : pattern_containers.py
with Apache License 2.0
from rgiordan
with Apache License 2.0
from rgiordan
def unfreeing_jacobian(self, folded_val, sparse=True):
base_flat_length = self.__base_pattern.flat_length(free=True)
base_freeflat_length = self.__base_pattern.flat_length(free=True)
jacobians = []
for item in itertools.product(*self.__array_ranges):
jac = self.__base_pattern.unfreeing_jacobian(
folded_val[item], sparse=True)
jacobians.append(jac)
sp_jac = block_diag(jacobians, format='coo')
if sparse:
return sp_jac
else:
return np.array(sp_jac.todense())
def freeing_jacobian(self, folded_val, sparse=True):
3
Source : pattern_containers.py
with Apache License 2.0
from rgiordan
with Apache License 2.0
from rgiordan
def freeing_jacobian(self, folded_val, sparse=True):
base_flat_length = self.__base_pattern.flat_length(free=True)
base_freeflat_length = self.__base_pattern.flat_length(free=True)
jacobians = []
for item in itertools.product(*self.__array_ranges):
jac = self.__base_pattern.freeing_jacobian(
folded_val[item], sparse=True)
jacobians.append(jac)
sp_jac = block_diag(jacobians, format='coo')
if sparse:
return sp_jac
else:
return np.array(sp_jac.todense())
@classmethod
0
Source : tracking.py
with MIT License
from alan-turing-institute
with MIT License
from alan-turing-institute
def figure_subspace_update(self, T, x_true=None):
self._fig_subspace.clf()
if x_true:
X_true = np.array([x_true[k] for k in range(0, T + 1)])
X_true = X_true.squeeze().T
X_pred = np.array([self._mu[k] for k in range(0, T + 1)])
X_pred = X_pred.squeeze().T
X_pred = X_pred.reshape(self._r, T + 1)
used = set()
for l in range(self._r):
ax = self._fig_subspace.add_subplot(
2, int((self._r + 1) / 2), l + 1
)
if x_true:
pl = np.argmin(
[
np.linalg.norm(X_true[l] - X_pred[m])
if not m in used
else np.inf
for m in range(self._r)
]
)
ax.plot(np.squeeze(X_true[l, :]), color="#004488", alpha=0.7)
ax.plot(np.squeeze(X_pred[pl, :]), "--", color="#bb5566")
used.add(pl)
else:
ax.plot(np.squeeze(X_pred[l, :]), "--", color="#bb5566")
ax.axis("off")
plt.pause(0.01)
def figure_error_update(self):
0
Source : tracking.py
with MIT License
from alan-turing-institute
with MIT License
from alan-turing-institute
def figure_error_update(self):
idx = sorted(self._E_train.keys())
E_train = np.array([self._E_train[i] for i in idx])
E_pred = np.array([self._E_pred[i] for i in idx])
if not self._E_theta is None:
E_theta = np.array([self._E_theta[i] for i in idx])
err = [E_train, E_pred, E_theta]
titles = [
"$||y^* - Cx||^2$ (train)",
"$||y^* - Cx||^2$ (pred)",
"$||\\theta^* - \\theta||^2$",
]
else:
err = [E_train, E_pred]
titles = ["$||y^* - Cx||^2$ (train)", "$||y^* - Cx||^2$ (pred)"]
self._fig_error.clf()
for l in range(len(err)):
ax = self._fig_error.add_subplot(len(err), 1, l + 1)
ax.plot(idx, err[l])
ax.title.set_text(titles[l])
plt.pause(0.01)
def figure_save(
0
Source : tracking.py
with MIT License
from alan-turing-institute
with MIT License
from alan-turing-institute
def figure_save(
self,
name,
filename,
y_obs=None,
x_true=None,
n_pred=None,
T=None,
fit_figsize=None,
):
assert name in ["fit", "bases", "cost_y", "cost_theta"]
if name == "cost_y":
idx = sorted(self._E_y.keys())
E_y = np.array([self._E_y[i] for i in idx])
plt.close(self._fig_error)
self._fig_error = plt.figure(figsize=(7.5, 2))
plt.plot(E_y, color="#bb5566")
plt.xlabel("Iterations", fontsize=14)
plt.ylabel("Frobenius norm", fontsize=14)
fig = self._fig_error
elif name == "cost_theta":
idx = sorted(self._E_theta.keys())
E_theta = np.array([self._E_theta[i] for i in idx])
plt.close(self._fig_error)
self._fig_error = plt.figure(figsize=(7.5, 2))
plt.plot(E_theta, color="#bb5566")
plt.xlabel("Iterations", fontsize=14)
plt.ylabel("Frobenius norm", fontsize=14)
fig = self._fig_error
elif name == "fit":
self._fig_fit = plt.figure(figsize=fit_figsize)
self.figure_fit_update(y_obs, n_pred, T)
fig = self._fig_fit
elif name == "bases":
self.figure_subspace_update(T, x_true=x_true)
fig = self._fig_subspace
fig.savefig(
filename,
dpi=None,
facecolor="w",
edgecolor="w",
orientation="portrait",
format="pdf",
bbox_inches="tight",
pad_inches=0,
metadata={'Creator': None, 'Producer': None, 'CreationDate': None},
)
def figures_save(
See More Examples