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

LR_Detection #52

Closed
wants to merge 8 commits into from
Closed

LR_Detection #52

wants to merge 8 commits into from

Conversation

AKuederle
Copy link
Contributor

No description provided.

@AKuederle AKuederle linked an issue Nov 15, 2023 that may be closed by this pull request
19 tasks
@AKuederle
Copy link
Contributor Author

@alexstihi I turned your branch into a PR, so that we have a place to add comments and discuss

@AKuederle AKuederle changed the base branch from main to cad2sec January 22, 2024 12:13
@AKuederle AKuederle changed the base branch from cad2sec to main January 22, 2024 12:13
This implementation now uses the dev guidelines for handling pre-trained models and parameters, available at: https://github.com/mobilise-d/gaitlink/blob/main/examples/dev_guides/_01_pretrained_models.py.

Also updated the reference data extractor to use reference_parameters_.wb_list and reference_parameters_.ic_list, instead of walking_bouts and initial_contacts.
Copy link
Contributor Author

@AKuederle AKuederle left a comment

Choose a reason for hiding this comment

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

Did a first pass :) Have a look. I will do a more in-depth review next week. If you have any changes before that feel frre to push them

from gaitlink.lr_detection import UllrichLRDetection


class UllrichLROptimizer():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we need this. You are basically just wrapping GridSearchCV




class LROptiPipeline(OptimizablePipeline):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is cool to have! Makes it easier to do optimization right away. I am not sure what the best place in the codebase and the best name for the class is, but let's leave it here for now.

# return y


def find_extrema_in_radius(data: np.ndarray,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These two funcitons are from gaitmap right? Can you Note that somewhere? :) Ideally with the link to the original implementation

Copy link
Contributor

Choose a reason for hiding this comment

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

These are from Martin's code, not gaitmap, however they are deprecated.

# TODO: Note that these models will need to be imported according to the groups of individuals they were trained on: HC, PD, MS, etc.

@base_lr_detector_docfiller
class PretrainedModel(StrEnum):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's Move this to the lr_detect_ML file, as it is specifc for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the deprecated version, and it will be removed in the future. I have updated the main UllrichLRDetection class to contain an inner class (as per the dev guidelines) holding the pre-trained model configurations, i.e. filtering parameters, pretrained sklearn models and sklearn min-max scalers. I don't think there will be a need for another PretrainedModel class...maybe?

model_path = base_dir / 'msproject_ms_model.gz'
return joblib.load(model_path)

# Note, these are not pretrained models, they are just some hyperparameters. They are here for convenience, since they were not available.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we really need this? Let's only support the actual pre-trained models that we actually have

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, see the PredefinedParameters inner class for UllrichLRDetection.

raise TypeError(f"Unknown model type {type(model)}. The model must be of type {ClassifierMixin}")

@base_lr_detector_docfiller
def detect(self, data: list[pd.DataFrame], ic_list: list[pd.DataFrame], sampling_rate_hz: float = 100):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Detect should have the same call signature as McCamley. So no list of dataframes, but just a asingle dataframe. Training is called on multiple datapoints, but inference always on one.


self.ic_lr.append(prediction_per_gs)

# ALEX: It might be more elegant to only return the value of the prediction and nothing else: i.e. do not store anything internally (data, ic_list, processed_data, predictions)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to follow the API contract that can be fullfilled by all algorithms.

return self


@base_lr_detector_docfiller
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you apply the docfiller, make use of the docfiller :)


# Fit the scaler if fit_scaler is True, otherwise just transform the data
if fit_scaler:
feature_df = pd.DataFrame(self.scaler.fit_transform(feature_df.values), columns=feature_df.columns, index=feature_df.index)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you fit the scaler, you should fit it on the entire data not per GS or am I wrong? Is this intended that you normalize each GS?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct, somehow I missed this. I will update this in the next push.


def __init__(self,
model: ClassifierMixin = None,
scaler: MinMaxScaler = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally set the actual default instead of None

@AKuederle AKuederle mentioned this pull request Mar 8, 2024
@AKuederle
Copy link
Contributor Author

Started extracting individual Algos into separate PRs.

First one #100

Will leave this one open, until others are merged

@AKuederle
Copy link
Contributor Author

Second one #106

@AKuederle
Copy link
Contributor Author

Both new PRs merged. Closing this one as well

@AKuederle AKuederle closed this Apr 17, 2024
@AKuederle AKuederle deleted the LR_Det_Ullrich branch June 28, 2024 14:18
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.

[ALGO] {LR_Det_Ullrich}
2 participants