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

Update AbstractParams.py #186

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions whobpyt/datatypes/AbstractParams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@
from whobpyt.datatypes.parameter import par

class AbstractParams:
# This class stores the parameters used by a model. The parameters may be for the Neural Mass Model and/or Neuroimaging Modality.
# It should be useable by both the pytorch model for training and a numpy model for parameter verification.

'''
This class stores the parameters used by a model. The parameters may be for the Neural Mass Model and/or Neuroimaging Modality.
It should be useable by both the pytorch model for training and a numpy model for parameter verification.
'''
def __init__(self, **kwargs):
# Define the parameters using the par data structure
'''
Initialize the AbstractParams object and define the parameters using the par data structure

Args:
**kwargs: Keyword arguments for the model parameters.

Returns:
None
'''
pass

def getFittedNames(self):
'''
Function to obtain the named list of parameters being fitted

Returns:
Named list of parameters that are being fitted
'''
# Returns a named list of paramters that are being fitted
# Assumes the par datastructure is being used for parameters

Expand All @@ -26,10 +41,19 @@ def getFittedNames(self):
return fp

def to(self, device):
'''
Moves all parameters between CPU and GPU

Args:
device: torch.device object defining wether CPU or GPU

Returns:
None
'''
# Moves all parameters between CPU and GPU

vars_names = [a for a in dir(self) if not a.startswith('__')]
for var_name in vars_names:
var = getattr(self, var_name)
if (type(var) == par):
var.to(device)
var.to(device)
Loading