Swapnil Saurav

Restricted Boltzmann Machine and Its Application

A restricted Boltzmann machine (RBM) is a generative stochastic artificial neural network that can learn a probability distribution over its set of inputs. Restricted Boltzmann machines can also be used in deep learning networks. In particular, deep belief networks can be formed by “stacking” RBMs and optionally fine-tuning the resulting deep network with gradient descent and backpropagation. This deep learning algorithm became very popular after the Netflix Competition where RBM was used as a collaborative filtering technique to predict user ratings for movies and beat most of its competition. It is useful for regression, classification, dimensionality reduction, feature learning, topic modelling and collaborative filtering.

Restricted Boltzmann Machines are stochastic two layered neural networks which belong to a category of energy based models that can detect inherent patterns automatically in the data by reconstructing input. They have two layers visible and hidden. Visible layer has input nodes (nodes which receive input data) and the hidden layer is formed by nodes which extract feature information from the data and the output at the hidden layer is a weighted sum of input layers. They don’t have any output nodes and they don’t have typical binary output through which patterns are learnt. The learning process happens without that capability which makes them different. We only take care of input nodes and don’t worry about hidden nodes. Once the input is provided, RBM’s automatically capture all the patterns, parameters and correlation among the data.

What is Boltzman Machine?

Let’s first undertand what’s Boltzman Machine. Boltzmann Machine was first invented in 1985 by Geoffrey Hinton, a professor at the University of Toronto. He is a leading figure in the deep learning community and is referred to by some as the “Godfather of Deep Learning”.

Boltzman Machine
  • Boltzmann Machine is a generative unsupervised model, which involves learning a probability distribution from an original dataset and using it to make inferences about never before seen data.
  • Boltzmann Machine has an input layer (also referred to as the visible layer) and one or several hidden layers (also referred to as the hidden layer).
  • Boltzmann Machine uses neural networks with neurons that are connected not only to other neurons in other layers but also to neurons within the same layer.
  • Everything is connected to everything. Connections are bidirectional, visible neurons connected to each other and hidden neurons also connected to each other
  • Boltzmann Machine doesn’t expect input data, it generates data. Neurons generate information regardless they are hidden or visible.
  • For Boltzmann Machine all neurons are the same, it doesn’t discriminate between hidden and visible neurons. For Boltzmann Machine whole things are system and its generating state of the system.

In Boltzmann Machine, we use our training data and feed into the Boltzmann Machine as input to help the system adjust its weights. It resembles our system not any such system in the world. It learns from the input, what are the possible connections between all these parameters, how do they influence each other and therefore it becomes a machine that represents our system. Boltzmann Machine consists of a neural network with an input layer and one or several hidden layers. The neurons in the neural network make stochastic decisions about whether to turn on or off based on the data we feed during training and the cost function the Boltzmann Machine is trying to minimize. By doing so, the Boltzmann Machine discovers interesting features about the data, which help model the complex underlying relationships and patterns present in the data.

This Boltzmann Machine uses neural networks with neurons that are connected not only to other neurons in other layers but also to neurons within the same layer. That makes training an unrestricted Boltzmann machine very inefficient and Boltzmann Machine had very little commercial success.
Boltzmann Machines are primarily divided into two categories: Energy-based Models (EBMs) and Restricted Boltzmann Machines (RBM). When these RBMs are stacked on top of each other, they are known as Deep Belief Networks (DBN). Our focus of discussion here is the RBM.

Restricted Boltzmann Machines (RBM)

Restricted Boltzman Machine Algorithm
  • What makes RBMs different from Boltzmann machines is that visible node isn’t connected to each other, and hidden nodes aren’t connected with each other. Other than that, RBMs are exactly the same as Boltzmann machines.
  • It is a probabilistic, unsupervised, generative deep machine learning algorithm.
  • RBM’s objective is to find the joint probability distribution that maximizes the log-likelihood function.
  • RBM is undirected and has only two layers, Input layer, and hidden layer
  • All visible nodes are connected to all the hidden nodes. RBM has two layers, visible layer or input layer and hidden layer so it is also called an asymmetrical bipartite graph.
  • No intralayer connection exists between the visible nodes. There is also no intralayer connection between the hidden nodes. There are connections only between input and hidden nodes.
  • The original Boltzmann machine had connections between all the nodes. Since RBM restricts the intralayer connection, it is called a Restricted Boltzmann Machine.
  • Since RBMs are undirected, they don’t adjust their weights through gradient descent and backpropagation. They adjust their weights through a process called contrastive divergence. At the start of this process, weights for the visible nodes are randomly generated and used to generate the hidden nodes. These hidden nodes then use the same weights to reconstruct visible nodes. The weights used to reconstruct the visible nodes are the same throughout. However, the generated nodes are not the same because they aren’t connected to each other.

Simple Understanding of RBM

Problem Statement: Let’s take an example of a small café just across a street where people come in the evening to hang out. We see that normally three people: Geeta, Meeta and Paavit visit frequently. Not always all of them show up together. We have all the possible combinations of these three people showing up. It could be just Geeta, Meeta or Paavit show up or Geeta and Meeta come at the same time or Paavit and Meeta or Paavit and Geeta or all three of them show up or none of them show up on some days. All the possibilities are valid.

Left to Right: Geeta, Meeta, Paavit

Let’s say, you watch them coming everyday and make a note of it. Let’s take first day, Meeta and Geeta comes and Paavit didn’t. Second day, Paavit comes but Geeta and Meeta doesn’t. After noticing for 15 days, you find that only these two possibilities are repeated. As represented in the table.

Visits of Geeta, Meeta and Paavit to the cafe

That’s an interesting finding and more so when we come to know that these three people are totally unknown to each other. You also find out that there are two café managers: Ratish and Satish. Lets tabulate it again with 5 people now (3 visitors and 2 managers).

Visits of customer and presence of manager on duty

We find that, Geeta and Meeta likes Ratish so they show up when Ratish is on duty. Paavit likes Satish so he shows up only when Satish is on duty. So, we look at the data we might say that Geeta and Meeta went to the café on the days Ratish is on duty and Paavit went when Satish is on duty. Lets add some weights.

Customers and Managers relation with weights

Since we see that customers in our dataset, we call them as visible layer. Managers are not shown in the dataset, we call it as hidden layer. This is an example of Restricted Boltzmann Machine (RBM).

RBM

(… to be continued…)

Working of RBM

RBM is a Stochastic Neural Network which means that each neuron will have some random behavior when activated. There are two other layers of bias units (hidden bias and visible bias) in an RBM. This is what makes RBMs different from autoencoders. The hidden bias RBM produces the activation on the forward pass and the visible bias helps RBM to reconstruct the input during a backward pass. The reconstructed input is always different from the actual input as there are no connections among the visible units and therefore, no way of transferring information among themselves.

Step 1

The above image shows the first step in training an RBM with multiple inputs. The inputs are multiplied by the weights and then added to the bias. The result is then passed through a sigmoid activation function and the output determines if the hidden state gets activated or not. Weights will be a matrix with the number of input nodes as the number of rows and the number of hidden nodes as the number of columns. The first hidden node will receive the vector multiplication of the inputs multiplied by the first column of weights before the corresponding bias term is added to it.

Here is the formula of the Sigmoid function shown in the picture:

So the equation that we get in this step would be,

where h(1) and v(0) are the corresponding vectors (column matrices) for the hidden and the visible layers with the superscript as the iteration v(0) means the input that we provide to the network) and a is the hidden layer bias vector.

(Note that we are dealing with vectors and matrices here and not one-dimensional values.)

Now this image shows the reverse phase or the reconstruction phase. It is similar to the first pass but in the opposite direction. The equation comes out to be:

where v(1) and h(1) are the corresponding vectors (column matrices) for the visible and the hidden layers with the superscript as the iteration and b is the visible layer bias vector.

Now, the difference v(0)−v(1) can be considered as the reconstruction error that we need to reduce in subsequent steps of the training process. So the weights are adjusted in each iteration so as to minimize this error and this is what the learning process essentially is.

In the forward pass, we are calculating the probability of output h(1) given the input v(0) and the weights W denoted by:

And in the backward pass, while reconstructing the input, we are calculating the probability of output v(1) given the input h(1) and the weights W denoted by:

The weights used in both the forward and the backward pass are the same. Together, these two conditional probabilities lead us to the joint distribution of inputs and the activations:

Reconstruction is different from regression or classification in that it estimates the probability distribution of the original input instead of associating a continuous/discrete value to an input example. This means it is trying to guess multiple values at the same time. This is known as generative learning as opposed to discriminative learning that happens in a classification problem (mapping input to labels).

Let us try to see how the algorithm reduces loss or simply put, how it reduces the error at each step. Assume that we have two normal distributions, one from the input data (denoted by p(x)) and one from the reconstructed input approximation (denoted by q(x)). The difference between these two distributions is our error in the graphical sense and our goal is to minimize it, i.e., bring the graphs as close as possible. This idea is represented by a term called the Kullback–Leibler divergence.

KL-divergence measures the non-overlapping areas under the two graphs and the RBM’s optimization algorithm tries to minimize this difference by changing the weights so that the reconstruction closely resembles the input. The graphs on the right-hand side show the integration of the difference in the areas of the curves on the left.

This gives us intuition about our error term. Now, to see how actually this is done for RBMs, we will have to dive into how the loss is being computed. All common training algorithms for RBMs approximate the log-likelihood gradient given some data and perform gradient ascent on these approximations.

Contrastive Divergence

Here is the pseudo-code for the CD algorithm:

CD Algorithm pseudo code

Applications:
* Pattern recognition : RBM is used for feature extraction in pattern recognition problems where the challenge is to understand the hand written text or a random pattern.
* Recommendation Engines : RBM is widely used for collaborating filtering techniques where it is used to predict what should be recommended to the end user so that the user enjoys using a particular application or platform. For example : Movie Recommendation, Book Recommendation
* Radar Target Recognition : Here, RBM is used to detect intra pulse in Radar systems which have very low SNR and high noise.

Source: wikipedia (https://en.wikipedia.org/wiki/Restricted_Boltzmann_machine)

Installating R Studio

The RStudio IDE is a set of integrated tools designed to help you be more productive with R and Python. It includes a console, syntax-highlighting editor that supports direct code execution, and a variety of robust tools for plotting, viewing history, debugging and managing your workspace.

LEARN MORE ABOUT THE RSTUDIO IDE

If you want to start practicing r programs then R Studio is the best IDE. In this section, I will write the steps on how you can install RStudio Desktop for your personal use. RStudio Desktop is totally free to use.

Steps:

  1. First install R
  2. Install R Studio Desktop

To Install R:

  1. Open an internet browser and go to www.r-project.org.
  2. Click the “download R” link in the middle of the page under “Getting Started.”
  3. Select a CRAN location (a mirror site) and click the corresponding link.  
  4. Click on the “Download R for Windows” link at the top of the page.  
  5. Click on the “install R for the first time” link at the top of the page.
  6. Click “Download R for Windows” and save the executable file somewhere on your computer.  Run the .exe file and follow the installation instructions.  
  7. Now that R is installed, you need to download and install RStudio. 

To Install RStudio

  1. Go to www.rstudio.com and click on the “Download RStudio” button.
  2. Click on “Download RStudio Desktop.”
  3. Click on the version recommended for your system, or the latest Windows version, and save the executable file.  Run the .exe file and follow the installation instructions.     

I hope you have installed R and R studio and now you are ready to practice your programs.

Installation of Anaconda for Python on Local Machine

Installing on Windows

  1. Download the installer:

  2. Verify your installer hashes.

  3. Double-click the .exe file.

  4. Follow the instructions on the screen.

    If you are unsure about any setting, accept the defaults. You can change them later.

    When installation is finished, from the Start menu, open the Anaconda Prompt.

  5. Test your installation. In your terminal window or Anaconda Prompt, run the command conda list. A list of installed packages appears if it has been installed correctly.

Installing in silent mode

Note

The following instructions are for Miniconda. For Anaconda, substitute Anaconda for Miniconda in all of the commands.

To run the the Windows installer for Miniconda in silent mode, use the /S argument. The following optional arguments are supported:

  • /InstallationType=[JustMe|AllUsers]—Default is JustMe.

  • /AddToPath=[0|1]—Default is 0

  • /RegisterPython=[0|1]—Make this the system’s default Python. 0 indicates JustMe, which is the default. 1 indicates AllUsers.

  • /S—Install in silent mode.

  • /D=<installation path>—Destination installation path. Must be the last argument. Do not wrap in quotation marks. Required if you use /S.

All arguments are case-sensitive.

EXAMPLE: The following command installs Miniconda for the current user without registering Python as the system’s default:

start /wait "" Miniconda3-latest-Windows-x86_64.exe /InstallationType=JustMe /RegisterPython=0 /S /D=%UserProfile%\Miniconda3

Updating conda

  1. Open your Anaconda Prompt from the start menu.

  2. Navigate to the anaconda directory.

  3. Run conda update conda.

Uninstalling conda

  1. In the Windows Control Panel, click Add or Remove Program.

  2. Select Python X.X (Miniconda), where X.X is your version of Python.

  3. Click Remove Program.


Information is shared here from the official Anaconda website: 
https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html
Refer this website to install on Linus, Mac etc
Free Python Webinar

Python expert Swapnil Saurav conducted one-hour long Python Webinar for those who want to learn Python programming. The session was conducted on March 5th 6-7pm India time. This was conducted as part of Swapnil’s mission to make India Python literate. The webinar was attended by over 30 participants.

Following topics were covered in the session:

  1. Why is gaining popular
  2. Top features of Python
  3. Brief history
  4. Download, Installation and Working of Python.exe, Pycharm and using Google Colab
  5. Print() function
  6. Variables
  7. Basic datatypes – Int, String

List of participants included:

  1. Borra John
  2. Shivakumar
  3. Ajan S
  4. Juhaira K
  5. Sankar K
  6. Velmurugan A
  7. Loga Varshini.P
  8. Bhuwan Kumar Sharma
  9. Aswini M
  10. Harini Sri A.R.
  11. K. Swetha
  12. Rohan S Lolage
  13. M. Jaya varshini
  14. Nathalie Joy D. Fronda
  15. S. Sanjay
  16. Inika.R.G.
  17. Kanividya G.P.
  18. Indu Bala
  19. Sivanarul Selvan S
  20. Shrasti Agrawal
  21. S. Srinivas
  22. Pandu Rangan C.R
  23. M. Hemapriya
  24. Muskan Mahato
  25. Debjit Biswas
  26. Noor Mohammed G
  27. Chauhan Mitul Kumar
  28. Souvik Chakraborty
  29. Navneet Singh
  30. Kapil RJ
  31. Gagan Manocha

Attached here is the presentation deck:

Presentation slides
Cloud Computing Basics – 1

Cloud computing is a computing term or metaphor that evolved in the late 2000s, based on utility and consumption of computer resources. Cloud computing is about moving computing from the single desktop PC/Data centers to Internet.

Figure 1.1: Cloud computing terms

Cloud: The “Cloud” is the default symbol of the internet in diagrams

Computing: The broader term of “Computing” encompasses- computation, coordination logic and storage.

Chapter 1.1: Fundamentals of cloud computing

Let’s take an example, you wish to play Ninja Fighters game with your friend on your smartphone. You go to the app store, download the app, log in, find your friend and within five minutes, you’re having fun. This ability to request services for yourself when you need them in cloud computing terms is known as on-demand self-service. You didn’t need to go to a physical store, you didn’t need to call someone to place an order and you didn’t need to sit on hold or wait for anyone else to do anything for you. Another example is of Gmail. You don’t need to install any software nor do you need hard disk space to save your emails -It’s all in the “cloud” managed by Google. In cloud computing, you don’t care what kind of software it is, all you care about is that the service offered is available and reliable. As more users join the game, the cloud is able to quickly grow or shrink to meet the change in demand—elasticity in techie terms. This is possible because a cloud provider, like IBM, has a massive number of servers pooled together that can be balanced between its various customers. But ultimately, you don’t care as long as it’s available for you.

1.1.1Features of Cloud Computing

Figure 2: NIST Visual Model of Cloud Computing Definition

Figure 2: NIST Visual Model of Cloud Computing Definition

The generally accepted definition of Cloud Computing comes from the National Institute of Standards and Technology (NIST). The NIST definition runs to several hundred words but essentially says that:

Cloud computing is a model for enabling convenient, on-demand network access to a shared pool of configurable computing resources (e.g., networks, servers, storage, applications, and services) that can be rapidly provisioned and released with minimal management effort or service provider interaction.

What this simply means is the ability for end users to utilize parts of bulk resources and that these resources can be acquired quickly and easily. NIST also offers up several characteristics that it sees as essential for a service to be considered “Cloud”. These characteristics include;

  • On-demand self-service: The ability for an end user to sign up and receive services without the long delays that have characterized traditional IT
  • Broad network access: Ability to access the service via standard platforms (desktop, laptop, mobile etc)
  • Resource pooling: Resources are pooled across multiple customers
  • Rapid elasticity: Capability can scale to cope with demand peaks
  • Measured Service: Billing is metered and delivered as a utility service

1.1.2Types of Cloud

With cloud computing technology, large pools of resources can be connected through private or public networks.

Figure 3: Types of Cloud (Deployment Model)

What are the differences between these types of cloud computing, and how can you determine the right cloud path for your organization? Here are some fundamentals of each to help with the decision-making process().

Public

Public clouds are made available to the general public by a service provider who hosts the cloud infrastructure. Generally, public cloud providers like Amazon AWS, Microsoft and Google own and operate the infrastructure and offer access over the Internet. With this model, customers have no visibility or control over where the infrastructure is located. It is important to note that all customers on public clouds share the same infrastructure pool with limited configuration, security protections and availability variances.

Public Cloud customers benefit from economies of scale, because infrastructure costs are spread across all users, allowing each individual client to operate on a low-cost, “pay-as-you-go” model. Another advantage of public cloud infrastructures is that they are typically larger in scale than an in-house enterprise cloud, which provides clients with seamless, on-demand scalability. These clouds offer the greatest level of efficiency in shared resources; however, they are also more vulnerable than private clouds.

A public cloud is the obvious choice when:

  • Your standardized workload for applications is used by lot of people, such as e-mail.
  • You need to test and develop an application code.
  • You need incremental capacity i.e. the ability to add resources for peak times.
  • You’re doing collaboration projects.

Private

Private cloud is cloud infrastructure dedicated to a particular organization. Private clouds allow businesses to host applications in the cloud, while addressing concerns regarding data security and control, which is often lacking in a public cloud environment.  It is not shared with other organizations, whether managed internally or by a third-party, and it can be hosted internally or externally.

There are two variations of private clouds:

On-Premise Private CloudExternally Hosted
This type of cloud is hosted within an organization’s own facility. A businesses IT department would incur the capital and operational costs for the physical resources with this model. On-Premise Private Clouds are best used for applications that require complete control and configurability of the infrastructure and security.Externally hosted private clouds are also exclusively used by one organization, but are hosted by a third party specializing in cloud infrastructure. The service provider facilitates an exclusive cloud environment with full guarantee of privacy. This format is recommended for organizations that prefer not to use a public cloud infrastructure due to the risks associated with the sharing of physical resources.

Undertaking a private cloud project requires a significant level and degree of engagement to virtualize the business environment, and it will require the organization to reevaluate decisions about existing resources. Private clouds are more expensive but also more secure when compared to public clouds. An Info-Tech survey shows that 76% of IT decision-makers will focus exclusively on the private cloud, as these clouds offer the greatest level of security and control.

When to opt for a Private Cloud?

  • You need data sovereignty but want cloud efficiencies
  • You want consistency across services
  • You have more server capacity than your organization can use
  • Your data center must become more efficient
  • You want to provide private cloud services

Hybrid

Hybrid Clouds are a composition of two or more clouds (private, community or public) that remain unique entities but are bound together offering the advantages of multiple deployment models. In a hybrid cloud, you can leverage third party cloud providers in either a full or partial manner; increasing the flexibility of computing. Augmenting a traditional private cloud with the resources of a public cloud can be used to manage any unexpected surges in workload.

Hybrid cloud architecture requires both on-premise resources and off-site server based cloud infrastructure. By spreading things out over a hybrid cloud, you keep each aspect of your business in the most efficient environment possible. The downside is that you have to keep track of multiple cloud security platforms and ensure that all aspects of your business can communicate with each other.

Here are a couple of situations where a hybrid environment is best:

  • Your company wants to use a SaaS application but is concerned about security.
  • Your company offers services that are tailored for different vertical markets. You can use a public cloud to interact with the clients but keep their data secured within a private cloud.
  • You can provide public cloud to your customers while using a private cloud for internal IT.

Community

A community cloud is a is a multi-tenant cloud service model that is shared among several or organizations and that is governed, managed and secured commonly by all the participating organizations or a third party managed service provider. Community clouds are a hybrid form of private clouds built and operated specifically for a targeted group. These communities have similar cloud requirements and their ultimate goal is to work together to achieve their business objectives.

The goal of community clouds is to have participating organizations realize the benefits of a public cloud with the added level of privacy, security, and policy compliance usually associated with a private cloud. Community clouds can be either on-premise or off-premise.

Here are a couple of situations where a community cloud environment is best:

  • Government organizations within a state that need to share resources
  • A private HIPAA compliant cloud for a group of hospitals or clinics
  • Telco community cloud for telco DR to meet specific FCC regulations

Cloud computing is about shared IT infrastructure or the outsourcing of a company’s technology.  It is essential to examine your current IT infrastructure, usage and needs to determine which type of cloud computing can help you best achieve your goals.  Simply, the cloud is not one concrete term, but rather a metaphor for a global network and how to best utilize its advantages depends on your individual cloud focus.

1.1.3Advantages & Disadvantages

Advantagesof Cloud Computing

Cloud computing presents a huge opportunity for businesses.Let’s look at some of them:

Cost Efficient

Cloud computing is probably the most cost efficient method to use, maintain and upgrade. Traditional desktop software costs companies a lot in terms of finance. Adding up the licensing fees for multiple users can prove to be very expensive for the establishment concerned. The cloud, is available at much cheaper rates and can significantly lower the company’s IT expenses. Besides, there are many one-time-payment, pay-as-you-go and other scalable options available, which makes it reasonable.

Almost Unlimited Storage

Storing information in the cloud gives you almost unlimited storage capacity. Hence, you no more need to worry about running out of storage space or increasing your current storage space availability. 

Backup and Recovery

Since all your data is stored in the cloud, backing it up and restoring the same is relatively much easier than storing the same on a physical device. Furthermore, most cloud service providers are usually competent enough to handle recovery of information. Hence, this makes the entire process of backup and recovery much simpler than other traditional methods of data storage.

Automatic Software Integration

In the cloud, software integration is usually something that occurs automatically. This means that you do not need to take additional efforts to customize and integrate your applications as per your preferences. This aspect usually takes care of itself. You can also handpick just those services and software applications that you think will best suit your particular enterprise.  

Easy Access to Information

Once you register yourself in the cloud, you can access the information from anywhere, where there is an Internet connection.

Quick Deployment

Cloud computing gives you the advantage of quick deployment. Once you opt for this method of functioning, your entire system can be fully functional in a matter of a few minutes, dependingupon the exact kind of technology that you need for your business.

Disadvantages of Cloud Computing

Cloud computing also has some challengessuch as:

Technical Issues

Though it is true that information and data on the cloud can be accessed anytime and from anywhere at all, there are times when this system can have some serious dysfunction. Technology is always prone to outages and other technical issues. Even the best cloud service providers run into this kind of trouble, in spite of keeping up high standards of maintenance. Besides, you will need a very good Internet connection to be logged onto the server at all times. You will invariably be stuck in case of network and connectivity problems. 

Security in the Cloud

The other major issue while in the cloud is that of security issues. Before adopting this technology, you should know that you will be surrendering all your company’s sensitive information to a third-party cloud service provider. This could potentially put your company to great risk. Hence, you need to make absolutely sure that you choose the most reliable service provider, who will keep your information totally secure.

Prone to Attack

Storing information in the cloud could make your company vulnerable to external hack attacks and threats. As you are well aware, nothing on the internet is completely secure and hence, there is always the lurking possibility of stealth of sensitive data.

Know Everything About Cloud Computing
Beginners guide to cloud computing

The origin of cloud computing can be traced back as far as 1961 when John McCarthy first conceived the idea. His vision was that computation should be arranged and organized as a public utility to lower the cost of computing, enhance reliability, and relieve users from owning and operating complicated computing infrastructure. And, since then, improvement in legacy technologies like virtualization, commodity and Grid computing has brought about the realization of the cloud computing paradigm. Cloud computing’s flexibility and scalability has continued to enhance the agility and effectiveness of huge organizations, meeting reliability, and the efficiency of large-scale applications. However, performance requirements remain a serious concern and studies and have shown that performance variability is a critical concern for cloud application providers. The reason for that is because it impacts a lot the end-user’s quality of experience. In this discussion, we are going to see in details what cloud computing is, clouds deployment models, delivery models, datacenters, and more.   

What Is Cloud Computing?

It can be defined as a paradigm change in how computation is delivered and utilized. It is based on the idea that the processing of information can take place more effectively on large computing farms and storage systems accessible via the Internet. It offers a set of technologies which enable provision of computational resources like compute and storage as a service via the Internet either on a pay-per-use or on-demand mode.

Two factors that contribute to the high adoption rate of the cloud are; – (1) its ability to offer smooth scalability and elasticity to consumers without huge initial capital expenses and (2) it provides resources that can be metered so that users are only billed for they have consumed. The two appeal factors have led to a drastic change in how IT (Information Technology) departments and application providers organize and manage IT services.

https://youtu.be/HegVrE0g6dIWatch the video of this content

Cloud Delivery Models

Depending on the abstraction level in which a service is provided, public clouds have three main delivery models. These are as below:

  • Infrastructure as a Service (IaaS)–  this involves fundamental computing resources like servers, network, and storage that are provided. Consumers are responsible for installing the operating system (OS) and can create arbitrary applications using application development tools of their choice. Various IaaS providers are available and they include Google Cloud Platform, Rackspace, Amazon EC2, and Microsoft Azure Infrastructure.
  • Platform as a Service (PaaS)– this model gives cloud users the capability to develop, deploy, and manage apps using app development tools, operating systems, APIs, and hardware supported by a provider. The cloud user controls only the application, its architecture, and hosting space configuration but not the network, storage, servers, or even the principal operating system. Among the most renowned PaaS offerings available today are Windows Azure, Google App Engine, and Amazon’s Elastic Beanstalk.
  • Software as a Service (SaaS)- this occurs when end-users start using finished applications accessible via various client devices over the Internet, together with the required software, OS, network, and hardware. The users can enjoy some measure of minimal customization, but they have limited control on the application, its platform, and underlying infrastructure. Some of SaaS applications are Web 2.0 applications (like WordPress & LinkedIn), accounting systems (e.g. NetSuite), and Customer Relationship Management (e.g. ServiceNow).

Clouds Deployment Models

How are cloud infrastructures categorized? The classification can be based on either ownership or how they are managed. Five deployment models are available for cloud infrastructure so far and they are as described below:

  1. Private clouds– they are managed and used by individual entities. Several organizations adopt these clouds to accrue the benefits of cloud computing like scalability and flexibility, and at the same time having complete control on its infrastructure and security.
  2. Public clouds– these are infrastructures managed by an organization which leases them to third-parties on a pay-per-use basis. Public clouds include Rackspace, Google Cloud Platform, and Microsoft Azure.
  3. Community clouds– they are used and share by a group (s) of people or organizations with a mutual interest e.g. the North Carolina Education Cloud (NCEdCloud).
  4. Hybrid clouds– these are called hybrid because it involves a merger between two or more clouds. For instance, if a large organization which hosts its core IT infrastructure on a private or community clouds wants to expand its capacity to meet a sudden surge in user demand, it can team up with at least a public cloud for that purpose. It will do so by leasing public cloud resources and hence the name, “hybrid clouds.” The mechanism through which that happens is called cloud bursting.
  5. Federated clouds– these are an emerging type of clouds consisting of only public clouds, only private clouds or both to provide end-users with seemingly unlimited computing utility service. These clouds enable high interoperability and compatibility between different cloud services through open APIs that allows cloud users to distribute services based on offerings from various vendors or transfer data easily across platforms. An example of federated clouds is one established among numerous datacenters owned by a single cloud provider.

Cloud Datacenters

What are cloud datacenters? They can be referred to as the power houses of cloud computing as they house several servers, communications, and storage systems needed for cloud computing. The servers, communications, and storage systems are co-located in the datacenters because of their similar physical security, environmental, and maintenance requirements. Hence, the consolidation of such resources help in ensuring their effective utilization. Multiple applications cloud providers can share server resources, thus, avoiding under-utilization and server stretch in datacenters.

The technology that makes consolidation and sharing better is called virtualization technology. It provides performance isolation among co-located applications. Consolidation is cost-efficient as it reduces capital and operational expenses, and lowers energy consumption. Two mainstream platforms are available for realizing virtualization today (hypervisor-based virtualization and container-based virtualization). Hypervisor-based virtualization e.g. Xen, KVM, and Hyper-V imitates a machine hardware and allows instances of the imitation (i.e. virtual machines, VMs) to run on a different physical machine managed by a specialized operating system called the hypervisor. The approach, however, is OS agnostic since the guest OS (OS installed in the VM) may be different from the host OS (OS running on the physical host of the VM).

Container-based visualization does not emulate hardware platform, but provides visualization at the OS-level to reduce performance and speed overhead of the hypervisor-based visualization. It allows multiple isolated Linux environments (containers) to share the base kernel of the host OS. Examples of container-based visualization platforms are LXC, Docker, and OpenVZ. Despite enjoying an increasing adoption, containers still cannot match VMs which remain to be the common unit of cloud deployments because of the technology’s maturity. VMs can be easily moved from one server to another to balance the load across the datacenter or merge workloads on fewer servers.

VMs are also easy-to-manage software-defined units and they facilitate the elasticity of the cloud. It is also possible to replicate them across servers (horizontal scaling) and their resource capacity (such as CPU cores) can be reduced or increased to address overload or underload situations (vertical scaling). Infrastructure as a Software (IaaS) datacenters face a challenge of resource allocation. The concern is how to optimally share or distribute computing, storage, and network resources among a set of VMs in a way that tries to equally meet service objectives of both service providers and cloud provider.

Software-Defined Infrastructures

There is a need for increased automation and programmability as the adoption of cloud computing for performing various roles grows. One such role is running mission-critical and performance-sensitive applications like analytics, mobile services, the Internet of Things (IoT), and machine-to-machine communications. It means that there is an increased demand for agility, performance, and energy efficiency. And, that is what has led to the recent trend towards Software-Defined Infrastructures (SDI).

To facilitate automation, several studies have applied autonomic computing techniques in different aspects of managing current clouds like resource allocation, rescheduling, and energy management. SDIs are anticipated to change the compute, storage, and network infrastructures to software-defined and vigorously programmable entities. But, what is a SDI? A simple definition could be; it is an infrastructure that is consistently transforming itself by properly exploiting heterogeneous capabilities and utilizing insights obtained from built-in deep monitoring to constantly honor consumer SLAs amid provider’s constraints such as cost and energy constraints. There are currently only a few SDI products or platforms available, but many of the technology’s aspects are still evolving. Even so, below are the key architectural components of SDIs:

  • Software-defined Compute (SDC)– it performs two roles; – (1) enhancing the programmability of existing virtualized compute resources like VMs, containers, and virtual CPUs and (2) leveraging specialized processing units e.g. GPUs (graphical processing units), FPGAs (field-programmable gate arrays), and other accelerators. It decouples the provision of heterogeneous compute resources from the existing hardware or OS so that it is based on identified or discovered workload needs.  
  • Software-defined Network (SDN)- its function is the separation of control and management functions of the network infrastructures away from the hardware to the server. It does so to improve performance isolation, security, programmability, and effectiveness. By means of virtualization, it allows network resources to be transformed to virtual devices (like links, end-points, & switches) that connect various virtual storage and compute instances.
  • Software-defined Storage- it functions to manage huge data volumes by separating the control and management functions from the data storage system. Such separation helps in reducing management complexity and lower the cost of infrastructure.

A SDI controller manages all SDI components by providing the control intelligence needed to meet workload requirements. It uses the classical MAPE loop to consistently monitor the current state of SDI entities.

Cloud Stakeholders and Their Roles

Cloud stakeholders are usually grouped into one of three roles depending on the service delivery models. The role of the cloud provider or IP (Infrastructure provider) ranges from infrastructure provision in IaaS, platforms and infrastructure provision in PaaS, to the provision of the whole cloud stack (infrastructure, platforms, and applications) in SaaS.

Cloud users or SP (Service Providers) are mostly found under the IaaS and PaaS model. They use the infrastructure and/or platform given by the cloud provider to host application services that are used the end-user. Interactions in terms of roles between the cloud stakeholders (cloud and service providers) are administered by an official document known as the Service Level Agreement (SLA). 

The SLA describes what quality of service is expected and the legal agreements. A characteristic SLA constitutes important elements like the service credits and service guarantees(outlines functional metrics e.g. response time, availability, and safety that a cloud provider needs to meet during the service guarantee period). A service credit is a sum credited to a customer or put in place towards a future payment when the IP cannot meet the service guarantees.

Conclusion

Cloud computing is here to stay with us. It’s what drives every IT operation. Most cloud providers know what their role in providing hosting platforms is and they will strive to maintain their offering. It’s my hope that this discussion has shed some light about cloud computing for you.

How to get date and time in Python

Python has a module called as datetime which gives the current date and time in Python. Datetime module comes with pre-built so we dont have to install it explicitly but we do need to import the module. datetime module provide some functions to get the current date as well as time. You can get complete information from the document website here. In this article, we will look at the some of the important functions and implement with examples. Let’s look at them.

date.today():
today() method of date class under datetime module returns a date object which contains the value of Today’s date.

Syntax: date.today()
Returns: Return the current local date.

Implementation of datetime

# Import the module datetime
import datetime as dt

# Returns the current local date using class date
today_date = dt.date.today()
print("Today's date: ", today_date)
# We can extract date, month and year separately too
print("Today's date: ", today_date.day,"-",today_date.month,"-",today_date.year)

To know what is inside datetime, we can use dir() function to get a list containing all attributes of a module.

import datetime
print(dir(datetime))

Output:

['MAXYEAR', 'MINYEAR', 'builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'spec', 'date', 'datetime', 'datetime_CAPI', 'sys', 'time', 'timedelta', 'timezone', 'tzinfo']

We have already seen the date class. Other commonly used classes are: time, datetime, timedelta

We can create object of Time class to represent time. example:

from datetime import time
import datetime as dt
from time import strftime

current_time = dt.datetime.now()
print("current_time =", current_time.time())
#change the format
print(dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

# time(hour, minute and second)
time1 = time(11, 34, 56)
print("Given time =", time1)

time2 = time(hour = 11, minute = 34, second = 56)
print("Given time =", time2)

# time(hour, minute, second, microsecond)
time3 = time(11, 34, 56, 234566)
print("Given time =", time3)
Speaker at ATAL online FDP on “The Internet of Things and Everything- IOT/IOE”

I am so pleased to share the news that I was one of the speakers at the ATAL Online Faculty Development Program, a 5-days course conducted by Chandigarh University and was Organized By Department of Electronics & Communication Engineering, Chandigarh University. The programme was accepted and approved by AICTE Training and Learning (ATAL) Academy cell.

The sessions were conducted by the team of eminent academicians and industry experts possessing in-depth knowledge in the area of Internet of Everything. Topis covered were:

  • Introduction to embedded systems, IOT and IOE
  • Internet of Everything v Internet of things
  • IOT Network and Protocols
  • IOT System architecture -Design and Development
  • IOT Programming and Simulator
  • Security and Privacies issues in IOT
  • Cloud deployment and its application in IOT
  • IOT/IOE in Healthcare applications
  • AI Powered IOT/IOE
  • Building a sample IOT application

I spoke on Day 5 Session 1. My topic was “IoT for Retail Management”.

Other speakers at the event were:

In my next blog, I will write about the content I presented at the event. Stay tuned!

How classes and objects are used in Python

Python is said to be a pure object oriented programming language and almost everything you come across in Python is an object. A class can be defined as a user-defined type that, by having its own methods (functions) and property (variables), define what object will look like. An object is a single instance of a class. You can create many objects from the same class type.

Creating a class in Python
class keyword is used in Python to create a class, an example is shown below. We create a class named Books with a property named total_count:

class Books:
total_count = 5

Creating an object
class is just a blueprint. In order to use the class, we need to create an object. In below example, lets create an object called learn_python and using this we will print the value of total_count:

class Books:
total_count = 5
python_book = Books()
print(python_book.total_count)

The init() Function
Let’s look at an important member of the class. We are talking about init() function. Infact all classes have this function, which is always called an object of the class in being created. This function is called automatically so you dont have to specifically call this. We use the init() function to initialize values or properties that needs to be assigned to the object immediately when created. In the below example, we create a class Books and using the init() function, we have automatically assigning title and the cost to the object:

class Books:
def __init__(self, title, cost):
self.title = title
self.cost = cost

python_book = Books("Learn and Practice Python Programming", 136)
print(python_book.title)
print(python_book.cost)

Object Functions
A class will also have object functions or methods. Functions that are defined in objects, belong to object (and not to the class). It means that the objects will use these functions and the result returned will be specific to the objects. These are characterised by self keyword as first parameter being passed. Let’s add a function to our class Books which will print the title of the book. This is called object function because it knows which objects are referencing and the title value is linked to that object only.
Example:

class Books:
def __init__(self, title, cost):
self.title = title
self.cost = cost
def gettitle(self):
print("Title of the book is: "+self.title)

python_book = Books("Learn and Practice Python Programming", 136)
print(python_book.title)
print(python_book.cost)
python_book.gettitle()

The self parameter used in object functions is to show the reference to the current object associated to the class.
Please note, it does not have to be named self, we can use any name we like it but whatever name we choose, that has to be the first parameter of the object functions.

We will end our discussion here. We will develop a mini application using classes in next article.

Python 3.10 – what can we expect from it?

Image above shows how CASE statement can be implemented in Python, wait you cant make it work today but surely can after 4th October, that is after Python 3.10 is made available for all of us. In the 3.10 version, we will see some of the most fascinating features like structural pattern matching, parenthesized context managers, more typing, and improved error messages to make our life easier.

In 2020, Guido van Rossum, the creator of Python, committed the first documentation showing the new switch-statements, which have been named Structural Pattern Matching. Python is not using the switch keyword for its Structural Pattern Matching as other programming languages do, instead, it will be using match keywords. So it might be possible that we would refer to it as a Python match case statement instead of a Python switch case.

The new structural pattern matching will help us to match variables against one or even one of a set of possible values. This will no doubt be very powerful feature and will make it possible to write code for a variety of scenarios. One example is offcourse the code added as an image above. Lets look at another example:

Let’s try to use match case Statement and implement the weekday calculator as example:

def weekday(day):
    match day:
        case 1:
            return "Sunday"
        case 2:
            return "Monday"
        case 3:
            return "Tuesday"
        case 4:
            return "Wednesday"
        case 5:
            return "Thursday"
        case 6:
            return "Friday"
        case 7:
            return "Saturday"
        #wildcard case
         case _:
            return "Please Enter a Valid Day Number"

 print(weekday(1))   #Sunday
 print(weekday(4))  #Wednesday
 print(weekday(7))  #Saturday
 print(weekday(11)) #Please Enter a Valid Day Number

Impressed? There is more to come. Using, what is called as structural pattern matching, we can perform the same match-case logic even based on whether the structure of our comparison object matches a given pattern.

To demonstrate, lets take two dictionaries:

dict_a = {
    'id': 1,
    'meta': {
        'source': 'abc',
        'location': 'west'
    }
}

dict_b = {
    'id': 2,
    'source': 'def',
    'location': 'west'
}

 We could write a pattern to match dict_a like:

{
    'id': int,
    'meta': {'source': str,
             'location': str}
}

A pattern to match dict_b like:

 {    'id': int,
    'source': str,
    'location': str
}

We can now put both of these together in a match-case statement:

# loop through both dictionaries and a 'test'
for d in [dict_a, dict_b, 'test']:
   match d:
       case {'id': ident,
             'meta': {'source': source,
                      'location': loc}}:
           print(ident, source, loc)
       case {'id': ident,
             'source': source,
             'location': loc}:
           print(ident, source, loc)
       case _:
           print('no match')

Watch out for my next few articles in which I will cover:

  • Parenthesized context managers
  • More Python typing features
  • Display better error messages

Stay tuned. Do comment here if you liked this article.