-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add session context to logs and fix the failing tests in CircleCI
- Loading branch information
Showing
10 changed files
with
47 additions
and
35 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
__author__ = 'Abdulrahman Semrie<[email protected]>' | ||
|
||
from models.objmodel import EnsembleModel | ||
import os | ||
from crossval.moses_runner import MosesRunner | ||
from sklearn.model_selection import StratifiedShuffleSplit | ||
import pandas as pd | ||
import random | ||
import logging | ||
from crossval.model_evaluator import ModelEvaluator | ||
import math | ||
from utils.feature_count import combo_parser, ComboTreeTransform | ||
from scipy import stats | ||
import tempfile | ||
|
||
import pandas as pd | ||
from scipy import stats | ||
from sklearn.model_selection import StratifiedShuffleSplit | ||
|
||
from crossval.model_evaluator import ModelEvaluator | ||
from crossval.moses_runner import MosesRunner | ||
from models.objmodel import EnsembleModel | ||
from utils.feature_count import combo_parser, ComboTreeTransform | ||
from config import get_logger | ||
|
||
class CrossValidation: | ||
""" | ||
|
@@ -30,7 +30,7 @@ def __init__(self, session, db, filter_type, value, cwd): | |
self.db = db | ||
self.filter = filter_type | ||
self.filter_value = value | ||
self.logger = logging.getLogger("mozi_snet") | ||
self.logger = get_logger(session.mnemonic) | ||
self.fold_files = [] | ||
self._set_dir() | ||
|
||
|
@@ -67,7 +67,7 @@ def run_folds(self): | |
|
||
fold_fname = f"fold_{i}.csv" | ||
self.fold_files.append(fold_fname) | ||
self.logger.info(f"Got {len(fold_models)} for fold_{i}") | ||
self.logger.info(f"Got {len(fold_models)} models for fold_{i}") | ||
# CrossValidation.merge_fold_files(fold_fname, files) | ||
self.logger.info("Evaluating fold: %d" % i) | ||
scored_models = self.score_fold(fold_models, train_file, test_file) | ||
|
@@ -111,7 +111,7 @@ def run_seeds(self, seeds, i, file): | |
output_file = tempfile.NamedTemporaryFile(mode="w+") | ||
moses_options = " ".join([self.session.moses_options, "--random-seed " + str(seed)]) | ||
|
||
moses_runner = MosesRunner(file, output_file.name, moses_options) | ||
moses_runner = MosesRunner(file, output_file.name, moses_options, self.session.mnemonic) | ||
returncode, stdout, stderr = moses_runner.run_moses() | ||
|
||
if returncode != 0: | ||
|
@@ -142,7 +142,7 @@ def score_fold(self, models, train_file, test_file): | |
:param test_file: The file containing the test set | ||
:return: | ||
""" | ||
model_evaluator = ModelEvaluator(self.session.target_feature) | ||
model_evaluator = ModelEvaluator(self.session.target_feature, self.session.mnemonic) | ||
|
||
test_matrix = model_evaluator.run_eval(models, test_file) | ||
train_matrix = model_evaluator.run_eval(models, train_file) | ||
|
@@ -196,7 +196,7 @@ def majority_vote(self): | |
their individual scores and the combined score | ||
""" | ||
data = {"model": [], "recall": [], "precision": [], "accuracy": [], "f1_score": [], "p_value": []} | ||
model_eval = ModelEvaluator(self.session.target_feature) | ||
model_eval = ModelEvaluator(self.session.target_feature, self.session.id) | ||
filtered_models = [] | ||
for _, v in self.result_models.items(): | ||
res = self.filter.cut_off(v, self.filter_value) | ||
|
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 |
---|---|---|
@@ -1,19 +1,18 @@ | ||
__author__ = 'Abdulrahman Semrie<[email protected]>' | ||
|
||
from models.objmodel import MosesModel | ||
import subprocess | ||
import logging | ||
import re | ||
import tempfile | ||
import fileinput | ||
import subprocess | ||
from config import get_logger | ||
from models.objmodel import MosesModel | ||
|
||
|
||
class MosesRunner: | ||
""" | ||
A class that handles running of the MOSES binary program | ||
""" | ||
|
||
def __init__(self, input_file, output_file, moses_opts): | ||
def __init__(self, input_file, output_file, moses_opts, session_id): | ||
""" | ||
:param input_file: The input file to run MOSES on | ||
:param output_file: The file to write MOSES program outputs to | ||
|
@@ -24,7 +23,7 @@ def __init__(self, input_file, output_file, moses_opts): | |
self.moses_options = moses_opts | ||
if not "W1" in moses_opts: moses_opts += ' -W1' | ||
self.output_regex = re.compile(r"(-?\d+) (.+) \[(.+)\]") | ||
self.logger = logging.getLogger("mozi_snet") | ||
self.logger = get_logger(session_id) | ||
|
||
def run_moses(self): | ||
""" | ||
|
@@ -65,5 +64,4 @@ def format_combo(self, combo_file): | |
complexity = match.group(3).split(",")[2].split("=")[1] | ||
models.append(MosesModel(model, complexity)) | ||
|
||
self.logger.info(f"Num of combo models {len(models)}") | ||
return models |
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
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
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