Added linear regression model for power.

This commit is contained in:
Hunter Nichols 2020-12-09 15:31:43 -08:00
parent b1a7e0e55b
commit 0adcf8935f
2 changed files with 24 additions and 18 deletions

View File

@ -600,7 +600,7 @@ class lib:
OPTS.word_size, OPTS.word_size,
OPTS.words_per_row, OPTS.words_per_row,
self.sram.width * self.sram.height] self.sram.width * self.sram.height]
char_results = m.get_prediction(model_inputs) char_results = m.get_predictions(model_inputs)
#self.d = elmore(self.sram, self.sp_file, self.corner) #self.d = elmore(self.sram, self.sp_file, self.corner)
# char_results = self.d.analytical_delay(self.slews,self.loads) # char_results = self.d.analytical_delay(self.slews,self.loads)

View File

@ -13,42 +13,48 @@ from globals import OPTS
import debug import debug
relative_data_path = "/sim_data" relative_data_path = "/sim_data"
data_filename = "data.csv" delay_data_filename = "data.csv"
power_data_filename = "power_data.csv"
tech_path = os.environ.get('OPENRAM_TECH') tech_path = os.environ.get('OPENRAM_TECH')
data_dir = tech_path+'/'+OPTS.tech_name+relative_data_path data_dir = tech_path+'/'+OPTS.tech_name+relative_data_path
class linear_regression(): class linear_regression():
def __init__(self): def __init__(self):
self.model = None self.delay_model = None
self.power_model = None
def get_prediction(self, model_inputs): def get_predictions(self, model_inputs):
file_path = data_dir +'/'+data_filename delay_file_path = data_dir +'/'+delay_data_filename
scaled_inputs = np.asarray([scale_input_datapoint(model_inputs, file_path)]) power_file_path = data_dir +'/'+power_data_filename
scaled_inputs = np.asarray([scale_input_datapoint(model_inputs, delay_file_path)])
features, labels = get_scaled_data(file_path) predictions = []
self.train_model(features, labels) for path, model in zip([delay_file_path, power_file_path], [self.delay_model, self.power_model]):
scaled_pred = self.model_prediction(scaled_inputs) features, labels = get_scaled_data(path)
pred = unscale_data(scaled_pred.tolist(), file_path) model = self.generate_model(features, labels)
debug.info(1,"Unscaled Prediction = {}".format(pred)) scaled_pred = self.model_prediction(model, scaled_inputs)
return pred pred = unscale_data(scaled_pred.tolist(), path)
debug.info(1,"Unscaled Prediction = {}".format(pred))
predictions.append(pred)
return predictions
def train_model(self, features, labels): def generate_model(self, features, labels):
""" """
Supervised training of model. Supervised training of model.
""" """
self.model = LinearRegression() model = LinearRegression()
self.model.fit(features, labels) model.fit(features, labels)
return model
def model_prediction(self, features): def model_prediction(self, model, features):
""" """
Have the model perform a prediction and unscale the prediction Have the model perform a prediction and unscale the prediction
as the model is trained with scaled values. as the model is trained with scaled values.
""" """
pred = self.model.predict(features) pred = model.predict(features)
debug.info(1, "pred={}".format(pred))
return pred return pred