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
Loss function clarity #28
Changes from 22 commits
210b570
645b3e8
ae46603
3e437cc
6bde08c
9acc21d
c7563b7
da2825d
96f5e14
62de902
31519d6
4919e36
a66752c
d29f036
9156347
b8d16e2
c1fbe0f
2206feb
8c3035d
91d105e
9288d64
a5019ea
9cbb003
e17194f
034f42a
3470fcc
0f09414
b642843
3778fe0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
from typing import Optional, Tuple | ||
from typing import Optional, Tuple, Union | ||
|
||
import numpy as np | ||
from scipy.interpolate import interp1d | ||
|
||
from .aliases import ArrayOfParameterVectors, ParameterVector | ||
from .aliases import ArrayOfParameterVectors, DirectionVector, ParameterVector | ||
|
||
|
||
def get_random_normal_vector(dimension: int) -> ParameterVector: | ||
def get_random_normal_vector(dimension: Union[int, Tuple]) -> DirectionVector: | ||
"""Helper function to generate a vector with a specified dimension and norm=1.""" | ||
random_vector = np.random.normal(0, 1, size=dimension) | ||
return random_vector / np.linalg.norm(random_vector) | ||
|
||
|
||
def get_random_orthonormal_vector(base_vector: ParameterVector) -> ParameterVector: | ||
def get_random_orthonormal_vector(base_vector: DirectionVector) -> DirectionVector: | ||
"""Helper function to generate a random orthogonal vector with respect to | ||
a provided base vector.""" | ||
random_vector = np.random.normal(size=base_vector.shape) | ||
random_vector = np.random.normal(size=np.shape(base_vector)) | ||
new_vector = ( | ||
random_vector | ||
- np.dot(random_vector, base_vector) | ||
- np.dot(random_vector.flatten(), base_vector.flatten()) | ||
* base_vector | ||
/ np.linalg.norm(base_vector) ** 2 | ||
) | ||
|
@@ -87,7 +87,7 @@ def relative_periodic_trajectory_wrap( | |
|
||
def get_coordinates_on_direction( | ||
points: ArrayOfParameterVectors, | ||
direction: np.ndarray, | ||
direction: DirectionVector, | ||
origin: Optional[ParameterVector] = None, | ||
in_units_of_direction: bool = False, | ||
) -> np.ndarray: | ||
|
@@ -107,12 +107,19 @@ def get_coordinates_on_direction( | |
norm_direction = np.linalg.norm(direction) | ||
if in_units_of_direction: | ||
direction = direction / norm_direction | ||
return np.dot(points, direction) / norm_direction | ||
return ( | ||
np.tensordot( | ||
points, | ||
direction, | ||
axes=(range(1, len(points.shape)), range(len(direction.shape))), | ||
) | ||
/ norm_direction | ||
) | ||
|
||
|
||
def direction_linspace( | ||
origin: ParameterVector, | ||
direction: np.ndarray, | ||
direction: DirectionVector, | ||
n_points: int, | ||
endpoints: Tuple[float, float] = (-1, 1), | ||
) -> ArrayOfParameterVectors: | ||
|
@@ -148,3 +155,11 @@ def uniformly_distribute_trajectory( | |
) | ||
eval_points = np.linspace(0, 1, num=n_points) | ||
return weight_interpolator(eval_points) | ||
|
||
|
||
def _norm_of_arrayofparametervectors(param_array: ArrayOfParameterVectors): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about the name of the function... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about just |
||
ax_indices = tuple(range(len(param_array.shape))) | ||
t_dot = np.tensordot( | ||
param_array, param_array, axes=(ax_indices[1:], ax_indices[1:]) | ||
) | ||
return np.array(np.sqrt(np.diag(t_dot))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are using
_norm_of_arrayofparametervectors
in a different module than it comes from (i.e. inelastic_band
and not ingeometric
, I think it makes more sense to not make it private?Not 100% sure though, thoughts @alexjuda?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. It is only a helper function for us though. I doubt that anyone would need that apart from us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can recommend a 3-fold distinction for project symbols – public/internal/fileprivate based on a convention with leading underscores in the module and symbol names;
module
,function
_module
,function
_function
The above use case looks like an "internal" one :). Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexjuda In our case the content of
geometric
packages should be public, so not really ;)@MSRudolph fine 🤷♂️