• No results found

Automating rule creation in a Smart Home prototype with Learning Classifier System

N/A
N/A
Protected

Academic year: 2021

Share "Automating rule creation in a Smart Home prototype with Learning Classifier System"

Copied!
50
0
0

Loading.... (view fulltext now)

Full text

(1)

INOM

EXAMENSARBETE TEKNIK,

GRUNDNIVÅ, 15 HP ,

Automating rule creation in a

Smart Home prototype with

Learning Classifier System

ANTON ANDERZÉN

MARKUS WINROTH

KTH

(2)

TRITA TRITA-EECS-EX-2018:272

(3)

Abstract

The name ”smart homes” gives a promise of intelligent behavior. Today au-tomation of the home environment is a manual task, with the creation of rules controlling devices relying on the user. For smart homes this tedious manual task can be automated. The purpose of this thesis is development of a pro-totype that will help users in smart homes create rules. The rules should be automatically created by the use of a machine learning solution. A learning classifier system algorithm is found as a suitable machine learning solution. A learning classifier system is used to find and create rules from sensor data. In the prototype a Raspberry Pi is used to collect the data. This data is pro-cessed by the learning classifier system, generating a set of rules. These rules predict actions for controlling a smart lighting system. The rules are tinuously updated with new sensory information from the environment con-stantly reevaluating the previous found rules. The learning classifier system prototype solves the problem of how rules can be generated automatically by the use of machine learning.

Keywords: Artificial Intelligence; Learning Classifier System; Smart Homes; Machine Learning; Reinforcement Learning; Device Hub

(4)

Abstract

Uttrycket ”smarta hem” utlovar ett intelligent beteende. Idag är automatis-eringen av hemmiljön en manuell uppgift, där användaren formulerar re-gler som styr systemet. I smarta hem kan denna uppgift bli automatiserad. Syftet med denna kandidatuppsats är att utveckla en prototyp som ska hjälpa användare i smarta hem att skapa regler. Reglerna ska skapas automatiskt med hjälp av en maskininlärningslösning. Ett självlärande klassificeringssys-tem bedöms uppfylla den kravställning som görs. Det självlärande klassifi-ceringssystemet används för att skapa regler från sensordata. I prototypen används en Raspberry Pi för att samla in data. Insamlad data behandlas av det självlärande klassificeringssystem som genererar en uppsättning re-gler. Dessa regler används för att kontrollera ett smart ljussystem. Reglerna uppdateras kontinuerligt med ny sensorinformation från omgivningen och utvärderar de tidigare funna reglerna. Den självlärande klassificeringssystem-prototypen löser problemet om hur regler kan skapas automatiskt med hjälp av maskininlärning.

Nyckelord: Artificiell Intelligens; Självlärande Klassificeringssystem; Smarta Hem; Maskininlärning; Belöningsinlärning; Kontrollenhet

(5)

Contents

1 Introduction 1 1.1 Background . . . 1 1.2 Problem . . . 2 1.3 Purpose . . . 2 1.4 Goal . . . 2

1.4.1 Benefits, Ethics and Sustainability . . . 2

1.5 Methodology . . . 3 1.6 Stakeholders . . . 4 1.7 Delimitations . . . 4 1.8 Outline . . . 4 2 Machine Learning 5 2.1 Learning methods . . . 5 2.2 Genetic algorithm . . . 6

2.3 Learning Classifier System . . . 6

2.4 Artificial Neural Networks . . . 8

2.5 Decision trees . . . 10 3 Control Unit 12 3.1 Sensors . . . 12 3.2 Connectable devices . . . 12 3.3 Connection protocols . . . 13 3.4 Related Work . . . 13 4 Method 15 4.1 Scientific Method and Methodologies . . . 15

4.2 Project Methods . . . 16

4.2.1 Sequential method . . . 16

4.2.2 Iterative method . . . 17

5 Applied Methodology 19 5.1 Hardware Requirements . . . 19

5.2 Model Requirements and Delimitations . . . 20

5.3 Algorithm Requirements . . . 20

5.4 Iterative Work . . . 21

6 The system 22 6.1 The test environment . . . 22

6.2 Comparing algorithms . . . 22

6.3 Data collection . . . 23

6.4 Evaluation of the algorithm . . . 25

7 Implementing the algorithm 26 7.1 Grabbing . . . 26

7.2 Matching . . . 27

7.3 Covering . . . 28

(6)

7.5 Subsumption . . . 29

7.6 Genetic algorithm . . . 30

7.7 Deletion . . . 31

7.8 Evaluating the Implementation . . . 32

7.9 Summary and reflection . . . 34

7.10 Third party evaluation . . . 35

8 Conclusions 37 8.1 Discussion . . . 38

8.2 Future work . . . 38

(7)

1

Introduction

Artificial intelligence [1] is a research area of creating intelligent behavior in com-puter systems. In recent years, artificial intelligence has become a buzz word. Ar-tificial intelligence is techniques used to draw conclusion from large sets of data, perform statistical analysis and decision systems based on reasoning strategies. This can be used to create intelligent behavior in homes [2]. Temporal data min-ing is the process of extractmin-ing knowledge from continuously collected data [3]. The temporal data mining is a big part of the smart homes sensory system, since the sensors continuously generate large quantities of data [4]. Collected data can be used for automation of devices in smart homes by contributing to the systems knowledge base [5].

A smart home [2] is a home containing technologies that assists occupants with their comfort, security and entertainment [6]. The smart home manages commu-nication in the technology within the home, and the outside world. Products able to communicate with each other can act upon data received. Any electrical devices in a home could potentially be turned into a smart product and make the home act smarter. To create intelligent behavior in the smart home system, many rules that simplify ordinary life need to be designed by the user [7]. To automate the process of creating rules, artificial intelligence techniques can be used [5].

1.1

Background

Artificial intelligence techniques have potential to be used in smart homes [5]. One of the techniques that can be used is machine learning. Machine learning [8] is the process of training a system to recognize patterns in data. To train a ma-chine learning system, feedback is used to rate the predictions in some way. This can be done by supervising the outcome of the trained system and comparing it to expected result, called supervised machine learning. To use supervised ma-chine learning, a set of expected outcomes for specific inputs are needed. In some cases, there is no set of expected results, which means that supervised learning is not possible. When the outcome cannot be supervised, unsupervised machine learning can be used. Unsupervised machine learning has no expected result but is trained to discover internal relations in the input data. Not all machine learning techniques can be classified as either supervised or unsupervised. Reinforcement learning is a technique that does not need examples of input or output data, but instead works with a feedback system. In reinforcement learning the machine learning system is rewarded when a good prediction is made and punished when a bad prediction is done. This makes the reinforcement learning system modify itself to receive more awards and thus be better at predicting actions. [9]

Machine learning approaches are found in smart homes in the form of devices like, home security devices [10] and service robots [11]. Smart home systems have been made as a gateway for devices to communicate and share data to each other[7,12]. Even though some devices in smart homes use machine learning, the smart home systems as a central unit does not. The Homey [13] and Samsung SmartThings [12] use an interface for controlling all connected devices. These smart home

(8)

sys-tems allow the user to create rules to control the devices. A rule could be that the system turns off a device at a certain sensor value. The rule creation in the Homey and Samsung SmartThings systems require that the user manually creates rules.

1.2

Problem

To create a smart behavior in smart homes many rules for several different kinds of devices will be needed to be created by the user. The manual creation of rules in the smart home systems of today is an exhausting and demanding manual process. The user may not have time or the technological knowledge of how to create good rules to control the devices. The tedious task that is rule creation can be automated by a smart home system by the use of machine learning. Machine learning solu-tions can find patterns in data from smart home devices and automatically create rules to control the connected devices. How can rules be generated automatically by the use of machine learning?

1.3

Purpose

The purpose of this thesis is development of a prototype that will help users in smart homes create rules. The rules should be automatically created by the use of a machine learning solution. Machine learning is not only applicable in smart homes, therefore the thesis is relevant for not only a smart home system prototype but for larger scale smart homes, and other areas where machine learning can be applied.

1.4

Goal

The goal of this project is to build a smart home system prototype. The prototype should be able to autonomously create rules on how to control the connected de-vices based on different sensor data. The automation of rule creation should be achieved with the use of machine learning.

1.4.1 Benefits, Ethics and Sustainability

Smart systems have ways of contributing to society by increasing the effectiveness of devices that is already used. A lighting system controlled by measured sensor data from around the home can save energy when the respective system is not needed. Another thing to consider is the possible rebound effect that with this new smart control system, consumers might buy additional smart products. This might lead to the products consuming more energy in total, than with fewer, non-smart products.

Since the system will be monitoring homes to a certain extent, integrity and secu-rity are two elements that must be considered. Since the system does not collect information that can be linked to a specific person the ”General Data Protection Regulation” law [14] does not directly apply. However, the data collected might be interesting to external actors. This affects the end-users that will need to be informed on what data is collected and assured that it is protected.

(9)

From a sustainability viewpoint, using the three dimensions of sustainable de-velopment [15], the system has part environmental, part economical and part so-cial impact. The environmental impacts of the system can be both positive with decreased energy use in smart systems, and negative increased consumption, pro-duction of units for example. This can be analyzed in three steps by first looking at the life-cycle of the product, then the applications direct effects, lastly the be-havioral changes that the product might have made possible [16]. In this case the production of the parts, the energy use and the recycling process of the disposed product make up the first life-cycle part. The application of this product will hope-fully decrease the energy used in homes without compensation of the functional-ity of the smart home systems. The behavioral changes that the product induces might lead to negative consequences. More high-technological products will have to be produced to get the level of intelligence that are expected of a system like this. This would lead to consequences for the environment.

1.5

Methodology

The Qualitative research method is related to meanings, opinions and behaviors. This can be used to create a hypothesis, theory or a computer system. Data col-lection is continued until saturated. Smaller data sets are used, sufficient enough to produce reliable results [17]. The Qualitative research method is used when observing and interpreting reality with the aim of developing a theory that will explain what was experienced. The Quantitative research method is used when the research starts with a theory or hypothesis and validate if it holds true or not [18]. This can be used to test theories or functionality in existing systems. The hypothesis needs to be measurable in a quantifiable manner. Large data sets are needed to produce results that are statistically significant [17]. A qualitative re-search methodology will be used since this thesis will not start with a theory or hypothesis and the system will not result in the amount of measurable data needed to use a quantitative method.

Inductive approach is creating theories from observations and patterns. It is also used in system development. Qualitative methods are most commonly used for collecting data for when using an inductive approach. Conclusions are bound to behaviors, opinions, and experiences. Because of this, enough data must be used to support the reasons of these conclusions [17]. During this project an inductive approach is used. The inductive approach makes it possible to gather relevant in-formation and use that inin-formation in the prototypes’ development.

During the literature study information was collected from several online databases such as Google Scholar, IEEE Xplore, Primo. Google Scholar and IEEE Xplore was used to find scientific reports. Primo was used to find scientific reports and books related to the subject. Information on specific related products such as specifica-tions was found on the websites of said products. Informal interviews with stake-holder Anne Håkansson are held to identify and delimit a problem for the thesis.

(10)

1.6

Stakeholders

A stakeholder of this thesis is associate professor Anne Håkansson at Royal In-stitute of Technology (KTH). Håkansson conducts research within Computer sci-ence with the focus on artificial intelligsci-ence. For this project Håkansson provides a testbed and help in the process of formulating a problem relevant for the area smart homes. She is interested in the results of this thesis project for further re-search within the area.

1.7

Delimitations

This thesis focuses on exploring how a machine learning algorithm can set up rules to control smart home devices. The possibility to apply other artificial in-telligence techniques will not be evaluated. The resulting system is tested in an office environment, this should be noted as it excludes tests in other alternative environments where other performance might be relevant. The project in this the-sis is to be considered as a platform for future implementations within the area of automating smart homes.

1.8

Outline

The remainder of this thesis is structured as follows. In chapter two, the theo-retical background, machine learning algorithms are described. In chapter three, technical information on the devices used in the project is described. Methods, chapter four, describe what project methods are used during the project and ex-plain why some other methods might have been disregarded. Beyond that, it also describes what the scientific methodology is and how it is used. Chapter five de-scribes the use of research methodology in the collection of requirements for the prototype. It also describes how the project method was used in development. In chapter six, the setup of the system and data collection in its entirety is described. Here the comparison of the candidates is presented and a choice of an algorithm to implement is made. In chapter seven, Implementing the Algorithm, the re-sult of the project work is presented. The rere-sult is a description of the algorithm implementation, as well as evaluation of the algorithm. Chapter eight is where conclusions are drawn based on the resulting implementation. Beyond this, the project and research methodologies are described. The effects of the resulting im-plementation are also discussed and relevant continuation of the conducted work is proposed.

(11)

2

Machine Learning

Machine learning brings together statistics and computer science to enable com-puters to learn how to do a certain task without being programmed to do so. For example, when giving the task of categorizing images containing either an apple or and orange, the machine learning algorithm tries to find statistical patterns within multiple pictures of apples and oranges. The images used for training the system is usually called a training set. The patterns recognized can be features like the shape or the color of the object in the image. With this statistical patterns the algorithm will be able to recognize if a new image contain either an apple or an orange. Machine learning is often classified into either supervised learning, unsupervised learning or reinforcement learning [9]. All three machine learning methods receive input data and predict an output value.

2.1

Learning methods

Supervised learning algorithms are trained with input data paired with a known desired output. Supervised learning trains on a dataset with inputs linked to de-sired outputs and find correlations in the data [8]. With every new dataset con-taining input data and correct outputs, a supervised algorithm compares its actual output with the correct output from the data instance to find any errors and mod-ifies the predicted outcomes according to the error found. Once the algorithm is trained it can be fed some new input and predict an outcome based on the corre-lations found in the training dataset.

There is two main types of supervised learning, classification and regression. Clas-sification is when the system predicts a continuous value as the probability of an outcome. If the task is to distinguish if the outcome should be A or B, the system could produce an outcome of 0.7 for A and 0.3 for B, meaning that the system is 70% sure that A is correct and 30% chance that B could be correct [19]. When there are problems that cannot be solved with only 2 different kinds of outputs, regression could be used instead. Regression differs from classification in the way that the output from the regression is a quantity instead of either A or B. Instead of just giving two different outputs and the probability between them, regression can give a specific value [19]. For example, if regression is used as a salary pre-dictor, the age, sex, work experience etc could be used as an input and the system would then predict a value as the salary of the corresponding input data based on previously trained datasets.

Unsupervised learning is not trained on a desired outcome. Instead, unsuper-vised learning tries to find patterns within the input data, a process called cluster-ing. [20]. Clustering is the task of grouping a set of inputs together that is more similar with other inputs in the same cluster then in other clusters. [9].

Reinforcement learning is a machine learning method which works with giving positive or negative feedback to an agent depending on its actions. An agent is an autonomous entity which gets input about the environment and makes an action to try to reach its goal. The environment can be entirely artificial, with the only

(12)

inputs being from the computer itself in the form of keyboard inputs, databases, or events from other programs. The environment can also be the environment around us, getting input from sensors an agent could explore a room and perform tasks that leads to a desired goal. Given a pool of possible actions, an agent pre-dicts which action it thinks leads to the goal. If the prediction is accurate the agent is fed positive feedback and gets encouraged to do the same action again. If the agent preforms poorly it is given negative feedback and tries to avoid that action in the future. Over time the pool of actions gets weighted depending on how much closer the action got the agent to the goal. An action which constantly gets the agent closer to the goal will have more chance to be chosen as the next prediction with the same input values from the environment. [21]

2.2

Genetic algorithm

A genetic algorithm is used for finding optimized solutions to a problem based on the theory of natural selection and evolutionary biology. There are multiple differ-ent ways to design a genetic algorithm. The basics of a genetic algorithm initiates with generating a random population of suitable solutions to a problem. The next step is to evaluate the fitness of the solutions. The fitness is a measurement of how close the solution is to the optimal solution, with other words how fit the solution is the problem. The fitness function varies depending on the given problem. The algorithm deletes the solutions that have a low fitness and keep the ones with a high fitness. By combining two solutions with high fitness, the algorithm can in-troduce actions not previously known. This way of combining solutions is called crossover.

The crossover is when two solutions gets chosen as parents, mix its features and create an offspring solution. Which two solutions to be selected as parents can be done in various ways, either the two solutions with the highest fitness is chosen or the algorithm can have different procedures to choose the parent. The mixing of features can be done in different ways. The most common ones use one or sev-eral crossover points. When there is only one crossover point the first features up to the crossover point is taken from the first parent and the rest of the features is taken from the second parent. There could also be implemented a low chance of mutation of each feature within the solution. If a mutation occurs the feature affected switches value to another value possible. This is done to further explore the possible solutions. One iteration of all these steps is often called a generation. A genetic algorithms strength lies in that it iterates over many generations, con-stantly trying to find a higher fitting solution until a end criterion is met. One well used end criterion are a maximum amount of generations. Another end criteria is to stop if the algorithm has not found any better solution in the last 20-30% of generations [22].

2.3

Learning Classifier System

Learning classifier systems (LCS) is a machine learning approach which combines genetic algorithms, reinforcement learning and heuristics to create adaptive rule-based systems. The foundation for LCS was made by David E. Goldberg and John

(13)

H. Holland with their work Genetic Algorithms and Machine Learning [22]. The rules are often represented in the usual production system form of ”IF condition THEN action” which suits this project well. Learning classifier system do not de-fine exactly how the system should be or which algorithms to use, it is more to be considered as a design composing of different parts. [23]

The environment consists of a data-set with several training sets. Each training set consist of different features and a class. The features are different conditions, for example one feature could be temperature and the value of that condition could be 10. The class is the action that the rule takes. If all of the conditions are met, the action is taken. Learning classifier system relies on incremental learning, which is that it learns one instance from the environment at a time. One instance is taken from the environment, goes through the learning stage of LCS and the returns to the environment. This is repeated until a end criterion is met. [24]

The LCS algorithm consists of seven steps.

• 1. Grabbing - Takes a training instance from the environment

• 2. Matching - Matching checks if the training instance conditions matches any conditions already in the population of rules. If it is a match it is moved to the match set. The match set is divided into two different parts. First part is called the correct set, this is the set where all the matches that also matches the class is stored. The other part is called the incorrect set, this is the set where all the matches that does not have the same class is stored. • 3. Covering - This is only done if the correct set is empty. Covering is one

of two ways that LCS can introduce new rules into the population. Cover-ing works by generatCover-ing a rule condition that randomly specifies a subset of attribute values in the current training instance. The predicted class of the rule is set to the same as the current training instance.

• 4. Parameter updates - Every condition in the population has attached pa-rameters to it. The papa-rameters is values like how many times it got correctly matched and the fitness of the condition. Fitness is the value that describes the quality of the condition. A high fitness value means that the suggested solution is accurate. This stage is where all the parameters of every condi-tion in the populacondi-tion are updated depending on the matching set. If the condition were in the correct set it gets increased values for fitness and if it were in the incorrect set it get decreased value in fitness.

• 5. Subsumption - This is the step where the learning machine checks if there are any rules that can be covered by other rules in the population to be more generalized. The fitness value of the subsumer needs to be equal or greater than for the subsumed rule.

• 6. Genetic Algorithm - This step is where a genetic algorithm is applied to discover new conditions to put in the population. How many new conditions to discover and put into the population depends on what type of genetic al-gorithm the LCS use.

(14)

• 7. Deletion - Deletion is the removal of conditions with a bad fitness. This is to ensure that the population stays relevant to the environment.

The steps can be broken down into different categories depending on what they do in the algorithm. The steps covering and genetic algorithm is the only way the algorithm can discover new rules. Subsumption and deletion is the steps where rules can be deleted. The rest of the steps, grabbing, matching and parameter updates is where the algorithm evaluates the population.

2.4

Artificial Neural Networks

An artificial neural network can be used for drawing conclusions from data, called classification. The overall structure of the artificial neural network is as displayed in figure2. It has three types of layers, the input layer, the hidden layers, and the output layer. Each layer consists of neurons, inspired by the neurons in the brain which collect, process, and spread information. The internal structure of the neu-ron is displayed in figure1.

Figure 1: The internal structure of a single neuron in an artificial neural network. Source: Anton Anderzén

The neuron takes input from one or several sources and sums up the data from these sources. In addition to the ordinary inputs, a bias input is added. The sum is fed into an activation function, were the bias can control the value at which the activation function will make the node fire. The activation function used can be a threshold function, sigmoid function or some other function with similar effects. A key point of the activation function is that it can be tuned by a bias to control the output value. [25]

(15)

Figure 2: A graph displaying the general structure of an artificial neural network. Source: Anton Anderzén

The neural network structure described in figure2and this section is a feed-forward network structure. In figure2the network has two hidden layers, it could have more or less, but at least one. A feed-forward neural network has no internal state, but the outputs are always a function of the current inputs. The input layers neu-rons are fed with information from the observed environment. Every input neuron then passes forward the processed information to all neurons in the hidden layer through a weighted path. The hidden layer neurons process the information re-ceived, and sends it forward to another hidden layer or the output layer depending on the number of hidden layers. Each output layer neuron represents a separate class, and its value represents the likelihood of that specific class given the current input. [25]

What outputs a specific input will result in is determined by the weights of the paths between the neurons in the network. These weights can all be adjusted to change the function of the network. This is done by back-propagation, an expected outcome for a specific input is compared to the actual output. The error discov-ered between the expected and the actual output minimized is by recalibrating the

(16)

weights backwards through the layers. The training, by back-propagation is done for a part of a disjoint set of data. The other part of data is kept as an evaluation set, so that an accuracy of the trained network can be calculated. [25]

Some problems exist with artificial neural networks. Overfitting is one of these problems. Overfitting occurs when a neural network is trained for a specific set of data so that it makes few generalizations. The accuracy for the examples in the training set is very good but the ability to classify new examples, like the eval-uation set, is not. Underfitting is another of these problems, occurring when the training was not sufficient at all. The conclusions of a network that is underfitting, will be too general and result in a low accuracy. The black box problem is another of these, the difficulty being that the internal relations and representations of the hidden layers is hard to discover. The black box problem [26] leads problems in some applications where validation of a given solution is needed. There have been successful attempts to extract rules that tell on a high level how the network is coming up with a solution, as in the work Extraction of similarity based fuzzy rules from artificial neural networks [27]. [25]

2.5

Decision trees

A decision tree is a predictive model that maps out all possible decision paths in the form of a tree. The root of a decision tree branches of into several solutions. Each branch in the tree represents a choice between several different alternatives and each leaf node represents a decision or action as shown in figure3. [28]

Figure 3: A basic decision tree. Source: Markus Winroth

(17)

The data set can contain both discrete and continues data. Decision trees is a su-pervised learning algorithm, meaning that the input data is always corresponding to an output data. The algorithm maps out all the decision paths from the data to form the tree. The learning data corresponding to figure3is shown in figure4. The data set is usually split into a training set and an evaluation set. The training set is the data which the algorithm uses to form a decision tree from. The evalua-tion set is the data which is used to evaluate how good the generated decision tree is. To be able to form a good and accurate decision tree the training set needs to be plenty and diverse. If the training set is to narrow the decision tree risk being overfitted. Overfitted is when the outcome of the algorithm is trained on data that is either to narrow or too noisy. The training data can be too noisy if there is a lot of data that counteract each other or if a lot of the data is not relevant to the problem you want to solve with the decision tree. [29]

Figure 4: A table of data illustrating data that could be used for a decision tree. Source: Markus Winroth

One great advantage decision trees has got over other decision support systems is that the visual representation is easy to understand and interpret. A big dis-advantage of decision trees is that it is unstable in the sense that small change in data can change the entire structure of the tree and give a completely different tree then the one before the new data. One often used technique to make a decision tree more stable is to produce numerous different decision trees on the same data and then evaluate which one of the generated trees fits the evaluation set the best. [18]

(18)

3

Control Unit

Which single-board computer to choose for the control unit depends on the re-quirements. The computer need to have sufficient input/output pins to be able to connect different sensors which will gather data. The computer also needs to have good connectivity such as Wi-Fi [30] and Bluetooth [31] to be able to con-trol different devices. One commonly used single-board computer that fits these conditions well is the Raspberry Pi [32]. Another common single-board comput-ers that fit many of the criteria is an Arduino Uno [33]. The Arduino Uno has a built-in analog to digital converter. This can be good if sensors are not digital. The drawback of the Arduino Uno for this prototypes purpose is that it does not come with a preattached Wi-Fi or Bluetooth module. Due to the drawbacks of the Arduino Uno the Raspberry Pi Model 3B is a better fit to build the prototype with. Raspberry Pi [32] is a small single-board computer made by The Raspberry Pi Foundation. The small size and good specifications of the Raspberry Pi suits many different projects. With preattached Wi-Fi and Bluetooth and 40 input/output pins the area of usage is very broad. To be able to gather data from the sensors and feed them into a machine learning system, a platform is needed to run the code on. For this project the Raspbian [34] is used as the platform. Raspbian is a free operating system based on Debian [35] and is optimized for the Raspberry Pi [32] hardware. Raspbian comes with a lot of preinstalled packages needed by developers for the Raspberry Pi. One preinstalled package that comes with Rasp-bian is the programming language Python [36]. Python is an easy to use language that a lot of different devices and sensors support. For this project Python is used to collect and store data from the sensors.

3.1

Sensors

The prototype needs a way to gather environmental data to base prediction on. For this purpose, a variety of sensors is needed. In this project two different sen-sors are used. A light sensor measuring the amount of light in the environment to easier find correlation between the intensity of light and the usage of light prod-ucts. The model of the light sensor is a Grove light sensor [37]. Grove light sensor is a light dependent resistor. The resistance declines with the intensity of light. This produces a value between 0 and 1024. The value is stored in the prototype in intervals of 100.

The second sensor is a Panasonic motion sensor [38]. With a range of 12 me-ter the sensor suits the need of detecting movement in a home environment more than enough. A sensor with a lower detection range could be used. The motion sensor works with infrared signals that produce an output of either 1 or 0. The output 1 corresponds to movement and 0 corresponds to no movement.

3.2

Connectable devices

To be able to discover a rule based on both sensor and device data the system needs to be able to gather data from the usage of the connected devices. The

(19)

de-vices used in the project is presented in this sub chapter, but any device that can be connected to the raspberry pi [32] should work.

Ikea Trådfri [39] is a smart home lighting system that uses the ZigBee Light Link standard [40]. The Ikea Trådfri product line consists of control units, LED lamps, LED light panels and LED doors. All of the products in the Ikea Trådfri system can work as a standalone product with the IKEA Trådfri mobile app [41] [42]. Trådfri units can also be controlled by the IKEA Bridge, that in turn is controlled through the Trådfri application by the end user [39]. Depending on what Trådfri unit is used, the parameters that are controllable may vary. Some units handle 20 differ-ent preset colors, while other more simple devices handle differdiffer-ent temperature of the light [39].

Philips Hue is a smart home lighting system that uses the ZigBee Light Link stan-dard [43]. Philips Hue consists of a wide arrange of smart lightning products [44]. The Philips Hue Bridge is the control unit where all the other Philip Hue products connects to and it can get commands from Philips App [45] and com-municate these to the connected devices. Philips Hue White is the most basic of the lightning systems, with a white light that can be dimmed and controlled using the Philips Hue Bridge. The bridge need to be connected to a router in the vicinity of the lamps to be able to control them.

3.3

Connection protocols

There are many different protocols to use for communication with the Raspberry Pi [32] . The protocol related to this thesis is ZigBee [46] since ZigBee is used by both Ikea Trådfri and Philips Hue. ZigBee is a standard for wireless communica-tion. The architecture of the ZigBee standard defines how the Application Support SubLayer and Network layer should look like. The lower layers are based on the IEEE 802.15.4 [47] standard which defines the Media Access Control layer and the Physical layer. The physical layer operates mainly via the 2,4GHz band. IEEE 802.15.4 is a wireless mesh network that is very energy efficient when compared to standard Wi-Fi [30]. Therefore, ZigBee is mainly used in smart home systems that operates on batteries and benefits from the low power usage.

For a product to be classified as a ZigBee certified product it needs to fulfill the ZigBee Proforma requirements [40]. ZigBee Light Link is a standard branched from the ZigBee standard [48]. The ZigBee Light Link is focused on the com-munication between smart lightning systems. Since Light Link is based upon the same standard as all the other ZigBee standards it can easily communicate with them and be integrated in the same smart home solution.

3.4

Related Work

There is few smart home systems that have the ability to set up rules to control the connected devices. One of the smart hubs that allows the use of rules is Athom Homey [13]. Athom Homey is a smart hub that operates on an app-based sys-tem. The Homey hub lets you connect any device that there is an app that gives

(20)

support for that device on their app page [49]. Users are allowed and encouraged to add support for devices that are not yet on the app page. The Athom Homey supports devices that uses Wi-Fi 802.11b/g/n [30], ZigBee [46], Z-Wave [50], 433 MHz, 868 MHz, Infrared and Near Field Communication (NFC) [13]. There are many devices that have official apps from the Homey developers, for example Ikea Trådfri and Philips Hue [49]. Homey Flow is an interface where the user can setup rules that control all the connected devices [7].

Samsungs SmartThings Hub [51] is another central control unit that lets the user connect specific ZigBee [46] and Z-wave [50] devices and act as an communica-tion hub between these. Not all devices that is communicating through the ZigBee or Z-wave protocols can communicate with the Hub, only specific brands are able do to so [52]. The SmartThings Hub comes with an app [53,54] that lets you scan after nearby devices, connect and control them via its interface. The SmartThings product line contains amongst other things various sensors, some examples are smoke detectors, motion sensors and door/windows sensors [12].

Enkos [55] is a simulated LCS based approach on solving automating rules in con-trol units. The two aims of Enkos are to minimize the electrical energy consump-tion from the connected devices meanwhile trying to maximize the consumers comfort by making the right predictions. Enkos approach to the problem is to simulate one year data that is divided into time slots for every 30 minutes. The data consists of a time variable, the lightness in the area and if there are any pres-ence of a person. The devices are labeled with electrical consumption parame-ters. The system checks the combinations of lightning devices that gives the least amount of electrical consumption that still meats the light criteria of the room for any given time slot. The Enkos system tries to weigh how important the potential decrease of electrical consumption is versus how important it is to keep the con-sumer happy based on how well the prediction was. If the prediction has a low fitness the system could choose to ignore the prediction and keep the light off to save more electricity. [55]

(21)

4

Method

In this chapter the methods that are used during the course of the project is de-scribed. The methods of choice are presented, both the scientific and the project methods.

4.1

Scientific Method and Methodologies

This thesis is about how rules can be generated automatically by the use of a suit-able machine learning algorithm. This question cannot be evaluated in a quan-tifiable manner, but can be evaluated qualitatively to create a hypothesis, theory or computer system. Since the nature of this thesis is qualitative, methods and methodologies suitable for qualitative research were chosen.

The philosophical assumption is the ground point where the research starts. This thesis assumes Interpretivism. The phenomena are explored by depth and com-plexity. The view is that the project is bound to opinions, perspectives, and ex-periences. This is useful when developing a computer system that is not heavily bound to the users’ interactions with a system interface. [17]

Applied research method is used when solving known problems. It involves an-swering specific questions. A set of circumstances are examined, and the results are context specific. It is used to develop practical applications and technologies. The method builds on existing research and uses data directly from the work. [17] Inductive approach is creating theories from observations and patterns. It is also used in development. Qualitative methods are most commonly used for collect-ing data. Conclusions are bound to behaviors, opinions, and experiences. Because of this, enough data must be used to support the reasons of these conclusions. [56] The research strategy should provide guidelines for the research, including or-ganizing, planning, designing. Grounded theory is a research strategy that is grounded in data. It is an inductive method used to discover theories. System-atically data is collected and analyses to reevaluate the theories. [57]

The data collection is the process of retrieving information for the research. Inter-views are used as a tool for information retrieval. Informal interInter-views or discov-ery interviews are used when a strict schedule and predefined questions are not important. It contains open-ended questions and questions can be added as the interview progresses. The interview can provide in-depth information since the responder is allowed to talk openly about the subjects. It also allows the conver-sation to be more controlled since the interview can be steered in a new direction when an interesting subject emerges. [58]

Text and languages specifically concern collecting data by finding meaningful text and documents. Text and languages is not a data collection method that is used for this thesis, even though much of the information collected is written sources. [17]

(22)

Other information used in the research was collected from several online databases such as Google Scholar, IEEE Xplore and Primo. Google Scholar and IEEE Xplore was used to find scientific reports. Primo was used to find scientific reports and books related to the subject. Information on specific related products such as specifications was found on the websites of said products. Information on the dif-ferent smart home systems, sensors and devices available was found with Google searches with corresponding terms.

Analytic Induction and Grounded Theory are two ways of analyzing data that fits qualitative and inductive research. Both Analytic Induction and Grounded Theory work iteratively by continuously collecting data and analyzing it. The iterations continue until no found case discredits the hypothesis or theory. [17]

Quality Assurance in qualitative research using an inductive approach, must use validity, dependability, confirmability, transferability and ethics. Validity is the part that makes sure that the research is conducted in a correct way. Depend-ability is evaluated by applying quality audits to the conclusions drawn from the result. Confirmability is making sure that the research has been made without personal assessments that affect the result. Transferability is to present the re-search in a descriptive way so that it can serve as material for future rere-search. Ethics are context specific to the research conducted. Ethics should be applied so that the integrity of participants is protected, and treating sensitive material with care. [17]

4.2

Project Methods

To conduct the work throughout the thesis project in an effective way, structured work is needed. This can be achieved through implementing a project methodol-ogy. However, not all methods are equal nor are they suitable for all types projects. Two of the more common methods, one of them used during the work, is intro-duced in this part.

4.2.1 Sequential method

In some projects, the plan needs to be executed in specific steps with a set order. For this sequential methods can be used. One example of the working ways of se-quential methods is the waterfall method.

The waterfall method is a project planning method with clear cut phases. The requirements phase comes first. In the requirements phase all the requirements need to be gathered to give a clear picture of the whole [59]. The design phase fol-lows after the requirement phase. First the product is designed without particular software or hardware systems in mind. After getting a general design, the product will be redesigned to fit limitations of the hardware or software technologies. Af-ter the design phase comes the implementation phase. The implementation phase consists of writing the code according to previous design and requirements. The verification phase follows after implementation phase. Verification of the work

(23)

done during the implementation is done in this step. When the product is de-ployed, maintenance phase follows. The customer will be using the product and the system is changed if mistakes were made during the process, or the require-ments of the system changed. [59]

Another sequential project method is the Critical Path Method [60]. The main purpose of the critical path method is to calculate the time needed to complete the project. This is done by identifying the dependencies of tasks in the project, and the time required to complete them. By adding up the longest chain of de-pendencies, a time estimate of the project found. Any delay in these critical activ-ities will result in a delayed project. The Critical Path Method is a tool that helps scheduling of the project [60]. There are some weaknesses of the Critical Path Method. If the activities time estimates are not stable, or the implementation ac-tivities change, the critical path must be reevaluated [61]. Another weakness is that big projects get very complex activity relationships, thus it gets harder to have one single clearly defined critical path [61].

4.2.2 Iterative method

Projects that are not well defined from the beginning might benefit from using an iterative method. This way the plan is continuously reevaluated during the course of the project. Agile methods use iterations to focus on delivering working parts of the project, in steps.

The agile manifesto states the ideas that the agile development methods have in common [62]. In agile development individuals, interactions, working software, customer collaboration and responding to change are some things that are highly valued. Scrum is one method of implementing agile development. The product owner comes up with a prioritized backlog for the ideas of the project [63]. The team then works out smaller tasks from these. Tasks should be of manageable size meaning that they can be completed within a sprint of one to four weeks. A sprint backlog is created from tasks at the top of the product backlog. During the sprint, the team has a daily meeting where progress and adjustments are presented. The length of the sprints is fixed and in the end of every sprint, evaluation is done to improve working methodology and address other team problems [63].

Extreme Programming or XP, is another agile method. In the second edition of XP, some key points are brought up [64]. Sit together, pair programming, stories, weekly cycle, and test first programming are some of these. These focus on sim-plicity of having all the people working in the same place, together. Code should have tests written first to assure that the later developed code fits the original re-quirements of the test and is bug free. In XP the weekly cycle is the schedule, meeting in the beginning of the week to pick what stories to work on, the end of the week these should be tested working features [64]. XP is suitable for smaller groups and systems whose functionality may need changes over time [65]. Close-ness to the customer is also a requirement to be able to use XP. In agile methods quality assurance of software is a part of the development process and the respon-sibility is put on the developer [66]. Because of the iterative methodology, with

(24)

evaluation occurring throughout the development, it is applied earlier and more frequently than in sequential methods [66].

During this project an agile project method is be used. A strength using this over the waterfall method is the iterative process running through both project and re-search methods. The working process will be as described in figure5. The orange boxes, Identify features and Planning are the initial phases of the project. In this step the features needed for the system to be complete are identified. The features are ordered from the internal dependencies of the features. An example of these internal dependencies is, to develop A, B needs to be in place, and to develop B, C needs to be finished.

Figure 5: A chart showing the workflow of the project. Source: Anton Anderzén

The steps in the green boxes in figure 5, Iteration planning, Implementation, Testing and evaluating, and Iteration evaluation are repeated in iterations for each part of the system. The Iteration planning is taking the next feature from the list of ordered features and dividing into smaller tasks. The tasks are then or-dered by internal dependencies, after that the task of highest priority is brought into the implementation step. Implementation is the step where the tasks are im-plemented and integrated into the system. Testing and evaluating is done for each implemented task. The task is tested as a part, and as integrated in the system. Eventual problem areas to consider with this new task implemented are identified. Iteration evaluation is evaluation of the iteration that was just com-pleted. The working process is evaluated and newly found tasks are brought in to the next iteration. After the iteration is completed a new iteration is planned until the project is finished.

The red box in figure5, Delivery of prototype is the final step, when everything is implemented and evaluated. Here the prototype is considered finished and it is delivered. During the project, understanding of the problem and solution will improve.

(25)

5

Applied Methodology

Investigating how a smart home automation system can be implemented needs the development of a prototype. Many investigations need to be made before de-velopment can start, what devices should be used, what algorithm is best suited to control the system, what environment should the prototype be tested in? This can be summed up as the requirements gathering but is also the part of the project methodology called ”Identify features” in figure5. When choices are made for de-vices and algorithms, alternative solutions are left out. Choices therefore need to be based on clearly defined requirements.

The requirement for the algorithm is defined and the algorithm is chosen before defining any requirements for the hardware. To decide what machine learning algorithms should be used the initial assumption is that the prototypes internal representation of the rules would be similar to that of the Homey and Samsung Smart Homes systems. To work in a user interactive environment a decision is made to find an algorithm that uses explicit representation of rules, that allows for manual addition and removal. Hardware requirements are researched and defined with the information on the algorithm requirements already in place.

5.1

Hardware Requirements

There are several different sensors and devices to choose from available on the market today. To be able to narrow down amongst all the different devices, a set of requirements are specified. During internal discussions and informal inter-views with the stakeholder it was found that the prototype should be implemented with some of the devices in use in homes today. Google searches with the terms smart home devices, single board computer and smart home sensors gave knowl-edge about what requirements for the prototype and peripherals is needed. The requirements were gathered in three steps. First the requirements for the control unit is finalized, after that the requirements for the devices used, and lastly the different sensor requirements are set.

In the central control unit, there are several functions that are required. One prop-erty of the control unit is that it needs to be small enough to be able to easily be moved around in a room but still fit all the other criteria. The control unit needs to be able to gather data and run an algorithm to process this data in real time, for this requirement a minimum amount of processing power is needed. The con-trol unit needs the ability to send and receive information from a broad variety of device, for this the control unit needs to have a Wi-Fi, an Ethernet and Bluetooth connections. The control unit needs to have sufficient input/output pins to be able to connect at least four different sensors that each need one data pin. The unit also needs to have the ability to store information computed from the algorithm. With these requirements, a control unit that fit the criteria and ultimately is chosen is the Raspberry Pi 3 Model B.

Even though the system should be able to work with any peripheral device that has connectivity for it, some requirements is set for which devices to choose. These

(26)

requirements are set to avoid eventual problems that could occur with less opti-mal devices. The device chosen easily needs to be able to receive an action from the control unit and perform it instantly. Upon request from the control unit, the device needs to be able to send information about the current state of the device back to the control unit. The the device needs to be established on the market and have good documentations. There are several different device categories that can fulfill all these requirements. From the different categories of devices in smart homes, a lightning system is chosen because it is one of the more commonly used types of devices in smart homes. Philips Hue lightning system is chosen as a fit for all the device requirements. The requirements for the sensors used is that the data gathered needs to be relevant to a home environment and that the sensors need to have a way to transfer these data to a control unit. The sensors chosen that fit these requirements are the Grove light sensor and Panasonic motion sensor.

5.2

Model Requirements and Delimitations

To develop and test a smart home automation system a physical environment needs to be set up. The Philips Hue lighting system, the light sensor and the move-ment sensor need to be static in the physical environmove-ment to ensure the collected data is of good quality and consistent. During this thesis project an office space which is provided from the stakeholder is used. This makes for good integrity of data, but it does not mirror perfectly the use of smart systems in actual home envi-ronments. In an office setting, the working hours on weekdays involve movement and turned on lights. In a home environment, the opposite is true. During week-ends and weeknights there might also be more varied user behavior than in the office setting.

5.3

Algorithm Requirements

In ”Application of AI in Home Automation” [67] artificial neural networks and decision trees are brought up as machine learning algorithms interesting in au-tomating smart home behavior. An implementation of a learning classifier system called ”Enkos” has successfully been shown to automate smart home behavior in a computer simulated experiment [55]. These three machine learning algorithms: artificial neural networks, decision trees, and learning classifier systems are the candidates found for automating smart homes.

In smart home systems of today, such as ”Samsung Smart Things” [51] and ”Homey” [13], a user interface with explicit representation of rules are used. The user can interact with the system by modifying rules in interfaces paired with the systems. As input data the algorithms should use sensor data from the physical environ-ment, and date and time information. This data should then be processed and involved in some learning step, to later be able to output a predicted action for a specific input.

The requirements needed for the algorithm are:

(27)

• Receive input from sensor systems and give action predictions as output. • Explicit representation of the decisions made by the algorithm, with

modi-fication available.

5.4

Iterative Work

In figure5the first step of the project method is stated as Identify features. The identification of features needed for the system is done by gathering requirements, as presented earlier in this chapter. The second part of the project methodology is Planning. The planning step is a process of taking the features and dividing them into tasks, plan the implementation and prioritize and order the tasks. The initial planning is done by taking the features gathered in a concrete list, as an example the device requirements lead to a set of devices to use. This leads naturally to start with assembly of the control device and peripherals. The assembly of the control device and peripherals is divided into: setting up the Raspberry Pi [32] develop-ment environdevelop-ment, connecting the movedevelop-ment sensor, connecting the light sensor, connecting the devices. This is taken into an Iteration planning step, where the first step is planning what task to do during the iteration to come. The highest pri-ority is setting up the Raspberry Pi development environment, the decided plan is to do this by installing the operating system and get it ready to run a simple python script that fetches the date and time.

The Implementation step is installing the operating system and installing the nec-essary programs to run a python script that fetches the date and time. Testing and Evaluation is done by writing, compiling, and running a python script that fetches the date and time. Lastly for the first iteration is Iteration Evaluation, this is done by evaluating the work done during this iteration. Is the whole task completed? Are there any new tasks that need to be accounted for? If so, the tasks discovered are accounted for in the next Iteration Planning step. This iterative process is repeated for the sensor systems, Philips Hue systems, design of input data struc-ture, all parts of the algorithm and testing of the implementation. When all tasks are finished in the last iteration, the prototype is evaluated as a whole. If no new tasks are discovered the prototype will be delivered as a whole in the Delivery of prototype step.

(28)

6

The system

A system needs to be set up that can control the devices and monitor the environ-ment. The key to solving the problem of automation in smart homes is finding a suitable algorithm. To find a suitable algorithm, properties of different algorithms need to be compared. After the sensor and light system is working, data needs to be collected and transformed to fit the algorithm of choice. The algorithm then has to be implemented and after this the system has to be trained to fit the user data. When the algorithm has trained for a set of previously collected data, the key objective can be considered finished, even though the algorithm will continue the learning process.

6.1

The test environment

The system is set up using a Raspberry Pi as the main control unit. The Raspberry Pi is connected to a lighting sensor and a movement sensor. The movement sen-sor is connected to the Raspberry Pi on a digital port with an internal pull-down resistor activated. The result is a stable signal of 0 as input if the sensor has not registered movement, and a signal of 1 if the sensor has registered movement. The lighting sensor in use is analog, this results in some obstacles since the Raspberry Pi only accepts digital input. This could be solved with an external Analog to Digi-tal converter chip, but it would need one digiDigi-tal input per bit in the read value. To manage the use of digital pins, another microcomputer, an Arduino Uno, reads the light sensor value on an Analog to Digital converter pin. This is then commu-nicated by USB to the Raspberry Pi. To prevent the Arduino to read and send the light value constantly a basic lock is implemented. The way the lock works is that the Arduino waits for an incoming serial communication, only when the Arduino receives a signal it reads and sends the light value back to the Raspberry Pi. To be able to test the algorithm properly some devices are needed. The devices play a big role in the system. The system both needs to be able gather their cur-rent status and be able to control the devices after the prediction is made. For this project two Philips Hue lamps are used. To be able to communicate with the lamps a Philips Hue Bridge connected to the prototype via a router is used. The Raspberry Pi communicates through the Hue bridge to gather the lamps status, switch them on and off and to change the brightness of the lamps.

6.2

Comparing algorithms

When creating a smart home controller that solves the problems related to man-ual creation of rules, several machine learning algorithms can be used. During the first part of this thesis project, a comparison is made between different ma-chine learning algorithms. A neural network algorithm could be applied to this problem and could be able to create accurate predictions. However, additional support would have to be added to visualize the implicit rule conditions that are hidden in the networks weights. This is a problem in testing, and potentially a problem for the user of the smart home system. Rules need to be accessible so that the logic of the system can be followed. A variant of decision trees could also

(29)

be applied to solve this problem. Decision trees would not have the obstacle of vi-sual representation of the rules that a neural network has. One disadvantage of a decision tree would be that it is unstable, introducing new data points can shift the overall structure of the tree. This could be fixed with creating multiple decision trees and evaluating all of them to see which fits the evaluation data the best. But even when creating multiple decision trees and choosing the one with the best fit, still introduces a risk because of how the decision tree generation works. Every time the system makes a new decision tree there is a risk that it deviates from the previous trees, creating new rules not previously seen. The new tree might not no longer include the rules that are relevant for the user. This would mean that the system might miss some of the generated rules that other algorithms will include. Learning classifier system (LCS) is another implementation that can solve the problem. An LCS would be able to find and create rules based of new data points continuously while maintaining a strong core rule base with high fitness values. When the algorithm creates new rules in either the covering step or in the genetic algorithm, the rule starts of with a low fitness. The low fitness of newly introduced rules means that there is a low risk of the recently created rule to be chosen as a prediction. With every new data point the rules in the rule base that fit the data point will see a rise in fitness. By iterating this process as new data points come in, rules will be able to get higher fitness and therefore be chosen as the predic-tion. This gives stability in the system and an advantage compared to the instable behavior of decision tree algorithms. Another advantage of the LCS is that the rules in the rule base could easily be visualized as they are represented explicitly. The explicit representation in the rule base means that an interface for removal of rules that the user deems unnecessary could be easily implemented. This gives an advantage compared to the implicit representation of rules used in decision trees and neural networks. In the smart home systems of today, where users control the rule base completely this is an important aspect. The LCS could be used together with the rules created by the user, integrated in the system. Given the advantages and disadvantages discovered during the literature study, the algorithm of choice is an LCS.

6.3

Data collection

To fit the LCS algorithm a conversion from continuous to discrete data values should be used. The data is structured as displayed in figure6. The DataInstance-Value column represents the actual discrete number that the system uses to en-code the sensor data gathered for the LCS algorithm. This encoding ensures that rules that are created don’t reference a specific time point, or a specific light value. The encoded data results in a much narrower range of possible rules, than if using the continuous values directly from the sensor and time inputs. The current state of the devices, implicitly the actions performed by the use, at any point are saved as the action label for the current data instance as shown in figure7.

Each time that an action is performed by the user, data is added to the collection. To catch the patterns emerging when the user is not interacting with the system, loss of daylight or lights being turned off for a long time, data is added every time

(30)

a DataInstanceValue changes. Since one of the values collected by the system is quarters, data will be stored once every 15 minutes. This is independent of the actions performed by the user, and collects the current state of the environment as a string structured as displayed in figure6and figure7.

Figure 6: A table illustrating the division of continuous data into discrete repre-sentation of value ranges. Source: Anton Anderzén

Figure 7: A table showing the way device state is represented in the data collection. Lamp is either L1 or L2. State is either 0 or 1. LightValue is a value between 0 and 255. Source: Anton Anderzén

To be able to automatically collect data a script called datagrab is written in Python. The datagrab script checks whether any data values or device states has changed since last loop iteration. If the data values have changed the datagrab script will call upon the LCS algorithm to make a prediction for the current data instance. If any of the devices states has changed the script will save the current data values along with the new device state to store in a dumpfile. The dumpfile is read and cleared by the LCS every time the system makes a prediction. This way the LCS is continuously fed with new data from the surrounding environment.

(31)

6.4

Evaluation of the algorithm

To be able to evaluate how well the algorithm performs over time, a significant amount of data is needed. Three different test cases are made. First test case is to run the system with no previously gathered data, the second test case is to test the system with one week worth of data and the last test case is with 4 week’s worth of data. The first test case does not require any data gathered and could be tested directly. The second test case needs a week worth of data. To achieve a week full of data points, data is gathered for 24 hours during a normal work day. The full day of data is then copied seven times to form a full week of data. In the 24-hour data some noise is introduced for the different days of the week on some features to not exactly match the originally recorded day but still be reasonable compared to previously seen feature values. The last test case needs 4 weeks of data. The week of data from the full week test case is copied four times. Week two, three and four is altered to not exactly match week ones’ data but still be simulated to represent normal work days. The simulated data is stored in two different text files. One text file for one week and another file for the four weeks. The format of the data in the text files is the same format that the LCS system reads its data. The files can be fed into the LCS algorithm to simulate that data was already gathered and processed during the amount of time it represents.

To be able to measure the tests against each other, the same input values needs to be fed into all three different test cases. For this purpose, three different test inputs are made. All the test inputs are on a Monday but differ in time, light value, motion and actions. The first test input is 0,7,2,0,2,0,L1,0,254 and 0,7,2,0,2,0,L2,0,254. These two strings of data represent two different devices at 07:00, with no move-ment, the light value 2 and both devices turned off. In both of the generated test cases these inputs match up with rules that support the action state of the test in-put. The second test input is 0,9,3,0,2,1,L1,0,254 and 0,9,3,0,2,1,L2,0,254. These input values represents the time 09:00 with movement, but both the devices are off. In the test cases the devices that match those features has an action that say that the devices should be on with a brightness of 254. The third test input is 0,20,6,0,3,0,L1,1,254 and 0,20,6,0,3,0,L1,1,254. These inputs represent the time 20:00 with no movement and both devices turned on. These two strings has sup-port in the test cases that the devices should be off.

(32)

7

Implementing the algorithm

The implementation of the learning classifier system is divided in to seven sepa-rate steps. A graphical illustration of the implementation of the prototype is shown in figure8. Figure8is divided in ten parts for referencing purposes. The popula-tion of rules, step two, is used for all steps in the algorithm. Step one takes sensor and device data from the smart home environment. Step ten feeds back a pre-dicted action to the smart home environment. The five and eight steps are rule discovery processes. Matched rules in step three are put in the correct set in step four, the non-matching rules are put in the incorrect set in step four. The different stages of the implemented algorithm are described in detail in this chapter.

Figure 8: A visual representation of the learning classifier system algorithms steps. Source: Anton Anderzén and Markus Winroth

7.1

Grabbing

Grabbing is the step where the algorithm fetches data values from the environ-ment. This is done with a Python script that gathers sensor data every time a value changes in the sensors or devices. The collected data is stored in a text file called dumpfile. The data that is saved into the dumpfile is formatted as displayed in figure9. Dumpfile is read by the grabbing function when the LCS-algorithm is called upon and feeds forward the data instances in the file line per line. After

(33)

a data instance has been read from the file, the file is cleared from the read data instance. The data instances read will be processed by the LCS into a rule format and written to a text file called rulebase where all rules are stored. At the system startup the rules from the rulebase file are loaded into the rule base. By saving in the rulebase file, the original data instance can be removed from the system but still have an impact if the system is restarted.

Figure 9: Format of the lines written to the dumpfile when a value changes in the sensors or devices. Source: Anton Anderzén

7.2

Matching

Matching is where the algorithm checks which rules in the rule base that matches all the environment variable values, the features, completely with new data in-stance. If the feature of the rule from the rule base is ”None” it counts as a match for that feature category. The matched rules are divided into a correct set and an incorrect set. All the rules in the rule base that match both the features and the action are put in to the correct set and all the rules that fit the features but not the action are put into the incorrect set. If the correct rule set is empty when the whole rule base has been matched, the system will move to the step Covering. If the correct set contains at least one matched rule the algorithm moves to the up-date parameters step. The full matching procedure can be seen in algorithm1.

References

Related documents

46 Konkreta exempel skulle kunna vara främjandeinsatser för affärsänglar/affärsängelnätverk, skapa arenor där aktörer från utbuds- och efterfrågesidan kan mötas eller

The increasing availability of data and attention to services has increased the understanding of the contribution of services to innovation and productivity in

Av tabellen framgår att det behövs utförlig information om de projekt som genomförs vid instituten. Då Tillväxtanalys ska föreslå en metod som kan visa hur institutens verksamhet

I consent to Karolinska Institutet, and thereby Cancer Research KI, to use my personal data for editorial and marketing purposes.. Karolinska Institutet is not obliged to notify me

While there are many promising opportunities for implementing data-driven technologies in the Stockholm metro, it is difficult to determine what additional data sources

The table shows the average effect of living in a visited household (being treated), the share of the treated who talked to the canvassers, the difference in turnout

In Section 3, we present the main result of the paper: The inverse DFT using only a nite number of uniformly spaced frequency response samples combined with a subspace identi

The modular server–client infrastructure is divided into a back-end (running the data processing unit) and a front-end (running the visualization and control unit).. The data flow