def transform_streamels(self, streamels): check_streamels_1D(streamels) check_streamels_continuous(streamels) if self.A0 is not None: check_streamels_1D_size(streamels, self.A0.shape[1]) self.A = self._get_A(streamels) if self.A.shape[1] != streamels.size: msg = ('I expect a matrix with rows %d, got %s' % (streamels.size, self.A.shape)) raise ValueError(msg) # Save original constraints that we can pass to inverse() self.old_streamels = streamels.copy() streamels2 = np.zeros(self.A.shape[0], streamel_dtype) streamels2['kind'][:] = ValueFormats.Continuous find_polytope_bounds_after_linear(streamels, self.A, streamels2) self.lower = streamels2['lower'].copy() self.upper = streamels2['upper'].copy() streamels2['default'] = self.transform_value(streamels['default']) return streamels2
def find_polytope_bounds_after_linear(streamels, A, streamels2): ''' Fills the 'lower' and 'upper' part of streamels2 given the A transform. ''' M, N = A.shape check_streamels_1D_size(streamels, N) check_streamels_1D_size(streamels2, M) is_diagonal = (M == N) and allclose(np.diag(np.diagonal(A)), A) if is_diagonal: streamels2['lower'] = np.dot(A, streamels['lower']) streamels2['upper'] = np.dot(A, streamels['upper']) else: # TODO: do something smarter here norm = np.abs(A).sum() # XXX lb = np.max(np.abs(streamels['lower'])) ub = np.max(np.abs(streamels['upper'])) B = max(lb, ub) streamels2['lower'] = -B * norm streamels2['upper'] = +B * norm