The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Mar 29th, 2024, 6:08am
Pages: 1
Send Topic Print
Machine-Learning-based-Behavioral Modelling (Read 407 times)
rhanna
New Member
*
Offline



Posts: 4

Machine-Learning-based-Behavioral Modelling
Apr 19th, 2021, 6:30am
 
Hello,

I need your help in debugging/tips to debug a Verilog-A module that I created based on the training of a Recurrent Neural Network (RNN).

The model is supposed to solve the non-linear differential system of equations coming from the RNN representation.

I will summarize everything in steps so that it will be easier to discuss it afterward.

1. I created a testbench for a chain of inverters and got the data (Vin,Iout) in .csv format after interpolation to a timestep=1e-9 s.

Attached testbench: https://drive.google.com/file/d/1n5uyi9_nTurEUgIai_yb0RWwVqGcYBIx/view?usp=shari...
and sample of Iout: https://drive.google.com/file/d/1APHkSRnFl5gxAFEDcvrW81Ygpvv7yMO5/view?usp=shari...
and training_data.csv: https://drive.google.com/file/d/1iKuxfxAz4b-mrt8UOs0gPqNqQfSwCnre/view?usp=shari...

2.Train/test datasets are pre-processed (scaled/normalized/standardized ...) to fit the RNN model used.
After tuning model parameters, it’s tested against unseen stimuli.

Attached learning curves: https://drive.google.com/file/d/1iF3D_tp4-F8p6B3sVirlBFtKVEoFMdUk/view?usp=shari...
RNN prediction: https://drive.google.com/file/d/1ufzQZsS19DvamE_oCMx9N6YZoM43tYTD/view?usp=shari...
and parameters matrices: https://drive.google.com/file/d/1eXxqaCrzyDqMTLY8N0_7Mp8-7QM1GkNP/view?usp=shari...

3. The parameter arrays are flattened to be used as 1-D vectors in the Verilog-A module (since multi-D is not allowed in Verilog-A)

Below, you will find a listing of my code which is basically using Spectre to solve the continuous non-linear system of equations of the RNN model.

[code]////////////////////////////////////////////////////////////////////////////////
////////////////////////////////
///7_inv_verilogA_module
////////////////////////////

`include "constants.vams"
`include "disciplines.vams"

module test_inverter2 ( Iout, Vin );

//port declaration
input Vin;
output Iout;
electrical Vin, Iout;

//hidden nodes declaration, 2-layer RNN: 1st layer has 3 neurons and 2nd layer has 5 neurons, the temporary nodes used to assign voltage derivatives into it (since it’s not allowed to use ddt() inside a function like tanh())  
parameter integer n1=3;              //n1= hidden layer1 size
parameter integer n2=5;              //n2= hidden layer2 size
electrical [0:n1-1] x1_node;         //hidden nodes
electrical [0:n2-1] x2_node;
electrical [0:n1-1] d1;                    //temporary nodes
electrical [0:n2-1] d2;                    //temporary nodes
electrical c;                                       //temporary node

//parameters declaration
parameter real h=1e-9;                                               //RNN fixed time step (the one I used for interpolation in the beginning)
parameter real alpha=0.1;                                         //a parameter used to control simulation time
parameter real Iout_max=1e-3*1.9939;                //from SPICE simulation: to transform normalized values to real (mA) values
parameter real Iout_min=1e-3*-2.6195;                 //from SPICE simulation

parameter real w_Vin [0:n1-1]='{0.10170481,  1.1620824 ,  1.7734492};                 //input-to-hidden_layer1 weights
parameter real w_rec1 [0:8]= '{0.10170481, -0.40005976,  0.14853652, 1.1620824 , -0.06963143,  0.05867661, 1.7734492 ,  0.31620947,  0.5098805};                            //hidden_layer1 weights
parameter real b_rec1 [0:n1-1]='{-0.50272906, -0.05936602, -0.46315792};                //hidden_layer1 bias

parameter real w_rec1_rec2 [0:14]='{-0.67627287, -0.04143657, -1.079608, 0.87122226,  1.3332181 ,  0.8582899, 2.5318332 ,  1.631965  ,  4.0227246, -0.09900661,  0.00793644,  0.06182678, -0.3101116 ,  0.8634078 , -0.19305223};      //hidden_layer1-to-hidden_layer2 weights
parameter real w_rec2 [0:24]= '{1.1629704 , -0.97594476,  0.78621966,  0.11768469,  0.6982709, -0.55858546, -0.84081393, -0.18030712, -0.6326557 , -0.09535989, 0.74122816,  0.4803622 ,  1.3021479 , -0.5180566 ,  0.01114371, 0.11297118,  0.00577774,  0.18186042,  1.215576  , -0.34975305, 0.79326946, -0.22687317, -0.12298498,  0.72878057, -0.54428524};     //hidden_layer2 weights
parameter real b_rec2 [0:n2-1]='{-1.2327499 ,  0.24767102,  0.01692279, -0.07469982, -0.39443454};                    //hidden_layer2 bias
parameter real w_Iout [0:n2-1]='{0.0646118 ,  0.08837312, -0.3694181 ,  0.6734518 , -0.80057806};                     //hidden_layer2-to-output weights
parameter real b_Iout=0.12989566;                       //output bias

genvar  i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13;                        //loop iterators
real mul_Vin_w_Vin, mul_c_w_Vin, y, Iout_norm;                            //products of matrices multiplication (for example: mul_Vin_w_Vin : is input voltage * input-to-hidden_layer1 weights)
real mul_x1_node_w_rec1 [0:n1-1];
real mul_x2_node_w_rec2 [0:n2-1];
real mul_x1_node_w_rec1_w_rec2 [0:n2-1];

//the analog process
              analog begin

                             $strobe("****************************new time step ******************************");
                             //$debug("****************************new iteration******************************");
                                           
                             //1. intialize local variables
                             mul_Vin_w_Vin= 0;
                             mul_c_w_Vin= 0;
                             y=0;
                             Iout_norm=0;

       
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.