<s> import numpy as np <EOL> import copy <EOL> all = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def construct_preprocessor ( trainingset , list_of_processors ) : <EOL> combined_processor = lambda x : x <EOL> for processor in list_of_processors : <EOL> combined_processor = processor ( combined_processor ( trainingset ) ) <EOL> return combined_processor <EOL> def standarize ( trainingset ) : <EOL> """<STR_LIT>""" <EOL> def encoder ( dataset ) : <EOL> manipulated_dataset = copy . deepcopy ( dataset ) <EOL> for instance in manipulated_dataset : <EOL> instance . features = ( instance . features - means ) / stds <EOL> return manipulated_dataset <EOL> training_data = np . array ( [ instance . features for instance in trainingset ] ) <EOL> means = training_data . mean ( axis = <NUM_LIT:0> ) <EOL> stds = training_data . std ( axis = <NUM_LIT:0> ) <EOL> return encoder <EOL> def replace_nan ( trainingset , replace_with = None ) : <EOL> """<STR_LIT>""" <EOL> training_data = np . array ( [ instance . features for instance in trainingset ] ) . astype ( np . float64 ) <EOL> def encoder ( dataset ) : <EOL> manipulated_dataset = copy . deepcopy ( dataset ) <EOL> for instance in manipulated_dataset : <EOL> instance . features = instance . features . astype ( np . float64 ) <EOL> if np . sum ( np . isnan ( instance . features ) ) : <EOL> if replace_with == None : <EOL> instance . features [ np . isnan ( instance . features ) ] = means [ np . isnan ( instance . features ) ] <EOL> else : <EOL> instance . features [ np . isnan ( instance . features ) ] = replace_with <EOL> return manipulated_dataset <EOL> if replace_with == None : <EOL> means = np . mean ( np . nan_to_num ( training_data ) , axis = <NUM_LIT:0> ) <EOL> return encoder <EOL> def whiten ( trainingset , epsilon = <NUM_LIT> ) : <EOL> training_data = np . array ( [ instance . features for instance in trainingset ] ) <EOL> def encoder ( dataset ) : <EOL> manipulated_dataset = copy . deepcopy ( dataset ) <EOL> for instance in manipulated_dataset : <EOL> instance . features = np . dot ( instance . features , W ) <EOL> return manipulated_dataset <EOL> covariance = np . dot ( training_data . T , training_data ) <EOL> d , V = np . linalg . eig ( covariance ) <EOL> D = np . diag ( <NUM_LIT:1.> / np . sqrt ( d + epsilon ) ) <EOL> W = np . dot ( np . dot ( V , D ) , V . T ) <EOL> return encoder </s>
