summaryrefslogtreecommitdiffstats
path: root/polymatrix/expression/mixins/derivativeexprmixin.py
diff options
context:
space:
mode:
authorMichael Schneeberger <michael.schneeberger@fhnw.ch>2022-08-04 15:23:02 +0200
committerMichael Schneeberger <michael.schneeberger@fhnw.ch>2022-08-04 15:23:02 +0200
commitde0f75c08b6d18b52dd5e595d82eecff15e02895 (patch)
treec06c731f6a9cd8ca7013e8f24c66a8e4c182ea02 /polymatrix/expression/mixins/derivativeexprmixin.py
parentadd max_degree, max and filter operator (diff)
downloadpolymatrix-de0f75c08b6d18b52dd5e595d82eecff15e02895.tar.gz
polymatrix-de0f75c08b6d18b52dd5e595d82eecff15e02895.zip
clean up and restructurings
Diffstat (limited to 'polymatrix/expression/mixins/derivativeexprmixin.py')
-rw-r--r--polymatrix/expression/mixins/derivativeexprmixin.py116
1 files changed, 3 insertions, 113 deletions
diff --git a/polymatrix/expression/mixins/derivativeexprmixin.py b/polymatrix/expression/mixins/derivativeexprmixin.py
index 4fc48a5..32823e5 100644
--- a/polymatrix/expression/mixins/derivativeexprmixin.py
+++ b/polymatrix/expression/mixins/derivativeexprmixin.py
@@ -4,12 +4,11 @@ import collections
import dataclasses
import itertools
import typing
-from polymatrix.expression.init.initderivativekey import init_derivative_key
-from polymatrix.expression.init.initpolymatrix import init_poly_matrix
+from polymatrix.polymatrix.init.initpolymatrix import init_poly_matrix
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
-from polymatrix.expression.polymatrix import PolyMatrix
-from polymatrix.expression.expressionstate import ExpressionState
+from polymatrix.polymatrix.polymatrix import PolyMatrix
+from polymatrix.expressionstate.expressionstate import ExpressionState
from polymatrix.expression.utils.getderivativemonomials import get_derivative_monomials
from polymatrix.expression.utils.getvariableindices import get_variable_indices
@@ -42,115 +41,6 @@ class DerivativeExprMixin(ExpressionBaseMixin):
state, diff_wrt_variables = get_variable_indices(state, self.variables)
- # def get_derivative_terms(
- # monomial_terms,
- # diff_wrt_variable: int,
- # state: ExpressionState,
- # considered_variables: set,
- # ):
-
- # if self.introduce_derivatives:
-
- # raise Exception('not implemented')
-
- # def gen_new_variables():
- # for monomial in monomial_terms.keys():
- # for var in monomial:
- # if var not in diff_wrt_variables and var not in considered_variables:
- # yield var
-
- # new_variables = set(gen_new_variables())
-
- # new_considered_variables = considered_variables | new_variables
-
- # def acc_state_candidates(acc, new_variable):
- # state, candidates = acc
-
- # key = init_derivative_key(
- # variable=new_variable,
- # with_respect_to=diff_wrt_variable,
- # )
- # state = state.register(key=key, n_param=1)
-
- # state, auxillary_derivation_terms = get_derivative_terms(
- # monomial_terms=state.auxillary_equations[new_variable],
- # diff_wrt_variable=diff_wrt_variable,
- # state=state,
- # considered_variables=new_considered_variables,
- # )
-
- # if 1 < len(auxillary_derivation_terms):
- # derivation_variable = state.offset_dict[key][0]
-
- # state = dataclasses.replace(
- # state,
- # auxillary_equations=state.auxillary_equations | {derivation_variable: auxillary_derivation_terms},
- # )
-
- # return state, candidates + (new_variable,)
-
- # else:
- # return state, candidates
-
- # *_, (state, confirmed_variables) = itertools.accumulate(
- # new_variables,
- # acc_state_candidates,
- # initial=(state, tuple()),
- # )
-
- # else:
- # confirmed_variables = tuple()
-
- # derivation_terms = collections.defaultdict(float)
-
- # for monomial, value in monomial_terms.items():
-
- # # # count powers for each variable
- # # monomial_cnt = dict(collections.Counter(monomial))
- # monomial_cnt = dict(monomial)
-
- # def differentiate_monomial(dependent_variable, derivation_variable=None):
- # def gen_diff_monomial():
- # for current_variable, current_count in monomial:
-
- # if current_variable is dependent_variable:
- # sel_counter = current_count - 1
-
- # else:
- # sel_counter = current_count
-
- # # for _ in range(sel_counter):
- # # yield current_variable
- # yield current_variable, sel_counter
-
- # if derivation_variable is not None:
- # yield derivation_variable
-
- # diff_monomial = tuple(sorted(gen_diff_monomial()))
-
- # return diff_monomial, value * monomial_cnt[dependent_variable]
-
- # if diff_wrt_variable in monomial_cnt:
- # diff_monomial, value = differentiate_monomial(diff_wrt_variable)
- # derivation_terms[diff_monomial] += value
-
- # # only used if introduce_derivatives == True
- # for candidate_variable in monomial_cnt.keys():
- # if candidate_variable in considered_variables or candidate_variable in confirmed_variables:
- # key = init_derivative_key(
- # variable=candidate_variable,
- # with_respect_to=diff_wrt_variable,
- # )
- # derivation_variable = state.offset_dict[key][0]
-
- # diff_monomial, value = differentiate_monomial(
- # dependent_variable=candidate_variable,
- # derivation_variable=derivation_variable,
- # )
- # derivation_terms[diff_monomial] += value
-
- # return state, dict(derivation_terms)
-
terms = {}
for row in range(underlying.shape[0]):