EME 210
Data Analytics for Energy Systems

Common Transfer Functions

PrintPrint

Read It: Common Transfer Functions

Enter image and alt text here. No sizes!
ADD IMAGE: L27:Slide 8
Enter image credit here

[00:35:50.39] So here are some common transfer functions. And here I'm restricting myself to the popular ones that can be coded in the machine learning tools that I'll introduce you to in the Python coding here. So, we've got relu-- relative likelihood-- a sigmoid, hypergeometric tangent function, elu, selu, all these different things here.  

[00:36:17.60] So what are these? So here I define them mathematically. But perhaps a more convenient way to see how they behave is what these functions look like when you plot them over x's. So, this is obviously our x-axis on the horizontal. And so relu, if your x is negative-- so if the total sum of all the weights times all the x's turns out to be negative, then you go to 0.  

[00:36:50.86] If it's positive, and it just returns whatever that sum of all the weights times all the x's is. A pretty simple function-- turns out that this works really well. So, this is widely used-- a very popular transfer function to use.  

[00:37:08.59] Then we've got a sigmoid function. Looks like this s 10h-- kind of similar shape, more steep. These are also-- I should say, these also work well, but they tend to take longer to calculate because of the more complex math in here.  

[00:37:31.82] So you have to take the exponent of the x's and add 1 to it and do 1 divided by that. And this has even more exponents in it. And those kind of tend to just take a little more computational time.  

[00:37:41.60] But you might think, when you do this once, it's a difference of a fraction of a second. But when you multiply that over maybe hundreds of nodes and maybe thousands of iterations, then it starts becoming inconvenient in terms of how much time it takes. So this may be widely used just because it's so simple.  

[00:38:10.59] This elu function-- so this is also fairly popular. It does have this exponent in here, and so it does take longer to take than relu. But it tends to-- it will sometimes perform better than relu. What I mean by that is it may reduce the number of overall epochs you need, the number of iterations you need.  

[00:38:35.86] It may get you a model that fits well sooner than relu. And so even though each step takes longer to calculate, if you can do it in fewer steps, overall, you're saving some time. And then this selu, this tends to only work well when you have something called dense layers.  

[00:38:56.22] What I mean by dense layers is this, where each hidden layer has a bunch of nodes, and they're all connected to each other. Each one is connected to all the others. This is dense layering.  

[00:39:18.51] So anyway, so these are some common and popular transfer functions that you can kind of play around with in the code and see what works better for your given data set. And these are the functions, so to back up a bit, that we can sub in for f here, that are wrapping around the sum of weights times x's.  


Try It: OPTION 1 GOOGLE COLAB

  1. Click the Google Colab file used in the video here.
  2. Go to the Colab file and click "File" then "Save a copy in Drive", this will create a new Colab file that you can edit in your own Google Drive account.
  3. Once you have it saved in your Drive, try to implement the following code to import a file of your choice by mounting your Google Drive:

Note: You must be logged into your PSU Google Workspace in order to access the file.

from google.colab import drive

drive.mount('/content/drive')

import pandas as pd

df = pd.read_csv('yourfilename.csv')

df # print the dataframe

Once you have implemented this code on your own, come back to this page to test your knowledge.


OPTION 2 : DATACAMP

 Try It: OPTION 2 DataCamp - Apply Your Coding Skills

Dictionaries are a quick way to create a variable from scratch. However, their functionality is limited, so we will often want to convert those dictionaries into DataFrames. Try to code this conversion in the cell below. Hint: Make sure to import the Pandas library.

# This will get executed each time the exercise gets initialized. # Create a Simple Dictionary mydict = {'Name':['Amy', 'Bob', 'Clair', 'Daisy'], 'Birthday':['9/3/1991', '4/21/1988', '4/21/1990', '11/11/1989'], 'Age':[31, 34, 32, 33]} # convert the dictionary to a DataFrame # print the values in the 'Birthday' column # Create a Simple Dictionary mydict = {'Name':['Amy', 'Bob', 'Clair', 'Daisy'], 'Birthday':['9/3/1991', '4/21/1988', '4/21/1990', '11/11/1989'], 'Age':[31, 34, 32, 33]} # convert the dictionary to a DataFrame import pandas as pd mydataframe = pd.DataFrame(mydict) # print the values in the 'Birthday' column mydataframe['Birthday']


Assess It: Check Your Knowledge

Knowledge Check (replace question)