Skip to content

Commit

Permalink
fixed bug#315 with the feature name order for the pdelibrary and weak…
Browse files Browse the repository at this point in the history
…pdelibrary, replaced the nonlinear diffusion example in notebook 12 with a more extensive example on compressible flow, and fixed a small typo in notebook 10
  • Loading branch information
znicolaou committed Apr 25, 2023
1 parent a24f943 commit f83bf20
Show file tree
Hide file tree
Showing 4 changed files with 333 additions and 244 deletions.
144 changes: 72 additions & 72 deletions examples/10_PDEFIND_examples.ipynb

Large diffs are not rendered by default.

386 changes: 237 additions & 149 deletions examples/12_weakform_SINDy_examples.ipynb

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions pysindy/feature_library/pde_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,12 @@ def get_feature_names(self, input_features=None):
feature_names.append("1")

# Include any non-derivative terms
function_feature_names = []
for i, f in enumerate(self.functions):
for c in self._combinations(
n_features, f.__code__.co_argcount, self.interaction_only
):
feature_names.append(
function_feature_names.append(
self.function_names[i](*[input_features[j] for j in c])
)

Expand All @@ -308,27 +309,27 @@ def derivative_string(multiindex):
return ret

# Include derivative terms
derivative_feature_names = []
for k in range(self.num_derivatives):
for j in range(n_features):
feature_names.append(
derivative_feature_names.append(
input_features[j] + "_" + derivative_string(self.multiindices[k])
)
feature_names = feature_names + function_feature_names
feature_names = feature_names + derivative_feature_names

# Include mixed non-derivative + derivative terms
if self.include_interaction:
for k in range(self.num_derivatives):
for i, f in enumerate(self.functions):
for c in self._combinations(
n_features,
f.__code__.co_argcount,
self.interaction_only,
):
for jj in range(n_features):
feature_names.append(
self.function_names[i](*[input_features[j] for j in c])
+ input_features[jj]
+ "_"
+ derivative_string(self.multiindices[k])
)
feature_names = (
feature_names
+ np.char.add(
np.array(function_feature_names).reshape(1, -1),
np.array(derivative_feature_names).reshape(-1, 1),
)
.reshape(-1)
.tolist()
)

return feature_names

@x_sequence_or_item
Expand Down
14 changes: 7 additions & 7 deletions pysindy/feature_library/weak_pde_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,13 +762,13 @@ def derivative_string(multiindex):
# Include mixed non-derivative + integral terms
if self.include_interaction:
for k in range(self.num_derivatives):
for i, f in enumerate(self.functions):
for c in self._combinations(
n_features,
f.__code__.co_argcount,
self.interaction_only,
):
for jj in range(n_features):
for jj in range(n_features):
for i, f in enumerate(self.functions):
for c in self._combinations(
n_features,
f.__code__.co_argcount,
self.interaction_only,
):
feature_names.append(
self.function_names[i](
*[input_features[j] for j in c]
Expand Down

0 comments on commit f83bf20

Please sign in to comment.