2021-01-13 23:07:52 +01:00
|
|
|
# See LICENSE for licensing information.
|
|
|
|
|
#
|
2023-01-29 07:56:27 +01:00
|
|
|
# Copyright (c) 2016-2023 Regents of the University of California and The Board
|
2021-01-13 23:07:52 +01:00
|
|
|
# of Regents for the Oklahoma Agricultural and Mechanical College
|
|
|
|
|
# (acting for and on behalf of Oklahoma State University)
|
|
|
|
|
# All rights reserved.
|
|
|
|
|
#
|
2021-06-07 21:26:45 +02:00
|
|
|
from sklearn.neural_network import MLPRegressor
|
2022-11-27 22:01:20 +01:00
|
|
|
from openram import debug
|
|
|
|
|
from openram import OPTS
|
|
|
|
|
from .regression_model import regression_model
|
2021-01-13 23:07:52 +01:00
|
|
|
|
|
|
|
|
|
2021-01-19 23:19:50 +01:00
|
|
|
class neural_network(regression_model):
|
2021-01-13 23:07:52 +01:00
|
|
|
|
|
|
|
|
def __init__(self, sram, spfile, corner):
|
|
|
|
|
super().__init__(sram, spfile, corner)
|
|
|
|
|
|
2021-06-07 21:26:45 +02:00
|
|
|
def get_model(self):
|
|
|
|
|
return MLPRegressor(solver='lbfgs', alpha=1e-5,
|
|
|
|
|
hidden_layer_sizes=(40, 40, 40, 40), random_state=1)
|
|
|
|
|
|
2021-01-13 23:07:52 +01:00
|
|
|
def generate_model(self, features, labels):
|
|
|
|
|
"""
|
2021-06-07 21:26:45 +02:00
|
|
|
Training multilayer model
|
2021-01-13 23:07:52 +01:00
|
|
|
"""
|
2022-07-22 18:52:38 +02:00
|
|
|
|
2021-06-07 21:26:45 +02:00
|
|
|
flat_labels = np.ravel(labels)
|
|
|
|
|
model = self.get_model()
|
|
|
|
|
model.fit(features, flat_labels)
|
2022-07-22 18:52:38 +02:00
|
|
|
|
2021-01-13 23:07:52 +01:00
|
|
|
return model
|
2022-07-22 18:52:38 +02:00
|
|
|
|
|
|
|
|
def model_prediction(self, model, features):
|
2021-01-13 23:07:52 +01:00
|
|
|
"""
|
|
|
|
|
Have the model perform a prediction and unscale the prediction
|
|
|
|
|
as the model is trained with scaled values.
|
|
|
|
|
"""
|
2022-07-22 18:52:38 +02:00
|
|
|
|
2021-01-13 23:07:52 +01:00
|
|
|
pred = model.predict(features)
|
2021-06-07 21:26:45 +02:00
|
|
|
reshape_pred = np.reshape(pred, (len(pred),1))
|
|
|
|
|
return reshape_pred
|