Reader small image

You're reading from  Expert C++ - Second Edition

Product typeBook
Published inAug 2023
PublisherPackt
ISBN-139781804617830
Edition2nd Edition
Right arrow
Authors (5):
Marcelo Guerra Hahn
Marcelo Guerra Hahn
author image
Marcelo Guerra Hahn

Marcelo Guerra Hahn, With over 18 years of experience in software development and data analysis, Marcelo Guerra Hahn is a seasoned expert in C++, C#, and Azure. As an Engineering Manager at Microsoft C++ Team and former leader of SoundCommerce's engineering team, Marcelo's passion for data and informed decision-making shines through. He shares his knowledge as a lecturer at esteemed institutions like Lake Washington Institute of Technology and University of Washington. Through this book, Marcelo aims to empower readers with advanced C++ techniques, honed by real-world experience, to become proficient programmers and skilled data analysts.
Read more about Marcelo Guerra Hahn

Araks Tigranyan
Araks Tigranyan
author image
Araks Tigranyan

Araks Tigranyan is a passionate software engineer at Critical Techworks, with an unwavering love for the world of programming, particularly in C++. Her dedication to crafting efficient and innovative solutions reflects her genuine passion for coding. Committed to excellence and driven by curiosity, Araks continuously explores new technologies, going above and beyond to deliver exceptional work. Beyond programming, Araks finds solace in sports, with football holding a special place in her heart. As an author, Araks aspires to share her profound expertise in C++ and inspire readers to embark on their programming journeys.
Read more about Araks Tigranyan

John Asatryan
John Asatryan
author image
John Asatryan

John Asatryan, the Head of Code Republic Lab at Picsart Academy, seamlessly blends his academic background in International Economic Relations from the Armenian State University of Economics with his ventures in technology and education. Driven by a genuine passion for coding, John's commitment to empowering aspiring developers is evident in his expertise in the field. His unwavering dedication to bridging the gap between education and technology inspires others to pursue their coding dreams.
Read more about John Asatryan

Vardan Grigoryan
Vardan Grigoryan
author image
Vardan Grigoryan

Vardan Grigoryan is a senior backend engineer and C++ developer with more than 9 years of experience. Vardan started his career as a C++ developer and then moved to the world of server-side backend development. While being involved in designing scalable backend architectures, he always tries to incorporate the use of C++ in critical sections that require the fastest execution time. Vardan loves tackling computer systems and program structures on a deeper level. He believes that true excellence in programming can be achieved by means of a detailed analysis of existing solutions and by designing complex systems.
Read more about Vardan Grigoryan

Shunguang Wu
Shunguang Wu
author image
Shunguang Wu

Shunguang Wu is a senior professional staff at Johns Hopkins University Applied Physics Laboratory, and received his PhDs in theoretical physics and electrical engineering from Northwestern University (China) and Wright State University (USA), respectively. He published about 50 reviewed journal papers in the area of nonlinear dynamics, statistical signal processing and computer vision in his early career. His professional C++ experience started with teaching undergraduate courses in the late 1990s. Since then he has been designing and developing lots of R&D and end-user application software using C++ in world-class academic and industrial laboratories. These projects span both the Windows and Linux platforms.
Read more about Shunguang Wu

View More author details
Right arrow

Understanding and Using C++ in Machine Learning Tasks

This book aims to provide you with a comprehensive guide to leveraging the power of C++ in the field of machine learning (ML). Whether you’re a beginner exploring the realms of artificial intelligence (AI) or an experienced developer looking to expand your skill set, this book will equip you with the knowledge and tools necessary to apply C++ effectively to ML tasks. ML has become a fundamental discipline in the realm of AI, enabling computers to learn from data and make predictions or decisions without explicit programming. As the demand for intelligent systems continues to grow, so does the need for robust programming languages that can handle the computational complexities of ML algorithms. This is where C++ shines. So, whether you’re a researcher, a data scientist, or simply a curious learner, we hope this book will serve as your roadmap to mastering C++ in the realm of ML. We invite you to dive in, experiment...

Technical requirements

The g++ compiler with the -std=c++2a option was used to compile the examples in this chapter. You can find the source files that were used in this chapter at https://github.com/PacktPublishing/Expert-C-2nd-edition.

Introduction to AI

The simplest definition of AI is robots acting like humans. It is the intelligence demonstrated by machines. And this is where the discussion around the definition of intelligence comes in: how can we define it for machines, and at what level should we shout out loud that we are dealing with an intelligent machine?

If you are not familiar with the different tests we can use to verify the intelligence of a machine, one of the popular ways to do so is the Turing test. The idea is to have an interrogator asking questions to two people, one of them being a machine and the other a human. If the interrogator can’t make a clear distinction between those two, the machine should be considered intelligent.

Note

The Turing test is named after Alan Turing. The test was introduced in his paper, Computing Machinery and Intelligence, in 1950. He proposed using the imitation game to determine whether a machine thinks like a human.

The people being interrogated...

ML

ML takes us to a whole new level of making machines execute tasks the way humans do, maybe even better. Compared to the fields we introduced previously, the goal of ML is to build systems that can do things without specific instructions. In the journey of inventing artificially intelligent machines, we should take a closer look at human intelligence. When a child is born, they don’t express intelligent behavior; instead, they start to slowly become familiar with the surrounding world. There is no recorded evidence of any 1-month-old child solving differential equations or composing music. In the same way that a child learns and discovers the world, ML is concerned with building the foundational models that directly perform the tasks and learning how to do them. That’s the fundamental difference between setting up a system to carry out predefined instructions and letting it figure it out on its own.

When a child starts walking, taking things, talking, and asking...

Neural networks

Neural networks are designed to recognize patterns. They are modeled after the human brain; more specifically, we speak about neurons of the brain and their artificial counterparts – artificial neurons. A neuron in the human brain is illustrated in the following diagram:

Figure 16.9 – A neuron in the human brain

Figure 16.9 – A neuron in the human brain

A neuron communicates with other neurons via synapses. The basic functionality of a neuron is processing a portion of data and producing signals based on that data. In programming terms, a neuron takes a set of inputs and produces an output.

That’s why the following diagram makes it clear why an artificial neuron is similar to the human brain’s neuron structure:

Figure 16.10 – The human brain’s neuron structure

Figure 16.10 – The human brain’s neuron structure

ANNs consist of interconnected artificial neurons or nodes organized in layers, and they are primarily used for ML and pattern recognition tasks....

Clustering

Clustering is concerned with grouping a set of objects to distribute them into groups of similar objects. Also known as cluster analysis, this is a set of techniques and algorithms that intends to group similar objects, producing clusters. The simplest illustrative introduction would be grouping a set of colored objects into different groups consisting of objects of the same color, as follows:

Figure 16.11 – Clustering

Figure 16.11 – Clustering

Although we are discussing AI tasks in this chapter, we suggest that you first try to solve problems with the knowledge base that you have so far. Let’s think about how we would categorize objects by similarity. First of all, we should have a basic idea of what the object will look like. In the preceding example, we are looking at an object’s shape, color, dimensions (the width and height of a 2D object), and so on. Without going much deeper, a basic representation of an object might look like this:

classObject...

Regression analysis

Regression analysis is concerned with finding the deviations for one value from another. The simplest way of understanding regression analysis is through the graphs for functions in mathematics. You might recall the graph for the f(x) = y function:

Figure 16.12 – Graph for the f(x) = y function

Figure 16.12 – Graph for the f(x) = y function

For every value of x, the function results in a fixed value for y. Regression analysis is somewhat similar to the preceding graph as it is concerned with finding a relationship between variables. More specifically, it estimates relationships between a dependent variable and several independent variables. The dependent variable is also known as an outcome, while the independent variables are also referred to as features. The number of features might be 1.

The most common form of regression analysis is linear regression. It looks similar to the preceding graph. Here’s an example representing the relationship between hours spent...

C++ and ML

It’s now no longer a secret that ML is more about math than programming. Computer science has its roots in mathematics and, in the early years, computer scientists were mathematicians first. You might be familiar with several eminent scientists, including Alan Turing, John von Neuman, Claude Shannon, Norbert Wiener, Niklaus Wirth, Donald Knuth, and many others. All of them are mathematicians with a special love for technology. During its development, computer programming became a more friendly field to newcomers. In the last two or three decades, computer programmers stopped being forced to learn math before developing useful programs. Languages evolved into more and more high-level tools that allow almost everyone to code.

There are plenty of frameworks that make this job easier for programmers. It now takes a matter of weeks to grasp some framework or a high-level programming language and create a new program. Programs, however, tend to repeat themselves. It...

Summary

In this chapter, we introduced ML, alongside its categories and applications. It is a rapidly growing field of study that has numerous applications in building intelligent systems. We categorized ML into supervised, unsupervised, and reinforcement learning algorithms. Each of these categories has its applications in solving tasks, such as classification, clustering, regression, and machine translation.

Then, we implemented a simple learning algorithm that defines a calculation function based on experiences provided as input. We called this a dataset and used it to train the system. Training with datasets (called experiences) is one of the key properties of ML systems.

Finally, we introduced and discussed ANNs and applied them to recognize patterns. ML and neural networks go hand in hand in solving tasks. This chapter provided you with a necessary introduction to this field, along with several examples of tasks, so that you can spend some time diving into the topic. This...

Questions

Answer the following questions to test your knowledge of this chapter:

  1. What is ML?
  2. What are the differences between the supervised and unsupervised learning algorithms?
  3. Give some examples of ML applications.
  4. How would you modify the CalculationMachine class to change its behavior after training it with a different set of experiences?
  5. What is the purpose of neural networks?

Further reading

To learn more about the topics that were covered in this chapter, take a look at the following resources:

  • Artificial Intelligence and Machine Learning Fundamentals: https://www.packtpub.com/product/artificial-intelligence-and-machine-learning-fundamentals/9781789801651
  • Machine Learning Fundamentals: https://www.packtpub.com/product/machine-learning-fundamentals/9781789803556
  • Hands-On Machine Learning for Algorithmic Trading: https://subscription.packtpub.com/search?query=hands%20machine%20learning%20algorithmic%20trading
  • OpenCV: https://opencv.org/
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Expert C++ - Second Edition
Published in: Aug 2023Publisher: PacktISBN-13: 9781804617830
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (5)

author image
Marcelo Guerra Hahn

Marcelo Guerra Hahn, With over 18 years of experience in software development and data analysis, Marcelo Guerra Hahn is a seasoned expert in C++, C#, and Azure. As an Engineering Manager at Microsoft C++ Team and former leader of SoundCommerce's engineering team, Marcelo's passion for data and informed decision-making shines through. He shares his knowledge as a lecturer at esteemed institutions like Lake Washington Institute of Technology and University of Washington. Through this book, Marcelo aims to empower readers with advanced C++ techniques, honed by real-world experience, to become proficient programmers and skilled data analysts.
Read more about Marcelo Guerra Hahn

author image
Araks Tigranyan

Araks Tigranyan is a passionate software engineer at Critical Techworks, with an unwavering love for the world of programming, particularly in C++. Her dedication to crafting efficient and innovative solutions reflects her genuine passion for coding. Committed to excellence and driven by curiosity, Araks continuously explores new technologies, going above and beyond to deliver exceptional work. Beyond programming, Araks finds solace in sports, with football holding a special place in her heart. As an author, Araks aspires to share her profound expertise in C++ and inspire readers to embark on their programming journeys.
Read more about Araks Tigranyan

author image
John Asatryan

John Asatryan, the Head of Code Republic Lab at Picsart Academy, seamlessly blends his academic background in International Economic Relations from the Armenian State University of Economics with his ventures in technology and education. Driven by a genuine passion for coding, John's commitment to empowering aspiring developers is evident in his expertise in the field. His unwavering dedication to bridging the gap between education and technology inspires others to pursue their coding dreams.
Read more about John Asatryan

author image
Vardan Grigoryan

Vardan Grigoryan is a senior backend engineer and C++ developer with more than 9 years of experience. Vardan started his career as a C++ developer and then moved to the world of server-side backend development. While being involved in designing scalable backend architectures, he always tries to incorporate the use of C++ in critical sections that require the fastest execution time. Vardan loves tackling computer systems and program structures on a deeper level. He believes that true excellence in programming can be achieved by means of a detailed analysis of existing solutions and by designing complex systems.
Read more about Vardan Grigoryan

author image
Shunguang Wu

Shunguang Wu is a senior professional staff at Johns Hopkins University Applied Physics Laboratory, and received his PhDs in theoretical physics and electrical engineering from Northwestern University (China) and Wright State University (USA), respectively. He published about 50 reviewed journal papers in the area of nonlinear dynamics, statistical signal processing and computer vision in his early career. His professional C++ experience started with teaching undergraduate courses in the late 1990s. Since then he has been designing and developing lots of R&D and end-user application software using C++ in world-class academic and industrial laboratories. These projects span both the Windows and Linux platforms.
Read more about Shunguang Wu