-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add synthetic test data integration test utils, and use them for loss value decrease tests. #2789
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Utilities for producing synthetic test data that is convergence-friendly.""" | ||
|
||
from collections import namedtuple | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from sklearn.model_selection import train_test_split | ||
|
||
RANDOM_SEED = 42 | ||
NUMBER_OBSERVATIONS = 200 | ||
|
||
GeneratedData = namedtuple("GeneratedData", "train_df validation_df test_df") | ||
|
||
|
||
def get_feature_configs(): | ||
input_features = [ | ||
{"name": "x", "type": "number"}, | ||
] | ||
output_features = [ | ||
{ | ||
"name": "y", | ||
"type": "number", | ||
"loss": {"type": "mean_squared_error"}, | ||
"decoder": { | ||
"num_fc_layers": 2, | ||
"fc_output_size": 64, | ||
}, | ||
} | ||
] | ||
|
||
return input_features, output_features | ||
|
||
|
||
def get_generated_data(): | ||
# function generates simple training data that guarantee convergence | ||
# within 30 epochs for suitable config | ||
|
||
# generate data | ||
np.random.seed(RANDOM_SEED) | ||
x = np.array(range(NUMBER_OBSERVATIONS)).reshape(-1, 1) | ||
y = 2 * x + 1 + np.random.normal(size=x.shape[0]).reshape(-1, 1) | ||
raw_df = pd.DataFrame(np.concatenate((x, y), axis=1), columns=["x", "y"]) | ||
|
||
# create training data | ||
train, valid_test = train_test_split(raw_df, train_size=0.7) | ||
|
||
# create validation and test data | ||
validation, test = train_test_split(valid_test, train_size=0.5) | ||
|
||
return GeneratedData(train, validation, test) | ||
|
||
|
||
def get_generated_data_for_optimizer(): | ||
# function generates simple training data that guarantee convergence | ||
# within 30 epochs for suitable config | ||
|
||
# generate data | ||
np.random.seed(RANDOM_SEED) | ||
x = np.array(range(NUMBER_OBSERVATIONS)).reshape(-1, 1) | ||
y = 2 * x + 1 + np.random.normal(size=x.shape[0]).reshape(-1, 1) | ||
raw_df = pd.DataFrame(np.concatenate((x, y), axis=1), columns=["x", "y"]) | ||
raw_df["x"] = (raw_df["x"] - raw_df["x"].min()) / (raw_df["x"].max() - raw_df["x"].min()) | ||
raw_df["y"] = (raw_df["y"] - raw_df["y"].min()) / (raw_df["y"].max() - raw_df["y"].min()) | ||
|
||
# create training data | ||
train, valid_test = train_test_split(raw_df, train_size=0.7) | ||
|
||
# create validation and test data | ||
validation, test = train_test_split(valid_test, train_size=0.5) | ||
|
||
return GeneratedData(train, validation, test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this into
integration_tests/utils.py?
. Alternatively, we can rename this toutil_synthetic_test_data.py
. I'm personally in favor of the formerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a self-encapsulated set of library functions, I'd actually prefer to keep it in a separate file, also since
integration_tests/utils.py
is already quite large.