Trending March 2024 # How Does Rune Work In Go Language? # Suggested April 2024 # Top 8 Popular

You are reading the article How Does Rune Work In Go Language? updated in March 2024 on the website Hatcungthantuong.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 How Does Rune Work In Go Language?

Introduction to Golang Rune

Web development, programming languages, Software testing & others

Syntax

Below is a simple syntax for the where we show how we can create a run, so basically it is simply assigning the characters or punctuation to the run variable. We can explain the below syntax in the following steps .

First, we have taken a variable run, here you can give any name to this variable and assign them values.

Next, we get the Unicode of the run variable. Simply with the command reflect.Type(run).

Remember the reflect is the package which we need to import to see the Unicode value of the run, or of the characters.

Please see the below syntax for understanding.

run := symbol of punctuation reflect.TypeOf(run) How Does Rune Work in Go language?

So before understanding the working of the runs we need to understand why it is being introduced, actually there are many languages and punctuation’s so it plays a role of the intermediate which allow many languages to work and a unique code for every language so that it will be easily understandable in a common way for all other languages. We can discuss the working of the runs in the following steps.

When we write any string with more than one character it will not work with that, as it is made for single characters.

We can see an example of UTF-8 which encodes the all Unicode for 1 to 4 bytes and here out of the 4 bytes 1 byte will be used for the ASCII characters and remaining will be used for the runs.

We should be aware that every ASCII contains a total of 256 attributes. Out of these 256 characters, 128 characters are the numbers from 0-127 these are reserved for them.

We do not have to do anything to perform the runs it manages internally, which Unicode generation is there internally, if anyone wishes to see the Unicode for any characters they can see by using reflect package of the go language. Now to use the reflect package of the go language we need to import the reflect.

We will see that out of the reflect package that every character has a unique value and that unique value is Unicode, this code will be the same for all the languages so that everyone can use them without hesitation and thinking as an issue for the other people to use this in their languages.

Once we assign some value of character or punctuation to any variable there will be a Unicode for that will also be there and that uncode will be similar for other environments which gives flexibility.

Examples to Implement Golang Rune

In the below, we have given some of the examples for the string and numeric and symbols type characters and we were tried to print the value of them. In case if we want to execute these examples then we can create a file with the name of chúng tôi and copy and paste the examples of the below codes and run the command go run chúng tôi We can even create file any name according to our requirements.

Example #1

Below is an example where we are working with the runs generated with the character and we are printing the output of every character and their Unicode also. We are also printing the type of character.

Code:

package main import ( "fmt" "reflect" ) func main() { code1 := 'B' code2 := 'g' code3 :='a' fmt.Printf("The actual code is : %c; The Unicode is: %U; Type: %s", code1, code1, reflect.TypeOf(code1)) fmt.Printf("nThe actual code is : %c; The Unicode is: %U; Type: %s", code2, code2, reflect.TypeOf(code2)) fmt.Printf("nThe actual code is : The Unicode is: %U; Type: %s", code3, reflect.TypeOf(code3)) }

Example #2

Below is an example where we are working with the runs generated with the numeric and we are printing the output of every numeric value and their Unicode also. We are also printing the type of numeric.

Code:

package main import ( "fmt" "reflect" ) func main() { r1:= '1' r2:= '2' r3:='3' fmt.Printf("The actual code is : %c; The Unicode is: %U; Type: %s", r1, r1, reflect.TypeOf(r1)) fmt.Printf("nThe actual code is : %c; The Unicode is: %U; Type: %s", r2, r2, reflect.TypeOf(r2)) fmt.Printf("nThe actual code is : The Unicode is: %U; Type: %s", r3, reflect.TypeOf(r3)) }

Output:

Example #3

Code:

package main import ( "fmt" "reflect" ) func main() { r1:= '*' r2:= '#' r3:='&' fmt.Printf("The actual code is : %c; The Unicode is: %U; Type: %s", r1, r1, reflect.TypeOf(r1)) fmt.Printf("nThe actual code is : %c; The Unicode is: %U; Type: %s", r2, r2, reflect.TypeOf(r2)) fmt.Printf("nThe actual code is : The Unicode is: %U; Type: %s", r3, reflect.TypeOf(r3)) }

Output:

Conclusion

From this tutorial, we learned the basic concept of the runs in the go language and we learned the working and its syntax. We also focus on some of its examples for understanding the runs for the character’s number and for the symbols.

Recommended Article

This is a guide to Golang Rune. Here we discuss the basic concept of the Golang Rune and its syntax along with the help of some useful examples and Code Implementation. You can also go through our other suggested articles to learn more –

You're reading How Does Rune Work In Go Language?

How Does Mutex Work In Go Language With Examples?

Introduction to Golang Mutex

Web development, programming languages, Software testing & others

Syntax of Golang Mutex

In the below syntax we can see the locking and unlocking of the operation.

First we lock with the help of the mutex, remember to use the mutex we need to import the package called sync, and on sync we can call the mutex locking.

Here locking means it will not take any other call till it will not complete the current call.

Second we are performing the operation, you can take any operation like addition or calculation of the amount from your current account also.

Once the activity for which the code block is there will be done the unlock will be called.

Unlock will remove the locking which we applied on the code block and again another call be taken.

Remember we use this only for locking to any very critical type of the code block and that code block is not needed to run in the concurrent (Here concurrent means the call should be made only for the code which can not run for multiple time for an user or related one specific attribute ).

Given below is the syntax:

mutex.Lock() y = y - number mutex.Unlock() How does Mutex work in Go Language?

You must have withdraw money from ATM many times suppose in your account there is 5000 rupees and you are doing ATM transaction as well as you are paying to some other shop also by using online medium of transaction in that case it can be possible that in ATM you have withdraw amount 5000 and 5000 you are trying to pay to your shop by online, now how to control this because if we will not control this than both the transaction can be done if both happens at the same time. Hence it will be a loss for the banks, so to avoid this kind of situations we use the concept of mutex which allow us for locking of particular code block. Here such case it will lock the code block for once it will find any transaction and will not allow other transaction till previous transaction which started will not complete.

Given below is the working of Mutex:

Mutex is the part of the sync, so to use the mutex we need to import the sync package of the go language.

Once we use the mutex.lock() whatever the code lock next to it will be there it will block that code till the execution of the code block will not complete.

Code blocks can be anything like calculation of any arithmetic calculation or calculation of the payment transactions.

Finally the process of unlocking mutex.unlock so once the unlocking get call means the code has completed and next execution for the code block can be allowed.

Examples of Golang Mutex

Given below are the examples mentioned:

Example #1

In this example we can see the race conditions which means code block is not getting locked and it will be called simultaneously and hence before completion of the previous call it will make another call and hence it will go into the race conditions.

Code:

package main import ( "fmt" "sync" ) var UPT = 0 func worker(st *sync.WaitGroup) { UPT = UPT + 1 st.Done() } func main() { var s sync.WaitGroup for i := 0; i < 1000; i++ { s.Add(1) go worker(&s) } s.Wait() fmt.Println("The y value is", UPT) }

Output:

Example #2

Code:

package main import ( "fmt" "sync" ) var UTV = 0 func worker(wt *sync.WaitGroup, k *sync.Mutex) { k.Lock() UTV = UTV + 1 k.Unlock() wt.Done() } func main() { var s sync.WaitGroup var n sync.Mutex for i := 0; i < 1001; i++ { s.Add(1) go worker(&s, &n) } s.Wait() fmt.Println("The y value is", UTV) }

Output:

Conclusion

From this article we saw the basic concept of the mutex in the go language, we saw the working of the mutex and we also saw about the syntax of the mutex. We focused on the some of the important examples of the mutex which can be used for real world.

Recommended Articles

This is a guide to Golang Mutex. Here we discuss the introduction, syntax, and working of mutex in go language along with programming examples. You may also have a look at the following articles to learn more –

How Does Pseudocode Algorithm Work?

Introduction to Pseudocode Algorithm

Pseudocode algorithm is used while programming or is associated with writing algorithms. Pseudocode is a method that helps the programmer to define an algorithm’s implementation. We can also say that pseudocode is a cooked-up representation of a basic algorithm. In pseudocode algorithms, the algorithms are represented using pseudo codes as it is easier for anyone to interpret the pseudo-codes even if they do not have any programming background or are used to a different programming language. As the name explains itself, pseudo-codes is a false code that can be understood by a layman with a basic knowledge of programming.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

How does Pseudocode Algorithm Work?

Writing an algorithm using pseudocodes is quite similar to writing in a coding language. Writing an algorithm is done on its own line in sequence. Generally, uppercase is used for writing the instructions and lowercase is used for writing the variables and the messages are written is sentence case. In pseudocode, the question is asked in INPUT and the message is printed by the OUTPUT.

Examples of Pseudocode Algorithm

Following are the examples as given below:

Example #1

In this example, we will check if the user has age below 50 years or more.

Step 1

Put the input value

The input is stored in the respective variable ‘age’

INPUT user inputs their age

STORE the user’s input in the age variable

Step 2

OUTPUT ‘My age is less than 50’

ELSE

OUTPUT ‘My age greater than 50’

OUTPUT ‘My age is:’ age

Actual Code:

print(“My age is :”, Age)

Output:

Example #2

Step 1

Put the input value

The input is stored in the respective variable ‘age’

INPUT user inputs their age

STORE the user’s input in the age variable

Step 2

Code:

OUTPUT ‘My age is:’ age

Code:

print(“My age is :”, Age)

Output:

Example #3

Step 1

Put the input value of Rahul’s age

The input is stored in the respective variable ‘Rahul’

INPUT user inputs their Rahul’s age

STORE the user’s input in the Rahul variable

Step 2

IF rahul< 50 THEN

OUTPUT ‘Rahul age is less than 50’

ELSE

OUTPUT ‘Rahul age greater than 50’

OUTPUT ‘Rahul age is:’ Rahul

Put the input value of Ankush’s age

The input is stored in the respective variable ‘Ankush’

INPUT user inputs their Ankush’s age

STORE the user’s input in the ankushvariable

Step 4

IF ankush<50 THEN

OUTPUT ‘Ankush age is less than 50’

ELSE

OUTPUT ‘Ankush age greater than 50’

OUTPUT ‘Ankush age is:’ Ankush

Step 5

Another condition is used here, where the values under the variables ‘Rahul’ and ‘Ankush’. If the condition fulfils then print the output statement otherwise print the else statement.

OUTPUT ‘Rahul is elder than Ankush’

ELSE

OUTPUT ‘Ankush is elder than Rahul’

Actual Code:

end

Output:

Example #4

Step 1

Put the input value of age

The input is stored in the respective variable ‘age’

INPUT user inputs their age

OUTPUT ‘Actually I am:’ age

Step 2

IF age == 60 THEN

OUTPUT ‘Got to know that, your age is 60’

Step 3

IF age==5 THEN

OUTPUT ‘Got to know that, your age is 5’

Step 4

ELSEIF age==0 THEN

OUTPUT ‘Got to know that, you are not born :P’

ELSE

OUTPUT ‘Sorry! I guess we are unable to determine your age’

OUTPUT ‘Told you man! my age is:’ age

Actual Code:

print(“Told you man! my age is: “, Age )

Output:

Advantages

Pseudo codes help the codes to majorly focus on the logic which is to be used in the program rather than the syntax of the programming language.

Pseudo codes are independent of any programming language which makes it easier to translate it into various languages.

The coders are given the liberty to express their logic in plain English language without any restraints of major syntaxes.

Writing actual codes become easier for the coder if they use pseudo-codes for writing the algorithm initially. As basic algorithms are not so concise and pseudo codes make the algorithm concise enough to make it more readable and easier for modification.

If we compare flow charts to pseudo-codes, flow charts are lengthier to write and difficult to represent. On the other hand, pseudo-codes are easier to write and programs can be easily translated. The coders just have to focus on the meaning underlined. The major line of focus is to solve the problem with logic rather than being stuck at using the language perfectly.

Using pseudo-code words and phrases while writing an algorithm eases the process of translation of algos into actual programming codes.

Conclusion Recommended Articles

This is a guide to Pseudocode Algorithm. Here we also discuss the definition and how the pseudocode algorithm works along with different examples and its code implementation. You may also have a look at the following articles to learn more –

How Does Snapchat Ai Work?

What to know

Snapchat’s MyAI is powered by OpenAI’s GPT 3.5 large language model. 

Snapchat is one of the first clients of OpenAI’s enterprise offering – Foundry – which provides dedicated compute power to run its AI model.

Snapchat’s My AI is essentially the free version of ChatGPT with its own set of capabilities and limitations that come from being tied to a social media platform.

It’s the season of artificial intelligence, and everyone’s buying into the game. From Microsoft to Google, everyone wants a piece of the AI pie and Snapchat is one of the recent players to join the growing list of companies integrating AI into their platforms to one-up the competition. Its ‘My AI’ chatbot offering is the result of just such an endeavor. But how does Snapchat’s AI exactly work? Let’s find out.

Related: How to Turn On Snapchat My AI

What is Snapchat’s My AI?

My AI is Snapchat’s version of a GPT-powered chatbot, bringing all the capabilities of generative AI to its social media platform. As one would expect from generative AI, it can be used to strike up general conversations over topics of varied kinds. 

Snapchatters can get it to write poems on the fly, suggest AR filters for snaps, gifts to purchase, restaurants to visit, and a whole lot more. 

Once My AI is available to you on Snapchat, you will see it added to your list of friends and will sit at the very top of the ‘Chat’ screen for easy access.

You can talk to it like any other friend on your list, customize its name and avatar, send it snaps, add it to group chats, and do just about everything that you can with generative AI tools like ChatGPT. 

You can unpin My AI from your Chat screen if it’s not to your liking, or clear it from your chat feed. But it will continue to remain on your list of friends, even with a Snapchat+ subscription.

Snapchat hopes My AI will be the personal AI assistant that you can turn to on a regular basis. Going forward, it appears that users will have to make space for the My AI chatbot on Snapchat, whether they like it or not.

Related: Snapchat My AI Not Working: 8 Ways to Fix

How does Snapchat My AI work?

To understand how Snapchat’s My AI works, we’ll need to dive into the language models and architectures that it is based on.

Built on GPT architecture

Snapchat’s My AI is built off of OpenAI’s GPT technology. So, it is going to be very similar to ChatGPT. Being a client of OpenAI has allowed Snapchat (and others) to bring generative AI capabilities to its platform by essentially leveraging the power of the GPT LLM and the copious amounts of data that it’s been trained on. 

Snapchat is one of the first to use OpenAI’s GPT architectural model as part of the latter’s Foundry developer platform. This lets Snapchat use dedicated computational resources for its AI models so users can get quick, snappy responses from the My AI chatbot. Though the exact GPT version that Snapchat uses hasn’t been disclosed, the underlying architecture is likely a modified version of GPT 3.5. 

Related: 9 Funny Things to Say to Snapchat AI

What can Snapchat AI do?

Thanks to the aforementioned language model and GPT architecture, My AI can generate human-like messages and converse in natural languages. But being on Snapchat, it has a few social media tricks up its sleeve.  

My AI can recommend you AR filters and lenses to spruce up your snaps…

… provide recommendations for places to eat or things to do, play games with you, or just hang out and have a laugh. It can also be brought into your conversations with friends with the @myai command in group chats to answer your questions. 

Moreover, Snapchat is looking to add the ability for My AI to snap you back with completely AI-generated images which will make for some fun conversations with AI whenever it’s made available.

Sure, it can sometimes be a little biased in its responses and may hallucinate about factual information from time to time. But that isn’t news to anyone who’s ever used such generative AI tools before. ChatGPT still is grappling with that issue and people still use it anyway.  

Snapchat AI shortcomings

Given all its GPT-powered prowess, Snapchat’s My AI isn’t all like ChatGPT. It can’t write essays for you or help you with your math homework, or code. It also isn’t connected to the web like Microsoft Bing or Google Bard and can’t serve as your daily news update either.

Snappers should see My AI as the free version of ChatGPT with its own set of capabilities and limitations that come from being tied to a social media platform. 

Related: How to Break Snapchat AI

FAQ

Let’s take a look at a few commonly asked queries about Snapchat’s My AI chatbot.

How is AI used in Snapchat?

Snapchat’s My AI uses generative artificial intelligence models built by OpenAI. It is designed to serve you as a personal assistant with AI capabilities that can do just about everything that chatbots built on GPT architectures can do.  

Is Snapchat AI free?

Yes, Snapchat’s My AI comes free with the latest update. 

Is My AI on Snapchat safe?

Depending on who you ask, you may get a slightly different answer about Snapchat’s My AI’s safety. Some users have reported concern over its ability to access your location without permission, while many believe its content moderation is broken and might generate harmful responses. However, as My AI continues to develop, users can expect Snap to redress these issues.  

Snapchat is one of the first OpenAI clients to use ChatGPT-like language models and dedicated compute as part of the latter’s Foundry developer platform. My AI’s capabilities and the speed with which it responds are a direct result of that. With reliability and moderation being bettered over time, users may come to eventually use My AI as Snapchat intends. 

We hope this guide helped you understand how Snapchat’s My AI works behind the scenes and what you can do with it. Until next time! Keep snapping.

Related: 2 Ways to Turn Off Snapchat AI

How Does Backward Propagation Work In Neural Networks?

This article was published as a part of the Data Science Blogathon                      

Introduction

We have dived deep into what is a Neural Network, its structure and components, Gradient Descent, its limitations and how are neurons estimated, and the working of the forward propagation.

Forward Propagation is the way to move from the Input layer (left) to the Output layer (right) in the neural network. The process of moving from the right to left i.e backward from the Output to the Input layer is called the Backward Propagation.

Backward Propagation is the preferable method of adjusting or correcting the weights to reach the minimized loss function. In this article, we shall explore this second technique of Backward Propagation in detail by understanding how it works mathematically, why it is the preferred method. A caution, the article is going to be a mathematically heavy one but wait for the end to see how this method looks in action 🙂

Table of Contents

Setting up the Base

Contribution of each Weight and Bias on the Error

Matrix Form of the Backward Propagation

Setting up the Base

Let’s say we want to use the neural network to predict house prices. For our understanding purpose here, we will take a subset dummy dataset having four input variables and six observations here with the input having a dimension of 4*5:

The neural network for this subset data looks like below:

Source: researchgate.net

The architecture of the neural network is [4, 5, 1] with:

4 independent variables, Xs in the input layer

5 nodes in the hidden layer, and

Since we have a regression problem at hand, we will have one node in the output layer.

A Neural Network operates by:

Initializing the weights with some random values, which are mostly between 0 and 1.

Compute the output to calculate the loss or the error term.

Then, adjust the weights so that to minimize the loss.

We repeat these three steps until have reached the optimum solution of the minimum loss function or exhausted the pre-defined epochs (i.e. the number of iterations).

Now, the computation graph after applying the sigmoid activation function is:

In case you are wondering how and from where this equation arrived and why there will be matrix dimensions then request you to read the previous article to understand the mechanism of how neural networks work and are estimated.

Building on this, the first step in Backward Propagation to calculate the error. In our regression problem, we shall take the loss function = (Y-Y^)2/2 where Y is actual values and Y^ is predicted values. For simplicity, replacing Y^ with O, so the error E becomes = (Y-O)2/2.

Our goal is to minimize the error that is clearly dependent on Y, which is the actual observed values, and on the output, which is further is dependent on the:

input values

coefficients or betas of the input variables

biases, the

activation function

, and

Optimizers

Now, we can neither change the input variables nor the actual Y values however, we can change the other factors. The activation function and the optimizers are the tuning parameters – and we can change these based on our requirement.

The other two factors: the coefficients or betas of the input variables (Wis) and the biases (bho, bih) are updated using the Gradient descent algorithm with the following equation:

Wnew = Wold – (α * dE/dW)

where,

Wnew = the new weight of Xi

Wold = the old weight of the Xi

α = learning rate

dE/dW is the partial derivative of the error for each of the Xs. It is the rate of change of the error to the change in weight.

In the backward propagation, we adjust these weights or the betas in the output. The weights and biases between the respective input, hidden and output layers we have here are Wih, bih, Who, and bho:

Wih: weight between the input and the hidden layer

bih: bias between the input and the hidden layer

Who: weight between the hidden and the output layer

bho: bias between the hidden and the output layer

In the first iteration, we randomly initialize the weights. In the second iteration, we change the weights of the hidden layer that is closest to the output layer. In this case, we go from the output layer, hidden layer, and then to the input layer.

Contribution of each Weight and Bias on the Error

Now, we have to calculate how much each of these weights (Wis) and biases (bis) contribute to the error term. For this, we need to calculate the rate of change of error to the respective weights and bias parameters.

In other words, we need to compute the terms: dE/dWih, dE/dbih, dE/dWho, and dE/dbho. This is not a direct task. It is a series of steps involving the Chain Rule.

The weight, Who, between the hidden and the output layer:

From the above graph we can see that the error E is not directly dependent on the Who:

The error term is dependent on the Output O

Output O is further dependent on Z2, and

Z2 is dependent on Who

Therefore we employ the chain rule to compute the rate of change in error to the change in weight Who and it becomes:

dE/dWho = dE/dO * dO/dZ2 * dZ2/dWho

Now, we take the partial derivatives of each of these individual terms:

E = (Y-O)2/2.

The partial derivative of error with respect to Output is: dE/dO = 2*(Y-O)*(-1)/2 = (O-Y)

The partial derivative of Output with respect to Z2, as output O = Sigmoid of Z2 and the derivative of sigmoid is:

dO/dZ2 = sigmoid(Z2) *(1-sigmoid(Z2)) = O*(1-O)

The partial derivative of Z2 with respect to Who is:

dZ2/dWho = d(WhoT * h1 + bh0)/dWho

dZ2/dWho = d(WhoT * h1)/dWho + d(bho/Who) = h1 + 0 = h1

Therefore, dE/dWho = dE/dO * dO/dZ2 * dZ2/dWho becomes:

dE/dWho = (O-Y) * O*(1-O) * h1

Similarly, we will calculate the contribution for each of the other parameters in this manner.

For the bias, bho, between the hidden and the output layer:

dE/dbho = dE/dO * dO/dZ2 * dZ2/dbho

dE/dbho = (O-Y) * O*(1-O) * 1

The weight, Wih, between the input and the hidden layer:

From the above graph we can see that the terms are dependent as below:

Error term is dependent on the Output O

Output O is dependent on 

Z2

Z2 this time is dependent on h1

h1 is dependent on Z1, and

Z1 is dependent on Wih

dE/dWih = dE/dO * dO/dZ2 * dZ2/dh1 * dh1/dZ1 * dZ1/dWih

So, this time, apart from the initial above dE/dO, dO/dZ2, we have the partial derivatives as follow:

The partial derivative of Z2 with respect to h1 is:

dZ2/dh1 = d(WhoT * h1 + bho)/dh1

dZ2/dh1 = d(WhoT * h1)/dh1 + d(bho/h1) = Who + 0 = Who

The partial derivative of h1 with respect to Z1, as h1 = Sigmoid of Z1 and the derivative of sigmoid is:

dh1/dZ1 = sigmoid(Z1) *(1-sigmoid(Z1)) = h1* (1 – h1)

The partial derivative of Z1 with respect to Wih is: X

dZ1/dWih = d(WihT * X + bih)/dWih

dZ1/dWih = d(WihT * X)/dWih + d(bih/Wih) = X + 0 = X

Hence, the equation after plugging the partial derivative value is:

dE/dWih = dE/dO * dO/dZ2 * dZ2/dh1 * dh1/dZ1 * dZ1/dWih

dE/dWih = (O-Y) * O*(1-O) * Who * h1(1-h1) * X

The bias, bih, between the input and the hidden layer:

dE/dbih = dE/dO * dO/dZ2 * dZ2/dh1 * dh1/dZ1 * dZ1/dbih

dE/dbih = (O-Y) * O*(1-O) * Who * h1(1-h1) * 1

Now, that we have computed these terms we can update the parameters using the following respective update equations:

Wih = Wih – (α * dE/dWih)

bih = bih – (α * dE/dbih)

Who = Who – (α * dE/dWho)

bho = bho – (α * dE/dbho)

Now, moving to another method to perform backward propagation …

Matrix Form of the Backward Propagation

The backward propagation can also be solved in the matrix form. The computation graph for the structure along with the matrix dimensions is:

Z1 = WihT * X + bih

where,

Wih is the weight matrix between the input and the hidden layer with the dimension of 4*5

WihT, is the transpose of Wih, having shape 5*4

X is the input variables having dimension 4*5, and

bih is a bias term, has a single value here as considering the same for all the neurons.

Z2 = WhoT * h1 + bho

where,

Who is the weight matrix between the hidden and the output layer with shape 5*1

WhoT, is the transpose of Who having a dimension of 1*5

h1 is the result after the applying activation function on the outcome from the hidden layer with a shape of 5*5, and

bho is the bias term, 

has a single value here as considering the same for all the neurons.

To summarize, the four equations of the rate of change of error with the different parameters are:

dE/dWho = dE/dO * dO/dZ2 * dZ2/dWho = (O-Y) * O*(1-O) * h1

dE/dbho = dE/dO * dO/dZ2 * dZ2/dbho = (O-Y) * O*(1-O) * 1

dE/dWih = dE/dO * dO/dZ2 * dZ2/dh1 * dh1/dZ1 * dZ1/dWih = (O-Y) * O*(1-O) * Who * h1(1-h1) * X

dE/dbih = dE/dO * dO/dZ2 * dZ2/dh1 * dh1/dZ1 * dZ1/dbih = (O-Y) * O*(1-O) * Who * h1(1-h1) * 1

Now, lets’ see how we can perform matrix multiplication on each of these equations. For the weight matrix between the hidden and the output layer, Who.

Let us understand how the shape of this Who must be similar to that of the shape of dE/dWho, which is to used to update the weight in the following equation:

Who = Who – (α * dE/dWho)

We saw above that dE/dWho is computed using the chain rule and is of the result:

dE/dWho = dE/dO * dO/dZ2 * dZ2/dWho

dE/dWho = (O-Y) * O*(1-O) * h1

Breaking the individual components of this above equation we see each part’s dimension:

dE/dO = (O-Y) as both O and Y have the same shape of 1*5. Hence, dE/dO is of dimension 1*5.

dO/dZ2 = O*(1-O) having a shape of 1*5, and

dZ2/dWho = h1, which is of the shape 5*5

Now, performing matrix multiplication on this equation. As we know, matrix multiplication can be done when the number of columns of the first matrix must be equal to the number of rows of the second matrix. Where this matrix multiplication rule defies, we will take the transpose of one of the matrices to conduct the multiplication.

On applying this our equation takes the form of:

dE/dWho = dZ2/dWho . [dE/dO * dO/dZ2] T

dE/dWho = (5X5) . [(1X5) *(1X5)]T

dE/dWho = (5X5) . (5X1) = 5X1

Therefore, the shape of dE/dWho 5*1 is the same as that of Who 5*1 which will be updated using the Gradient Descent update equation.

In the same manner, we can find perform the backward propagation for the other parameters using matrix multiplication and the respective equations will be:

dE/dWho = dZ2/dWho . [dE/dO * dO/dZ2] T

dE/dbho = dZ2/dbho . [dE/dO * dO/dZ2 ]T

dE/dWih = dZ1/dWih . [dh1/dZ1 * dZ2/dh1. (dE/dO * dO/dZ2)] T

dE/dbih = dZ1/dbih . [dh1/dZ1 * dZ2/dh1. (dE/dO * dO/dZ2)] T

Where, (.) dot is the dot product and * is the element wise product.

Endnotes

To summarize, as promised, below is a very cool gif that shows how backward propagation operates in reaching to the solution by minimizing the loss function or error:

Backward Propagation is the preferred method for adjusting the weights and biases since it is faster to converge as we move from output to the hidden layer. Here, we change the weights of the hidden layer that is closest to the output layer, re-calculate the loss and if further need to reduce the error then repeat the entire process and in that order move towards the input layer.

Whereas in the forward propagation, the pecking order is from the input layer, hidden, and then to the output layer which takes more time to converge to the optimum solution of the minimum loss function.

Thank You. Happy Learning! 🙂

The media shown in this article are not owned by Analytics Vidhya and are used at the Author’s discretion.

Related

How Does Umask Work In Linux With Syntax?

Introduction to Linux Umask

UMASK is an abbreviation for user mask and is sometimes called a User file creation mask. In Linux, there are many instances when one would need to create a file or a directory as per the use case requirement. While doing this, one needs to make sure that the permission of the newly created file or directory should comply with the use case scenarios. Now, suppose a Linux system is used for developing applications suited for only one kind of scenario tackling. In that case, it is erstwhile to change the base permission or the default permission of the newly created files or folders. UMASK is the command that comes in handy while fixing the default permission to something that most applications being developed in that Linux box would typically have.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax

Before we even jump into understanding what scenarios umask would help or what is the working principle of umask, it is beneficial to understand the syntax behind the umask so that while going through the working principle, we can keep the syntax in mind.

Syntax #1

0: read-write and execute

1: read & write

2: read & execute

3: read-only

4: write & execute

5: write only

6: execute only

7: no permission

If you recall from a previous understanding of file permission, you would see that the numbers are just the opposite of the actual file permission numbers. The reason is the calculation we will talk about. Using the numbers in the umask, you would see that the permission to the file or directory is the one you would be expecting as text and not the numbers listed above. So, for example, after calculation, if umask is 1st number is 0, you would get 7 or 6 as the 1st number post calculation, and that is exactly the number for reading, write and execute for a file or directory, respectively.

Syntax #2 umask u=rwx, g=, o=

Here umask is the same keyword, u refers to users, g refers to groups,o refers to others. And the letters r refers to read,w refers to write,x refers to execute. Here as well, there is a calculation that will follow to get to the actual file permission.

How Does Umask Work in Linux?

In order to understand how umask works in Linux, it is more important to note a few important parameters that become the base for obtaining the file permissions. By default, base permission for a file is 666, and the directory is 777. Number 7 won’t exist, and number 6 will have action as No permission in case of files. This is because it is a rule of thumb that files with execute permissions are not allowed to be created by Linux, and one would need to do that after the file is created and as a separate step!

The next thing is how and where do we change the value of umask. This needs to be changed in the ~/.bashrc file. ~/.bashrc lets you set parameters or attributes or configurations for terminal sessions. In case you need to change the umask for only current sessions, you would need to put it as a command-line input.

umask 027 umask

Output:

Once you have set the umask values, these will try to be used as a NOT operator to calculate the file permissions. As already mentioned, the default base permission for files is 666. The directory is 777; let us look at 2 different calculations (for files and directory) to understand how we arrive at permission numbers from the umask code.

Get File permission

The intention is to subtract the umask number from the base permission to get the actual file permission. For example, if the umask is 027 [0 (read & write for user), 2 (read-only for the group), 7 (no permission for others)] then the calculation is as follows:

Base permission: 666

umask: 027

File permission: 666 – 027 = 640* (rw-r—–)

*Please note that 6 – 7 is -1, but in Linux, it is adjusted to be 0.

Get Directory Permission

The intention is to subtract the umask number from the base permission to get the actual file permission. For example, if the umask is 022 [0 (read, write& execute for user), 2 (read & execute for group and others)] then the calculation is as follows:

Base permission: 777

umask: 027

File permission: 777 – 022 = 750 (rwxr-x—)

Groups can read and execute into a directory but can only read a file inside it.

Others can do nothing, i.e., no permission.

Without umask

Code:

mkdir new DirWO touch new FileWO ls -l

Output:

With umask

Code:

umask 027 mkdir newDir touch new File ls -l

Output:

A useful tip: Try to first understand the base scenario and then watch out for permission in a numerical form. Then subtract it from the base permission to get the umask number.

Conclusion

In this article, we have learned about how we use scenario-based numbering to understand what the default umask number should be, and then in accordance with that, we set up the umask either in bashrc or only for that terminal only as per requirement.

Recommended Articles

We hope that this EDUCBA information on “Linux Umask” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about How Does Rune Work In Go Language? on the Hatcungthantuong.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!