Skip to content

Commit

Permalink
remove function d_mui_muj
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Keil committed Jan 14, 2020
1 parent 1cf1d32 commit f74b059
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 100 deletions.
7 changes: 0 additions & 7 deletions src/pymor/operators/basic.py
Expand Up @@ -161,13 +161,6 @@ def d_mu(self, component, index=()):
from pymor.operators.constructions import ZeroOperator
return ZeroOperator(self.range, self.source, name=self.name + '_d_mu')

def d_mui_muj(self, component_i, component_j, index_i=(), index_j=()):
if self.parametric:
raise NotImplementedError
else:
from pymor.operators.constructions import ZeroOperator
return ZeroOperator(self.range, self.source, name=self.name + '_d_mui_muj')

class ListVectorArrayOperatorBase(OperatorBase):

def _prepare_apply(self, U, mu, kind, least_squares=False):
Expand Down
12 changes: 0 additions & 12 deletions src/pymor/operators/constructions.py
Expand Up @@ -168,18 +168,6 @@ def d_mu(self, component, index=()):
derivative_coefficients.append(0.)
return self.with_(coefficients=derivative_coefficients, name=self.name + '_d_mu')

def d_mui_muj(self, component_i, component_j, index_i=(), index_j=()):
for op in self.operators:
if op.parametric:
raise NotImplementedError
second_derivative_coefficients = []
for coef in self.coefficients:
if isinstance(coef, Parametric):
second_derivative_coefficients.append(coef.d_mui_muj(component_i, component_j, index_i, index_j))
else:
second_derivative_coefficients.append(0.)
return self.with_(coefficients=second_derivative_coefficients, name=self.name + '_d_mui_muj')

def apply_inverse(self, V, mu=None, least_squares=False):
if len(self.operators) == 1:
if self.coefficients[0] == 0.:
Expand Down
21 changes: 0 additions & 21 deletions src/pymor/operators/interfaces.py
Expand Up @@ -257,27 +257,6 @@ def d_mu(self, component, index=()):
"""
pass

@abstractmethod
def d_mui_muj(self, component_i, component_j, index_i=(), index_j=()):
"""Return the operator's second derivative with respect to indices of parameter components i and j.
Parameters
----------
component_i
Parameter component i
component_j
Parameter component j
index_i
index in the parameter component i
index_j
index in the parameter component j
Returns
-------
New |Operator| representing the second order partial derivative.
"""
pass

def as_range_array(self, mu=None):
"""Return a |VectorArray| representation of the operator in its range space.
Expand Down
51 changes: 13 additions & 38 deletions src/pymor/parameters/functionals.py
Expand Up @@ -49,12 +49,6 @@ def d_mu(self, component, index=()):
return ConstantParameterFunctional(1, name=self.name + '_d_mu')
return ConstantParameterFunctional(0, name=self.name + '_d_mu')

def d_mui_muj(self, component_i, component_j, index_i=(), index_j=()):
check_i, _ = self._check_and_parse_input(component_i, index_i)
check_j, _ = self._check_and_parse_input(component_j, index_j)
return ConstantParameterFunctional(0, name=self.name + '_d_mui_muj')


class GenericParameterFunctional(ParameterFunctionalInterface):
"""A wrapper making an arbitrary Python function a |ParameterFunctional|
Expand Down Expand Up @@ -100,31 +94,21 @@ def d_mu(self, component, index=()):
partial derivatives in self.parameter_type')
else:
if component in self.derivative_mappings:
return GenericParameterFunctional(self.derivative_mappings[component][index],
self.parameter_type, name=self.name + '_d_mu')
else:
raise ValueError('derivative mappings does not contain item {}'.format(component))
return ConstantParameterFunctional(0, name=self.name + '_d_mu')

def d_mui_muj(self, component_i, component_j, index_i=(), index_j=()):
check_i, index_i = self._check_and_parse_input(component_i, index_i)
check_j, index_j = self._check_and_parse_input(component_j, index_j)
if check_i and check_j:
if self.second_derivative_mappings is None:
raise ValueError('You must provide a dict of expressions for all \
second order partial derivatives in self.parameter_type')
else:
if component_i in self.second_derivative_mappings:
column_i = self.second_derivative_mappings[component_i][index_i]
if component_j in column_i:
return GenericParameterFunctional(column_i[component_j][index_j],
self.parameter_type, name=self.name + '_d_mui_muj')
if self.second_derivative_mappings is None:
return GenericParameterFunctional(self.derivative_mappings[component][index],
self.parameter_type, name=self.name + '_d_mu')
else:
raise ValueError('hessian mappings does not contain item {} for \
item {}'.format(component_j,component_i))
if component in self.second_derivative_mappings:
return GenericParameterFunctional(self.derivative_mappings[component][index],
self.parameter_type, name=self.name + '_d_mu',
derivative_mappings=self.second_derivative_mappings[component][index])
else:
return GenericParameterFunctional(self.derivative_mappings[component][index],
self.parameter_type, name=self.name + '_d_mu',
derivative_mappings={})
else:
raise ValueError('hessian mappings does not contain item {}'.format(component_i))
return ConstantParameterFunctional(0, name=self.name + '_d_mui_muj')
raise ValueError('derivative expressions does not contain item {}'.format(component))
return ConstantParameterFunctional(0, name=self.name + '_d_mu')


class ExpressionParameterFunctional(GenericParameterFunctional):
Expand Down Expand Up @@ -231,9 +215,6 @@ def evaluate(self, mu=None):
def d_mu(self, component, index=()):
raise NotImplementedError

def d_mui_muj(self, component_i, component_j, index_i=(), index_j=()):
raise NotImplementedError

class ConjugateParameterFunctional(ParameterFunctionalInterface):
"""Conjugate of a given |ParameterFunctional|
Expand Down Expand Up @@ -261,9 +242,6 @@ def evaluate(self, mu=None):
def d_mu(self, component, index=()):
raise NotImplementedError

def d_mui_muj(self, component_i, component_j, index_i=(), index_j=()):
raise NotImplementedError

class ConstantParameterFunctional(ParameterFunctionalInterface):
"""|ParameterFunctional| returning a constant value for each parameter.
Expand All @@ -284,6 +262,3 @@ def evaluate(self, mu=None):

def d_mu(self, component, index=()):
return self.with_(constant_value=0, name=self.name + '_d_mu')

def d_mui_muj(self, component_i, component_j, index_i=(), index_j=()):
return self.with_(constant_value=0, name=self.name + '_d_mui_muj')
44 changes: 22 additions & 22 deletions src/pymortests/mu_derivatives.py
Expand Up @@ -19,10 +19,10 @@ def test_ProjectionParameterFunctional():
derivative_to_first_index = pf.d_mu('mu', 0)
derivative_to_second_index = pf.d_mu('mu', 1)

second_derivative_first_first = pf.d_mui_muj('mu', 'mu', 0, 0)
second_derivative_first_second = pf.d_mui_muj('mu', 'mu', 0, 1)
second_derivative_second_first = pf.d_mui_muj('mu', 'mu', 1, 0)
second_derivative_second_second = pf.d_mui_muj('mu', 'mu', 1, 1)
second_derivative_first_first = pf.d_mu('mu', 0).d_mu('mu', 0)
second_derivative_first_second = pf.d_mu('mu', 0).d_mu('mu', 1)
second_derivative_second_first = pf.d_mu('mu', 1).d_mu('mu', 0)
second_derivative_second_second = pf.d_mu('mu', 1).d_mu('mu', 1)

der_mu_1 = derivative_to_first_index.evaluate(mu)
der_mu_2 = derivative_to_second_index.evaluate(mu)
Expand Down Expand Up @@ -63,15 +63,15 @@ def test_ExpressionParameterFunctional():
der_mu_2 = derivative_to_second_mu_index.evaluate(mu)
der_nu = derivative_to_nu_index.evaluate(mu)

second_derivative_first_mu_first_mu = epf.d_mui_muj('mu', 'mu', 0, 0)
second_derivative_first_mu_second_mu = epf.d_mui_muj('mu', 'mu', 0, 1)
second_derivative_first_mu_nu = epf.d_mui_muj('mu', 'nu', 0)
second_derivative_second_mu_first_mu = epf.d_mui_muj('mu', 'mu', 1, 0)
second_derivative_second_mu_second_mu = epf.d_mui_muj('mu', 'mu', 1, 1)
second_derivative_second_mu_nu = epf.d_mui_muj('mu', 'nu', 1)
second_derivative_nu_first_mu = epf.d_mui_muj('nu', 'mu', (), 0)
second_derivative_nu_second_mu = epf.d_mui_muj('nu', 'mu', (), 1)
second_derivative_nu_nu = epf.d_mui_muj('nu', 'nu')
second_derivative_first_mu_first_mu = epf.d_mu('mu', 0).d_mu('mu', 0)
second_derivative_first_mu_second_mu = epf.d_mu('mu', 0).d_mu('mu', 1)
second_derivative_first_mu_nu = epf.d_mu('mu', 0).d_mu('nu')
second_derivative_second_mu_first_mu = epf.d_mu('mu', 1).d_mu('mu', 0)
second_derivative_second_mu_second_mu = epf.d_mu('mu', 1).d_mu('mu', 1)
second_derivative_second_mu_nu = epf.d_mu('mu', 1).d_mu('nu')
second_derivative_nu_first_mu = epf.d_mu('nu').d_mu('mu', 0)
second_derivative_nu_second_mu = epf.d_mu('nu').d_mu('mu', 1)
second_derivative_nu_nu = epf.d_mu('nu').d_mu('nu')

hes_mu_1_mu_1 = second_derivative_first_mu_first_mu.evaluate(mu)
hes_mu_1_mu_2 = second_derivative_first_mu_second_mu.evaluate(mu)
Expand Down Expand Up @@ -158,15 +158,15 @@ def test_d_mu_of_LincombOperator():
eval_mu_2 = op_sensitivity_to_second_mu.evaluate_coefficients(mu)
eval_nu = op_sensitivity_to_nu.evaluate_coefficients(mu)

second_derivative_first_mu_first_mu = operator.d_mui_muj('mu', 'mu', 0, 0)
second_derivative_first_mu_second_mu = operator.d_mui_muj('mu', 'mu', 0, 1)
second_derivative_first_mu_nu = operator.d_mui_muj('mu', 'nu', 0)
second_derivative_second_mu_first_mu = operator.d_mui_muj('mu', 'mu', 1, 0)
second_derivative_second_mu_second_mu = operator.d_mui_muj('mu', 'mu', 1, 1)
second_derivative_second_mu_nu = operator.d_mui_muj('mu', 'nu', 1)
second_derivative_nu_first_mu = operator.d_mui_muj('nu', 'mu', (), 0)
second_derivative_nu_second_mu = operator.d_mui_muj('nu', 'mu', (), 1)
second_derivative_nu_nu = operator.d_mui_muj('nu', 'nu')
second_derivative_first_mu_first_mu = operator.d_mu('mu', 0).d_mu('mu', 0)
second_derivative_first_mu_second_mu = operator.d_mu('mu', 0).d_mu('mu', 1)
second_derivative_first_mu_nu = operator.d_mu('mu', 0).d_mu('nu')
second_derivative_second_mu_first_mu = operator.d_mu('mu', 1).d_mu('mu', 0)
second_derivative_second_mu_second_mu = operator.d_mu('mu', 1).d_mu('mu', 1)
second_derivative_second_mu_nu = operator.d_mu('mu', 1).d_mu('nu')
second_derivative_nu_first_mu = operator.d_mu('nu').d_mu('mu', 0)
second_derivative_nu_second_mu = operator.d_mu('nu').d_mu('mu', 1)
second_derivative_nu_nu = operator.d_mu('nu').d_mu('nu')

hes_mu_1_mu_1 = second_derivative_first_mu_first_mu.evaluate_coefficients(mu)
hes_mu_1_mu_2 = second_derivative_first_mu_second_mu.evaluate_coefficients(mu)
Expand Down

0 comments on commit f74b059

Please sign in to comment.