OpenRAM/compiler/characterizer/neural_network.py

43 lines
1.3 KiB
Python
Raw Normal View History

2021-01-13 23:07:52 +01:00
# See LICENSE for licensing information.
#
2024-01-03 23:32:44 +01:00
# Copyright (c) 2016-2024 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.
#
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
class neural_network(regression_model):
2021-01-13 23:07:52 +01:00
def __init__(self, sram, spfile, corner):
super().__init__(sram, spfile, corner)
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):
"""
Training multilayer model
2021-01-13 23:07:52 +01:00
"""
2022-07-22 18:52:38 +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)
reshape_pred = np.reshape(pred, (len(pred),1))
return reshape_pred