Esempio n. 1
0
def _check_dims(y_pred, y_true):
    if y_true.shape[-1] == 1 and y_pred.shape[-1] != 1:
        n_c = y_pred.shape[-1]
        y_true = true_one_hot(y_true, n_c)
    if y_true.shape != y_pred.shape:
        raise UnsupportedShapeError(y_true.shape, y_pred.shape)
    return y_true
Esempio n. 2
0
 def __call__(self, shape):
     if isinstance(shape, int):
         return self.gain * np.eye(shape)
     elif len(shape) == 2:
         return self.gain * np.eye(*shape)
     else:
         raise UnsupportedShapeError(shape, 'N or (N, M)')
Esempio n. 3
0
	def add_data(self, x):
		"""Add features to a dataset."""
		x = np.array(x)
		if self.target is not None:
			if x.shape[0] != self.target.shape[0]:
				raise UnsupportedShapeError(x.shape[0], self.target.shape[0])
		self.data = x
		return self
Esempio n. 4
0
	def add_targets(self, y):
		"""add labels to a dataset."""
		y = np.array(y)
		if self.data is not None:
			if self.data.shape[0] != y.shape[0]:
				raise UnsupportedShapeError(y.shape[0], self.data.shape[0])
		self.target = y

		return self
Esempio n. 5
0
	def __init__(self, x=None, y=None):
		self.data = None
		self.target = None
		if x is not None:
			self.data = np.array(x)
		if y is not None:
			self.target = np.array(y)
		if x is not None and y is not None:
			if self.data.shape[0] != self.target.shape[0]:
				raise UnsupportedShapeError(x.shape[0], y.shape[0])
		self.is_batched = False
Esempio n. 6
0
def _check_dims(weights, dw):
    if weights.shape != dw.shape:
        raise UnsupportedShapeError(dw.shape, weights.shape)
Esempio n. 7
0
 def add_input_shape_to_layers(self, n_in):
     if n_in != self.n_in:
         raise UnsupportedShapeError(n_in, self.n_in)
     if self.layers:
         return self.layers[-1].n_out