hexsha stringlengths 40 40 | repo stringlengths 7 114 | path stringlengths 4 124 | license listlengths 1 9 | language stringclasses 1
value | identifier stringlengths 1 71 | return_type stringlengths 1 749 ⌀ | original_string stringlengths 76 22.7k | original_docstring stringlengths 16 7.61k | docstring stringlengths 16 2.47k | docstring_tokens listlengths 6 477 | code stringlengths 14 10.2k | code_tokens listlengths 6 996 | short_docstring stringlengths 2 644 | short_docstring_tokens listlengths 1 116 | comment listlengths 1 89 | parameters listlengths 0 64 | docstring_params dict |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
c6f867dd2fe8c6394de4bb2acdfbb61ed0bc1857 | encode1/democrance | src/customers/api_v1/serializers.py | [
"Apache-2.0"
] | Python | create | <not_specific> | def create(self, validated_data):
"""
Overriding the default create method of the Model serializer.
:param validated_data: data containing all the details of customer
:return: returns a successfully created customer record
"""
validated_user = validated_data.pop('user')
... |
Overriding the default create method of the Model serializer.
:param validated_data: data containing all the details of customer
:return: returns a successfully created customer record
| Overriding the default create method of the Model serializer. | [
"Overriding",
"the",
"default",
"create",
"method",
"of",
"the",
"Model",
"serializer",
"."
] | def create(self, validated_data):
validated_user = validated_data.pop('user')
user_data = {
'username': validated_user.get('email'),
'first_name': validated_user.get('first_name'),
'last_name': validated_user.get('last_name'),
'email': validated_user.get('... | [
"def",
"create",
"(",
"self",
",",
"validated_data",
")",
":",
"validated_user",
"=",
"validated_data",
".",
"pop",
"(",
"'user'",
")",
"user_data",
"=",
"{",
"'username'",
":",
"validated_user",
".",
"get",
"(",
"'email'",
")",
",",
"'first_name'",
":",
"... | Overriding the default create method of the Model serializer. | [
"Overriding",
"the",
"default",
"create",
"method",
"of",
"the",
"Model",
"serializer",
"."
] | [
"\"\"\"\n Overriding the default create method of the Model serializer.\n :param validated_data: data containing all the details of customer\n :return: returns a successfully created customer record\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "validated_data",
"type": null
}
] | {
"returns": [
{
"docstring": "returns a successfully created customer record",
"docstring_tokens": [
"returns",
"a",
"successfully",
"created",
"customer",
"record"
],
"type": null
}
],
"raises": [],
"params": [
{
"identi... |
6640d942523b988a0451ee537107cf94adec91a3 | encode1/democrance | src/policy/api_v1/apiviews.py | [
"Apache-2.0"
] | Python | patch | <not_specific> | def patch(self, request, *args, **kwargs):
"""
View that allow the update the status of a quote
"""
self.quote_id = request.data.get('quote_id')
return self.partial_update(request, *args, **kwargs) |
View that allow the update the status of a quote
| View that allow the update the status of a quote | [
"View",
"that",
"allow",
"the",
"update",
"the",
"status",
"of",
"a",
"quote"
] | def patch(self, request, *args, **kwargs):
self.quote_id = request.data.get('quote_id')
return self.partial_update(request, *args, **kwargs) | [
"def",
"patch",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"quote_id",
"=",
"request",
".",
"data",
".",
"get",
"(",
"'quote_id'",
")",
"return",
"self",
".",
"partial_update",
"(",
"request",
",",
"*",... | View that allow the update the status of a quote | [
"View",
"that",
"allow",
"the",
"update",
"the",
"status",
"of",
"a",
"quote"
] | [
"\"\"\"\n View that allow the update the status of a quote\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "request",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "request",
"type": null,
"docstring": null,
"docstring_tokens"... |
04d22d6c424d97ba67901d3e0bd8ec0c737d8124 | encode1/democrance | src/policy/api_v1/serializers.py | [
"Apache-2.0"
] | Python | create | <not_specific> | def create(self, validated_data):
"""
create method of the serializer.
:param validated_data: data containing customer_id and policy type
:return: returns a successfully created Quote for the customer
"""
errors = OrderedDict()
try:
customer = Customer... |
create method of the serializer.
:param validated_data: data containing customer_id and policy type
:return: returns a successfully created Quote for the customer
| create method of the serializer. | [
"create",
"method",
"of",
"the",
"serializer",
"."
] | def create(self, validated_data):
errors = OrderedDict()
try:
customer = Customer.objects.get(id=validated_data['customer']['id'])
except Customer.DoesNotExist as exc:
errors['customer_id'] = [ErrorDetail(string=exc, code='invalid')]
try:
coverage = Co... | [
"def",
"create",
"(",
"self",
",",
"validated_data",
")",
":",
"errors",
"=",
"OrderedDict",
"(",
")",
"try",
":",
"customer",
"=",
"Customer",
".",
"objects",
".",
"get",
"(",
"id",
"=",
"validated_data",
"[",
"'customer'",
"]",
"[",
"'id'",
"]",
")",... | create method of the serializer. | [
"create",
"method",
"of",
"the",
"serializer",
"."
] | [
"\"\"\"\n create method of the serializer.\n :param validated_data: data containing customer_id and policy type\n :return: returns a successfully created Quote for the customer\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "validated_data",
"type": null
}
] | {
"returns": [
{
"docstring": "returns a successfully created Quote for the customer",
"docstring_tokens": [
"returns",
"a",
"successfully",
"created",
"Quote",
"for",
"the",
"customer"
],
"type": null
}
],
"raises": [... |
04d22d6c424d97ba67901d3e0bd8ec0c737d8124 | encode1/democrance | src/policy/api_v1/serializers.py | [
"Apache-2.0"
] | Python | update | <not_specific> | def update(self, instance, validated_data):
"""
Update and return an existing `Quote` instance, given the validated data.
"""
# this check will prevent it from update to the same state
if instance.state != validated_data.get('status'):
instance.state = validated_data.... |
Update and return an existing `Quote` instance, given the validated data.
| Update and return an existing `Quote` instance, given the validated data. | [
"Update",
"and",
"return",
"an",
"existing",
"`",
"Quote",
"`",
"instance",
"given",
"the",
"validated",
"data",
"."
] | def update(self, instance, validated_data):
if instance.state != validated_data.get('status'):
instance.state = validated_data.get('status')
instance.save()
PolicyHistory.objects.create(policy=instance, state=instance.state)
return instance | [
"def",
"update",
"(",
"self",
",",
"instance",
",",
"validated_data",
")",
":",
"if",
"instance",
".",
"state",
"!=",
"validated_data",
".",
"get",
"(",
"'status'",
")",
":",
"instance",
".",
"state",
"=",
"validated_data",
".",
"get",
"(",
"'status'",
"... | Update and return an existing `Quote` instance, given the validated data. | [
"Update",
"and",
"return",
"an",
"existing",
"`",
"Quote",
"`",
"instance",
"given",
"the",
"validated",
"data",
"."
] | [
"\"\"\"\n Update and return an existing `Quote` instance, given the validated data.\n \"\"\"",
"# this check will prevent it from update to the same state"
] | [
{
"param": "self",
"type": null
},
{
"param": "instance",
"type": null
},
{
"param": "validated_data",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "instance",
"type": null,
"docstring": null,
"docstring_tokens... |
44a817bd273cda9b9149850a5a583cbb6602048c | Tscott7/proj10-scheduler | meetings/free_times.py | [
"Artistic-2.0"
] | Python | calculate_free_times | <not_specific> | def calculate_free_times(busy_blocks, start_time, end_time):
'''
Takes a start time, end time, and a list of lists that hold two arrow objects, a start and end time for the events.
'''
merge(busy_blocks)
completed_free_times = []
start_time = str(start_time).replace('T', ' ')
start_time = (arrow.get(start_time)... |
Takes a start time, end time, and a list of lists that hold two arrow objects, a start and end time for the events.
| Takes a start time, end time, and a list of lists that hold two arrow objects, a start and end time for the events. | [
"Takes",
"a",
"start",
"time",
"end",
"time",
"and",
"a",
"list",
"of",
"lists",
"that",
"hold",
"two",
"arrow",
"objects",
"a",
"start",
"and",
"end",
"time",
"for",
"the",
"events",
"."
] | def calculate_free_times(busy_blocks, start_time, end_time):
merge(busy_blocks)
completed_free_times = []
start_time = str(start_time).replace('T', ' ')
start_time = (arrow.get(start_time), 'YYYY-MM-DD HH:mm:ssZZ')
end_time = str(end_time).replace('T', ' ')
end_time = (arrow.get(end_time), 'YYYY-MM-DD HH:mm:ssZZ'... | [
"def",
"calculate_free_times",
"(",
"busy_blocks",
",",
"start_time",
",",
"end_time",
")",
":",
"merge",
"(",
"busy_blocks",
")",
"completed_free_times",
"=",
"[",
"]",
"start_time",
"=",
"str",
"(",
"start_time",
")",
".",
"replace",
"(",
"'T'",
",",
"' '"... | Takes a start time, end time, and a list of lists that hold two arrow objects, a start and end time for the events. | [
"Takes",
"a",
"start",
"time",
"end",
"time",
"and",
"a",
"list",
"of",
"lists",
"that",
"hold",
"two",
"arrow",
"objects",
"a",
"start",
"and",
"end",
"time",
"for",
"the",
"events",
"."
] | [
"'''\n\tTakes a start time, end time, and a list of lists that hold two arrow objects, a start and end time for the events. \n\t'''",
"# Should be unreachable",
"# Block is in time range"
] | [
{
"param": "busy_blocks",
"type": null
},
{
"param": "start_time",
"type": null
},
{
"param": "end_time",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "busy_blocks",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "start_time",
"type": null,
"docstring": null,
"docstri... |
44a817bd273cda9b9149850a5a583cbb6602048c | Tscott7/proj10-scheduler | meetings/free_times.py | [
"Artistic-2.0"
] | Python | sort | <not_specific> | def sort(busy_blocks):
'''
Goes through a list of busy blocks of time and puts them in order based on their start times.
'''
busy_blocks.sort(key = lambda row: row[0])
return busy_blocks |
Goes through a list of busy blocks of time and puts them in order based on their start times.
| Goes through a list of busy blocks of time and puts them in order based on their start times. | [
"Goes",
"through",
"a",
"list",
"of",
"busy",
"blocks",
"of",
"time",
"and",
"puts",
"them",
"in",
"order",
"based",
"on",
"their",
"start",
"times",
"."
] | def sort(busy_blocks):
busy_blocks.sort(key = lambda row: row[0])
return busy_blocks | [
"def",
"sort",
"(",
"busy_blocks",
")",
":",
"busy_blocks",
".",
"sort",
"(",
"key",
"=",
"lambda",
"row",
":",
"row",
"[",
"0",
"]",
")",
"return",
"busy_blocks"
] | Goes through a list of busy blocks of time and puts them in order based on their start times. | [
"Goes",
"through",
"a",
"list",
"of",
"busy",
"blocks",
"of",
"time",
"and",
"puts",
"them",
"in",
"order",
"based",
"on",
"their",
"start",
"times",
"."
] | [
"'''\n\tGoes through a list of busy blocks of time and puts them in order based on their start times.\n\t'''"
] | [
{
"param": "busy_blocks",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "busy_blocks",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
44a817bd273cda9b9149850a5a583cbb6602048c | Tscott7/proj10-scheduler | meetings/free_times.py | [
"Artistic-2.0"
] | Python | merge | null | def merge(busy_blocks):
'''
Goes through a list of busy blocks of time and make sure than none of them overlap. If they do,
we merge them together so that the list is as small as possible.
'''
merged_busy_blocks = []
finished_busy_blocks = []
sort(busy_blocks)
for block in busy_blocks:
for checker in busy_bl... |
Goes through a list of busy blocks of time and make sure than none of them overlap. If they do,
we merge them together so that the list is as small as possible.
| Goes through a list of busy blocks of time and make sure than none of them overlap. If they do,
we merge them together so that the list is as small as possible. | [
"Goes",
"through",
"a",
"list",
"of",
"busy",
"blocks",
"of",
"time",
"and",
"make",
"sure",
"than",
"none",
"of",
"them",
"overlap",
".",
"If",
"they",
"do",
"we",
"merge",
"them",
"together",
"so",
"that",
"the",
"list",
"is",
"as",
"small",
"as",
... | def merge(busy_blocks):
merged_busy_blocks = []
finished_busy_blocks = []
sort(busy_blocks)
for block in busy_blocks:
for checker in busy_blocks:
if block[1] < checker[0] or checker[1] < block[0]:
break
elif block[0] > checker[0] and block[1] > checker[1]:
block[0] = checker[0]
merged_busy_block... | [
"def",
"merge",
"(",
"busy_blocks",
")",
":",
"merged_busy_blocks",
"=",
"[",
"]",
"finished_busy_blocks",
"=",
"[",
"]",
"sort",
"(",
"busy_blocks",
")",
"for",
"block",
"in",
"busy_blocks",
":",
"for",
"checker",
"in",
"busy_blocks",
":",
"if",
"block",
... | Goes through a list of busy blocks of time and make sure than none of them overlap. | [
"Goes",
"through",
"a",
"list",
"of",
"busy",
"blocks",
"of",
"time",
"and",
"make",
"sure",
"than",
"none",
"of",
"them",
"overlap",
"."
] | [
"'''\n\tGoes through a list of busy blocks of time and make sure than none of them overlap. If they do, \n\twe merge them together so that the list is as small as possible.\n\t'''"
] | [
{
"param": "busy_blocks",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "busy_blocks",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
88288f2e8ae720014cfa749dfdb8981103c735a0 | Tscott7/proj10-scheduler | meetings/flask_main.py | [
"Artistic-2.0"
] | Python | startup | <not_specific> | def startup():
"""
The startup page that either takes in a meeting id or allows you to create a new meeting.
"""
app.logger.debug("Entering startup")
meeting_id = flask.request.form.get("meeting_id")
app.logger.debug("meeting_id = " + str(meeting_id))
try:
db_names = db.collection_names()
if meeti... |
The startup page that either takes in a meeting id or allows you to create a new meeting.
| The startup page that either takes in a meeting id or allows you to create a new meeting. | [
"The",
"startup",
"page",
"that",
"either",
"takes",
"in",
"a",
"meeting",
"id",
"or",
"allows",
"you",
"to",
"create",
"a",
"new",
"meeting",
"."
] | def startup():
app.logger.debug("Entering startup")
meeting_id = flask.request.form.get("meeting_id")
app.logger.debug("meeting_id = " + str(meeting_id))
try:
db_names = db.collection_names()
if meeting_id in db_names:
app.logger.debug("Found database entry")
flask.g.does_not_exist = 1
... | [
"def",
"startup",
"(",
")",
":",
"app",
".",
"logger",
".",
"debug",
"(",
"\"Entering startup\"",
")",
"meeting_id",
"=",
"flask",
".",
"request",
".",
"form",
".",
"get",
"(",
"\"meeting_id\"",
")",
"app",
".",
"logger",
".",
"debug",
"(",
"\"meeting_id... | The startup page that either takes in a meeting id or allows you to create a new meeting. | [
"The",
"startup",
"page",
"that",
"either",
"takes",
"in",
"a",
"meeting",
"id",
"or",
"allows",
"you",
"to",
"create",
"a",
"new",
"meeting",
"."
] | [
"\"\"\"\n The startup page that either takes in a meeting id or allows you to create a new meeting.\n \"\"\""
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
88288f2e8ae720014cfa749dfdb8981103c735a0 | Tscott7/proj10-scheduler | meetings/flask_main.py | [
"Artistic-2.0"
] | Python | new | <not_specific> | def new():
"""
Creates a new meeting in the database based on the ID entered.
"""
app.logger.debug("Entering new")
new_meeting_id = flask.request.form.get("new_meeting_id")
app.logger.debug("new_meeting_id = " + str(new_meeting_id))
#try:
db_names = db.collection_names()
if new_meeting_id in db_names:... |
Creates a new meeting in the database based on the ID entered.
| Creates a new meeting in the database based on the ID entered. | [
"Creates",
"a",
"new",
"meeting",
"in",
"the",
"database",
"based",
"on",
"the",
"ID",
"entered",
"."
] | def new():
app.logger.debug("Entering new")
new_meeting_id = flask.request.form.get("new_meeting_id")
app.logger.debug("new_meeting_id = " + str(new_meeting_id))
db_names = db.collection_names()
if new_meeting_id in db_names:
app.logger.debug("ID already exists")
flask.g.exists = 2
return flask.re... | [
"def",
"new",
"(",
")",
":",
"app",
".",
"logger",
".",
"debug",
"(",
"\"Entering new\"",
")",
"new_meeting_id",
"=",
"flask",
".",
"request",
".",
"form",
".",
"get",
"(",
"\"new_meeting_id\"",
")",
"app",
".",
"logger",
".",
"debug",
"(",
"\"new_meetin... | Creates a new meeting in the database based on the ID entered. | [
"Creates",
"a",
"new",
"meeting",
"in",
"the",
"database",
"based",
"on",
"the",
"ID",
"entered",
"."
] | [
"\"\"\"\n Creates a new meeting in the database based on the ID entered.\n \"\"\"",
"#try:",
"#except:",
"#app.logger.debug(\"Error finding collection or first time through\")",
"#flask.g.exists = 1"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
88288f2e8ae720014cfa749dfdb8981103c735a0 | Tscott7/proj10-scheduler | meetings/flask_main.py | [
"Artistic-2.0"
] | Python | invite | <not_specific> | def invite():
"""
A page to invite other users to enter their google calendar to make a meeting with multiple people
"""
return flask.render_template('invite.html') |
A page to invite other users to enter their google calendar to make a meeting with multiple people
| A page to invite other users to enter their google calendar to make a meeting with multiple people | [
"A",
"page",
"to",
"invite",
"other",
"users",
"to",
"enter",
"their",
"google",
"calendar",
"to",
"make",
"a",
"meeting",
"with",
"multiple",
"people"
] | def invite():
return flask.render_template('invite.html') | [
"def",
"invite",
"(",
")",
":",
"return",
"flask",
".",
"render_template",
"(",
"'invite.html'",
")"
] | A page to invite other users to enter their google calendar to make a meeting with multiple people | [
"A",
"page",
"to",
"invite",
"other",
"users",
"to",
"enter",
"their",
"google",
"calendar",
"to",
"make",
"a",
"meeting",
"with",
"multiple",
"people"
] | [
"\"\"\"\n A page to invite other users to enter their google calendar to make a meeting with multiple people\n \"\"\""
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
5ab85961ce5beab0aab1b8e17478d9f4b8154cfb | dilawarm/federated | federated/optimization/centralized.py | [
"CC-BY-4.0"
] | Python | centralized_pipeline | float | def centralized_pipeline(
name: str,
output: str,
epochs: int,
batch_size: int,
optimizer: str,
model: str,
learning_rate: float,
) -> float:
"""Function runs centralized training pipeline.
Args:
name (str): Name of the experiment.\n
output (str): Where to save confi... | Function runs centralized training pipeline.
Args:
name (str): Name of the experiment.\n
output (str): Where to save config files. Defaults to history.\n
epochs (int): Number of epochs. Defaults to 15.\n
batch_size (int): Batch size. Defaults to 32.\n
optimizer (str): Which ... | Function runs centralized training pipeline. | [
"Function",
"runs",
"centralized",
"training",
"pipeline",
"."
] | def centralized_pipeline(
name: str,
output: str,
epochs: int,
batch_size: int,
optimizer: str,
model: str,
learning_rate: float,
) -> float:
model = MODELS[model]()
optimizer = OPTIMIZERS[optimizer](learning_rate)
train_dataset, test_dataset, _ = get_datasets(
train_batc... | [
"def",
"centralized_pipeline",
"(",
"name",
":",
"str",
",",
"output",
":",
"str",
",",
"epochs",
":",
"int",
",",
"batch_size",
":",
"int",
",",
"optimizer",
":",
"str",
",",
"model",
":",
"str",
",",
"learning_rate",
":",
"float",
",",
")",
"->",
"... | Function runs centralized training pipeline. | [
"Function",
"runs",
"centralized",
"training",
"pipeline",
"."
] | [
"\"\"\"Function runs centralized training pipeline.\n\n Args:\n name (str): Name of the experiment.\\n\n output (str): Where to save config files. Defaults to history.\\n\n epochs (int): Number of epochs. Defaults to 15.\\n\n batch_size (int): Batch size. Defaults to 32.\\n\n o... | [
{
"param": "name",
"type": "str"
},
{
"param": "output",
"type": "str"
},
{
"param": "epochs",
"type": "int"
},
{
"param": "batch_size",
"type": "int"
},
{
"param": "optimizer",
"type": "str"
},
{
"param": "model",
"type": "str"
},
{
"param... | {
"returns": [
{
"docstring": "Training time after centralized learning.",
"docstring_tokens": [
"Training",
"time",
"after",
"centralized",
"learning",
"."
],
"type": "float"
}
],
"raises": [],
"params": [
{
"identifier":... |
cdc5fdb0425057f9b1ef187a9e8dba42bec4bc92 | dilawarm/federated | federated/utils/compression_utils.py | [
"CC-BY-4.0"
] | Python | build_encoded_broadcast_fn | te.core.Encoder | def build_encoded_broadcast_fn(weights: tf.Tensor) -> te.core.Encoder:
"""Function for encoding weights with uniform quantization.
Args:
weights (tf.Tensor): Weights of the model.
Returns:
te.core.Encoder: Encoder.
"""
if weights.shape.num_elements() > 0:
return te.encoders... | Function for encoding weights with uniform quantization.
Args:
weights (tf.Tensor): Weights of the model.
Returns:
te.core.Encoder: Encoder.
| Function for encoding weights with uniform quantization. | [
"Function",
"for",
"encoding",
"weights",
"with",
"uniform",
"quantization",
"."
] | def build_encoded_broadcast_fn(weights: tf.Tensor) -> te.core.Encoder:
if weights.shape.num_elements() > 0:
return te.encoders.as_simple_encoder(
te.encoders.uniform_quantization(bits=4),
tf.TensorSpec(weights.shape, weights.dtype),
)
else:
return te.encoders.as_s... | [
"def",
"build_encoded_broadcast_fn",
"(",
"weights",
":",
"tf",
".",
"Tensor",
")",
"->",
"te",
".",
"core",
".",
"Encoder",
":",
"if",
"weights",
".",
"shape",
".",
"num_elements",
"(",
")",
">",
"0",
":",
"return",
"te",
".",
"encoders",
".",
"as_sim... | Function for encoding weights with uniform quantization. | [
"Function",
"for",
"encoding",
"weights",
"with",
"uniform",
"quantization",
"."
] | [
"\"\"\"Function for encoding weights with uniform quantization.\n\n Args:\n weights (tf.Tensor): Weights of the model.\n\n Returns:\n te.core.Encoder: Encoder.\n \"\"\""
] | [
{
"param": "weights",
"type": "tf.Tensor"
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": "te.core.Encoder"
}
],
"raises": [],
"params": [
{
"identifier": "weights",
"type": "tf.Tensor",
"docstring": "Weights of the model.",
"docstring_tokens": [
"We... |
cdc5fdb0425057f9b1ef187a9e8dba42bec4bc92 | dilawarm/federated | federated/utils/compression_utils.py | [
"CC-BY-4.0"
] | Python | encoded_broadcast_process | tff.templates.MeasuredProcess | def encoded_broadcast_process(
tff_model_fn: tff.learning.Model,
) -> tff.templates.MeasuredProcess:
"""Function for creating a MeasuredProcess used in federated learning. Uses `build_encoded_broadcast_fn` defined above. Returns MeasuredProcess
Args:
tff_model_fn (tff.learning.Model): Federated lea... | Function for creating a MeasuredProcess used in federated learning. Uses `build_encoded_broadcast_fn` defined above. Returns MeasuredProcess
Args:
tff_model_fn (tff.learning.Model): Federated learning model.
Returns:
tff.templates.MeasuredProcess: MesuredProcess object.
| Function for creating a MeasuredProcess used in federated learning. Uses `build_encoded_broadcast_fn` defined above. | [
"Function",
"for",
"creating",
"a",
"MeasuredProcess",
"used",
"in",
"federated",
"learning",
".",
"Uses",
"`",
"build_encoded_broadcast_fn",
"`",
"defined",
"above",
"."
] | def encoded_broadcast_process(
tff_model_fn: tff.learning.Model,
) -> tff.templates.MeasuredProcess:
return tff.learning.framework.build_encoded_broadcast_process_from_model(
tff_model_fn, build_encoded_broadcast_fn
) | [
"def",
"encoded_broadcast_process",
"(",
"tff_model_fn",
":",
"tff",
".",
"learning",
".",
"Model",
",",
")",
"->",
"tff",
".",
"templates",
".",
"MeasuredProcess",
":",
"return",
"tff",
".",
"learning",
".",
"framework",
".",
"build_encoded_broadcast_process_from... | Function for creating a MeasuredProcess used in federated learning. | [
"Function",
"for",
"creating",
"a",
"MeasuredProcess",
"used",
"in",
"federated",
"learning",
"."
] | [
"\"\"\"Function for creating a MeasuredProcess used in federated learning. Uses `build_encoded_broadcast_fn` defined above. Returns MeasuredProcess\n\n Args:\n tff_model_fn (tff.learning.Model): Federated learning model.\n\n Returns:\n tff.templates.MeasuredProcess: MesuredProcess object.\n \... | [
{
"param": "tff_model_fn",
"type": "tff.learning.Model"
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": "tff.templates.MeasuredProcess"
}
],
"raises": [],
"params": [
{
"identifier": "tff_model_fn",
"type": "tff.learning.Model",
"docstring": "Federated learning model.",
"... |
03c3153b905fc236dea04bacb41f4c52d73a46c6 | dilawarm/federated | federated/utils/differential_privacy.py | [
"CC-BY-4.0"
] | Python | gaussian_fixed_aggregation_factory | tff.aggregators.DifferentiallyPrivateFactory | def gaussian_fixed_aggregation_factory(
noise_multiplier: float, clients_per_round: int, clipping_value: float
) -> tff.aggregators.DifferentiallyPrivateFactory:
"""Function for differential privacy with fixed gaussian aggregation.
Args:
noise_multiplier (float): Noise multiplier.\n
clients... | Function for differential privacy with fixed gaussian aggregation.
Args:
noise_multiplier (float): Noise multiplier.\n
clients_per_round (int): Clients per round.\n
clipping_value (float): Clipping value.\n
Returns:
tff.aggregators.DifferentiallyPrivateFactory: Differential Pri... | Function for differential privacy with fixed gaussian aggregation. | [
"Function",
"for",
"differential",
"privacy",
"with",
"fixed",
"gaussian",
"aggregation",
"."
] | def gaussian_fixed_aggregation_factory(
noise_multiplier: float, clients_per_round: int, clipping_value: float
) -> tff.aggregators.DifferentiallyPrivateFactory:
return tff.aggregators.DifferentiallyPrivateFactory.gaussian_fixed(
noise_multiplier=noise_multiplier,
clients_per_round=clients_per_r... | [
"def",
"gaussian_fixed_aggregation_factory",
"(",
"noise_multiplier",
":",
"float",
",",
"clients_per_round",
":",
"int",
",",
"clipping_value",
":",
"float",
")",
"->",
"tff",
".",
"aggregators",
".",
"DifferentiallyPrivateFactory",
":",
"return",
"tff",
".",
"aggr... | Function for differential privacy with fixed gaussian aggregation. | [
"Function",
"for",
"differential",
"privacy",
"with",
"fixed",
"gaussian",
"aggregation",
"."
] | [
"\"\"\"Function for differential privacy with fixed gaussian aggregation.\n\n Args:\n noise_multiplier (float): Noise multiplier.\\n\n clients_per_round (int): Clients per round.\\n\n clipping_value (float): Clipping value.\\n\n\n Returns:\n tff.aggregators.DifferentiallyPrivateFac... | [
{
"param": "noise_multiplier",
"type": "float"
},
{
"param": "clients_per_round",
"type": "int"
},
{
"param": "clipping_value",
"type": "float"
}
] | {
"returns": [
{
"docstring": "Differential Privacy Factory.",
"docstring_tokens": [
"Differential",
"Privacy",
"Factory",
"."
],
"type": "tff.aggregators.DifferentiallyPrivateFactory"
}
],
"raises": [],
"params": [
{
"identifier": "noise... |
6893d4faeb84726f5fa08fd5bf94835767079a34 | dilawarm/federated | federated/main.py | [
"CC-BY-4.0"
] | Python | remove_slash | str | def remove_slash(path: str) -> str:
"""Remove slash in the end of path if present.
Args:
path (str): Path.
Returns:
str: Path without slash.
"""
if path[-1] == "/":
path = path[:-1]
return path | Remove slash in the end of path if present.
Args:
path (str): Path.
Returns:
str: Path without slash.
| Remove slash in the end of path if present. | [
"Remove",
"slash",
"in",
"the",
"end",
"of",
"path",
"if",
"present",
"."
] | def remove_slash(path: str) -> str:
if path[-1] == "/":
path = path[:-1]
return path | [
"def",
"remove_slash",
"(",
"path",
":",
"str",
")",
"->",
"str",
":",
"if",
"path",
"[",
"-",
"1",
"]",
"==",
"\"/\"",
":",
"path",
"=",
"path",
"[",
":",
"-",
"1",
"]",
"return",
"path"
] | Remove slash in the end of path if present. | [
"Remove",
"slash",
"in",
"the",
"end",
"of",
"path",
"if",
"present",
"."
] | [
"\"\"\"Remove slash in the end of path if present.\n\n Args:\n path (str): Path.\n\n Returns:\n str: Path without slash.\n \"\"\""
] | [
{
"param": "path",
"type": "str"
}
] | {
"returns": [
{
"docstring": "Path without slash.",
"docstring_tokens": [
"Path",
"without",
"slash",
"."
],
"type": "str"
}
],
"raises": [],
"params": [
{
"identifier": "path",
"type": "str",
"docstring": null,
"docstr... |
6893d4faeb84726f5fa08fd5bf94835767079a34 | dilawarm/federated | federated/main.py | [
"CC-BY-4.0"
] | Python | print_training_config | None | def print_training_config(args: dict) -> None:
"""Function for printing out training configuration.
Args:
args (dict): Training configuration dictionary.
"""
print(emoji.emojize("\nTraining Configuration :page_with_curl:", use_aliases=True))
print(json.dumps(args, indent=4, sort_keys=True),... | Function for printing out training configuration.
Args:
args (dict): Training configuration dictionary.
| Function for printing out training configuration. | [
"Function",
"for",
"printing",
"out",
"training",
"configuration",
"."
] | def print_training_config(args: dict) -> None:
print(emoji.emojize("\nTraining Configuration :page_with_curl:", use_aliases=True))
print(json.dumps(args, indent=4, sort_keys=True), end="\n\n")
time.sleep(3) | [
"def",
"print_training_config",
"(",
"args",
":",
"dict",
")",
"->",
"None",
":",
"print",
"(",
"emoji",
".",
"emojize",
"(",
"\"\\nTraining Configuration :page_with_curl:\"",
",",
"use_aliases",
"=",
"True",
")",
")",
"print",
"(",
"json",
".",
"dumps",
"(",
... | Function for printing out training configuration. | [
"Function",
"for",
"printing",
"out",
"training",
"configuration",
"."
] | [
"\"\"\"Function for printing out training configuration.\n\n Args:\n args (dict): Training configuration dictionary.\n \"\"\""
] | [
{
"param": "args",
"type": "dict"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "args",
"type": "dict",
"docstring": "Training configuration dictionary.",
"docstring_tokens": [
"Training",
"configuration",
"dictionary",
"."
],
"default": null,
"is_optional"... |
6893d4faeb84726f5fa08fd5bf94835767079a34 | dilawarm/federated | federated/main.py | [
"CC-BY-4.0"
] | Python | check_type | bool | def check_type(x: str, inp_type: type) -> bool:
"""Function for checking if a string can be converted to a certain type.
Args:
x (str): String to convert.\n
inp_type (type) : Type.
Returns:
bool: If x can be converted or not.
"""
try:
inp_type(x)
return True... | Function for checking if a string can be converted to a certain type.
Args:
x (str): String to convert.\n
inp_type (type) : Type.
Returns:
bool: If x can be converted or not.
| Function for checking if a string can be converted to a certain type. | [
"Function",
"for",
"checking",
"if",
"a",
"string",
"can",
"be",
"converted",
"to",
"a",
"certain",
"type",
"."
] | def check_type(x: str, inp_type: type) -> bool:
try:
inp_type(x)
return True
except:
return False | [
"def",
"check_type",
"(",
"x",
":",
"str",
",",
"inp_type",
":",
"type",
")",
"->",
"bool",
":",
"try",
":",
"inp_type",
"(",
"x",
")",
"return",
"True",
"except",
":",
"return",
"False"
] | Function for checking if a string can be converted to a certain type. | [
"Function",
"for",
"checking",
"if",
"a",
"string",
"can",
"be",
"converted",
"to",
"a",
"certain",
"type",
"."
] | [
"\"\"\"Function for checking if a string can be converted to a certain type.\n\n Args:\n x (str): String to convert.\\n\n inp_type (type) : Type.\n\n Returns:\n bool: If x can be converted or not.\n \"\"\""
] | [
{
"param": "x",
"type": "str"
},
{
"param": "inp_type",
"type": "type"
}
] | {
"returns": [
{
"docstring": "If x can be converted or not.",
"docstring_tokens": [
"If",
"x",
"can",
"be",
"converted",
"or",
"not",
"."
],
"type": "bool"
}
],
"raises": [],
"params": [
{
"identifier": "x... |
6893d4faeb84726f5fa08fd5bf94835767079a34 | dilawarm/federated | federated/main.py | [
"CC-BY-4.0"
] | Python | validate_type_input | Any | def validate_type_input(input_string: str, default: Any, inp_type: type) -> Any:
"""Custom input with validation for ints, floats, and bools.
Args:
input_string (str): Prompt string for input.\n
default (Any): Default value.\n
inp_type (type): Type to convert to.
Returns:
A... | Custom input with validation for ints, floats, and bools.
Args:
input_string (str): Prompt string for input.\n
default (Any): Default value.\n
inp_type (type): Type to convert to.
Returns:
Any: Converted input value.
| Custom input with validation for ints, floats, and bools. | [
"Custom",
"input",
"with",
"validation",
"for",
"ints",
"floats",
"and",
"bools",
"."
] | def validate_type_input(input_string: str, default: Any, inp_type: type) -> Any:
prompts = chain(
[input_string + f"(default: {boldify(default)}): "],
repeat(f"Input must be of type {inp_type}. Try again: "),
)
replies = map(input, prompts)
valid_response = next(filter(lambda x: check_ty... | [
"def",
"validate_type_input",
"(",
"input_string",
":",
"str",
",",
"default",
":",
"Any",
",",
"inp_type",
":",
"type",
")",
"->",
"Any",
":",
"prompts",
"=",
"chain",
"(",
"[",
"input_string",
"+",
"f\"(default: {boldify(default)}): \"",
"]",
",",
"repeat",
... | Custom input with validation for ints, floats, and bools. | [
"Custom",
"input",
"with",
"validation",
"for",
"ints",
"floats",
"and",
"bools",
"."
] | [
"\"\"\"Custom input with validation for ints, floats, and bools.\n\n Args:\n input_string (str): Prompt string for input.\\n\n default (Any): Default value.\\n\n inp_type (type): Type to convert to.\n\n Returns:\n Any: Converted input value.\n \"\"\""
] | [
{
"param": "input_string",
"type": "str"
},
{
"param": "default",
"type": "Any"
},
{
"param": "inp_type",
"type": "type"
}
] | {
"returns": [
{
"docstring": "Converted input value.",
"docstring_tokens": [
"Converted",
"input",
"value",
"."
],
"type": "Any"
}
],
"raises": [],
"params": [
{
"identifier": "input_string",
"type": "str",
"docstring": "Prom... |
6893d4faeb84726f5fa08fd5bf94835767079a34 | dilawarm/federated | federated/main.py | [
"CC-BY-4.0"
] | Python | validate_options_input | str | def validate_options_input(input_string: str, default: str, options: List[str]) -> str:
"""Custom input with validation where we have options.
Args:
input_string (str): Prompt string for input.\n
default (str): Default value.\n
options (List[str]): Options for input.\n
Returns:
... | Custom input with validation where we have options.
Args:
input_string (str): Prompt string for input.\n
default (str): Default value.\n
options (List[str]): Options for input.\n
Returns:
str: Input value.
| Custom input with validation where we have options. | [
"Custom",
"input",
"with",
"validation",
"where",
"we",
"have",
"options",
"."
] | def validate_options_input(input_string: str, default: str, options: List[str]) -> str:
prompts = chain(
[input_string + f"{options}. (default: {boldify(default)}): "],
repeat(f"Input must be one of {options}. Try again: "),
)
replies = map(input, prompts)
valid_response = next(filter(la... | [
"def",
"validate_options_input",
"(",
"input_string",
":",
"str",
",",
"default",
":",
"str",
",",
"options",
":",
"List",
"[",
"str",
"]",
")",
"->",
"str",
":",
"prompts",
"=",
"chain",
"(",
"[",
"input_string",
"+",
"f\"{options}. (default: {boldify(default... | Custom input with validation where we have options. | [
"Custom",
"input",
"with",
"validation",
"where",
"we",
"have",
"options",
"."
] | [
"\"\"\"Custom input with validation where we have options.\n\n Args:\n input_string (str): Prompt string for input.\\n\n default (str): Default value.\\n\n options (List[str]): Options for input.\\n\n\n Returns:\n str: Input value.\n \"\"\""
] | [
{
"param": "input_string",
"type": "str"
},
{
"param": "default",
"type": "str"
},
{
"param": "options",
"type": "List[str]"
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": "str"
}
],
"raises": [],
"params": [
{
"identifier": "input_string",
"type": "str",
"docstring": "Prompt string for input.\\n",
"docstring_tokens": [
"Prompt",
... |
3558a029b1a61d892719e0f45ce6a2a31178c2c1 | dilawarm/federated | federated/data/data_preprocessing.py | [
"CC-BY-4.0"
] | Python | create_dataset | Tuple[None, tff.simulation.ClientData] | def create_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[None, tff.simulation.ClientData]:
"""Function converts pandas dataframe to tensorflow federated dataset.
Args:
X (np.ndarray): Inputs.\n
y (np.ndarray): Outputs.\n
number_of_clients (int): The number... | Function converts pandas dataframe to tensorflow federated dataset.
Args:
X (np.ndarray): Inputs.\n
y (np.ndarray): Outputs.\n
number_of_clients (int): The number of clients to split the data between.\n
Returns:
[None, tff.simulation.ClientData]: Returns federated data distribu... | Function converts pandas dataframe to tensorflow federated dataset. | [
"Function",
"converts",
"pandas",
"dataframe",
"to",
"tensorflow",
"federated",
"dataset",
"."
] | def create_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[None, tff.simulation.ClientData]:
num_of_clients = NUM_OF_CLIENTS
total_ecg_count = len(X)
ecgs_per_set = int(np.floor(total_ecg_count / num_of_clients))
client_dataset = collections.OrderedDict()
for i in range(... | [
"def",
"create_dataset",
"(",
"X",
":",
"np",
".",
"ndarray",
",",
"y",
":",
"np",
".",
"ndarray",
",",
"number_of_clients",
":",
"int",
")",
"->",
"Tuple",
"[",
"None",
",",
"tff",
".",
"simulation",
".",
"ClientData",
"]",
":",
"num_of_clients",
"=",... | Function converts pandas dataframe to tensorflow federated dataset. | [
"Function",
"converts",
"pandas",
"dataframe",
"to",
"tensorflow",
"federated",
"dataset",
"."
] | [
"\"\"\"Function converts pandas dataframe to tensorflow federated dataset.\n\n Args:\n X (np.ndarray): Inputs.\\n\n y (np.ndarray): Outputs.\\n\n number_of_clients (int): The number of clients to split the data between.\\n\n\n Returns:\n [None, tff.simulation.ClientData]: Returns f... | [
{
"param": "X",
"type": "np.ndarray"
},
{
"param": "y",
"type": "np.ndarray"
},
{
"param": "number_of_clients",
"type": "int"
}
] | {
"returns": [
{
"docstring": "Returns federated data distribution.",
"docstring_tokens": [
"Returns",
"federated",
"data",
"distribution",
"."
],
"type": "[None, tff.simulation.ClientData]"
}
],
"raises": [],
"params": [
{
"ident... |
3558a029b1a61d892719e0f45ce6a2a31178c2c1 | dilawarm/federated | federated/data/data_preprocessing.py | [
"CC-BY-4.0"
] | Python | create_tff_dataset | tff.simulation.ClientData | def create_tff_dataset(clients_data: Dict) -> tff.simulation.ClientData:
"""Function converts dictionary to tensorflow federated dataset.
Args:
clients_data (Dict): Inputs.
Returns:
tff.simulation.ClientData: Returns federated data distribution.
"""
client_dataset = collections.Ord... | Function converts dictionary to tensorflow federated dataset.
Args:
clients_data (Dict): Inputs.
Returns:
tff.simulation.ClientData: Returns federated data distribution.
| Function converts dictionary to tensorflow federated dataset. | [
"Function",
"converts",
"dictionary",
"to",
"tensorflow",
"federated",
"dataset",
"."
] | def create_tff_dataset(clients_data: Dict) -> tff.simulation.ClientData:
client_dataset = collections.OrderedDict()
for client in clients_data:
data = collections.OrderedDict(
(
("label", np.array(clients_data[client][1], dtype=np.int32)),
("datapoints", np.ar... | [
"def",
"create_tff_dataset",
"(",
"clients_data",
":",
"Dict",
")",
"->",
"tff",
".",
"simulation",
".",
"ClientData",
":",
"client_dataset",
"=",
"collections",
".",
"OrderedDict",
"(",
")",
"for",
"client",
"in",
"clients_data",
":",
"data",
"=",
"collection... | Function converts dictionary to tensorflow federated dataset. | [
"Function",
"converts",
"dictionary",
"to",
"tensorflow",
"federated",
"dataset",
"."
] | [
"\"\"\"Function converts dictionary to tensorflow federated dataset.\n\n Args:\n clients_data (Dict): Inputs.\n\n Returns:\n tff.simulation.ClientData: Returns federated data distribution.\n \"\"\""
] | [
{
"param": "clients_data",
"type": "Dict"
}
] | {
"returns": [
{
"docstring": "Returns federated data distribution.",
"docstring_tokens": [
"Returns",
"federated",
"data",
"distribution",
"."
],
"type": "tff.simulation.ClientData"
}
],
"raises": [],
"params": [
{
"identifier": ... |
3558a029b1a61d892719e0f45ce6a2a31178c2c1 | dilawarm/federated | federated/data/data_preprocessing.py | [
"CC-BY-4.0"
] | Python | create_class_distributed_dataset | Tuple[Dict, tff.simulation.ClientData] | def create_class_distributed_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
"""Function distributes the data in a way such that each client gets one type of data.
Args:
X (np.ndarray): Input.\n
y (np.ndarray): Output.\n
num... | Function distributes the data in a way such that each client gets one type of data.
Args:
X (np.ndarray): Input.\n
y (np.ndarray): Output.\n
number_of_clients (int): Number of clients.\n
Returns:
[Dict, tff.simulation.ClientData]: A dictionary and a tensorflow federated dataset ... | Function distributes the data in a way such that each client gets one type of data. | [
"Function",
"distributes",
"the",
"data",
"in",
"a",
"way",
"such",
"that",
"each",
"client",
"gets",
"one",
"type",
"of",
"data",
"."
] | def create_class_distributed_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
n = len(X)
clients_data = {f"client_{i}": [[], []] for i in range(1, 6)}
for i in range(n):
index = np.where(y[i] == 1)[0][0]
clients_data[f"client_{ind... | [
"def",
"create_class_distributed_dataset",
"(",
"X",
":",
"np",
".",
"ndarray",
",",
"y",
":",
"np",
".",
"ndarray",
",",
"number_of_clients",
":",
"int",
")",
"->",
"Tuple",
"[",
"Dict",
",",
"tff",
".",
"simulation",
".",
"ClientData",
"]",
":",
"n",
... | Function distributes the data in a way such that each client gets one type of data. | [
"Function",
"distributes",
"the",
"data",
"in",
"a",
"way",
"such",
"that",
"each",
"client",
"gets",
"one",
"type",
"of",
"data",
"."
] | [
"\"\"\"Function distributes the data in a way such that each client gets one type of data.\n\n Args:\n X (np.ndarray): Input.\\n\n y (np.ndarray): Output.\\n\n number_of_clients (int): Number of clients.\\n\n Returns:\n [Dict, tff.simulation.ClientData]: A dictionary and a tensorfl... | [
{
"param": "X",
"type": "np.ndarray"
},
{
"param": "y",
"type": "np.ndarray"
},
{
"param": "number_of_clients",
"type": "int"
}
] | {
"returns": [
{
"docstring": "A dictionary and a tensorflow federated dataset containing the distributed dataset.",
"docstring_tokens": [
"A",
"dictionary",
"and",
"a",
"tensorflow",
"federated",
"dataset",
"containing",
"the",
... |
3558a029b1a61d892719e0f45ce6a2a31178c2c1 | dilawarm/federated | federated/data/data_preprocessing.py | [
"CC-BY-4.0"
] | Python | create_uniform_dataset | Tuple[Dict, tff.simulation.ClientData] | def create_uniform_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
"""Function distributes the data equally such that each client holds equal amounts of each class.
Args:
X (np.ndarray): Input.\n
y (np.ndarray): Output.\n
nu... | Function distributes the data equally such that each client holds equal amounts of each class.
Args:
X (np.ndarray): Input.\n
y (np.ndarray): Output.\n
number_of_clients (int): Number of clients.\n
Returns:
[Dict, tff.simulation.ClientData]: A dictionary and a tensorflow federat... | Function distributes the data equally such that each client holds equal amounts of each class. | [
"Function",
"distributes",
"the",
"data",
"equally",
"such",
"that",
"each",
"client",
"holds",
"equal",
"amounts",
"of",
"each",
"class",
"."
] | def create_uniform_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
clients_data = {f"client_{i}": [[], []] for i in range(1, number_of_clients + 1)}
for i in range(len(X)):
clients_data[f"client_{(i%number_of_clients)+1}"][0].append(X[i])
... | [
"def",
"create_uniform_dataset",
"(",
"X",
":",
"np",
".",
"ndarray",
",",
"y",
":",
"np",
".",
"ndarray",
",",
"number_of_clients",
":",
"int",
")",
"->",
"Tuple",
"[",
"Dict",
",",
"tff",
".",
"simulation",
".",
"ClientData",
"]",
":",
"clients_data",
... | Function distributes the data equally such that each client holds equal amounts of each class. | [
"Function",
"distributes",
"the",
"data",
"equally",
"such",
"that",
"each",
"client",
"holds",
"equal",
"amounts",
"of",
"each",
"class",
"."
] | [
"\"\"\"Function distributes the data equally such that each client holds equal amounts of each class.\n\n Args:\n X (np.ndarray): Input.\\n\n y (np.ndarray): Output.\\n\n number_of_clients (int): Number of clients.\\n\n Returns:\n [Dict, tff.simulation.ClientData]: A dictionary and... | [
{
"param": "X",
"type": "np.ndarray"
},
{
"param": "y",
"type": "np.ndarray"
},
{
"param": "number_of_clients",
"type": "int"
}
] | {
"returns": [
{
"docstring": "A dictionary and a tensorflow federated dataset containing the distributed dataset.",
"docstring_tokens": [
"A",
"dictionary",
"and",
"a",
"tensorflow",
"federated",
"dataset",
"containing",
"the",
... |
3558a029b1a61d892719e0f45ce6a2a31178c2c1 | dilawarm/federated | federated/data/data_preprocessing.py | [
"CC-BY-4.0"
] | Python | create_unbalanced_data | Tuple[Dict, tff.simulation.ClientData] | def create_unbalanced_data(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
"""Function distributes the data in such a way that one client only has one type of data, while the rest of the clients has non-iid data.
Args:
X (np.ndarray): Input.\n
... | Function distributes the data in such a way that one client only has one type of data, while the rest of the clients has non-iid data.
Args:
X (np.ndarray): Input.\n
y (np.ndarray): Output.\n
number_of_clients (int): Number of clients.\n
Returns:
[Dict, tff.simulation.ClientData... | Function distributes the data in such a way that one client only has one type of data, while the rest of the clients has non-iid data. | [
"Function",
"distributes",
"the",
"data",
"in",
"such",
"a",
"way",
"that",
"one",
"client",
"only",
"has",
"one",
"type",
"of",
"data",
"while",
"the",
"rest",
"of",
"the",
"clients",
"has",
"non",
"-",
"iid",
"data",
"."
] | def create_unbalanced_data(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
indices = np.arange(X.shape[0])
np.random.shuffle(indices)
X = X[indices]
y = y[indices]
clients_data = {f"client_{i}": [[], []] for i in range(1, number_of_clients + 1)}... | [
"def",
"create_unbalanced_data",
"(",
"X",
":",
"np",
".",
"ndarray",
",",
"y",
":",
"np",
".",
"ndarray",
",",
"number_of_clients",
":",
"int",
")",
"->",
"Tuple",
"[",
"Dict",
",",
"tff",
".",
"simulation",
".",
"ClientData",
"]",
":",
"indices",
"="... | Function distributes the data in such a way that one client only has one type of data, while the rest of the clients has non-iid data. | [
"Function",
"distributes",
"the",
"data",
"in",
"such",
"a",
"way",
"that",
"one",
"client",
"only",
"has",
"one",
"type",
"of",
"data",
"while",
"the",
"rest",
"of",
"the",
"clients",
"has",
"non",
"-",
"iid",
"data",
"."
] | [
"\"\"\"Function distributes the data in such a way that one client only has one type of data, while the rest of the clients has non-iid data.\n\n Args:\n X (np.ndarray): Input.\\n\n y (np.ndarray): Output.\\n\n number_of_clients (int): Number of clients.\\n\n Returns:\n [Dict, tff.... | [
{
"param": "X",
"type": "np.ndarray"
},
{
"param": "y",
"type": "np.ndarray"
},
{
"param": "number_of_clients",
"type": "int"
}
] | {
"returns": [
{
"docstring": "A dictionary and a tensorflow federated dataset containing the distributed dataset.",
"docstring_tokens": [
"A",
"dictionary",
"and",
"a",
"tensorflow",
"federated",
"dataset",
"containing",
"the",
... |
3558a029b1a61d892719e0f45ce6a2a31178c2c1 | dilawarm/federated | federated/data/data_preprocessing.py | [
"CC-BY-4.0"
] | Python | create_non_iid_dataset | Tuple[Dict, tff.simulation.ClientData] | def create_non_iid_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
"""Function distributes the data such that each client has non-iid data.
Args:
X (np.ndarray): Input.\n
y (np.ndarray): Output.\n
number_of_clients (int): Nu... | Function distributes the data such that each client has non-iid data.
Args:
X (np.ndarray): Input.\n
y (np.ndarray): Output.\n
number_of_clients (int): Number of clients.\n
Returns:
[Dict, tff.simulation.ClientData]: A dictionary and a tensorflow federated dataset containing the... | Function distributes the data such that each client has non-iid data. | [
"Function",
"distributes",
"the",
"data",
"such",
"that",
"each",
"client",
"has",
"non",
"-",
"iid",
"data",
"."
] | def create_non_iid_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
indices = np.arange(X.shape[0])
np.random.shuffle(indices)
X = X[indices]
y = y[indices]
clients_data = {f"client_{i}": [[], []] for i in range(1, number_of_clients + 1)}... | [
"def",
"create_non_iid_dataset",
"(",
"X",
":",
"np",
".",
"ndarray",
",",
"y",
":",
"np",
".",
"ndarray",
",",
"number_of_clients",
":",
"int",
")",
"->",
"Tuple",
"[",
"Dict",
",",
"tff",
".",
"simulation",
".",
"ClientData",
"]",
":",
"indices",
"="... | Function distributes the data such that each client has non-iid data. | [
"Function",
"distributes",
"the",
"data",
"such",
"that",
"each",
"client",
"has",
"non",
"-",
"iid",
"data",
"."
] | [
"\"\"\"Function distributes the data such that each client has non-iid data.\n\n Args:\n X (np.ndarray): Input.\\n\n y (np.ndarray): Output.\\n\n number_of_clients (int): Number of clients.\\n\n Returns:\n [Dict, tff.simulation.ClientData]: A dictionary and a tensorflow federated d... | [
{
"param": "X",
"type": "np.ndarray"
},
{
"param": "y",
"type": "np.ndarray"
},
{
"param": "number_of_clients",
"type": "int"
}
] | {
"returns": [
{
"docstring": "A dictionary and a tensorflow federated dataset containing the distributed dataset.",
"docstring_tokens": [
"A",
"dictionary",
"and",
"a",
"tensorflow",
"federated",
"dataset",
"containing",
"the",
... |
3558a029b1a61d892719e0f45ce6a2a31178c2c1 | dilawarm/federated | federated/data/data_preprocessing.py | [
"CC-BY-4.0"
] | Python | create_corrupted_non_iid_dataset | Tuple[Dict, tff.simulation.ClientData] | def create_corrupted_non_iid_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
"""Function distributes the data such that each client has non-iid data except client 1, which only has values in the interval [20, 40].
Args:
X (np.ndarray): Inpu... | Function distributes the data such that each client has non-iid data except client 1, which only has values in the interval [20, 40].
Args:
X (np.ndarray): Input.\n
y (np.ndarray): Output.\n
number_of_clients (int): Number of clients.\n
Returns:
[Dict, tff.simulation.ClientData]... | Function distributes the data such that each client has non-iid data except client 1, which only has values in the interval [20, 40]. | [
"Function",
"distributes",
"the",
"data",
"such",
"that",
"each",
"client",
"has",
"non",
"-",
"iid",
"data",
"except",
"client",
"1",
"which",
"only",
"has",
"values",
"in",
"the",
"interval",
"[",
"20",
"40",
"]",
"."
] | def create_corrupted_non_iid_dataset(
X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
indices = np.arange(X.shape[0])
np.random.shuffle(indices)
X = X[indices]
y = y[indices]
clients_data = {f"client_{i}": [[], []] for i in range(1, number_of_cli... | [
"def",
"create_corrupted_non_iid_dataset",
"(",
"X",
":",
"np",
".",
"ndarray",
",",
"y",
":",
"np",
".",
"ndarray",
",",
"number_of_clients",
":",
"int",
")",
"->",
"Tuple",
"[",
"Dict",
",",
"tff",
".",
"simulation",
".",
"ClientData",
"]",
":",
"indic... | Function distributes the data such that each client has non-iid data except client 1, which only has values in the interval [20, 40]. | [
"Function",
"distributes",
"the",
"data",
"such",
"that",
"each",
"client",
"has",
"non",
"-",
"iid",
"data",
"except",
"client",
"1",
"which",
"only",
"has",
"values",
"in",
"the",
"interval",
"[",
"20",
"40",
"]",
"."
] | [
"\"\"\"Function distributes the data such that each client has non-iid data except client 1, which only has values in the interval [20, 40].\n\n Args:\n X (np.ndarray): Input.\\n\n y (np.ndarray): Output.\\n\n number_of_clients (int): Number of clients.\\n\n Returns:\n [Dict, tff.s... | [
{
"param": "X",
"type": "np.ndarray"
},
{
"param": "y",
"type": "np.ndarray"
},
{
"param": "number_of_clients",
"type": "int"
}
] | {
"returns": [
{
"docstring": "A dictionary and a tensorflow federated dataset containing the distributed dataset.",
"docstring_tokens": [
"A",
"dictionary",
"and",
"a",
"tensorflow",
"federated",
"dataset",
"containing",
"the",
... |
3558a029b1a61d892719e0f45ce6a2a31178c2c1 | dilawarm/federated | federated/data/data_preprocessing.py | [
"CC-BY-4.0"
] | Python | load_data | Tuple[tff.simulation.ClientData, tff.simulation.ClientData, int] | def load_data(
normalized: bool = True,
data_analysis: bool = False,
data_selector: Callable[
[np.ndarray, np.ndarray, int], tff.simulation.ClientData
] = None,
number_of_clients: int = 5,
) -> Tuple[tff.simulation.ClientData, tff.simulation.ClientData, int]:
"""Function loads data from ... | Function loads data from csv-file and preprocesses the training and test data seperately.
Args:
normalized (bool, optional): Whether to normalize the data. Defaults to True.\n
data_analysis (bool, optional): Load data for data analysis. Defaults to False.\n
data_selector (Callable[ [np.ndar... | Function loads data from csv-file and preprocesses the training and test data seperately. | [
"Function",
"loads",
"data",
"from",
"csv",
"-",
"file",
"and",
"preprocesses",
"the",
"training",
"and",
"test",
"data",
"seperately",
"."
] | def load_data(
normalized: bool = True,
data_analysis: bool = False,
data_selector: Callable[
[np.ndarray, np.ndarray, int], tff.simulation.ClientData
] = None,
number_of_clients: int = 5,
) -> Tuple[tff.simulation.ClientData, tff.simulation.ClientData, int]:
train_file = "data/mitbih/mi... | [
"def",
"load_data",
"(",
"normalized",
":",
"bool",
"=",
"True",
",",
"data_analysis",
":",
"bool",
"=",
"False",
",",
"data_selector",
":",
"Callable",
"[",
"[",
"np",
".",
"ndarray",
",",
"np",
".",
"ndarray",
",",
"int",
"]",
",",
"tff",
".",
"sim... | Function loads data from csv-file and preprocesses the training and test data seperately. | [
"Function",
"loads",
"data",
"from",
"csv",
"-",
"file",
"and",
"preprocesses",
"the",
"training",
"and",
"test",
"data",
"seperately",
"."
] | [
"\"\"\"Function loads data from csv-file and preprocesses the training and test data seperately.\n\n Args:\n normalized (bool, optional): Whether to normalize the data. Defaults to True.\\n\n data_analysis (bool, optional): Load data for data analysis. Defaults to False.\\n\n data_selector (... | [
{
"param": "normalized",
"type": "bool"
},
{
"param": "data_analysis",
"type": "bool"
},
{
"param": "data_selector",
"type": "Callable[\n [np.ndarray, np.ndarray, int], tff.simulation.ClientData\n ]"
},
{
"param": "number_of_clients",
"type": "int"
}
] | {
"returns": [
{
"docstring": "A tuple of tff.simulation.ClientData.",
"docstring_tokens": [
"A",
"tuple",
"of",
"tff",
".",
"simulation",
".",
"ClientData",
"."
],
"type": "[tff.simulation.ClientData, tff.simulation.C... |
3558a029b1a61d892719e0f45ce6a2a31178c2c1 | dilawarm/federated | federated/data/data_preprocessing.py | [
"CC-BY-4.0"
] | Python | preprocess_dataset | Callable[[tf.data.Dataset], tf.data.Dataset] | def preprocess_dataset(
epochs: int, batch_size: int, shuffle_buffer_size: int
) -> Callable[[tf.data.Dataset], tf.data.Dataset]:
"""Function returns a function for preprocessing of a dataset.
Args:
epochs (int): How many times to repeat a batch.\n
batch_size (int): Batch size.\n
sh... | Function returns a function for preprocessing of a dataset.
Args:
epochs (int): How many times to repeat a batch.\n
batch_size (int): Batch size.\n
shuffle_buffer_size (int): Buffer size for shuffling the dataset.\n
Returns:
Callable[[tf.data.Dataset], tf.data.Dataset]: A calla... | Function returns a function for preprocessing of a dataset. | [
"Function",
"returns",
"a",
"function",
"for",
"preprocessing",
"of",
"a",
"dataset",
"."
] | def preprocess_dataset(
epochs: int, batch_size: int, shuffle_buffer_size: int
) -> Callable[[tf.data.Dataset], tf.data.Dataset]:
def _reshape(element: collections.OrderedDict) -> tf.Tensor:
return (tf.expand_dims(element["datapoints"], axis=-1), element["label"])
@tff.tf_computation(
tff.Se... | [
"def",
"preprocess_dataset",
"(",
"epochs",
":",
"int",
",",
"batch_size",
":",
"int",
",",
"shuffle_buffer_size",
":",
"int",
")",
"->",
"Callable",
"[",
"[",
"tf",
".",
"data",
".",
"Dataset",
"]",
",",
"tf",
".",
"data",
".",
"Dataset",
"]",
":",
... | Function returns a function for preprocessing of a dataset. | [
"Function",
"returns",
"a",
"function",
"for",
"preprocessing",
"of",
"a",
"dataset",
"."
] | [
"\"\"\"Function returns a function for preprocessing of a dataset.\n\n Args:\n epochs (int): How many times to repeat a batch.\\n\n batch_size (int): Batch size.\\n\n shuffle_buffer_size (int): Buffer size for shuffling the dataset.\\n\n\n Returns:\n Callable[[tf.data.Dataset], tf.... | [
{
"param": "epochs",
"type": "int"
},
{
"param": "batch_size",
"type": "int"
},
{
"param": "shuffle_buffer_size",
"type": "int"
}
] | {
"returns": [
{
"docstring": "A callable for preprocessing a dataset object.",
"docstring_tokens": [
"A",
"callable",
"for",
"preprocessing",
"a",
"dataset",
"object",
"."
],
"type": "Callable[[tf.data.Dataset], tf.data.Datas... |
71f9019cda8ac9b8baff754c81e34cc110becd19 | dilawarm/federated | federated/tests/rfa_test.py | [
"CC-BY-4.0"
] | Python | create_model | tf.keras.Model | def create_model(self) -> tf.keras.Model:
"""Creates model for RFA tests.
Returns:
tf.keras.Model: Model.
"""
def create_model_fn():
keras_model = tf.keras.models.Sequential(
[
tf.keras.layers.Input(shape=(10,)),
... | Creates model for RFA tests.
Returns:
tf.keras.Model: Model.
| Creates model for RFA tests. | [
"Creates",
"model",
"for",
"RFA",
"tests",
"."
] | def create_model(self) -> tf.keras.Model:
def create_model_fn():
keras_model = tf.keras.models.Sequential(
[
tf.keras.layers.Input(shape=(10,)),
tf.keras.layers.Dense(
1, kernel_initializer="zeros", use_bias=False
... | [
"def",
"create_model",
"(",
"self",
")",
"->",
"tf",
".",
"keras",
".",
"Model",
":",
"def",
"create_model_fn",
"(",
")",
":",
"keras_model",
"=",
"tf",
".",
"keras",
".",
"models",
".",
"Sequential",
"(",
"[",
"tf",
".",
"keras",
".",
"layers",
".",... | Creates model for RFA tests. | [
"Creates",
"model",
"for",
"RFA",
"tests",
"."
] | [
"\"\"\"Creates model for RFA tests.\n\n Returns:\n tf.keras.Model: Model.\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": "tf.keras.Model"
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_option... |
11d24d9b09674ee4dc2c214e3a4687e146a3d4b5 | dilawarm/federated | federated/tests/training_loops_test.py | [
"CC-BY-4.0"
] | Python | create_tff_model | TYPE | def create_tff_model(self) -> TYPE:
"""Function for creating TFF model.
Returns:
self.TYPE: TFF Model.
"""
input_spec = self.TYPE(
x=tf.TensorSpec(shape=[None, 784], dtype=tf.float32),
y=tf.TensorSpec(shape=[None, 1], dtype=tf.int64),
)
... | Function for creating TFF model.
Returns:
self.TYPE: TFF Model.
| Function for creating TFF model. | [
"Function",
"for",
"creating",
"TFF",
"model",
"."
] | def create_tff_model(self) -> TYPE:
input_spec = self.TYPE(
x=tf.TensorSpec(shape=[None, 784], dtype=tf.float32),
y=tf.TensorSpec(shape=[None, 1], dtype=tf.int64),
)
return tff.learning.from_keras_model(
keras_model=tff.simulation.models.mnist.create_keras_mod... | [
"def",
"create_tff_model",
"(",
"self",
")",
"->",
"TYPE",
":",
"input_spec",
"=",
"self",
".",
"TYPE",
"(",
"x",
"=",
"tf",
".",
"TensorSpec",
"(",
"shape",
"=",
"[",
"None",
",",
"784",
"]",
",",
"dtype",
"=",
"tf",
".",
"float32",
")",
",",
"y... | Function for creating TFF model. | [
"Function",
"for",
"creating",
"TFF",
"model",
"."
] | [
"\"\"\"Function for creating TFF model.\n\n Returns:\n self.TYPE: TFF Model.\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": "self.TYPE"
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": ... |
b545584989f721019fc405bd4f7d5a5824702522 | dilawarm/federated | federated/optimization/federated.py | [
"CC-BY-4.0"
] | Python | iterative_process_fn | tff.templates.IterativeProcess | def iterative_process_fn(
tff_model: tff.learning.Model,
server_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
aggregation_method: str = "fedavg",
client_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer] = None,
iterations: int = None,
client_weighting: tff.learning.ClientWei... | Function builds an iterative process that performs federated aggregation. The function offers federated averaging, federated stochastic gradient descent and robust federated aggregation.
Args:
tff_model (tff.learning.Model): Federated model object.\n
server_optimizer_fn (Callable[[], tf.keras.optim... | Function builds an iterative process that performs federated aggregation. The function offers federated averaging, federated stochastic gradient descent and robust federated aggregation. | [
"Function",
"builds",
"an",
"iterative",
"process",
"that",
"performs",
"federated",
"aggregation",
".",
"The",
"function",
"offers",
"federated",
"averaging",
"federated",
"stochastic",
"gradient",
"descent",
"and",
"robust",
"federated",
"aggregation",
"."
] | def iterative_process_fn(
tff_model: tff.learning.Model,
server_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
aggregation_method: str = "fedavg",
client_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer] = None,
iterations: int = None,
client_weighting: tff.learning.ClientWei... | [
"def",
"iterative_process_fn",
"(",
"tff_model",
":",
"tff",
".",
"learning",
".",
"Model",
",",
"server_optimizer_fn",
":",
"Callable",
"[",
"[",
"]",
",",
"tf",
".",
"keras",
".",
"optimizers",
".",
"Optimizer",
"]",
",",
"aggregation_method",
":",
"str",
... | Function builds an iterative process that performs federated aggregation. | [
"Function",
"builds",
"an",
"iterative",
"process",
"that",
"performs",
"federated",
"aggregation",
"."
] | [
"\"\"\"Function builds an iterative process that performs federated aggregation. The function offers federated averaging, federated stochastic gradient descent and robust federated aggregation.\n\n Args:\n tff_model (tff.learning.Model): Federated model object.\\n\n server_optimizer_fn (Callable[[]... | [
{
"param": "tff_model",
"type": "tff.learning.Model"
},
{
"param": "server_optimizer_fn",
"type": "Callable[[], tf.keras.optimizers.Optimizer]"
},
{
"param": "aggregation_method",
"type": "str"
},
{
"param": "client_optimizer_fn",
"type": "Callable[[], tf.keras.optimizers... | {
"returns": [
{
"docstring": "An Iterative Process.",
"docstring_tokens": [
"An",
"Iterative",
"Process",
"."
],
"type": "tff.templates.IterativeProcess"
}
],
"raises": [],
"params": [
{
"identifier": "tff_model",
"type": "tff.lear... |
b545584989f721019fc405bd4f7d5a5824702522 | dilawarm/federated | federated/optimization/federated.py | [
"CC-BY-4.0"
] | Python | federated_pipeline | float | def federated_pipeline(
name: str,
aggregation_method: str,
client_weighting: str,
keras_model_fn: str,
server_optimizer_fn: str,
server_optimizer_lr: float,
client_optimizer_fn: str,
client_optimizer_lr: float,
data_selector: str,
output: str,
client_epochs: int,
batch_s... | Function runs federated training pipeline on the dataset.
Args:
name (str): Experiment name.\n
aggregation_method (str): Aggregation method. Defaults to "fedavg".\n
client_weighting (str): Client weighting. Either Uniform or Data dependent. Defaults to NUM_EXAMPLES.\n
keras_model_fn... | Function runs federated training pipeline on the dataset. | [
"Function",
"runs",
"federated",
"training",
"pipeline",
"on",
"the",
"dataset",
"."
] | def federated_pipeline(
name: str,
aggregation_method: str,
client_weighting: str,
keras_model_fn: str,
server_optimizer_fn: str,
server_optimizer_lr: float,
client_optimizer_fn: str,
client_optimizer_lr: float,
data_selector: str,
output: str,
client_epochs: int,
batch_s... | [
"def",
"federated_pipeline",
"(",
"name",
":",
"str",
",",
"aggregation_method",
":",
"str",
",",
"client_weighting",
":",
"str",
",",
"keras_model_fn",
":",
"str",
",",
"server_optimizer_fn",
":",
"str",
",",
"server_optimizer_lr",
":",
"float",
",",
"client_op... | Function runs federated training pipeline on the dataset. | [
"Function",
"runs",
"federated",
"training",
"pipeline",
"on",
"the",
"dataset",
"."
] | [
"\"\"\"Function runs federated training pipeline on the dataset.\n\n Args:\n name (str): Experiment name.\\n\n aggregation_method (str): Aggregation method. Defaults to \"fedavg\".\\n\n client_weighting (str): Client weighting. Either Uniform or Data dependent. Defaults to NUM_EXAMPLES.\\n\n... | [
{
"param": "name",
"type": "str"
},
{
"param": "aggregation_method",
"type": "str"
},
{
"param": "client_weighting",
"type": "str"
},
{
"param": "keras_model_fn",
"type": "str"
},
{
"param": "server_optimizer_fn",
"type": "str"
},
{
"param": "server_op... | {
"returns": [
{
"docstring": "Returns training time after federated learning.",
"docstring_tokens": [
"Returns",
"training",
"time",
"after",
"federated",
"learning",
"."
],
"type": "float"
}
],
"raises": [],
"params": [
... |
b545584989f721019fc405bd4f7d5a5824702522 | dilawarm/federated | federated/optimization/federated.py | [
"CC-BY-4.0"
] | Python | model_fn | tff.learning.Model | def model_fn() -> tff.learning.Model:
"""
Function that takes a keras model and creates an tensorflow federated learning model.
"""
return tff.learning.from_keras_model(
keras_model=get_keras_model(),
input_spec=input_spec,
loss=loss_fn(),
... |
Function that takes a keras model and creates an tensorflow federated learning model.
| Function that takes a keras model and creates an tensorflow federated learning model. | [
"Function",
"that",
"takes",
"a",
"keras",
"model",
"and",
"creates",
"an",
"tensorflow",
"federated",
"learning",
"model",
"."
] | def model_fn() -> tff.learning.Model:
return tff.learning.from_keras_model(
keras_model=get_keras_model(),
input_spec=input_spec,
loss=loss_fn(),
metrics=metrics_fn(),
) | [
"def",
"model_fn",
"(",
")",
"->",
"tff",
".",
"learning",
".",
"Model",
":",
"return",
"tff",
".",
"learning",
".",
"from_keras_model",
"(",
"keras_model",
"=",
"get_keras_model",
"(",
")",
",",
"input_spec",
"=",
"input_spec",
",",
"loss",
"=",
"loss_fn"... | Function that takes a keras model and creates an tensorflow federated learning model. | [
"Function",
"that",
"takes",
"a",
"keras",
"model",
"and",
"creates",
"an",
"tensorflow",
"federated",
"learning",
"model",
"."
] | [
"\"\"\"\n Function that takes a keras model and creates an tensorflow federated learning model.\n \"\"\""
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
1f734114e4376ccd43acb776753e25125f061b02 | dilawarm/federated | federated/utils/rfa.py | [
"CC-BY-4.0"
] | Python | create_robust_measured_process | tff.templates.MeasuredProcess | def create_robust_measured_process(
model: tff.learning.Model, iterations: int, v: float, compression: bool = False
) -> tff.templates.MeasuredProcess:
"""Function that creates robust measured process used in federated aggregation.
Args:
model (tf.keras.Model): Model to train.\n
iterations ... | Function that creates robust measured process used in federated aggregation.
Args:
model (tf.keras.Model): Model to train.\n
iterations (int): Number of iterations.\n
v (float): L2 threshold.\n
compression (bool, optional): If the model should be compressed. Defaults to False.\n
... | Function that creates robust measured process used in federated aggregation. | [
"Function",
"that",
"creates",
"robust",
"measured",
"process",
"used",
"in",
"federated",
"aggregation",
"."
] | def create_robust_measured_process(
model: tff.learning.Model, iterations: int, v: float, compression: bool = False
) -> tff.templates.MeasuredProcess:
@tff.federated_computation
def initialize_measured_process() -> tff.FederatedType:
return tff.federated_value((), tff.SERVER)
@tff.tf_computatio... | [
"def",
"create_robust_measured_process",
"(",
"model",
":",
"tff",
".",
"learning",
".",
"Model",
",",
"iterations",
":",
"int",
",",
"v",
":",
"float",
",",
"compression",
":",
"bool",
"=",
"False",
")",
"->",
"tff",
".",
"templates",
".",
"MeasuredProces... | Function that creates robust measured process used in federated aggregation. | [
"Function",
"that",
"creates",
"robust",
"measured",
"process",
"used",
"in",
"federated",
"aggregation",
"."
] | [
"\"\"\"Function that creates robust measured process used in federated aggregation.\n\n Args:\n model (tf.keras.Model): Model to train.\\n\n iterations (int): Number of iterations.\\n\n v (float): L2 threshold.\\n\n compression (bool, optional): If the model should be compressed. Defa... | [
{
"param": "model",
"type": "tff.learning.Model"
},
{
"param": "iterations",
"type": "int"
},
{
"param": "v",
"type": "float"
},
{
"param": "compression",
"type": "bool"
}
] | {
"returns": [
{
"docstring": "Returns a `tff.templates.MeasuredProcess` which defines how to aggregate client updates.",
"docstring_tokens": [
"Returns",
"a",
"`",
"tff",
".",
"templates",
".",
"MeasuredProcess",
"`",
"wh... |
1f734114e4376ccd43acb776753e25125f061b02 | dilawarm/federated | federated/utils/rfa.py | [
"CC-BY-4.0"
] | Python | create_rfa_averaging | tff.templates.IterativeProcess | def create_rfa_averaging(
create_model: Callable[[], tff.learning.Model],
iterations: int,
v: float,
server_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
client_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
compression: bool = False,
) -> tff.templates.IterativeProcess:... | Function for setting up Robust Federated Aggregation.
Args:
create_model (Callable[[], tff.learning.Model]): Function for creating a model.\n
iterations (int): Calls to Secure Average Oracle.\n
v (float): L2 Threshold.\n
server_optimizer_fn (Callable[[], tf.keras.optimizers.Optimize... | Function for setting up Robust Federated Aggregation. | [
"Function",
"for",
"setting",
"up",
"Robust",
"Federated",
"Aggregation",
"."
] | def create_rfa_averaging(
create_model: Callable[[], tff.learning.Model],
iterations: int,
v: float,
server_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
client_optimizer_fn: Callable[[], tf.keras.optimizers.Optimizer],
compression: bool = False,
) -> tff.templates.IterativeProcess:... | [
"def",
"create_rfa_averaging",
"(",
"create_model",
":",
"Callable",
"[",
"[",
"]",
",",
"tff",
".",
"learning",
".",
"Model",
"]",
",",
"iterations",
":",
"int",
",",
"v",
":",
"float",
",",
"server_optimizer_fn",
":",
"Callable",
"[",
"[",
"]",
",",
... | Function for setting up Robust Federated Aggregation. | [
"Function",
"for",
"setting",
"up",
"Robust",
"Federated",
"Aggregation",
"."
] | [
"\"\"\"Function for setting up Robust Federated Aggregation.\n\n Args:\n create_model (Callable[[], tff.learning.Model]): Function for creating a model.\\n\n iterations (int): Calls to Secure Average Oracle.\\n\n v (float): L2 Threshold.\\n\n server_optimizer_fn (Callable[[], tf.keras... | [
{
"param": "create_model",
"type": "Callable[[], tff.learning.Model]"
},
{
"param": "iterations",
"type": "int"
},
{
"param": "v",
"type": "float"
},
{
"param": "server_optimizer_fn",
"type": "Callable[[], tf.keras.optimizers.Optimizer]"
},
{
"param": "client_opti... | {
"returns": [
{
"docstring": "Returns an Iterative Process with the RFA Averaging scheme",
"docstring_tokens": [
"Returns",
"an",
"Iterative",
"Process",
"with",
"the",
"RFA",
"Averaging",
"scheme"
],
"type": "tff.tem... |
da9d055131d6dc0de3d392b06d8cc4b7ad3796d6 | dilawarm/federated | federated/utils/data_utils.py | [
"CC-BY-4.0"
] | Python | randomly_select_clients_for_round | functools.partial | def randomly_select_clients_for_round(
population: int, num_of_clients: int, replace: bool = False, seed: int = None
) -> functools.partial:
"""This function creates a partial function for sampling random clients.
Args:
population (int): Client population size.\n
num_of_clients (int): Numbe... | This function creates a partial function for sampling random clients.
Args:
population (int): Client population size.\n
num_of_clients (int): Number of clients.\n
replace (bool, optional): With or without replacement. Defaults to False.\n
seed (int, optional): Random seed. Defaults ... | This function creates a partial function for sampling random clients. | [
"This",
"function",
"creates",
"a",
"partial",
"function",
"for",
"sampling",
"random",
"clients",
"."
] | def randomly_select_clients_for_round(
population: int, num_of_clients: int, replace: bool = False, seed: int = None
) -> functools.partial:
def select(round_number, seed, replace):
return np.random.RandomState().choice(
population, num_of_clients, replace=replace
)
return functo... | [
"def",
"randomly_select_clients_for_round",
"(",
"population",
":",
"int",
",",
"num_of_clients",
":",
"int",
",",
"replace",
":",
"bool",
"=",
"False",
",",
"seed",
":",
"int",
"=",
"None",
")",
"->",
"functools",
".",
"partial",
":",
"def",
"select",
"("... | This function creates a partial function for sampling random clients. | [
"This",
"function",
"creates",
"a",
"partial",
"function",
"for",
"sampling",
"random",
"clients",
"."
] | [
"\"\"\"This function creates a partial function for sampling random clients.\n\n Args:\n population (int): Client population size.\\n\n num_of_clients (int): Number of clients.\\n\n replace (bool, optional): With or without replacement. Defaults to False.\\n\n seed (int, optional): Ra... | [
{
"param": "population",
"type": "int"
},
{
"param": "num_of_clients",
"type": "int"
},
{
"param": "replace",
"type": "bool"
},
{
"param": "seed",
"type": "int"
}
] | {
"returns": [
{
"docstring": "A partial function for randomly selecting clients.",
"docstring_tokens": [
"A",
"partial",
"function",
"for",
"randomly",
"selecting",
"clients",
"."
],
"type": "functools.partial"
}
],
"... |
da9d055131d6dc0de3d392b06d8cc4b7ad3796d6 | dilawarm/federated | federated/utils/data_utils.py | [
"CC-BY-4.0"
] | Python | _convert_fn | tf.data.Dataset | def _convert_fn(dataset: tf.data.Dataset) -> tf.data.Dataset:
"""Converts dataset to tupled dataset.
Args:
dataset (tf.data.Dataset): Dataset.
Returns:
tf.data.Dataset: Returns tupled dataset.
"""
spec = dataset.element_spec
if isinstance(spec, collections.abc.Mapping):
... | Converts dataset to tupled dataset.
Args:
dataset (tf.data.Dataset): Dataset.
Returns:
tf.data.Dataset: Returns tupled dataset.
| Converts dataset to tupled dataset. | [
"Converts",
"dataset",
"to",
"tupled",
"dataset",
"."
] | def _convert_fn(dataset: tf.data.Dataset) -> tf.data.Dataset:
spec = dataset.element_spec
if isinstance(spec, collections.abc.Mapping):
return dataset.map(lambda observation: (observation["x"], observation["y"]))
else:
return dataset.map(lambda x, y: (x, y)) | [
"def",
"_convert_fn",
"(",
"dataset",
":",
"tf",
".",
"data",
".",
"Dataset",
")",
"->",
"tf",
".",
"data",
".",
"Dataset",
":",
"spec",
"=",
"dataset",
".",
"element_spec",
"if",
"isinstance",
"(",
"spec",
",",
"collections",
".",
"abc",
".",
"Mapping... | Converts dataset to tupled dataset. | [
"Converts",
"dataset",
"to",
"tupled",
"dataset",
"."
] | [
"\"\"\"Converts dataset to tupled dataset.\n\n Args:\n dataset (tf.data.Dataset): Dataset.\n\n Returns:\n tf.data.Dataset: Returns tupled dataset.\n \"\"\""
] | [
{
"param": "dataset",
"type": "tf.data.Dataset"
}
] | {
"returns": [
{
"docstring": "Returns tupled dataset.",
"docstring_tokens": [
"Returns",
"tupled",
"dataset",
"."
],
"type": "tf.data.Dataset"
}
],
"raises": [],
"params": [
{
"identifier": "dataset",
"type": "tf.data.Dataset",
... |
c1f5bf92151e722ef35bb7fa4c7a70047f1956b8 | dilawarm/federated | federated/models/models.py | [
"CC-BY-4.0"
] | Python | create_softmax_model | tf.keras.Sequential | def create_softmax_model() -> tf.keras.Sequential:
"""Creates a softmax regression model.
Returns:
tf.keras.Sequential: A softmax regresion model.
"""
model = Sequential(
[
layers.InputLayer(input_shape=[186, 1]),
layers.Flatten(),
layers.Dense(5),
... | Creates a softmax regression model.
Returns:
tf.keras.Sequential: A softmax regresion model.
| Creates a softmax regression model. | [
"Creates",
"a",
"softmax",
"regression",
"model",
"."
] | def create_softmax_model() -> tf.keras.Sequential:
model = Sequential(
[
layers.InputLayer(input_shape=[186, 1]),
layers.Flatten(),
layers.Dense(5),
]
)
return model | [
"def",
"create_softmax_model",
"(",
")",
"->",
"tf",
".",
"keras",
".",
"Sequential",
":",
"model",
"=",
"Sequential",
"(",
"[",
"layers",
".",
"InputLayer",
"(",
"input_shape",
"=",
"[",
"186",
",",
"1",
"]",
")",
",",
"layers",
".",
"Flatten",
"(",
... | Creates a softmax regression model. | [
"Creates",
"a",
"softmax",
"regression",
"model",
"."
] | [
"\"\"\"Creates a softmax regression model.\n\n Returns:\n tf.keras.Sequential: A softmax regresion model.\n \"\"\""
] | [] | {
"returns": [
{
"docstring": "A softmax regresion model.",
"docstring_tokens": [
"A",
"softmax",
"regresion",
"model",
"."
],
"type": "tf.keras.Sequential"
}
],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
928421a181a875ce1b9dfd81714ac9adc32e5019 | dilawarm/federated | federated/utils/training_loops.py | [
"CC-BY-4.0"
] | Python | centralized_training_loop | Tuple[tf.keras.callbacks.History, float] | def centralized_training_loop(
model: tf.keras.Model,
dataset: tf.data.Dataset,
name: str,
epochs: int,
output: str,
save_model: bool = True,
validation_dataset: tf.data.Dataset = None,
test_dataset: tf.data.Dataset = None,
) -> Tuple[tf.keras.callbacks.History, float]:
"""Function t... | Function trains a model on a dataset using centralized machine learning, and tests its performance.
Args:
model (tf.keras.Model): Model.\n
dataset (tf.data.Dataset): Dataset.\n
name (str): Experiment name.\n
epochs (int): Number of epochs.\n
output (str): Logs output destina... | Function trains a model on a dataset using centralized machine learning, and tests its performance. | [
"Function",
"trains",
"a",
"model",
"on",
"a",
"dataset",
"using",
"centralized",
"machine",
"learning",
"and",
"tests",
"its",
"performance",
"."
] | def centralized_training_loop(
model: tf.keras.Model,
dataset: tf.data.Dataset,
name: str,
epochs: int,
output: str,
save_model: bool = True,
validation_dataset: tf.data.Dataset = None,
test_dataset: tf.data.Dataset = None,
) -> Tuple[tf.keras.callbacks.History, float]:
log_dir = os.... | [
"def",
"centralized_training_loop",
"(",
"model",
":",
"tf",
".",
"keras",
".",
"Model",
",",
"dataset",
":",
"tf",
".",
"data",
".",
"Dataset",
",",
"name",
":",
"str",
",",
"epochs",
":",
"int",
",",
"output",
":",
"str",
",",
"save_model",
":",
"b... | Function trains a model on a dataset using centralized machine learning, and tests its performance. | [
"Function",
"trains",
"a",
"model",
"on",
"a",
"dataset",
"using",
"centralized",
"machine",
"learning",
"and",
"tests",
"its",
"performance",
"."
] | [
"\"\"\"Function trains a model on a dataset using centralized machine learning, and tests its performance.\n\n Args:\n model (tf.keras.Model): Model.\\n\n dataset (tf.data.Dataset): Dataset.\\n\n name (str): Experiment name.\\n\n epochs (int): Number of epochs.\\n\n output (str... | [
{
"param": "model",
"type": "tf.keras.Model"
},
{
"param": "dataset",
"type": "tf.data.Dataset"
},
{
"param": "name",
"type": "str"
},
{
"param": "epochs",
"type": "int"
},
{
"param": "output",
"type": "str"
},
{
"param": "save_model",
"type": "boo... | {
"returns": [
{
"docstring": "Returns the history object after fitting the model, and training time.",
"docstring_tokens": [
"Returns",
"the",
"history",
"object",
"after",
"fitting",
"the",
"model",
"and",
"training",
... |
928421a181a875ce1b9dfd81714ac9adc32e5019 | dilawarm/federated | federated/utils/training_loops.py | [
"CC-BY-4.0"
] | Python | federated_training_loop | Tuple[tff.Computation, float, float] | def federated_training_loop(
iterative_process: tff.templates.IterativeProcess,
get_client_dataset: Callable[[int], List[tf.data.Dataset]],
number_of_rounds: int,
name: str,
output: str,
batch_size: int,
number_of_training_points: int = None,
keras_model_fn: Callable[[], tf.keras.Model] ... | Function trains a model on a dataset using federated learning.
Args:
iterative_process (tff.templates.IterativeProcess): Iterative process.\n
get_client_dataset (Callable[[int], List[tf.data.Dataset]]): Function for getting dataset for clients.\n
number_of_rounds (int): Number of rounds.\n
... | Function trains a model on a dataset using federated learning. | [
"Function",
"trains",
"a",
"model",
"on",
"a",
"dataset",
"using",
"federated",
"learning",
"."
] | def federated_training_loop(
iterative_process: tff.templates.IterativeProcess,
get_client_dataset: Callable[[int], List[tf.data.Dataset]],
number_of_rounds: int,
name: str,
output: str,
batch_size: int,
number_of_training_points: int = None,
keras_model_fn: Callable[[], tf.keras.Model] ... | [
"def",
"federated_training_loop",
"(",
"iterative_process",
":",
"tff",
".",
"templates",
".",
"IterativeProcess",
",",
"get_client_dataset",
":",
"Callable",
"[",
"[",
"int",
"]",
",",
"List",
"[",
"tf",
".",
"data",
".",
"Dataset",
"]",
"]",
",",
"number_o... | Function trains a model on a dataset using federated learning. | [
"Function",
"trains",
"a",
"model",
"on",
"a",
"dataset",
"using",
"federated",
"learning",
"."
] | [
"\"\"\"Function trains a model on a dataset using federated learning.\n\n Args:\n iterative_process (tff.templates.IterativeProcess): Iterative process.\\n\n get_client_dataset (Callable[[int], List[tf.data.Dataset]]): Function for getting dataset for clients.\\n\n number_of_rounds (int): Nu... | [
{
"param": "iterative_process",
"type": "tff.templates.IterativeProcess"
},
{
"param": "get_client_dataset",
"type": "Callable[[int], List[tf.data.Dataset]]"
},
{
"param": "number_of_rounds",
"type": "int"
},
{
"param": "name",
"type": "str"
},
{
"param": "output"... | {
"returns": [
{
"docstring": "Returns the last state of the server and training time",
"docstring_tokens": [
"Returns",
"the",
"last",
"state",
"of",
"the",
"server",
"and",
"training",
"time"
],
"type": "[tff... |
7cac4021bbb75065eb0cb92953538f8e05d48367 | khailcon/utm2dd | utm2dd/utm2dd.py | [
"CC0-1.0"
] | Python | string_transform | <not_specific> | def string_transform(utm_string, easting_northing=True):
"""Parse UTM coordinate string into a Latitude/Longitude Tuple
Parameters
----------
utm_string : str
UTM coordinate string. Format as: "10M 551884.29mE 5278575.64mN"
easting_northing : bool, optional
Default=True.... | Parse UTM coordinate string into a Latitude/Longitude Tuple
Parameters
----------
utm_string : str
UTM coordinate string. Format as: "10M 551884.29mE 5278575.64mN"
easting_northing : bool, optional
Default=True. Set to False if UTM is formated with mN before mE.
Return... | Parse UTM coordinate string into a Latitude/Longitude Tuple | [
"Parse",
"UTM",
"coordinate",
"string",
"into",
"a",
"Latitude",
"/",
"Longitude",
"Tuple"
] | def string_transform(utm_string, easting_northing=True):
utm_strip = utm_string.strip()
split_UTM = utm_strip.split()
zone_num = float(split_UTM[0][:2])
zone_let = str(split_UTM[0][2:])
if easting_northing == True:
easting = float(split_UTM[1][:-2])
northing = float(split_UTM[2]... | [
"def",
"string_transform",
"(",
"utm_string",
",",
"easting_northing",
"=",
"True",
")",
":",
"utm_strip",
"=",
"utm_string",
".",
"strip",
"(",
")",
"split_UTM",
"=",
"utm_strip",
".",
"split",
"(",
")",
"zone_num",
"=",
"float",
"(",
"split_UTM",
"[",
"0... | Parse UTM coordinate string into a Latitude/Longitude Tuple | [
"Parse",
"UTM",
"coordinate",
"string",
"into",
"a",
"Latitude",
"/",
"Longitude",
"Tuple"
] | [
"\"\"\"Parse UTM coordinate string into a Latitude/Longitude Tuple\r\n \r\n Parameters\r\n ----------\r\n utm_string : str\r\n UTM coordinate string. Format as: \"10M 551884.29mE 5278575.64mN\"\r\n easting_northing : bool, optional\r\n Default=True. Set to False if UTM is formated with ... | [
{
"param": "utm_string",
"type": null
},
{
"param": "easting_northing",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": "tuple\r"
}
],
"raises": [],
"params": [
{
"identifier": "utm_string",
"type": null,
"docstring": "UTM coordinate string.",
"docstring_tokens": [
"UTM",
... |
7cac4021bbb75065eb0cb92953538f8e05d48367 | khailcon/utm2dd | utm2dd/utm2dd.py | [
"CC0-1.0"
] | Python | list_transform | <not_specific> | def list_transform(utm_list, coordinate_pairs=True, easting_northing=True):
"""Parse a list of UTM coordinates into either a list of latitude,longitude tuples or a dict of latitude and longitude lists
Parameters
----------
utm_list : list
a list of UTM coordinate strings. Strings formated... | Parse a list of UTM coordinates into either a list of latitude,longitude tuples or a dict of latitude and longitude lists
Parameters
----------
utm_list : list
a list of UTM coordinate strings. Strings formated as: "10M 551884.29mE 5278575.64mN"
coordinate_pairs : bool, optional
... | Parse a list of UTM coordinates into either a list of latitude,longitude tuples or a dict of latitude and longitude lists | [
"Parse",
"a",
"list",
"of",
"UTM",
"coordinates",
"into",
"either",
"a",
"list",
"of",
"latitude",
"longitude",
"tuples",
"or",
"a",
"dict",
"of",
"latitude",
"and",
"longitude",
"lists"
] | def list_transform(utm_list, coordinate_pairs=True, easting_northing=True):
if coordinate_pairs == True:
output = [string_transform(coordinate, easting_northing=easting_northing) for coordinate in utm_list]
elif coordinate_pairs == False:
lat = []
lon = []
for coordinate in utm_l... | [
"def",
"list_transform",
"(",
"utm_list",
",",
"coordinate_pairs",
"=",
"True",
",",
"easting_northing",
"=",
"True",
")",
":",
"if",
"coordinate_pairs",
"==",
"True",
":",
"output",
"=",
"[",
"string_transform",
"(",
"coordinate",
",",
"easting_northing",
"=",
... | Parse a list of UTM coordinates into either a list of latitude,longitude tuples or a dict of latitude and longitude lists | [
"Parse",
"a",
"list",
"of",
"UTM",
"coordinates",
"into",
"either",
"a",
"list",
"of",
"latitude",
"longitude",
"tuples",
"or",
"a",
"dict",
"of",
"latitude",
"and",
"longitude",
"lists"
] | [
"\"\"\"Parse a list of UTM coordinates into either a list of latitude,longitude tuples or a dict of latitude and longitude lists\r\n\r\n Parameters\r\n ----------\r\n utm_list : list\r\n a list of UTM coordinate strings. Strings formated as: \"10M 551884.29mE 5278575.64mN\"\r\n coordinate_pairs :... | [
{
"param": "utm_list",
"type": null
},
{
"param": "coordinate_pairs",
"type": null
},
{
"param": "easting_northing",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": ""
},
{
"docstring": "list of tuples: (Latitude, Longitude)",
"docstring_tokens": [
"list",
"of",
"tuples",
":",
"(",
"Latitude",
... |
7cac4021bbb75065eb0cb92953538f8e05d48367 | khailcon/utm2dd | utm2dd/utm2dd.py | [
"CC0-1.0"
] | Python | column_transform | <not_specific> | def column_transform(df, column_name, lat_column, lon_column, new_cols=False, easting_northing=True):
"""Parse a column of UTM coordinate strings from a Pandas Dataframe into Latitude Longitude columns.
For populating Lat Lon columns in a dataframe or creating those columns from a UTM coordinate column
... | Parse a column of UTM coordinate strings from a Pandas Dataframe into Latitude Longitude columns.
For populating Lat Lon columns in a dataframe or creating those columns from a UTM coordinate column
Parameters
----------
df : pandas dataframe
column_name: str
column name containi... | Parse a column of UTM coordinate strings from a Pandas Dataframe into Latitude Longitude columns.
For populating Lat Lon columns in a dataframe or creating those columns from a UTM coordinate column | [
"Parse",
"a",
"column",
"of",
"UTM",
"coordinate",
"strings",
"from",
"a",
"Pandas",
"Dataframe",
"into",
"Latitude",
"Longitude",
"columns",
".",
"For",
"populating",
"Lat",
"Lon",
"columns",
"in",
"a",
"dataframe",
"or",
"creating",
"those",
"columns",
"from... | def column_transform(df, column_name, lat_column, lon_column, new_cols=False, easting_northing=True):
df = df.copy()
if new_cols == False:
for coordinate in df.loc[:,column_name].astype(str):
if coordinate != 'nan':
latlong = string_transform(coordinate, easting_northing=eas... | [
"def",
"column_transform",
"(",
"df",
",",
"column_name",
",",
"lat_column",
",",
"lon_column",
",",
"new_cols",
"=",
"False",
",",
"easting_northing",
"=",
"True",
")",
":",
"df",
"=",
"df",
".",
"copy",
"(",
")",
"if",
"new_cols",
"==",
"False",
":",
... | Parse a column of UTM coordinate strings from a Pandas Dataframe into Latitude Longitude columns. | [
"Parse",
"a",
"column",
"of",
"UTM",
"coordinate",
"strings",
"from",
"a",
"Pandas",
"Dataframe",
"into",
"Latitude",
"Longitude",
"columns",
"."
] | [
"\"\"\"Parse a column of UTM coordinate strings from a Pandas Dataframe into Latitude Longitude columns.\r\n\r\n For populating Lat Lon columns in a dataframe or creating those columns from a UTM coordinate column\r\n\r\n Parameters\r\n ----------\r\n df : pandas dataframe\r\n\r\n column_name: str\r\... | [
{
"param": "df",
"type": null
},
{
"param": "column_name",
"type": null
},
{
"param": "lat_column",
"type": null
},
{
"param": "lon_column",
"type": null
},
{
"param": "new_cols",
"type": null
},
{
"param": "easting_northing",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": "A pandas dataframe copy of the input dataframe with the transformations\r"
}
],
"raises": [],
"params": [
{
"identifier": "df",
"type": null,
"docstring": null,
"docst... |
41fc75c484081068fb7201eaf2d4b8564959cfd7 | hcherkaoui/carpet | examples/utils.py | [
"BSD-3-Clause"
] | Python | synthesis_learned_algo | <not_specific> | def synthesis_learned_algo(x_train, x_test, A, D, L, lbda, all_n_layers,
type_, max_iter=300, device=None, net_kwargs=None,
verbose=1):
""" NN-algo solver for synthesis TV problem. """
net_kwargs = dict() if net_kwargs is None else net_kwargs
params = No... | NN-algo solver for synthesis TV problem. | NN-algo solver for synthesis TV problem. | [
"NN",
"-",
"algo",
"solver",
"for",
"synthesis",
"TV",
"problem",
"."
] | def synthesis_learned_algo(x_train, x_test, A, D, L, lbda, all_n_layers,
type_, max_iter=300, device=None, net_kwargs=None,
verbose=1):
net_kwargs = dict() if net_kwargs is None else net_kwargs
params = None
_, _, z0_test = init_vuz(A, D, x_test)
_, ... | [
"def",
"synthesis_learned_algo",
"(",
"x_train",
",",
"x_test",
",",
"A",
",",
"D",
",",
"L",
",",
"lbda",
",",
"all_n_layers",
",",
"type_",
",",
"max_iter",
"=",
"300",
",",
"device",
"=",
"None",
",",
"net_kwargs",
"=",
"None",
",",
"verbose",
"=",
... | NN-algo solver for synthesis TV problem. | [
"NN",
"-",
"algo",
"solver",
"for",
"synthesis",
"TV",
"problem",
"."
] | [
"\"\"\" NN-algo solver for synthesis TV problem. \"\"\"",
"# declare network",
"# save parameters",
"# get train and test error"
] | [
{
"param": "x_train",
"type": null
},
{
"param": "x_test",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "all_n_layers",
"ty... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x_train",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x_test",
"type": null,
"docstring": null,
"docstring_token... |
41fc75c484081068fb7201eaf2d4b8564959cfd7 | hcherkaoui/carpet | examples/utils.py | [
"BSD-3-Clause"
] | Python | analysis_learned_algo | <not_specific> | def analysis_learned_algo(x_train, x_test, A, D, L, lbda, all_n_layers, type_,
max_iter=300, device=None, net_kwargs=None,
verbose=1):
""" NN-algo solver for analysis TV problem. """
net_kwargs = dict() if net_kwargs is None else net_kwargs
params = None
... | NN-algo solver for analysis TV problem. | NN-algo solver for analysis TV problem. | [
"NN",
"-",
"algo",
"solver",
"for",
"analysis",
"TV",
"problem",
"."
] | def analysis_learned_algo(x_train, x_test, A, D, L, lbda, all_n_layers, type_,
max_iter=300, device=None, net_kwargs=None,
verbose=1):
net_kwargs = dict() if net_kwargs is None else net_kwargs
params = None
_, u0_train, _ = init_vuz(A, D, x_train)
_, u... | [
"def",
"analysis_learned_algo",
"(",
"x_train",
",",
"x_test",
",",
"A",
",",
"D",
",",
"L",
",",
"lbda",
",",
"all_n_layers",
",",
"type_",
",",
"max_iter",
"=",
"300",
",",
"device",
"=",
"None",
",",
"net_kwargs",
"=",
"None",
",",
"verbose",
"=",
... | NN-algo solver for analysis TV problem. | [
"NN",
"-",
"algo",
"solver",
"for",
"analysis",
"TV",
"problem",
"."
] | [
"\"\"\" NN-algo solver for analysis TV problem. \"\"\"",
"# declare network",
"# save parameters",
"# get train and test error"
] | [
{
"param": "x_train",
"type": null
},
{
"param": "x_test",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "all_n_layers",
"ty... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x_train",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x_test",
"type": null,
"docstring": null,
"docstring_token... |
41fc75c484081068fb7201eaf2d4b8564959cfd7 | hcherkaoui/carpet | examples/utils.py | [
"BSD-3-Clause"
] | Python | analysis_learned_taut_string | <not_specific> | def analysis_learned_taut_string(x_train, x_test, A, D, L, lbda, all_n_layers,
type_=None, max_iter=300, device=None,
net_kwargs=None, verbose=1):
""" NN-algo solver for analysis TV problem. """
net_kwargs = dict() if net_kwargs is None else net_... | NN-algo solver for analysis TV problem. | NN-algo solver for analysis TV problem. | [
"NN",
"-",
"algo",
"solver",
"for",
"analysis",
"TV",
"problem",
"."
] | def analysis_learned_taut_string(x_train, x_test, A, D, L, lbda, all_n_layers,
type_=None, max_iter=300, device=None,
net_kwargs=None, verbose=1):
net_kwargs = dict() if net_kwargs is None else net_kwargs
params = None
l_loss = []
def rec... | [
"def",
"analysis_learned_taut_string",
"(",
"x_train",
",",
"x_test",
",",
"A",
",",
"D",
",",
"L",
",",
"lbda",
",",
"all_n_layers",
",",
"type_",
"=",
"None",
",",
"max_iter",
"=",
"300",
",",
"device",
"=",
"None",
",",
"net_kwargs",
"=",
"None",
",... | NN-algo solver for analysis TV problem. | [
"NN",
"-",
"algo",
"solver",
"for",
"analysis",
"TV",
"problem",
"."
] | [
"\"\"\" NN-algo solver for analysis TV problem. \"\"\"",
"# Declare network for the given number of layers. Warm-init the first",
"# layers with parameters learned with previous networks if any.",
"# train",
"# save parameters",
"# get train and test error"
] | [
{
"param": "x_train",
"type": null
},
{
"param": "x_test",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "all_n_layers",
"ty... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x_train",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x_test",
"type": null,
"docstring": null,
"docstring_token... |
41fc75c484081068fb7201eaf2d4b8564959cfd7 | hcherkaoui/carpet | examples/utils.py | [
"BSD-3-Clause"
] | Python | synthesis_iter_algo | <not_specific> | def synthesis_iter_algo(x_train, x_test, A, D, L, lbda, all_n_layers, type_,
max_iter=300, device=None, net_kwargs=None,
verbose=1):
""" Iterative-algo solver for synthesis TV problem. """
net_kwargs = dict() if net_kwargs is None else net_kwargs
name = 'ISTA'... | Iterative-algo solver for synthesis TV problem. | Iterative-algo solver for synthesis TV problem. | [
"Iterative",
"-",
"algo",
"solver",
"for",
"synthesis",
"TV",
"problem",
"."
] | def synthesis_iter_algo(x_train, x_test, A, D, L, lbda, all_n_layers, type_,
max_iter=300, device=None, net_kwargs=None,
verbose=1):
net_kwargs = dict() if net_kwargs is None else net_kwargs
name = 'ISTA' if type_ == 'chambolle' else 'FISTA'
max_iter = all_n_l... | [
"def",
"synthesis_iter_algo",
"(",
"x_train",
",",
"x_test",
",",
"A",
",",
"D",
",",
"L",
",",
"lbda",
",",
"all_n_layers",
",",
"type_",
",",
"max_iter",
"=",
"300",
",",
"device",
"=",
"None",
",",
"net_kwargs",
"=",
"None",
",",
"verbose",
"=",
"... | Iterative-algo solver for synthesis TV problem. | [
"Iterative",
"-",
"algo",
"solver",
"for",
"synthesis",
"TV",
"problem",
"."
] | [
"\"\"\" Iterative-algo solver for synthesis TV problem. \"\"\""
] | [
{
"param": "x_train",
"type": null
},
{
"param": "x_test",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "all_n_layers",
"ty... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x_train",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x_test",
"type": null,
"docstring": null,
"docstring_token... |
41fc75c484081068fb7201eaf2d4b8564959cfd7 | hcherkaoui/carpet | examples/utils.py | [
"BSD-3-Clause"
] | Python | analysis_primal_iter_algo | <not_specific> | def analysis_primal_iter_algo(x_train, x_test, A, D, L, lbda, all_n_layers,
type_, max_iter=300, device=None,
net_kwargs=None, verbose=1):
""" Iterative-algo solver for synthesis TV problem. """
net_kwargs = dict() if net_kwargs is None else net_kwargs... | Iterative-algo solver for synthesis TV problem. | Iterative-algo solver for synthesis TV problem. | [
"Iterative",
"-",
"algo",
"solver",
"for",
"synthesis",
"TV",
"problem",
"."
] | def analysis_primal_iter_algo(x_train, x_test, A, D, L, lbda, all_n_layers,
type_, max_iter=300, device=None,
net_kwargs=None, verbose=1):
net_kwargs = dict() if net_kwargs is None else net_kwargs
name = 'ISTA' if type_ == 'ista' else 'FISTA'
max_i... | [
"def",
"analysis_primal_iter_algo",
"(",
"x_train",
",",
"x_test",
",",
"A",
",",
"D",
",",
"L",
",",
"lbda",
",",
"all_n_layers",
",",
"type_",
",",
"max_iter",
"=",
"300",
",",
"device",
"=",
"None",
",",
"net_kwargs",
"=",
"None",
",",
"verbose",
"=... | Iterative-algo solver for synthesis TV problem. | [
"Iterative",
"-",
"algo",
"solver",
"for",
"synthesis",
"TV",
"problem",
"."
] | [
"\"\"\" Iterative-algo solver for synthesis TV problem. \"\"\""
] | [
{
"param": "x_train",
"type": null
},
{
"param": "x_test",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "all_n_layers",
"ty... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x_train",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x_test",
"type": null,
"docstring": null,
"docstring_token... |
41fc75c484081068fb7201eaf2d4b8564959cfd7 | hcherkaoui/carpet | examples/utils.py | [
"BSD-3-Clause"
] | Python | analysis_dual_iter_algo | <not_specific> | def analysis_dual_iter_algo(x_train, x_test, A, D, L, lbda, all_n_layers,
type_, max_iter=300, device=None,
net_kwargs=None, verbose=1):
""" Chambolle solver for analysis TV problem. """
net_kwargs = dict() if net_kwargs is None else net_kwargs
Psi_A =... | Chambolle solver for analysis TV problem. | Chambolle solver for analysis TV problem. | [
"Chambolle",
"solver",
"for",
"analysis",
"TV",
"problem",
"."
] | def analysis_dual_iter_algo(x_train, x_test, A, D, L, lbda, all_n_layers,
type_, max_iter=300, device=None,
net_kwargs=None, verbose=1):
net_kwargs = dict() if net_kwargs is None else net_kwargs
Psi_A = np.linalg.pinv(A).dot(D)
inv_AtA = np.linalg.pinv... | [
"def",
"analysis_dual_iter_algo",
"(",
"x_train",
",",
"x_test",
",",
"A",
",",
"D",
",",
"L",
",",
"lbda",
",",
"all_n_layers",
",",
"type_",
",",
"max_iter",
"=",
"300",
",",
"device",
"=",
"None",
",",
"net_kwargs",
"=",
"None",
",",
"verbose",
"=",... | Chambolle solver for analysis TV problem. | [
"Chambolle",
"solver",
"for",
"analysis",
"TV",
"problem",
"."
] | [
"\"\"\" Chambolle solver for analysis TV problem. \"\"\"",
"# XXX step_size is here to homogenize API"
] | [
{
"param": "x_train",
"type": null
},
{
"param": "x_test",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "all_n_layers",
"ty... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x_train",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x_test",
"type": null,
"docstring": null,
"docstring_token... |
41fc75c484081068fb7201eaf2d4b8564959cfd7 | hcherkaoui/carpet | examples/utils.py | [
"BSD-3-Clause"
] | Python | analysis_primal_dual_iter_algo | <not_specific> | def analysis_primal_dual_iter_algo(x_train, x_test, A, D, L, lbda,
all_n_layers, type_, max_iter=300,
device=None, net_kwargs=None, verbose=1):
""" Condat-Vu solver for analysis TV problem. """
net_kwargs = dict() if net_kwargs is None else n... | Condat-Vu solver for analysis TV problem. | Condat-Vu solver for analysis TV problem. | [
"Condat",
"-",
"Vu",
"solver",
"for",
"analysis",
"TV",
"problem",
"."
] | def analysis_primal_dual_iter_algo(x_train, x_test, A, D, L, lbda,
all_n_layers, type_, max_iter=300,
device=None, net_kwargs=None, verbose=1):
net_kwargs = dict() if net_kwargs is None else net_kwargs
max_iter = all_n_layers[-1]
rho = 1.... | [
"def",
"analysis_primal_dual_iter_algo",
"(",
"x_train",
",",
"x_test",
",",
"A",
",",
"D",
",",
"L",
",",
"lbda",
",",
"all_n_layers",
",",
"type_",
",",
"max_iter",
"=",
"300",
",",
"device",
"=",
"None",
",",
"net_kwargs",
"=",
"None",
",",
"verbose",... | Condat-Vu solver for analysis TV problem. | [
"Condat",
"-",
"Vu",
"solver",
"for",
"analysis",
"TV",
"problem",
"."
] | [
"\"\"\" Condat-Vu solver for analysis TV problem. \"\"\""
] | [
{
"param": "x_train",
"type": null
},
{
"param": "x_test",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "all_n_layers",
"ty... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x_train",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x_test",
"type": null,
"docstring": null,
"docstring_token... |
e0d70cc5bbbef58982649f1b164c444cca632537 | hcherkaoui/carpet | carpet/datasets.py | [
"BSD-3-Clause"
] | Python | add_gaussian_noise | <not_specific> | def add_gaussian_noise(signal, snr, random_state=None):
""" Add a Gaussian noise to inout signal to output a noisy signal with the
targeted SNR.
Parameters
----------
signal : array, the given signal on which add a Guassian noise.
snr : float, the expected SNR for the output signal.
random_... | Add a Gaussian noise to inout signal to output a noisy signal with the
targeted SNR.
Parameters
----------
signal : array, the given signal on which add a Guassian noise.
snr : float, the expected SNR for the output signal.
random_state : int or None (default=None),
Whether to impose ... | Add a Gaussian noise to inout signal to output a noisy signal with the
targeted SNR.
Parameters
signal : array, the given signal on which add a Guassian noise.
snr : float, the expected SNR for the output signal.
random_state : int or None (default=None),
Whether to impose a seed on the random generation or not (for... | [
"Add",
"a",
"Gaussian",
"noise",
"to",
"inout",
"signal",
"to",
"output",
"a",
"noisy",
"signal",
"with",
"the",
"targeted",
"SNR",
".",
"Parameters",
"signal",
":",
"array",
"the",
"given",
"signal",
"on",
"which",
"add",
"a",
"Guassian",
"noise",
".",
... | def add_gaussian_noise(signal, snr, random_state=None):
rng = check_random_state(random_state)
s_shape = signal.shape
noise = rng.randn(*s_shape)
true_snr_num = np.linalg.norm(signal)
true_snr_deno = np.linalg.norm(noise)
true_snr = true_snr_num / (true_snr_deno + np.finfo(np.float).eps)
std... | [
"def",
"add_gaussian_noise",
"(",
"signal",
",",
"snr",
",",
"random_state",
"=",
"None",
")",
":",
"rng",
"=",
"check_random_state",
"(",
"random_state",
")",
"s_shape",
"=",
"signal",
".",
"shape",
"noise",
"=",
"rng",
".",
"randn",
"(",
"*",
"s_shape",
... | Add a Gaussian noise to inout signal to output a noisy signal with the
targeted SNR. | [
"Add",
"a",
"Gaussian",
"noise",
"to",
"inout",
"signal",
"to",
"output",
"a",
"noisy",
"signal",
"with",
"the",
"targeted",
"SNR",
"."
] | [
"\"\"\" Add a Gaussian noise to inout signal to output a noisy signal with the\n targeted SNR.\n\n Parameters\n ----------\n signal : array, the given signal on which add a Guassian noise.\n snr : float, the expected SNR for the output signal.\n random_state : int or None (default=None),\n ... | [
{
"param": "signal",
"type": null
},
{
"param": "snr",
"type": null
},
{
"param": "random_state",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "signal",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "snr",
"type": null,
"docstring": null,
"docstring_tokens": ... |
e0d70cc5bbbef58982649f1b164c444cca632537 | hcherkaoui/carpet | carpet/datasets.py | [
"BSD-3-Clause"
] | Python | _generate_1d_signal | <not_specific> | def _generate_1d_signal(A, L, s=0.1, snr=1.0, rng=None):
""" Generate one 1d synthetic signal. """
m = L.shape[0]
z = _generate_dirac(m=m, s=s, rng=rng)
u = z.dot(L)
x, _ = add_gaussian_noise(signal=u.dot(A), snr=snr, random_state=rng)
return x[None, :], u[None, :], z[None, :] | Generate one 1d synthetic signal. | Generate one 1d synthetic signal. | [
"Generate",
"one",
"1d",
"synthetic",
"signal",
"."
] | def _generate_1d_signal(A, L, s=0.1, snr=1.0, rng=None):
m = L.shape[0]
z = _generate_dirac(m=m, s=s, rng=rng)
u = z.dot(L)
x, _ = add_gaussian_noise(signal=u.dot(A), snr=snr, random_state=rng)
return x[None, :], u[None, :], z[None, :] | [
"def",
"_generate_1d_signal",
"(",
"A",
",",
"L",
",",
"s",
"=",
"0.1",
",",
"snr",
"=",
"1.0",
",",
"rng",
"=",
"None",
")",
":",
"m",
"=",
"L",
".",
"shape",
"[",
"0",
"]",
"z",
"=",
"_generate_dirac",
"(",
"m",
"=",
"m",
",",
"s",
"=",
"... | Generate one 1d synthetic signal. | [
"Generate",
"one",
"1d",
"synthetic",
"signal",
"."
] | [
"\"\"\" Generate one 1d synthetic signal. \"\"\""
] | [
{
"param": "A",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "s",
"type": null
},
{
"param": "snr",
"type": null
},
{
"param": "rng",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "A",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "L",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
ba863d1e74fbb69ed50b2be3327f5e32f68d96e1 | hcherkaoui/carpet | carpet/proximity.py | [
"BSD-3-Clause"
] | Python | pseudo_soft_th_numpy | <not_specific> | def pseudo_soft_th_numpy(z, lbda, step_size):
""" Pseudo Soft-thresholding for numpy array. """
assert z.ndim == 2
z_ = np.atleast_2d(_soft_th_numpy(z[:, 1:], lbda * step_size))
z0_ = np.atleast_2d(z[:, 0])
z0_ = z0_.T if z0_.shape[0] != z_.shape[0] else z0_
return np.concatenate((z0_, z_), axis... | Pseudo Soft-thresholding for numpy array. | Pseudo Soft-thresholding for numpy array. | [
"Pseudo",
"Soft",
"-",
"thresholding",
"for",
"numpy",
"array",
"."
] | def pseudo_soft_th_numpy(z, lbda, step_size):
assert z.ndim == 2
z_ = np.atleast_2d(_soft_th_numpy(z[:, 1:], lbda * step_size))
z0_ = np.atleast_2d(z[:, 0])
z0_ = z0_.T if z0_.shape[0] != z_.shape[0] else z0_
return np.concatenate((z0_, z_), axis=1) | [
"def",
"pseudo_soft_th_numpy",
"(",
"z",
",",
"lbda",
",",
"step_size",
")",
":",
"assert",
"z",
".",
"ndim",
"==",
"2",
"z_",
"=",
"np",
".",
"atleast_2d",
"(",
"_soft_th_numpy",
"(",
"z",
"[",
":",
",",
"1",
":",
"]",
",",
"lbda",
"*",
"step_size... | Pseudo Soft-thresholding for numpy array. | [
"Pseudo",
"Soft",
"-",
"thresholding",
"for",
"numpy",
"array",
"."
] | [
"\"\"\" Pseudo Soft-thresholding for numpy array. \"\"\""
] | [
{
"param": "z",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "step_size",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "z",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "lbda",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
ba863d1e74fbb69ed50b2be3327f5e32f68d96e1 | hcherkaoui/carpet | carpet/proximity.py | [
"BSD-3-Clause"
] | Python | pseudo_soft_th_tensor | <not_specific> | def pseudo_soft_th_tensor(z, lbda, step_size):
""" Soft-thresholding for Torch tensor. """
assert z.ndim == 2
z_ = z.clone()
z_[:, 1:] = _soft_th_tensor(z[:, 1:], lbda * step_size)
return z_ | Soft-thresholding for Torch tensor. | Soft-thresholding for Torch tensor. | [
"Soft",
"-",
"thresholding",
"for",
"Torch",
"tensor",
"."
] | def pseudo_soft_th_tensor(z, lbda, step_size):
assert z.ndim == 2
z_ = z.clone()
z_[:, 1:] = _soft_th_tensor(z[:, 1:], lbda * step_size)
return z_ | [
"def",
"pseudo_soft_th_tensor",
"(",
"z",
",",
"lbda",
",",
"step_size",
")",
":",
"assert",
"z",
".",
"ndim",
"==",
"2",
"z_",
"=",
"z",
".",
"clone",
"(",
")",
"z_",
"[",
":",
",",
"1",
":",
"]",
"=",
"_soft_th_tensor",
"(",
"z",
"[",
":",
",... | Soft-thresholding for Torch tensor. | [
"Soft",
"-",
"thresholding",
"for",
"Torch",
"tensor",
"."
] | [
"\"\"\" Soft-thresholding for Torch tensor. \"\"\""
] | [
{
"param": "z",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "step_size",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "z",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "lbda",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
5110834566e66f208fe738d56c41b056a3a10b46 | hcherkaoui/carpet | carpet/lista_base.py | [
"BSD-3-Clause"
] | Python | _init_network_parameters | null | def _init_network_parameters(self, initial_parameters=None):
""" Initialize the parameters of the network. """
if initial_parameters is None:
initial_parameters = {}
for layer_id in range(self.n_layers):
group_name = f'layer-{layer_id}'
if group_name in initi... | Initialize the parameters of the network. | Initialize the parameters of the network. | [
"Initialize",
"the",
"parameters",
"of",
"the",
"network",
"."
] | def _init_network_parameters(self, initial_parameters=None):
if initial_parameters is None:
initial_parameters = {}
for layer_id in range(self.n_layers):
group_name = f'layer-{layer_id}'
if group_name in initial_parameters.keys():
layer_params = initia... | [
"def",
"_init_network_parameters",
"(",
"self",
",",
"initial_parameters",
"=",
"None",
")",
":",
"if",
"initial_parameters",
"is",
"None",
":",
"initial_parameters",
"=",
"{",
"}",
"for",
"layer_id",
"in",
"range",
"(",
"self",
".",
"n_layers",
")",
":",
"g... | Initialize the parameters of the network. | [
"Initialize",
"the",
"parameters",
"of",
"the",
"network",
"."
] | [
"\"\"\" Initialize the parameters of the network. \"\"\"",
"# Finally get global parameters. This hook can be used to post-process",
"# initial-parameters."
] | [
{
"param": "self",
"type": null
},
{
"param": "initial_parameters",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "initial_parameters",
"type": null,
"docstring": null,
"docstr... |
5110834566e66f208fe738d56c41b056a3a10b46 | hcherkaoui/carpet | carpet/lista_base.py | [
"BSD-3-Clause"
] | Python | export_parameters | <not_specific> | def export_parameters(self):
""" Return a list with all the parameters of the network.
This list can be used to init a new network which will have the same
output. Usefull to save the parameters.
"""
return {
group_name: {k: p.detach().cpu().numpy()
... | Return a list with all the parameters of the network.
This list can be used to init a new network which will have the same
output. Usefull to save the parameters.
| Return a list with all the parameters of the network.
This list can be used to init a new network which will have the same
output. Usefull to save the parameters. | [
"Return",
"a",
"list",
"with",
"all",
"the",
"parameters",
"of",
"the",
"network",
".",
"This",
"list",
"can",
"be",
"used",
"to",
"init",
"a",
"new",
"network",
"which",
"will",
"have",
"the",
"same",
"output",
".",
"Usefull",
"to",
"save",
"the",
"pa... | def export_parameters(self):
return {
group_name: {k: p.detach().cpu().numpy()
for k, p in group_params.items()}
for group_name, group_params in self.parameter_groups.items()
} | [
"def",
"export_parameters",
"(",
"self",
")",
":",
"return",
"{",
"group_name",
":",
"{",
"k",
":",
"p",
".",
"detach",
"(",
")",
".",
"cpu",
"(",
")",
".",
"numpy",
"(",
")",
"for",
"k",
",",
"p",
"in",
"group_params",
".",
"items",
"(",
")",
... | Return a list with all the parameters of the network. | [
"Return",
"a",
"list",
"with",
"all",
"the",
"parameters",
"of",
"the",
"network",
"."
] | [
"\"\"\" Return a list with all the parameters of the network.\n\n This list can be used to init a new network which will have the same\n output. Usefull to save the parameters.\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5110834566e66f208fe738d56c41b056a3a10b46 | hcherkaoui/carpet | carpet/lista_base.py | [
"BSD-3-Clause"
] | Python | fit | <not_specific> | def fit(self, x, lbda):
""" Compute the output of the network, given x and regularization lbda
Parameters
----------
x : ndarray, shape (n_samples, n_dim)
input of the network.
lbda: float
Regularization level for the optimization problem.
"""
... | Compute the output of the network, given x and regularization lbda
Parameters
----------
x : ndarray, shape (n_samples, n_dim)
input of the network.
lbda: float
Regularization level for the optimization problem.
| Compute the output of the network, given x and regularization lbda
Parameters
x : ndarray, shape (n_samples, n_dim)
input of the network.
lbda: float
Regularization level for the optimization problem. | [
"Compute",
"the",
"output",
"of",
"the",
"network",
"given",
"x",
"and",
"regularization",
"lbda",
"Parameters",
"x",
":",
"ndarray",
"shape",
"(",
"n_samples",
"n_dim",
")",
"input",
"of",
"the",
"network",
".",
"lbda",
":",
"float",
"Regularization",
"leve... | def fit(self, x, lbda):
x = check_tensor(x, device=self.device)
lbda = check_tensor(lbda, device=self.device)
self._fit_all_network_batch_gradient_descent(x, lbda)
return self | [
"def",
"fit",
"(",
"self",
",",
"x",
",",
"lbda",
")",
":",
"x",
"=",
"check_tensor",
"(",
"x",
",",
"device",
"=",
"self",
".",
"device",
")",
"lbda",
"=",
"check_tensor",
"(",
"lbda",
",",
"device",
"=",
"self",
".",
"device",
")",
"self",
".",... | Compute the output of the network, given x and regularization lbda
Parameters | [
"Compute",
"the",
"output",
"of",
"the",
"network",
"given",
"x",
"and",
"regularization",
"lbda",
"Parameters"
] | [
"\"\"\" Compute the output of the network, given x and regularization lbda\n\n Parameters\n ----------\n x : ndarray, shape (n_samples, n_dim)\n input of the network.\n lbda: float\n Regularization level for the optimization problem.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
5110834566e66f208fe738d56c41b056a3a10b46 | hcherkaoui/carpet | carpet/lista_base.py | [
"BSD-3-Clause"
] | Python | transform | <not_specific> | def transform(self, x, lbda, output_layer=None):
""" Compute the output of the network, given x and regularization lbda
Parameters
----------
x : ndarray, shape (n_samples, n_dim)
input of the network.
lbda: float
Regularization level for the optimization... | Compute the output of the network, given x and regularization lbda
Parameters
----------
x : ndarray, shape (n_samples, n_dim)
input of the network.
lbda: float
Regularization level for the optimization problem.
output_layer : int (default: None)
... | Compute the output of the network, given x and regularization lbda
Parameters
x : ndarray, shape (n_samples, n_dim)
input of the network.
lbda: float
Regularization level for the optimization problem.
output_layer : int (default: None)
Layer to output from. It should be smaller than the number of
layers of the network... | [
"Compute",
"the",
"output",
"of",
"the",
"network",
"given",
"x",
"and",
"regularization",
"lbda",
"Parameters",
"x",
":",
"ndarray",
"shape",
"(",
"n_samples",
"n_dim",
")",
"input",
"of",
"the",
"network",
".",
"lbda",
":",
"float",
"Regularization",
"leve... | def transform(self, x, lbda, output_layer=None):
x = check_tensor(x, device=self.device)
lbda = check_tensor(lbda, device=self.device)
with torch.no_grad():
return self(
x, lbda, output_layer=output_layer
).detach().cpu().numpy() | [
"def",
"transform",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"x",
"=",
"check_tensor",
"(",
"x",
",",
"device",
"=",
"self",
".",
"device",
")",
"lbda",
"=",
"check_tensor",
"(",
"lbda",
",",
"device",
"=",
"s... | Compute the output of the network, given x and regularization lbda
Parameters | [
"Compute",
"the",
"output",
"of",
"the",
"network",
"given",
"x",
"and",
"regularization",
"lbda",
"Parameters"
] | [
"\"\"\" Compute the output of the network, given x and regularization lbda\n\n Parameters\n ----------\n x : ndarray, shape (n_samples, n_dim)\n input of the network.\n lbda: float\n Regularization level for the optimization problem.\n output_layer : int (def... | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
5110834566e66f208fe738d56c41b056a3a10b46 | hcherkaoui/carpet | carpet/lista_base.py | [
"BSD-3-Clause"
] | Python | transform_to_u | <not_specific> | def transform_to_u(self, x, lbda, output_layer=None):
"""Compute the output in primal analysis from given x and lbda
Parameters
----------
x : ndarray, shape (n_samples, n_dim)
input of the network.
lbda: float
Regularization level for the optimization pr... | Compute the output in primal analysis from given x and lbda
Parameters
----------
x : ndarray, shape (n_samples, n_dim)
input of the network.
lbda: float
Regularization level for the optimization problem.
output_layer : int (default: None)
Lay... | Compute the output in primal analysis from given x and lbda
Parameters
x : ndarray, shape (n_samples, n_dim)
input of the network.
lbda: float
Regularization level for the optimization problem.
output_layer : int (default: None)
Layer to output from. It should be smaller than the number of
layers of the network. If se... | [
"Compute",
"the",
"output",
"in",
"primal",
"analysis",
"from",
"given",
"x",
"and",
"lbda",
"Parameters",
"x",
":",
"ndarray",
"shape",
"(",
"n_samples",
"n_dim",
")",
"input",
"of",
"the",
"network",
".",
"lbda",
":",
"float",
"Regularization",
"level",
... | def transform_to_u(self, x, lbda, output_layer=None):
output = self.transform(x, lbda, output_layer=None)
if self._output == 'u-analysis':
return output
if self._output == 'z-synthesis':
return np.cumsum(output, axis=-1)
assert self._output == 'v-analysis_dual'
... | [
"def",
"transform_to_u",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output",
"=",
"self",
".",
"transform",
"(",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
"if",
"self",
".",
"_output",
"==",
"'u-an... | Compute the output in primal analysis from given x and lbda
Parameters | [
"Compute",
"the",
"output",
"in",
"primal",
"analysis",
"from",
"given",
"x",
"and",
"lbda",
"Parameters"
] | [
"\"\"\"Compute the output in primal analysis from given x and lbda\n\n Parameters\n ----------\n x : ndarray, shape (n_samples, n_dim)\n input of the network.\n lbda: float\n Regularization level for the optimization problem.\n output_layer : int (default: No... | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
5110834566e66f208fe738d56c41b056a3a10b46 | hcherkaoui/carpet | carpet/lista_base.py | [
"BSD-3-Clause"
] | Python | _fit_all_network_batch_gradient_descent | <not_specific> | def _fit_all_network_batch_gradient_descent(self, x, lbda):
""" Fit the parameters of the network. """
if self.net_solver_type == 'one_shot':
params = self.get_params_to_learn(up_to_layer=self.n_layers)
self._fit_sub_net_batch_gd(
x, lbda, params, self.n_layers, s... | Fit the parameters of the network. | Fit the parameters of the network. | [
"Fit",
"the",
"parameters",
"of",
"the",
"network",
"."
] | def _fit_all_network_batch_gradient_descent(self, x, lbda):
if self.net_solver_type == 'one_shot':
params = self.get_params_to_learn(up_to_layer=self.n_layers)
self._fit_sub_net_batch_gd(
x, lbda, params, self.n_layers, self.max_iter,
output_layer=self.n_l... | [
"def",
"_fit_all_network_batch_gradient_descent",
"(",
"self",
",",
"x",
",",
"lbda",
")",
":",
"if",
"self",
".",
"net_solver_type",
"==",
"'one_shot'",
":",
"params",
"=",
"self",
".",
"get_params_to_learn",
"(",
"up_to_layer",
"=",
"self",
".",
"n_layers",
... | Fit the parameters of the network. | [
"Fit",
"the",
"parameters",
"of",
"the",
"network",
"."
] | [
"\"\"\" Fit the parameters of the network. \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
5110834566e66f208fe738d56c41b056a3a10b46 | hcherkaoui/carpet | carpet/lista_base.py | [
"BSD-3-Clause"
] | Python | _fit_sub_net_batch_gd | null | def _fit_sub_net_batch_gd(self, x, lbda, params, layer_id, max_iter,
output_layer=None, eps=1e-20):
""" Fit the parameters of the sub-network. """
if output_layer is None:
output_layer = layer_id
with torch.no_grad():
z = self(x, lbda, output... | Fit the parameters of the sub-network. | Fit the parameters of the sub-network. | [
"Fit",
"the",
"parameters",
"of",
"the",
"sub",
"-",
"network",
"."
] | def _fit_sub_net_batch_gd(self, x, lbda, params, layer_id, max_iter,
output_layer=None, eps=1e-20):
if output_layer is None:
output_layer = layer_id
with torch.no_grad():
z = self(x, lbda, output_layer=output_layer)
prev_loss = self._loss... | [
"def",
"_fit_sub_net_batch_gd",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"params",
",",
"layer_id",
",",
"max_iter",
",",
"output_layer",
"=",
"None",
",",
"eps",
"=",
"1e-20",
")",
":",
"if",
"output_layer",
"is",
"None",
":",
"output_layer",
"=",
"laye... | Fit the parameters of the sub-network. | [
"Fit",
"the",
"parameters",
"of",
"the",
"sub",
"-",
"network",
"."
] | [
"\"\"\" Fit the parameters of the sub-network. \"\"\"",
"# noqa: E999",
"# Verbosity",
"# noqa: E999",
"# Gradient computation",
"# Compute a gradient step `-lr * grad`",
"# Back-tracking line search descent step with parameter c = 1/2",
"# Compute new possible loss",
"# Accepting the point when the... | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "params",
"type": null
},
{
"param": "layer_id",
"type": null
},
{
"param": "max_iter",
"type": null
},
{
"param": "output_laye... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
5110834566e66f208fe738d56c41b056a3a10b46 | hcherkaoui/carpet | carpet/lista_base.py | [
"BSD-3-Clause"
] | Python | _update_parameters | <not_specific> | def _update_parameters(self, parameters, lr):
""" Parameters update step for the gradient descent. """
max_norm_grad = 0.0
for param in parameters:
if param.grad is not None:
# do a descent step
param.data.add_(-lr, param.grad.data)
# ... | Parameters update step for the gradient descent. | Parameters update step for the gradient descent. | [
"Parameters",
"update",
"step",
"for",
"the",
"gradient",
"descent",
"."
] | def _update_parameters(self, parameters, lr):
max_norm_grad = 0.0
for param in parameters:
if param.grad is not None:
param.data.add_(-lr, param.grad.data)
current_norm_grad = param.grad.data.abs().max()
max_norm_grad = max(max_norm_grad, curre... | [
"def",
"_update_parameters",
"(",
"self",
",",
"parameters",
",",
"lr",
")",
":",
"max_norm_grad",
"=",
"0.0",
"for",
"param",
"in",
"parameters",
":",
"if",
"param",
".",
"grad",
"is",
"not",
"None",
":",
"param",
".",
"data",
".",
"add_",
"(",
"-",
... | Parameters update step for the gradient descent. | [
"Parameters",
"update",
"step",
"for",
"the",
"gradient",
"descent",
"."
] | [
"\"\"\" Parameters update step for the gradient descent. \"\"\"",
"# do a descent step",
"# compute gradient max norm"
] | [
{
"param": "self",
"type": null
},
{
"param": "parameters",
"type": null
},
{
"param": "lr",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "parameters",
"type": null,
"docstring": null,
"docstring_toke... |
dbc68e532b44755935c9fa4e65d82e19edb5e05f | hcherkaoui/carpet | carpet/checks.py | [
"BSD-3-Clause"
] | Python | check_tensor | <not_specific> | def check_tensor(*arrays, device=None, dtype=torch.float64,
requires_grad=None):
"""Take input arrays and return tensors with float64 type, on the
specified device and with requires_grad correctly set.
Parameters
----------
arrays: ndarray or Tensor or float
Input arrays to... | Take input arrays and return tensors with float64 type, on the
specified device and with requires_grad correctly set.
Parameters
----------
arrays: ndarray or Tensor or float
Input arrays to convert to torch.Tensor.
device: str or None (default: None)
Device on which the tensor are ... | Take input arrays and return tensors with float64 type, on the
specified device and with requires_grad correctly set.
Parameters
ndarray or Tensor or float
Input arrays to convert to torch.Tensor.
device: str or None (default: None)
Device on which the tensor are created.
requires_grad: bool or None (default: None)
I... | [
"Take",
"input",
"arrays",
"and",
"return",
"tensors",
"with",
"float64",
"type",
"on",
"the",
"specified",
"device",
"and",
"with",
"requires_grad",
"correctly",
"set",
".",
"Parameters",
"ndarray",
"or",
"Tensor",
"or",
"float",
"Input",
"arrays",
"to",
"con... | def check_tensor(*arrays, device=None, dtype=torch.float64,
requires_grad=None):
n_arrays = len(arrays)
result = []
for x in arrays:
initial_type = type(x)
if isinstance(x, np.ndarray) or isinstance(x, numbers.Number):
x = torch.tensor(x)
assert isinstanc... | [
"def",
"check_tensor",
"(",
"*",
"arrays",
",",
"device",
"=",
"None",
",",
"dtype",
"=",
"torch",
".",
"float64",
",",
"requires_grad",
"=",
"None",
")",
":",
"n_arrays",
"=",
"len",
"(",
"arrays",
")",
"result",
"=",
"[",
"]",
"for",
"x",
"in",
"... | Take input arrays and return tensors with float64 type, on the
specified device and with requires_grad correctly set. | [
"Take",
"input",
"arrays",
"and",
"return",
"tensors",
"with",
"float64",
"type",
"on",
"the",
"specified",
"device",
"and",
"with",
"requires_grad",
"correctly",
"set",
"."
] | [
"\"\"\"Take input arrays and return tensors with float64 type, on the\n specified device and with requires_grad correctly set.\n\n Parameters\n ----------\n arrays: ndarray or Tensor or float\n Input arrays to convert to torch.Tensor.\n device: str or None (default: None)\n Device on wh... | [
{
"param": "device",
"type": null
},
{
"param": "dtype",
"type": null
},
{
"param": "requires_grad",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dtype",
"type": null,
"docstring": null,
"docstring_tokens"... |
dbc68e532b44755935c9fa4e65d82e19edb5e05f | hcherkaoui/carpet | carpet/checks.py | [
"BSD-3-Clause"
] | Python | check_parameter | <not_specific> | def check_parameter(*arrays, device=None, dtype=torch.float64):
"""Take input arrays and return parameters with float64 type, on the
specified device.
Parameters
----------
arrays: ndarray or Tensor or float
Input arrays to convert to torch.Tensor.
device: str or None (default: None)
... | Take input arrays and return parameters with float64 type, on the
specified device.
Parameters
----------
arrays: ndarray or Tensor or float
Input arrays to convert to torch.Tensor.
device: str or None (default: None)
Device on which the tensor are created.
| Take input arrays and return parameters with float64 type, on the
specified device.
Parameters
ndarray or Tensor or float
Input arrays to convert to torch.Tensor.
device: str or None (default: None)
Device on which the tensor are created. | [
"Take",
"input",
"arrays",
"and",
"return",
"parameters",
"with",
"float64",
"type",
"on",
"the",
"specified",
"device",
".",
"Parameters",
"ndarray",
"or",
"Tensor",
"or",
"float",
"Input",
"arrays",
"to",
"convert",
"to",
"torch",
".",
"Tensor",
".",
"devi... | def check_parameter(*arrays, device=None, dtype=torch.float64):
n_arrays = len(arrays)
result = []
for x in arrays:
if not isinstance(x, torch.nn.Parameter):
x = torch.nn.Parameter(check_tensor(
x, requires_grad=True, device=device, dtype=dtype
))
resu... | [
"def",
"check_parameter",
"(",
"*",
"arrays",
",",
"device",
"=",
"None",
",",
"dtype",
"=",
"torch",
".",
"float64",
")",
":",
"n_arrays",
"=",
"len",
"(",
"arrays",
")",
"result",
"=",
"[",
"]",
"for",
"x",
"in",
"arrays",
":",
"if",
"not",
"isin... | Take input arrays and return parameters with float64 type, on the
specified device. | [
"Take",
"input",
"arrays",
"and",
"return",
"parameters",
"with",
"float64",
"type",
"on",
"the",
"specified",
"device",
"."
] | [
"\"\"\"Take input arrays and return parameters with float64 type, on the\n specified device.\n\n Parameters\n ----------\n arrays: ndarray or Tensor or float\n Input arrays to convert to torch.Tensor.\n device: str or None (default: None)\n Device on which the tensor are created.\n \... | [
{
"param": "device",
"type": null
},
{
"param": "dtype",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "device",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dtype",
"type": null,
"docstring": null,
"docstring_tokens"... |
4736b67f63630a2626a5ef8724483b8ae744b159 | hcherkaoui/carpet | carpet/metrics.py | [
"BSD-3-Clause"
] | Python | compute_prox_tv_errors | <not_specific> | def compute_prox_tv_errors(network, x, lbda):
"""Return the sub-optimality gap of the prox-tv at each iteration.
"""
if not isinstance(network, ListaTV):
raise ValueError("network should be of type {'ListaTV'}.")
if not hasattr(network, 'training_loss_'):
warnings.warn("network has not... | Return the sub-optimality gap of the prox-tv at each iteration.
| Return the sub-optimality gap of the prox-tv at each iteration. | [
"Return",
"the",
"sub",
"-",
"optimality",
"gap",
"of",
"the",
"prox",
"-",
"tv",
"at",
"each",
"iteration",
"."
] | def compute_prox_tv_errors(network, x, lbda):
if not isinstance(network, ListaTV):
raise ValueError("network should be of type {'ListaTV'}.")
if not hasattr(network, 'training_loss_'):
warnings.warn("network has not been trained before computing "
"prox_tv_errors.")
x =... | [
"def",
"compute_prox_tv_errors",
"(",
"network",
",",
"x",
",",
"lbda",
")",
":",
"if",
"not",
"isinstance",
"(",
"network",
",",
"ListaTV",
")",
":",
"raise",
"ValueError",
"(",
"\"network should be of type {'ListaTV'}.\"",
")",
"if",
"not",
"hasattr",
"(",
"... | Return the sub-optimality gap of the prox-tv at each iteration. | [
"Return",
"the",
"sub",
"-",
"optimality",
"gap",
"of",
"the",
"prox",
"-",
"tv",
"at",
"each",
"iteration",
"."
] | [
"\"\"\"Return the sub-optimality gap of the prox-tv at each iteration.\n \"\"\"",
"# retrieve parameters",
"# Get the correct prox depending on the layer_id and learn_prox",
"# apply one 'iteration'",
"# prox-tv as applied by the network",
"# exact prox-tv with taut-string algorithm",
"# log sub-opti... | [
{
"param": "network",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "network",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [... |
0a2769bfcd298cdb13cf4bef2bdc8848b72efd75 | hcherkaoui/carpet | carpet/lista_synthesis.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
_, _, z = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id ... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
_, _, z = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id in range(output_layer):
layer_params = self.parameter_groups[f'laye... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"_",
",",
"_",
",",
"z",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# apply one 'iteration'"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
0a2769bfcd298cdb13cf4bef2bdc8848b72efd75 | hcherkaoui/carpet | carpet/lista_synthesis.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
_, _, z = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id ... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
_, _, z = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id in range(output_layer):
layer_params = self.parameter_groups[f'laye... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"_",
",",
"_",
",",
"z",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# apply one 'iteration'"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
0a2769bfcd298cdb13cf4bef2bdc8848b72efd75 | hcherkaoui/carpet | carpet/lista_synthesis.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
_, _, z = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id ... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
_, _, z = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id in range(output_layer):
layer_params = self.parameter_groups[f'laye... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"_",
",",
"_",
",",
"z",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# apply one 'iteration'"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
f56172d5592573693dee74fd9affdf48acc66bb2 | hcherkaoui/carpet | carpet/lista_analysis_dual.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
v, _, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id ... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
v, _, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id in range(output_layer):
layer_params = self.parameter_groups[f'laye... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"v",
",",
"_",
",",
"_",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# mul_lbda = layer_params.get('threshold', 1.0)",
"# mul_lbda = check_tensor(mul_lbda)",
"# apply one 'dual iteration'",
"# v = torch.clamp(v, -lbda * mul_lbda, lbda * mul_lbda)"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
f56172d5592573693dee74fd9affdf48acc66bb2 | hcherkaoui/carpet | carpet/lista_analysis_dual.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
v, _, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id ... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
v, _, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id in range(output_layer):
layer_params = self.parameter_groups[f'laye... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"v",
",",
"_",
",",
"_",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# apply one 'dual iteration'"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
f56172d5592573693dee74fd9affdf48acc66bb2 | hcherkaoui/carpet | carpet/lista_analysis_dual.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
v, _, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id ... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
v, _, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id in range(output_layer):
layer_params = self.parameter_groups[f'laye... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"v",
",",
"_",
",",
"_",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# apply one 'dual iteration'"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
b5db054870512a637ffb096770c29f968ea6f24a | hcherkaoui/carpet | carpet/parameters.py | [
"BSD-3-Clause"
] | Python | list_parameters_from_groups | <not_specific> | def list_parameters_from_groups(parameter_groups, groups):
"""Return a list of all the parameters in a list of groups
"""
return [
p for group in groups
for p in parameter_groups[group].values()
] | Return a list of all the parameters in a list of groups
| Return a list of all the parameters in a list of groups | [
"Return",
"a",
"list",
"of",
"all",
"the",
"parameters",
"in",
"a",
"list",
"of",
"groups"
] | def list_parameters_from_groups(parameter_groups, groups):
return [
p for group in groups
for p in parameter_groups[group].values()
] | [
"def",
"list_parameters_from_groups",
"(",
"parameter_groups",
",",
"groups",
")",
":",
"return",
"[",
"p",
"for",
"group",
"in",
"groups",
"for",
"p",
"in",
"parameter_groups",
"[",
"group",
"]",
".",
"values",
"(",
")",
"]"
] | Return a list of all the parameters in a list of groups | [
"Return",
"a",
"list",
"of",
"all",
"the",
"parameters",
"in",
"a",
"list",
"of",
"groups"
] | [
"\"\"\"Return a list of all the parameters in a list of groups\n \"\"\""
] | [
{
"param": "parameter_groups",
"type": null
},
{
"param": "groups",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "parameter_groups",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "groups",
"type": null,
"docstring": null,
"docstr... |
787cea276bc2dc36c540c9378a5d755ab1c6055a | hcherkaoui/carpet | carpet/proximity_tv.py | [
"BSD-3-Clause"
] | Python | backward | <not_specific> | def backward(ctx, grad_output):
"""Compute the gradient of proxTV using implicit gradient."""
batch_size, n_dim = grad_output.shape
sign_z, = ctx.saved_tensors
device = grad_output.device
S = sign_z != 0
S[:, 0] = True
sign_z[:, 0] = 0
# XXX do clever comp... | Compute the gradient of proxTV using implicit gradient. | Compute the gradient of proxTV using implicit gradient. | [
"Compute",
"the",
"gradient",
"of",
"proxTV",
"using",
"implicit",
"gradient",
"."
] | def backward(ctx, grad_output):
batch_size, n_dim = grad_output.shape
sign_z, = ctx.saved_tensors
device = grad_output.device
S = sign_z != 0
S[:, 0] = True
sign_z[:, 0] = 0
L = torch.triu(torch.ones((n_dim, n_dim), dtype=torch.float64,
devi... | [
"def",
"backward",
"(",
"ctx",
",",
"grad_output",
")",
":",
"batch_size",
",",
"n_dim",
"=",
"grad_output",
".",
"shape",
"sign_z",
",",
"=",
"ctx",
".",
"saved_tensors",
"device",
"=",
"grad_output",
".",
"device",
"S",
"=",
"sign_z",
"!=",
"0",
"S",
... | Compute the gradient of proxTV using implicit gradient. | [
"Compute",
"the",
"gradient",
"of",
"proxTV",
"using",
"implicit",
"gradient",
"."
] | [
"\"\"\"Compute the gradient of proxTV using implicit gradient.\"\"\"",
"# XXX do clever computations",
"# n_dim x |S|",
"# 1 x |S|"
] | [
{
"param": "ctx",
"type": null
},
{
"param": "grad_output",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "ctx",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "grad_output",
"type": null,
"docstring": null,
"docstring_toke... |
787cea276bc2dc36c540c9378a5d755ab1c6055a | hcherkaoui/carpet | carpet/proximity_tv.py | [
"BSD-3-Clause"
] | Python | backward | <not_specific> | def backward(ctx, grad_output):
"""Compute the gradient of loss + mu*reg using a prox step.
The gradient is derived as the additive update that would be
used in a proximal gradient descent:
G(u) = (u - prox(u - eps * nabla(loss)(u), eps*lbda))/eps
with a small eps (here ha... | Compute the gradient of loss + mu*reg using a prox step.
The gradient is derived as the additive update that would be
used in a proximal gradient descent:
G(u) = (u - prox(u - eps * nabla(loss)(u), eps*lbda))/eps
with a small eps (here hard coded to 1e-10).
| Compute the gradient of loss + mu*reg using a prox step.
The gradient is derived as the additive update that would be
used in a proximal gradient descent.
with a small eps (here hard coded to 1e-10). | [
"Compute",
"the",
"gradient",
"of",
"loss",
"+",
"mu",
"*",
"reg",
"using",
"a",
"prox",
"step",
".",
"The",
"gradient",
"is",
"derived",
"as",
"the",
"additive",
"update",
"that",
"would",
"be",
"used",
"in",
"a",
"proximal",
"gradient",
"descent",
".",... | def backward(ctx, grad_output):
loss, reg, u, lbda = ctx.saved_tensors
device = u.device
eps = 1e-10
grad, = torch.autograd.grad(loss, u, only_inputs=True,
retain_graph=True)
x = (u - eps * grad).data
lbda = lbda.data
prox_x = c... | [
"def",
"backward",
"(",
"ctx",
",",
"grad_output",
")",
":",
"loss",
",",
"reg",
",",
"u",
",",
"lbda",
"=",
"ctx",
".",
"saved_tensors",
"device",
"=",
"u",
".",
"device",
"eps",
"=",
"1e-10",
"grad",
",",
"=",
"torch",
".",
"autograd",
".",
"grad... | Compute the gradient of loss + mu*reg using a prox step. | [
"Compute",
"the",
"gradient",
"of",
"loss",
"+",
"mu",
"*",
"reg",
"using",
"a",
"prox",
"step",
"."
] | [
"\"\"\"Compute the gradient of loss + mu*reg using a prox step.\n\n The gradient is derived as the additive update that would be\n used in a proximal gradient descent:\n\n G(u) = (u - prox(u - eps * nabla(loss)(u), eps*lbda))/eps\n\n with a small eps (here hard coded to 1e-10).\n ... | [
{
"param": "ctx",
"type": null
},
{
"param": "grad_output",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "ctx",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "grad_output",
"type": null,
"docstring": null,
"docstring_toke... |
bd7e3e2b566033a461fb0dac2f862a6aa2e77bbd | hcherkaoui/carpet | carpet/lista_analysis.py | [
"BSD-3-Clause"
] | Python | _initialize_prox_tv_per_layer | <not_specific> | def _initialize_prox_tv_per_layer(self, layer_id, layer_params,
initial_parameters_prox=None):
"""Create a Lista network to solve the proxTV sub problem.
Make sure to register correctly its parameter so that the training is
done properly for all net_solver_... | Create a Lista network to solve the proxTV sub problem.
Make sure to register correctly its parameter so that the training is
done properly for all net_solver_type values.
| Create a Lista network to solve the proxTV sub problem.
Make sure to register correctly its parameter so that the training is
done properly for all net_solver_type values. | [
"Create",
"a",
"Lista",
"network",
"to",
"solve",
"the",
"proxTV",
"sub",
"problem",
".",
"Make",
"sure",
"to",
"register",
"correctly",
"its",
"parameter",
"so",
"that",
"the",
"training",
"is",
"done",
"properly",
"for",
"all",
"net_solver_type",
"values",
... | def _initialize_prox_tv_per_layer(self, layer_id, layer_params,
initial_parameters_prox=None):
layer_prox_tv = ListaLASSO(
A=self.I_k, n_layers=self.n_inner_layers, learn_th=True,
initial_parameters=initial_parameters_prox,
name=f"Prox-TV... | [
"def",
"_initialize_prox_tv_per_layer",
"(",
"self",
",",
"layer_id",
",",
"layer_params",
",",
"initial_parameters_prox",
"=",
"None",
")",
":",
"layer_prox_tv",
"=",
"ListaLASSO",
"(",
"A",
"=",
"self",
".",
"I_k",
",",
"n_layers",
"=",
"self",
".",
"n_inner... | Create a Lista network to solve the proxTV sub problem. | [
"Create",
"a",
"Lista",
"network",
"to",
"solve",
"the",
"proxTV",
"sub",
"problem",
"."
] | [
"\"\"\"Create a Lista network to solve the proxTV sub problem.\n\n Make sure to register correctly its parameter so that the training is\n done properly for all net_solver_type values.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "layer_id",
"type": null
},
{
"param": "layer_params",
"type": null
},
{
"param": "initial_parameters_prox",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "layer_id",
"type": null,
"docstring": null,
"docstring_tokens... |
bd7e3e2b566033a461fb0dac2f862a6aa2e77bbd | hcherkaoui/carpet | carpet/lista_analysis.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
_, u, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id ... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
_, u, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
for layer_id in range(output_layer):
layer_params = self.parameter_groups[f'laye... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"_",
",",
"u",
",",
"_",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# apply one 'iteration'. We need an extra integration step as",
"# prox_tv is a synthesis algorithm which outputs the synthesis",
"# variable z and not the analysis one u."
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
bd7e3e2b566033a461fb0dac2f862a6aa2e77bbd | hcherkaoui/carpet | carpet/lista_analysis.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
_, u, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
mul_lbda = che... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
_, u, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
mul_lbda = check_tensor(1.0 / self.l_, device=self.device)
for layer_id in range(out... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"_",
",",
"u",
",",
"_",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# apply one 'iteration'"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
bd7e3e2b566033a461fb0dac2f862a6aa2e77bbd | hcherkaoui/carpet | carpet/lista_analysis.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
v, u, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
v_old, u_old =... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
v, u, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
v_old, u_old = v.clone(), u.clone()
for layer_id in range(output_layer):
... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"v",
",",
"u",
",",
"_",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# primal descent",
"# dual ascent",
"# update",
"# storing"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
bd7e3e2b566033a461fb0dac2f862a6aa2e77bbd | hcherkaoui/carpet | carpet/lista_analysis.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
v, u, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
v_old, u_old, ... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
v, u, _ = init_vuz(self.A, self.D, x, inv_A=self.inv_A_,
device=self.device)
v_old, u_old, _ = init_vuz(self.A, self.D, x, device=self.device)
for layer_id in ra... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"v",
",",
"u",
",",
"_",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# TODO constraint learning",
"# primal descent",
"# dual ascent",
"# update",
"# storing"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
bd7e3e2b566033a461fb0dac2f862a6aa2e77bbd | hcherkaoui/carpet | carpet/lista_analysis.py | [
"BSD-3-Clause"
] | Python | forward | <not_specific> | def forward(self, x, lbda, output_layer=None):
""" Forward pass of the network. """
output_layer = self.check_output_layer(output_layer)
# initialized variables
_, u, _ = init_vuz(self.A, self.D, x, device=self.device)
for layer_id in range(output_layer):
layer_para... | Forward pass of the network. | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | def forward(self, x, lbda, output_layer=None):
output_layer = self.check_output_layer(output_layer)
_, u, _ = init_vuz(self.A, self.D, x, device=self.device)
for layer_id in range(output_layer):
layer_params = self.parameter_groups[f'layer-{layer_id}']
step_size = layer_p... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"lbda",
",",
"output_layer",
"=",
"None",
")",
":",
"output_layer",
"=",
"self",
".",
"check_output_layer",
"(",
"output_layer",
")",
"_",
",",
"u",
",",
"_",
"=",
"init_vuz",
"(",
"self",
".",
"A",
",",
... | Forward pass of the network. | [
"Forward",
"pass",
"of",
"the",
"network",
"."
] | [
"\"\"\" Forward pass of the network. \"\"\"",
"# initialized variables",
"# retrieve parameters",
"# apply one 'iteration'"
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "output_layer",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
ecbf6f41d7e7ad8cee5b452ec9f880082d73ae38 | hcherkaoui/carpet | carpet/loss_gradient.py | [
"BSD-3-Clause"
] | Python | analysis_dual_grad | <not_specific> | def analysis_dual_grad(v, A, D, x, Psi_A=None):
""" Gradient for the dual formulation of the analysis problem. """
v = np.atleast_2d(v)
Psi_A = np.linalg.pinv(A).dot(D) if Psi_A is None else Psi_A
return (v.dot(Psi_A.T) - x).dot(Psi_A) | Gradient for the dual formulation of the analysis problem. | Gradient for the dual formulation of the analysis problem. | [
"Gradient",
"for",
"the",
"dual",
"formulation",
"of",
"the",
"analysis",
"problem",
"."
] | def analysis_dual_grad(v, A, D, x, Psi_A=None):
v = np.atleast_2d(v)
Psi_A = np.linalg.pinv(A).dot(D) if Psi_A is None else Psi_A
return (v.dot(Psi_A.T) - x).dot(Psi_A) | [
"def",
"analysis_dual_grad",
"(",
"v",
",",
"A",
",",
"D",
",",
"x",
",",
"Psi_A",
"=",
"None",
")",
":",
"v",
"=",
"np",
".",
"atleast_2d",
"(",
"v",
")",
"Psi_A",
"=",
"np",
".",
"linalg",
".",
"pinv",
"(",
"A",
")",
".",
"dot",
"(",
"D",
... | Gradient for the dual formulation of the analysis problem. | [
"Gradient",
"for",
"the",
"dual",
"formulation",
"of",
"the",
"analysis",
"problem",
"."
] | [
"\"\"\" Gradient for the dual formulation of the analysis problem. \"\"\""
] | [
{
"param": "v",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "Psi_A",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "v",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "A",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
ecbf6f41d7e7ad8cee5b452ec9f880082d73ae38 | hcherkaoui/carpet | carpet/loss_gradient.py | [
"BSD-3-Clause"
] | Python | analysis_dual_obj | <not_specific> | def analysis_dual_obj(v, A, D, x, lbda, Psi_A=None):
""" Cost for the dual formulation of the analysis problem. """
v = np.atleast_2d(v)
if np.all(np.abs(v) <= lbda):
n_samples = v.shape[0]
Psi_A = np.linalg.pinv(A).dot(D) if Psi_A is None else Psi_A
v_PsiAt = v.dot(Psi_A.T)
... | Cost for the dual formulation of the analysis problem. | Cost for the dual formulation of the analysis problem. | [
"Cost",
"for",
"the",
"dual",
"formulation",
"of",
"the",
"analysis",
"problem",
"."
] | def analysis_dual_obj(v, A, D, x, lbda, Psi_A=None):
v = np.atleast_2d(v)
if np.all(np.abs(v) <= lbda):
n_samples = v.shape[0]
Psi_A = np.linalg.pinv(A).dot(D) if Psi_A is None else Psi_A
v_PsiAt = v.dot(Psi_A.T)
cost = 0.5 * np.sum(v_PsiAt * v_PsiAt)
cost -= np.sum(np.di... | [
"def",
"analysis_dual_obj",
"(",
"v",
",",
"A",
",",
"D",
",",
"x",
",",
"lbda",
",",
"Psi_A",
"=",
"None",
")",
":",
"v",
"=",
"np",
".",
"atleast_2d",
"(",
"v",
")",
"if",
"np",
".",
"all",
"(",
"np",
".",
"abs",
"(",
"v",
")",
"<=",
"lbd... | Cost for the dual formulation of the analysis problem. | [
"Cost",
"for",
"the",
"dual",
"formulation",
"of",
"the",
"analysis",
"problem",
"."
] | [
"\"\"\" Cost for the dual formulation of the analysis problem. \"\"\""
] | [
{
"param": "v",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
},
{
"param": "Psi_A",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "v",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "A",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
ecbf6f41d7e7ad8cee5b452ec9f880082d73ae38 | hcherkaoui/carpet | carpet/loss_gradient.py | [
"BSD-3-Clause"
] | Python | analysis_primal_obj | <not_specific> | def analysis_primal_obj(z, A, D, x, lbda):
""" Cost for the primal formulation of the analysis problem. """
z = np.atleast_2d(z)
n_samples = z.shape[0]
residual = z.dot(A) - x
cost = 0.5 * np.sum(residual * residual)
reg = np.sum(np.abs(z.dot(D)))
return (cost + lbda * reg) / n_samples | Cost for the primal formulation of the analysis problem. | Cost for the primal formulation of the analysis problem. | [
"Cost",
"for",
"the",
"primal",
"formulation",
"of",
"the",
"analysis",
"problem",
"."
] | def analysis_primal_obj(z, A, D, x, lbda):
z = np.atleast_2d(z)
n_samples = z.shape[0]
residual = z.dot(A) - x
cost = 0.5 * np.sum(residual * residual)
reg = np.sum(np.abs(z.dot(D)))
return (cost + lbda * reg) / n_samples | [
"def",
"analysis_primal_obj",
"(",
"z",
",",
"A",
",",
"D",
",",
"x",
",",
"lbda",
")",
":",
"z",
"=",
"np",
".",
"atleast_2d",
"(",
"z",
")",
"n_samples",
"=",
"z",
".",
"shape",
"[",
"0",
"]",
"residual",
"=",
"z",
".",
"dot",
"(",
"A",
")"... | Cost for the primal formulation of the analysis problem. | [
"Cost",
"for",
"the",
"primal",
"formulation",
"of",
"the",
"analysis",
"problem",
"."
] | [
"\"\"\" Cost for the primal formulation of the analysis problem. \"\"\""
] | [
{
"param": "z",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "z",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "A",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
ecbf6f41d7e7ad8cee5b452ec9f880082d73ae38 | hcherkaoui/carpet | carpet/loss_gradient.py | [
"BSD-3-Clause"
] | Python | synthesis_primal_grad | <not_specific> | def synthesis_primal_grad(z, A, L, x):
""" Gradient for the primal formulation of the synthesis problem. """
z = np.atleast_2d(z)
LA = L.dot(A)
grad = (z.dot(LA) - x).dot(LA.T)
return grad | Gradient for the primal formulation of the synthesis problem. | Gradient for the primal formulation of the synthesis problem. | [
"Gradient",
"for",
"the",
"primal",
"formulation",
"of",
"the",
"synthesis",
"problem",
"."
] | def synthesis_primal_grad(z, A, L, x):
z = np.atleast_2d(z)
LA = L.dot(A)
grad = (z.dot(LA) - x).dot(LA.T)
return grad | [
"def",
"synthesis_primal_grad",
"(",
"z",
",",
"A",
",",
"L",
",",
"x",
")",
":",
"z",
"=",
"np",
".",
"atleast_2d",
"(",
"z",
")",
"LA",
"=",
"L",
".",
"dot",
"(",
"A",
")",
"grad",
"=",
"(",
"z",
".",
"dot",
"(",
"LA",
")",
"-",
"x",
")... | Gradient for the primal formulation of the synthesis problem. | [
"Gradient",
"for",
"the",
"primal",
"formulation",
"of",
"the",
"synthesis",
"problem",
"."
] | [
"\"\"\" Gradient for the primal formulation of the synthesis problem. \"\"\""
] | [
{
"param": "z",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "x",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "z",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "A",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
ecbf6f41d7e7ad8cee5b452ec9f880082d73ae38 | hcherkaoui/carpet | carpet/loss_gradient.py | [
"BSD-3-Clause"
] | Python | synthesis_primal_subgrad | <not_specific> | def synthesis_primal_subgrad(z, A, L, x, lbda):
""" Sub-gradient for the primal formulation of the synthesis problem. """
z = np.atleast_2d(z)
n = z.shape[0]
reg = np.concatenate([np.zeros((n, 1)), np.sign(z[:, 1:])], axis=1)
return synthesis_primal_grad(z, A, L, x) + lbda * reg | Sub-gradient for the primal formulation of the synthesis problem. | Sub-gradient for the primal formulation of the synthesis problem. | [
"Sub",
"-",
"gradient",
"for",
"the",
"primal",
"formulation",
"of",
"the",
"synthesis",
"problem",
"."
] | def synthesis_primal_subgrad(z, A, L, x, lbda):
z = np.atleast_2d(z)
n = z.shape[0]
reg = np.concatenate([np.zeros((n, 1)), np.sign(z[:, 1:])], axis=1)
return synthesis_primal_grad(z, A, L, x) + lbda * reg | [
"def",
"synthesis_primal_subgrad",
"(",
"z",
",",
"A",
",",
"L",
",",
"x",
",",
"lbda",
")",
":",
"z",
"=",
"np",
".",
"atleast_2d",
"(",
"z",
")",
"n",
"=",
"z",
".",
"shape",
"[",
"0",
"]",
"reg",
"=",
"np",
".",
"concatenate",
"(",
"[",
"n... | Sub-gradient for the primal formulation of the synthesis problem. | [
"Sub",
"-",
"gradient",
"for",
"the",
"primal",
"formulation",
"of",
"the",
"synthesis",
"problem",
"."
] | [
"\"\"\" Sub-gradient for the primal formulation of the synthesis problem. \"\"\""
] | [
{
"param": "z",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "z",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "A",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
ecbf6f41d7e7ad8cee5b452ec9f880082d73ae38 | hcherkaoui/carpet | carpet/loss_gradient.py | [
"BSD-3-Clause"
] | Python | synthesis_primal_obj | <not_specific> | def synthesis_primal_obj(z, A, L, x, lbda):
""" Cost for the primal formulation of the synthesis problem. """
z = np.atleast_2d(z)
n_samples = z.shape[0]
cost = 0.5 * np.sum(np.square(z.dot(L).dot(A) - x))
cost += lbda * np.sum(np.abs(z[:, 1:]))
return cost / n_samples | Cost for the primal formulation of the synthesis problem. | Cost for the primal formulation of the synthesis problem. | [
"Cost",
"for",
"the",
"primal",
"formulation",
"of",
"the",
"synthesis",
"problem",
"."
] | def synthesis_primal_obj(z, A, L, x, lbda):
z = np.atleast_2d(z)
n_samples = z.shape[0]
cost = 0.5 * np.sum(np.square(z.dot(L).dot(A) - x))
cost += lbda * np.sum(np.abs(z[:, 1:]))
return cost / n_samples | [
"def",
"synthesis_primal_obj",
"(",
"z",
",",
"A",
",",
"L",
",",
"x",
",",
"lbda",
")",
":",
"z",
"=",
"np",
".",
"atleast_2d",
"(",
"z",
")",
"n_samples",
"=",
"z",
".",
"shape",
"[",
"0",
"]",
"cost",
"=",
"0.5",
"*",
"np",
".",
"sum",
"("... | Cost for the primal formulation of the synthesis problem. | [
"Cost",
"for",
"the",
"primal",
"formulation",
"of",
"the",
"synthesis",
"problem",
"."
] | [
"\"\"\" Cost for the primal formulation of the synthesis problem. \"\"\""
] | [
{
"param": "z",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "L",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "lbda",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "z",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "A",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
ecbf6f41d7e7ad8cee5b452ec9f880082d73ae38 | hcherkaoui/carpet | carpet/loss_gradient.py | [
"BSD-3-Clause"
] | Python | loss_prox_tv_analysis | <not_specific> | def loss_prox_tv_analysis(x, u, lbda):
""" TV reg. loss function for Numpy variables. """
n_samples = u.shape[0]
data_fit = 0.5 * np.sum(np.square(u - x))
reg = lbda * np.sum(np.abs(np.diff(u, axis=-1)))
return (data_fit + reg) / n_samples | TV reg. loss function for Numpy variables. | TV reg. loss function for Numpy variables. | [
"TV",
"reg",
".",
"loss",
"function",
"for",
"Numpy",
"variables",
"."
] | def loss_prox_tv_analysis(x, u, lbda):
n_samples = u.shape[0]
data_fit = 0.5 * np.sum(np.square(u - x))
reg = lbda * np.sum(np.abs(np.diff(u, axis=-1)))
return (data_fit + reg) / n_samples | [
"def",
"loss_prox_tv_analysis",
"(",
"x",
",",
"u",
",",
"lbda",
")",
":",
"n_samples",
"=",
"u",
".",
"shape",
"[",
"0",
"]",
"data_fit",
"=",
"0.5",
"*",
"np",
".",
"sum",
"(",
"np",
".",
"square",
"(",
"u",
"-",
"x",
")",
")",
"reg",
"=",
... | TV reg. | [
"TV",
"reg",
"."
] | [
"\"\"\" TV reg. loss function for Numpy variables. \"\"\""
] | [
{
"param": "x",
"type": null
},
{
"param": "u",
"type": null
},
{
"param": "lbda",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "u",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
497873151a2136503b65044b4fc5b34e77a8bfe8 | hcherkaoui/carpet | carpet/utils.py | [
"BSD-3-Clause"
] | Python | v_to_u | <not_specific> | def v_to_u(v, x, A=None, D=None, inv_AtA=None, device='cpu'):
""" Return primal variable from dual variable. """
v = check_tensor(v, device=device)
x = check_tensor(x, device=device)
if inv_AtA is None:
if A is not None and D is not None:
A = check_tensor(A, device=device)
... | Return primal variable from dual variable. | Return primal variable from dual variable. | [
"Return",
"primal",
"variable",
"from",
"dual",
"variable",
"."
] | def v_to_u(v, x, A=None, D=None, inv_AtA=None, device='cpu'):
v = check_tensor(v, device=device)
x = check_tensor(x, device=device)
if inv_AtA is None:
if A is not None and D is not None:
A = check_tensor(A, device=device)
AtA = A.matmul(A.t())
inv_AtA = torch.pin... | [
"def",
"v_to_u",
"(",
"v",
",",
"x",
",",
"A",
"=",
"None",
",",
"D",
"=",
"None",
",",
"inv_AtA",
"=",
"None",
",",
"device",
"=",
"'cpu'",
")",
":",
"v",
"=",
"check_tensor",
"(",
"v",
",",
"device",
"=",
"device",
")",
"x",
"=",
"check_tenso... | Return primal variable from dual variable. | [
"Return",
"primal",
"variable",
"from",
"dual",
"variable",
"."
] | [
"\"\"\" Return primal variable from dual variable. \"\"\""
] | [
{
"param": "v",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "A",
"type": null
},
{
"param": "D",
"type": null
},
{
"param": "inv_AtA",
"type": null
},
{
"param": "device",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "v",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
924be18307bb84332b4ad295aca4c854dfe7719d | TC01/calcpkg | calcrepo/util.py | [
"MIT"
] | Python | replaceNewlines | <not_specific> | def replaceNewlines(string, newlineChar):
"""There's probably a way to do this with string functions but I was lazy.
Replace all instances of \r or \n in a string with something else."""
if newlineChar in string:
segments = string.split(newlineChar)
string = ""
for segment in segments:
string += segment
r... | There's probably a way to do this with string functions but I was lazy.
Replace all instances of \r or \n in a string with something else. | There's probably a way to do this with string functions but I was lazy.
Replace all instances of \r or \n in a string with something else. | [
"There",
"'",
"s",
"probably",
"a",
"way",
"to",
"do",
"this",
"with",
"string",
"functions",
"but",
"I",
"was",
"lazy",
".",
"Replace",
"all",
"instances",
"of",
"\\",
"r",
"or",
"\\",
"n",
"in",
"a",
"string",
"with",
"something",
"else",
"."
] | def replaceNewlines(string, newlineChar):
if newlineChar in string:
segments = string.split(newlineChar)
string = ""
for segment in segments:
string += segment
return string | [
"def",
"replaceNewlines",
"(",
"string",
",",
"newlineChar",
")",
":",
"if",
"newlineChar",
"in",
"string",
":",
"segments",
"=",
"string",
".",
"split",
"(",
"newlineChar",
")",
"string",
"=",
"\"\"",
"for",
"segment",
"in",
"segments",
":",
"string",
"+=... | There's probably a way to do this with string functions but I was lazy. | [
"There",
"'",
"s",
"probably",
"a",
"way",
"to",
"do",
"this",
"with",
"string",
"functions",
"but",
"I",
"was",
"lazy",
"."
] | [
"\"\"\"There's probably a way to do this with string functions but I was lazy.\n\t\tReplace all instances of \\r or \\n in a string with something else.\"\"\""
] | [
{
"param": "string",
"type": null
},
{
"param": "newlineChar",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "string",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "newlineChar",
"type": null,
"docstring": null,
"docstring_t... |
924be18307bb84332b4ad295aca4c854dfe7719d | TC01/calcpkg | calcrepo/util.py | [
"MIT"
] | Python | removeRootFromName | <not_specific> | def removeRootFromName(string):
"""Helper function to remove /pub, /files from string."""
global garbageRoots
for root in garbageRoots:
if root in string:
string = string[string.find(root) + len(root):]
return string | Helper function to remove /pub, /files from string. | Helper function to remove /pub, /files from string. | [
"Helper",
"function",
"to",
"remove",
"/",
"pub",
"/",
"files",
"from",
"string",
"."
] | def removeRootFromName(string):
global garbageRoots
for root in garbageRoots:
if root in string:
string = string[string.find(root) + len(root):]
return string | [
"def",
"removeRootFromName",
"(",
"string",
")",
":",
"global",
"garbageRoots",
"for",
"root",
"in",
"garbageRoots",
":",
"if",
"root",
"in",
"string",
":",
"string",
"=",
"string",
"[",
"string",
".",
"find",
"(",
"root",
")",
"+",
"len",
"(",
"root",
... | Helper function to remove /pub, /files from string. | [
"Helper",
"function",
"to",
"remove",
"/",
"pub",
"/",
"files",
"from",
"string",
"."
] | [
"\"\"\"Helper function to remove /pub, /files from string.\"\"\""
] | [
{
"param": "string",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "string",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5e081ea5db706706105bf794263180d56975ae1f | TC01/calcpkg | calcrepo/repos/__init__.py | [
"MIT"
] | Python | createRepoObjects | <not_specific> | def createRepoObjects():
"""Imports each 'plugin' in this package and creates a repo file from it"""
repositories = {}
repodir = os.path.join(getScriptLocation())
for importer, name, ispkg in pkgutil.iter_modules([repodir]):
module = importer.find_module(name).load_module(name)
repo_name = module.name
if modu... | Imports each 'plugin' in this package and creates a repo file from it | Imports each 'plugin' in this package and creates a repo file from it | [
"Imports",
"each",
"'",
"plugin",
"'",
"in",
"this",
"package",
"and",
"creates",
"a",
"repo",
"file",
"from",
"it"
] | def createRepoObjects():
repositories = {}
repodir = os.path.join(getScriptLocation())
for importer, name, ispkg in pkgutil.iter_modules([repodir]):
module = importer.find_module(name).load_module(name)
repo_name = module.name
if module.enabled:
repositories[repo_name] = module.getRepository()
return repos... | [
"def",
"createRepoObjects",
"(",
")",
":",
"repositories",
"=",
"{",
"}",
"repodir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"getScriptLocation",
"(",
")",
")",
"for",
"importer",
",",
"name",
",",
"ispkg",
"in",
"pkgutil",
".",
"iter_modules",
"(",
... | Imports each 'plugin' in this package and creates a repo file from it | [
"Imports",
"each",
"'",
"plugin",
"'",
"in",
"this",
"package",
"and",
"creates",
"a",
"repo",
"file",
"from",
"it"
] | [
"\"\"\"Imports each 'plugin' in this package and creates a repo file from it\"\"\""
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
b0d0beb84364b1ac7f80a692a31f7ec5b7b1f293 | TC01/calcpkg | calcrepo/info.py | [
"MIT"
] | Python | printData | null | def printData(self, output = sys.stdout):
"""Output all the file data to be written to any writable output"""
self.printDatum("Name : ", self.fileName, output)
self.printDatum("Author : ", self.author, output)
self.printDatum("Repository : ", self.repository, output)
self.printDatum("Catego... | Output all the file data to be written to any writable output | Output all the file data to be written to any writable output | [
"Output",
"all",
"the",
"file",
"data",
"to",
"be",
"written",
"to",
"any",
"writable",
"output"
] | def printData(self, output = sys.stdout):
self.printDatum("Name : ", self.fileName, output)
self.printDatum("Author : ", self.author, output)
self.printDatum("Repository : ", self.repository, output)
self.printDatum("Category : ", self.category, output)
self.printDatum("Downloads :... | [
"def",
"printData",
"(",
"self",
",",
"output",
"=",
"sys",
".",
"stdout",
")",
":",
"self",
".",
"printDatum",
"(",
"\"Name : \"",
",",
"self",
".",
"fileName",
",",
"output",
")",
"self",
".",
"printDatum",
"(",
"\"Author : \"",
",",
"sel... | Output all the file data to be written to any writable output | [
"Output",
"all",
"the",
"file",
"data",
"to",
"be",
"written",
"to",
"any",
"writable",
"output"
] | [
"\"\"\"Output all the file data to be written to any writable output\"\"\"",
"#\t\tprint(\"\\n\", output)"
] | [
{
"param": "self",
"type": null
},
{
"param": "output",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "output",
"type": null,
"docstring": null,
"docstring_tokens":... |
e6828463bd66b5fda69eef1ac102cf8adaea0792 | TC01/calcpkg | calcrepo/repo.py | [
"MIT"
] | Python | searchIndex | <not_specific> | def searchIndex(self, printData=True):
"""Search the index with all the repo's specified parameters"""
backupValue = copy.deepcopy(self.output.printData)
self.output.printData = printData
self.data = self.index.search(self.searchString, self.category, self.math, self.game, self.searchFiles, self.extension)
se... | Search the index with all the repo's specified parameters | Search the index with all the repo's specified parameters | [
"Search",
"the",
"index",
"with",
"all",
"the",
"repo",
"'",
"s",
"specified",
"parameters"
] | def searchIndex(self, printData=True):
backupValue = copy.deepcopy(self.output.printData)
self.output.printData = printData
self.data = self.index.search(self.searchString, self.category, self.math, self.game, self.searchFiles, self.extension)
self.output.printData = backupValue
return self.data | [
"def",
"searchIndex",
"(",
"self",
",",
"printData",
"=",
"True",
")",
":",
"backupValue",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"output",
".",
"printData",
")",
"self",
".",
"output",
".",
"printData",
"=",
"printData",
"self",
".",
"data",
... | Search the index with all the repo's specified parameters | [
"Search",
"the",
"index",
"with",
"all",
"the",
"repo",
"'",
"s",
"specified",
"parameters"
] | [
"\"\"\"Search the index with all the repo's specified parameters\"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "printData",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "printData",
"type": null,
"docstring": null,
"docstring_token... |
e6828463bd66b5fda69eef1ac102cf8adaea0792 | TC01/calcpkg | calcrepo/repo.py | [
"MIT"
] | Python | downloadFileFromUrl | <not_specific> | def downloadFileFromUrl(self, url):
"""Given a URL, download the specified file"""
fullurl = self.baseUrl + url
try:
urlobj = urllib2.urlopen(fullurl)
contents = urlobj.read()
except urllib2.HTTPError, e:
self.printd("HTTP error:", e.code, url)
return None
except urllib2.URLError, e:
self.print... | Given a URL, download the specified file | Given a URL, download the specified file | [
"Given",
"a",
"URL",
"download",
"the",
"specified",
"file"
] | def downloadFileFromUrl(self, url):
fullurl = self.baseUrl + url
try:
urlobj = urllib2.urlopen(fullurl)
contents = urlobj.read()
except urllib2.HTTPError, e:
self.printd("HTTP error:", e.code, url)
return None
except urllib2.URLError, e:
self.printd("URL error:", e.code, url)
return None
sel... | [
"def",
"downloadFileFromUrl",
"(",
"self",
",",
"url",
")",
":",
"fullurl",
"=",
"self",
".",
"baseUrl",
"+",
"url",
"try",
":",
"urlobj",
"=",
"urllib2",
".",
"urlopen",
"(",
"fullurl",
")",
"contents",
"=",
"urlobj",
".",
"read",
"(",
")",
"except",
... | Given a URL, download the specified file | [
"Given",
"a",
"URL",
"download",
"the",
"specified",
"file"
] | [
"\"\"\"Given a URL, download the specified file\"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "url",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "url",
"type": null,
"docstring": null,
"docstring_tokens": []... |
e6828463bd66b5fda69eef1ac102cf8adaea0792 | TC01/calcpkg | calcrepo/repo.py | [
"MIT"
] | Python | openIndex | <not_specific> | def openIndex(self, filename, description):
"""Attempt to delete and recreate an index, returns open file object or None."""
try:
os.remove(filename)
self.printd(" Deleted old " + description)
except:
self.printd(" No " + description + " found")
# Now, attempt to open a new index
try:
files ... | Attempt to delete and recreate an index, returns open file object or None. | Attempt to delete and recreate an index, returns open file object or None. | [
"Attempt",
"to",
"delete",
"and",
"recreate",
"an",
"index",
"returns",
"open",
"file",
"object",
"or",
"None",
"."
] | def openIndex(self, filename, description):
try:
os.remove(filename)
self.printd(" Deleted old " + description)
except:
self.printd(" No " + description + " found")
try:
files = open(filename, 'wt')
except:
self.printd("Error: Unable to create file " + filename + " in current folder. Quitting."... | [
"def",
"openIndex",
"(",
"self",
",",
"filename",
",",
"description",
")",
":",
"try",
":",
"os",
".",
"remove",
"(",
"filename",
")",
"self",
".",
"printd",
"(",
"\" Deleted old \"",
"+",
"description",
")",
"except",
":",
"self",
".",
"printd",
"(",
... | Attempt to delete and recreate an index, returns open file object or None. | [
"Attempt",
"to",
"delete",
"and",
"recreate",
"an",
"index",
"returns",
"open",
"file",
"object",
"or",
"None",
"."
] | [
"\"\"\"Attempt to delete and recreate an index, returns open file object or None.\"\"\"",
"# Now, attempt to open a new index"
] | [
{
"param": "self",
"type": null
},
{
"param": "filename",
"type": null
},
{
"param": "description",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "filename",
"type": null,
"docstring": null,
"docstring_tokens... |
7c0dea283e63f9389c8c822fd41eeb40aac1b82d | TC01/calcpkg | calcrepo/repos/cemetech.py | [
"MIT"
] | Python | updateFromArchivePage | null | def updateFromArchivePage(self, archiveRoot, names, files, parent = "/", verbose=False):
"""Helper function that works recursively over Cemetech file category/directory pages."""
root = archiveRoot + parent
archive = urllib.urlopen(root)
archiveText = archive.read()
archive.close()
# Recursively call t... | Helper function that works recursively over Cemetech file category/directory pages. | Helper function that works recursively over Cemetech file category/directory pages. | [
"Helper",
"function",
"that",
"works",
"recursively",
"over",
"Cemetech",
"file",
"category",
"/",
"directory",
"pages",
"."
] | def updateFromArchivePage(self, archiveRoot, names, files, parent = "/", verbose=False):
root = archiveRoot + parent
archive = urllib.urlopen(root)
archiveText = archive.read()
archive.close()
working = archiveText
folderString = 'solid #aaa;"><a href="index.php?mode=folder&path='
while folderString in wo... | [
"def",
"updateFromArchivePage",
"(",
"self",
",",
"archiveRoot",
",",
"names",
",",
"files",
",",
"parent",
"=",
"\"/\"",
",",
"verbose",
"=",
"False",
")",
":",
"root",
"=",
"archiveRoot",
"+",
"parent",
"archive",
"=",
"urllib",
".",
"urlopen",
"(",
"r... | Helper function that works recursively over Cemetech file category/directory pages. | [
"Helper",
"function",
"that",
"works",
"recursively",
"over",
"Cemetech",
"file",
"category",
"/",
"directory",
"pages",
"."
] | [
"\"\"\"Helper function that works recursively over Cemetech file category/directory pages.\"\"\"",
"# Recursively call this function on all subdirectories",
"# Now, step through all files and write them to the names and files objects",
"#/73/basic/games/aod73.zip&path=archives\"",
"# Get the filename and pa... | [
{
"param": "self",
"type": null
},
{
"param": "archiveRoot",
"type": null
},
{
"param": "names",
"type": null
},
{
"param": "files",
"type": null
},
{
"param": "parent",
"type": null
},
{
"param": "verbose",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "archiveRoot",
"type": null,
"docstring": null,
"docstring_tok... |
9bd262c1da36d391adf8e75b4474fbc153458a4a | douglasgusson/json-to-typescript-interfaces | json_to_ts/main.py | [
"MIT"
] | Python | python_type_to_typescript_type | str | def python_type_to_typescript_type(py_type: str) -> str:
"""
Converts Python type to TypeScript type.
"""
if py_type in ["int", "float"]:
return "number"
elif py_type == "bool":
return "boolean"
elif py_type == "str":
return "string"
elif py_type == "list":
re... |
Converts Python type to TypeScript type.
| Converts Python type to TypeScript type. | [
"Converts",
"Python",
"type",
"to",
"TypeScript",
"type",
"."
] | def python_type_to_typescript_type(py_type: str) -> str:
if py_type in ["int", "float"]:
return "number"
elif py_type == "bool":
return "boolean"
elif py_type == "str":
return "string"
elif py_type == "list":
return "Array<any>"
elif py_type == "dict":
return ... | [
"def",
"python_type_to_typescript_type",
"(",
"py_type",
":",
"str",
")",
"->",
"str",
":",
"if",
"py_type",
"in",
"[",
"\"int\"",
",",
"\"float\"",
"]",
":",
"return",
"\"number\"",
"elif",
"py_type",
"==",
"\"bool\"",
":",
"return",
"\"boolean\"",
"elif",
... | Converts Python type to TypeScript type. | [
"Converts",
"Python",
"type",
"to",
"TypeScript",
"type",
"."
] | [
"\"\"\"\n Converts Python type to TypeScript type.\n \"\"\""
] | [
{
"param": "py_type",
"type": "str"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "py_type",
"type": "str",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
9bd262c1da36d391adf8e75b4474fbc153458a4a | douglasgusson/json-to-typescript-interfaces | json_to_ts/main.py | [
"MIT"
] | Python | kebab_to_camel | str | def kebab_to_camel(kebab_str: str, first_caps: bool = False) -> str:
"""
Convert kebab-case to camelCase
"""
first, *others = kebab_str.split("-")
first = first_caps and first.capitalize() or first.lower()
return "".join([first, *map(str.title, others)]) |
Convert kebab-case to camelCase
| Convert kebab-case to camelCase | [
"Convert",
"kebab",
"-",
"case",
"to",
"camelCase"
] | def kebab_to_camel(kebab_str: str, first_caps: bool = False) -> str:
first, *others = kebab_str.split("-")
first = first_caps and first.capitalize() or first.lower()
return "".join([first, *map(str.title, others)]) | [
"def",
"kebab_to_camel",
"(",
"kebab_str",
":",
"str",
",",
"first_caps",
":",
"bool",
"=",
"False",
")",
"->",
"str",
":",
"first",
",",
"*",
"others",
"=",
"kebab_str",
".",
"split",
"(",
"\"-\"",
")",
"first",
"=",
"first_caps",
"and",
"first",
".",... | Convert kebab-case to camelCase | [
"Convert",
"kebab",
"-",
"case",
"to",
"camelCase"
] | [
"\"\"\"\n Convert kebab-case to camelCase\n \"\"\""
] | [
{
"param": "kebab_str",
"type": "str"
},
{
"param": "first_caps",
"type": "bool"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "kebab_str",
"type": "str",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "first_caps",
"type": "bool",
"docstring": null,
"docstr... |
a8716f160722af39a040602a819ae7762405c543 | williamjamir/demo_qt_inspector | demo-qt-inspector/application.py | [
"MIT"
] | Python | file_menu | null | def file_menu(self):
"""Create a file submenu with an Open File item that opens a file dialog."""
self.file_sub_menu = self.menu_bar.addMenu('File')
self.open_action = QAction('Open File', self)
self.open_action.setStatusTip('Open a file into Template.')
self.open_action.setShor... | Create a file submenu with an Open File item that opens a file dialog. | Create a file submenu with an Open File item that opens a file dialog. | [
"Create",
"a",
"file",
"submenu",
"with",
"an",
"Open",
"File",
"item",
"that",
"opens",
"a",
"file",
"dialog",
"."
] | def file_menu(self):
self.file_sub_menu = self.menu_bar.addMenu('File')
self.open_action = QAction('Open File', self)
self.open_action.setStatusTip('Open a file into Template.')
self.open_action.setShortcut('CTRL+O')
self.exit_action = QAction('Exit Application', self)
se... | [
"def",
"file_menu",
"(",
"self",
")",
":",
"self",
".",
"file_sub_menu",
"=",
"self",
".",
"menu_bar",
".",
"addMenu",
"(",
"'File'",
")",
"self",
".",
"open_action",
"=",
"QAction",
"(",
"'Open File'",
",",
"self",
")",
"self",
".",
"open_action",
".",
... | Create a file submenu with an Open File item that opens a file dialog. | [
"Create",
"a",
"file",
"submenu",
"with",
"an",
"Open",
"File",
"item",
"that",
"opens",
"a",
"file",
"dialog",
"."
] | [
"\"\"\"Create a file submenu with an Open File item that opens a file dialog.\"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a993254f100b103a5decf19a7e29776e036a07f4 | rohts-patil/VQA-Med-2019 | app.py | [
"MIT"
] | Python | load_properties | <not_specific> | def load_properties(filepath, sep="=", comment_char="#"):
"""
Read the file passed as parameter as a properties file.
"""
logging.info("Started loading config.properties.")
props = {}
with open(filepath, "rt") as f:
for line in f:
l = line.strip()
if l and not l.s... |
Read the file passed as parameter as a properties file.
| Read the file passed as parameter as a properties file. | [
"Read",
"the",
"file",
"passed",
"as",
"parameter",
"as",
"a",
"properties",
"file",
"."
] | def load_properties(filepath, sep="=", comment_char="#"):
logging.info("Started loading config.properties.")
props = {}
with open(filepath, "rt") as f:
for line in f:
l = line.strip()
if l and not l.startswith(comment_char):
key_value = l.split(sep)
... | [
"def",
"load_properties",
"(",
"filepath",
",",
"sep",
"=",
"\"=\"",
",",
"comment_char",
"=",
"\"#\"",
")",
":",
"logging",
".",
"info",
"(",
"\"Started loading config.properties.\"",
")",
"props",
"=",
"{",
"}",
"with",
"open",
"(",
"filepath",
",",
"\"rt\... | Read the file passed as parameter as a properties file. | [
"Read",
"the",
"file",
"passed",
"as",
"parameter",
"as",
"a",
"properties",
"file",
"."
] | [
"\"\"\"\n Read the file passed as parameter as a properties file.\n \"\"\""
] | [
{
"param": "filepath",
"type": null
},
{
"param": "sep",
"type": null
},
{
"param": "comment_char",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "filepath",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sep",
"type": null,
"docstring": null,
"docstring_tokens"... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.