Skip to content

Conversation

@mtereshchuk
Copy link

@mtereshchuk mtereshchuk commented Jun 8, 2022

Pull Request Template

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • New method (set a link to paper then)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests or set link to that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Copy link
Collaborator

@LastShekel LastShekel left a comment

Choose a reason for hiding this comment

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

Checkout numpy documentation, it should help you to improve code performance

_RANDOM_STATE = 42

def __init__(self, measures, kappa, estimator, score):
self._measures = measures
Copy link
Collaborator

Choose a reason for hiding this comment

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

Documentation with argument explanation and types needed in functions


for j in range(n_measures):
score = self._measures[j](X, y)
for i in range(n_features):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't you use numpy array assignment?

maximum = planes.max()
min_max_diff = maximum - minimum

for i in range(shape[0]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again you could use array assignment like
(Planes-minimum)/min_max_diff
Or use bumpy minmaxscaler

return normalized

def _kappa_filter(self, planes):
n_measures = len(self._measures)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are repeating this string, it is better to create class field with this value

n_measures = len(self._measures)

indexed = []
for i, plane in enumerate(planes):
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems you could just assign enumerate to indexed without for loop

kappa_indices = set()
for i in range(n_measures):
planes = sorted(planes, key=lambda p: p[1][i])
kappa_indices.add(planes[-self._kappa][0])
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if -self._kappa exceeds list index bounds?
You better check it as early as posible


filtered_indices = set()
for i in range(n_measures):
planes.sort(key=lambda p: p[1][i])
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that you already sorted it before

planes.sort(key=lambda p: p[1][i])

left = 0
while planes[left][0] not in kappa_indices:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Numpy where or count, should work faster


intersection = SortedSet(key=cmp_to_key(_double_list_cmp))
for k in range(dim):
for l in range(k + 1, dim):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely this could be optimised with numpy
4 nasted loops is too much


for j in range(dim):
point = np.zeros(dim)
point[j] = planes[i][j]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be made with numpy diagonal array

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.

2 participants