@@ -60,49 +60,40 @@ def equation_complexity_by_terms(system, equation_key):
6060 return np .count_nonzero (system .vals [equation_key ].weights_internal )
6161
6262
63- def equation_complexity_by_factors (system , equation_key ):
64- '''
65- Evaluate the complexity of the system of PDEs, evaluating a number of factors in terms for each
66- equation. In the evaluation, we consider only terms with non-zero weights and target, while
67- the free coefficient is not included in the final metric. Also, the real-valued factors are
68- not considered in the result.
69-
70- Parameters:
71- -----------
72- system - ``epde.structure.main_structures.SoEq`` object
73- The system, that is to be evaluated.
74-
75- Returns:
76- ----------
77- discrepancy : list of integers.
78- The values of the error metric: list entry for each of the equations.
79- '''
80- # eq_compl = 0
81-
82- # for idx, term in enumerate(system.vals[equation_key].structure):
83- # if idx < system.vals[equation_key].target_idx:
84- # if not system.vals[equation_key].weights_final[idx] == 0:
85- # eq_compl += len(term.structure)
86- # elif idx > system.vals[equation_key].target_idx:
87- # if not system.vals[equation_key].weights_final[idx-1] == 0:
88- # eq_compl += len(term.structure)
89- # else:
90- # eq_compl += len(term.structure)
91- # return eq_compl
63+ def _complexity_single_eq (system , equation_key ):
64+ # Index by ``weights_internal`` (always length ``len(structure)-1``,
65+ # one entry per non-target term in structure order) rather than
66+ # ``weights_final`` (zero-filtered to ``nnz+1`` by ``LASSOSparsity``
67+ # and ``VWSRSparsity``): structure-position indexing breaks against
68+ # ``weights_final`` whenever the sparsity step zeros more than one
69+ # weight.
70+ equation = system .vals [equation_key ]
9271 eq_compl = 0
93-
94- for idx , term in enumerate (system .vals [equation_key ].structure ):
95- if idx < system .vals [equation_key ].target_idx :
96- if not system .vals [equation_key ].weights_final [idx ] == 0 :
72+ for idx , term in enumerate (equation .structure ):
73+ if idx < equation .target_idx :
74+ if not equation .weights_internal [idx ] == 0 :
9775 eq_compl += complexity_deriv (term .structure )
98- elif idx > system . vals [ equation_key ] .target_idx :
99- if not system . vals [ equation_key ]. weights_final [idx - 1 ] == 0 :
76+ elif idx > equation .target_idx :
77+ if not equation . weights_internal [idx - 1 ] == 0 :
10078 eq_compl += complexity_deriv (term .structure )
10179 else :
10280 eq_compl += complexity_deriv (term .structure )
10381 return eq_compl
10482
10583
84+ def equation_complexity_by_factors (system , equation_key = None ):
85+ '''
86+ Evaluate the complexity of the system of PDEs as a number of factors in
87+ non-zero terms for each equation, excluding the free coefficient and
88+ real-valued factors. When ``equation_key`` is None, returns a per-equation
89+ tuple matching the ``system.vars_to_describe`` order; otherwise the scalar
90+ complexity for the named equation.
91+ '''
92+ if equation_key is None :
93+ return tuple (_complexity_single_eq (system , k ) for k in system .vars_to_describe )
94+ return _complexity_single_eq (system , equation_key )
95+
96+
10697def equation_terms_stability (system , equation_key = None ):
10798 if equation_key :
10899 assert system .vals [equation_key ].stability_calculated
0 commit comments