Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marc record tensornetwork entropy #94

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

SamTov
Copy link
Member

@SamTov SamTov commented Jun 5, 2023

No description provided.

Marc Sauter and others added 28 commits May 22, 2023 13:58
Merged branch 'Marc_record_fisher_trace' of https://github.com/zincware/ZnNL into Marc_record_fisher_trace
also moved the entropy calculations to the observables
saved the tensornetwork matrix in parsed data instead of a class
variable
Copy link
Member Author

@SamTov SamTov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is very well written, nice job. It would be great if you could look at the comments and make some of the changes and we can go from there.

loss_derivative = np.array([[5, 4, 3], [2, 1, 0]])

trace = compute_fisher_trace(loss_derivative=loss_derivative, ntk=ntk)
assert trace == 638 / 2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the 1/2 coming from? Is this just a simple solution to the analytic trace or are you normalising?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of these notebooks cleared of their output cells?

-------
Magnitude entropy of the matrix."""

magnitude_dist = compute_magnitude_density(gram_matrix=matrix)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be a normalised matrix?

if len(sorted_ntk.shape) == 4:
sorted_ntk = np.mean(sorted_ntk, axis=(2, 3))

"""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block should be removed for the merge into main.

from jax import vmap


def compute_tensornetwork_matrix(ntk: np.ndarray, targets: np.ndarray):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an output type:

def my_func(...) -> np.ndarray:

return tensornetwork_matrix


def _get_start_and_end_value(i, target_counts):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can put this into the matrix utils module and add a test for it.

@@ -244,7 +276,7 @@ def instantiate_recorder(self, data_set: dict = None, overwrite: bool = False):
if overwrite:
self._index_count = 0

# Check if we need an NTK computation and update the class accordingly
# Check if we need an NTK computation, update the class accordingly.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Or was this the line length issue?

@@ -342,7 +405,7 @@ def visualize_recorder(self):
-------

"""
raise NotImplementedError("Not yet available in ZnRND.")
raise NotImplementedError("Not yet available in ZnNL.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch

@@ -593,6 +701,7 @@ def gather_recording(self, selected_properties: list = None) -> dataclass:
db_data = self._data_storage.fetch_data(selected_properties)
# Add db data to the selected data dict.
for item, data in selected_data.items():
print(item)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove.

@@ -618,3 +727,27 @@ def _export_in_memory_data(self) -> dataclass:
}

return DataSet(**selected_data)

def _adjust_ntk_shape(self, parsed_data):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have tests for this? This can probably also be a matrix util but then it should be moved to the utils module and heavily tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant