As we know, smart cities and smart homes are new concepts emerging on computer science field. Theses concepts aims to automate city/home services by data evaluation to take decisions based on local citizien behavior improving their life quality.
One of these concepts that we can apply on our example purpose are Smart Grids.
The Smart Grid represents an unprecedented opportunity to move the energy industry into a new era of reliability, availability, and efficiency that will contribute to our economic and environmental health.The benefits associated with the Smart Grid include:
The Smart Grid will consist of millions of pieces and parts—controls, computers, power lines, and new technologies and equipment. One of the most important component on Smart Grid infrastructure are Smart Meters.
Smart meters provide the Smart Grid interface between you and your energy provider. For instance, smart meters will deliver signals from your energy provider that can help you cut your energy costs. Smart meters also provide utilities with greater information about how much electricity is being used throughout their service areas.
This energy information coming to and from your home through your smart meter can be run through a home energy management System (EMS), which will allow you to view it in an easy-to-understand format on your computer or hand-held device. A home EMS allows you to track your energy use in detail to better save energy. For instance, you can see the energy impact of various appliances and electronic products simply by monitoring your EMS while switching the devices on and off.
An EMS also allows you to monitor real-time information and price signals from your utility and create settings to automatically use power when prices are lowest. You can also choose settings that allow specific appliances and equipment to turn off automatically when a large demand threatens to cause an outage—avoiding peak demand rates, helping to balance the energy load in your area, and preventing blackouts. Your utility may provide financial incentives for doing so.
As mentioned before, in the smart grid structure, smart meters send customer's data to the energy provider.It creates threats in user's privacy.
As argued in Cyber Attack Impact on Critical Smart Grid Infrastructures:
"The basic concern about consumer threats is privacy
violation. Sensitive consumer data such as name, address, and
social security number, could be transmitted via Smart Meters
which may be an attractive target for attackers. Smart Meters
also handle consumers’ history, information depicting their
presence, individual preferences, social activities,
consumption habits, as well as health issues. Such
information could be exploited for various purposes, with the
advertising case to seem the most innocent among others."
As mentioned in the previous tutorials, PyGrid nodes allow us to perform remote operations on datasets keeping them into their hosts. We can apply MPC operations to anonymize data during these operations, that way, the energy provider will get access to the aggregated values anonymized by thousands of users.
We can replace default smart meters by Grid Nodes to preserve user's privacy.
In this section, we'll learn how to publish private dataset on your PyGrid node and also, how companies can use private data without get access to their values.
NOTE: At the time of running this notebook, we were running the grid components in background mode.
Components:
In this fictional use case, we'll set energy tariff based on the usage of it. We'll measure the average energy spent by some houses (bob, alice and bill houses) to define a new value to the energy tariff.This measure will be made 4 times in a day.
As a customer, we need to register our grid node (smart meter or home assistant) on grid network. On top of that, we need to populate the node with energy spent in a certain time interval.
1 - Register grid node on grid network (This was done by starting the node).
2 - Populate node.
PS: Each customer needs to populate their own nodes with energy spent by home appliances, or receive it by an energy meter that lives on customer's house.
In [ ]:
import syft as sy
import torch as th
from syft.grid.clients.dynamic_fl_client import DynamicFLClient
hook = sy.TorchHook(th)
In [ ]:
bob_home_assistant = DynamicFLClient(hook, "ws://localhost:3000")
# smart light bulb
lb_energy_data_chunk = th.tensor([ 5.0, 8.5, 9.7, 2.5]).tag("#energy-consumption", "#light-bulb").describe("light bulb energy consumption(Kwatts)")
# smart coffe pot
coffe_energy_data_chunk = th.tensor([2.5, 3.7, 1.2, 1.0]).tag("#energy-consumption", "#coffe-pot").describe("coffe pot energy consumption(Kwatts)")
# smart fridge
fridge_energy_data_chunk = th.tensor([8.0, 4.9, 7, 10.9]).tag("#energy-consumption", "#fridge").describe("Fridge energy consumption(Kwatts)")
# Sending to home assistant
lb_energy_data_chunk.send(bob_home_assistant, garbage_collect_data=False)
coffe_energy_data_chunk.send(bob_home_assistant, garbage_collect_data=False)
fridge_energy_data_chunk.send(bob_home_assistant, garbage_collect_data=False)
In [ ]:
alice_home_assistant = DynamicFLClient(hook, "ws://localhost:3001")
# smart light bulb
lb_energy_data_chunk = th.tensor([ 3.0, 2.5, 6.7, 4.5]).tag("#energy-consumption", "#light-bulb").describe("light bulb energy consumption(Kwatts)")
# smart coffe pot
coffe_energy_data_chunk = th.tensor([0.5, 1.7, 5.2, 1.0]).tag("#energy-consumption", "#coffe-pot").describe("coffe pot energy consumption(Kwatts)")
# smartfridge
fridge_energy_data_chunk = th.tensor([3.0, 4.9, 8, 5.9]).tag("#energy-consumption", "#fridge").describe("Fridge energy consumption(Kwatts)")
# Sending to home assistant
lb_energy_data_chunk.send(alice_home_assistant , garbage_collect_data=False)
coffe_energy_data_chunk.send(alice_home_assistant , garbage_collect_data=False)
fridge_energy_data_chunk.send(alice_home_assistant, garbage_collect_data=False)
In [ ]:
bill_home_assistant = DynamicFLClient(hook, "ws://localhost:3002")
# smart light bulb
lb_energy_data_chunk = th.tensor([ 8.0, 7.5, 9.7, 2.5]).tag("#energy-consumption", "#light-bulb").describe("light bulb energy consumption(Kwatts)")
# smartfridge
fridge_energy_data_chunk = th.tensor([3.7, 4.3, 8, 5.9]).tag("#energy-consumption", "#fridge").describe("Fridge energy consumption(Kwatts)")
# Sending to home assistant
lb_energy_data_chunk.send(bill_home_assistant, garbage_collect_data=False)
fridge_energy_data_chunk.send(bill_home_assistant, garbage_collect_data=False)
As a company, we need to search by all nodes registered on the smart grid (grid network) asking for their energy spents.
PS: It's important to note that we must not be able to retrieve their data, otherwise someone would be able to get this data and apply statistical tools to discover customers ' habits by patterns found on the usage of home appliances. Therefore, all arithmetic operations should be made remotelly.
In [ ]:
my_smart_grid = sy.PublicGridNetwork(hook, "http://localhost:5000")
In [ ]:
# Energy spent with fridge
results = my_smart_grid.search("#energy-consumption")
print("Results: ", results)
In [ ]:
from functools import reduce
def sum_energy_spent_by_home(home_id, query_dict):
# It will aggregate home appliances' spent remotelly.
# Example: If we have light-bulb and fridge at the same house, we need to aggregate it on the user's device.
return reduce(lambda x,y: x + y, query_dict[home_id])
def smart_city_aggregation(x,y):
print("Sending X(", x.location, ") to Y(", y.location, ").")
x.location.connect_nodes(y.location)
return x.move(y.location) + y
energy_spent_by_houses = [ sum_energy_spent_by_home(home_id, results) for home_id in results.keys() ]
total_spend = reduce(lambda x, y: smart_city_aggregation(x,y), energy_spent_by_houses)
In [ ]:
p_average = total_spend / 3 # Total spent divided by number of houses
Now we can recover the value of the energy average because it has been anonymized by the aggregation. A malicious agent won't be able to extract a piece of information about any specific customer.
PS: We're using an array to represent energy spent at different times of the day. (6 hours between each measure)
In [ ]:
average = p_average.get()
In [ ]:
def update_tariff(energy_average):
energy_coefficient = 0.5
energy_constant = 5
return energy_average * energy_coefficient + energy_constant
In [ ]:
energy_tariff = th.stack(list(map(lambda x: update_tariff(x), average)))
In [ ]:
energy_tariff
With the new regulation such as GDPR, enterprises are under pressure to have less freedom with how they use - and more importantly how they analyze - personal information. However, as we can see in this example,companies can use aggregated/anonymized values to keep improving their services without use customers' data directly.
Congratulations on completing this notebook tutorial! If you enjoyed this and would like to join the movement toward privacy preserving, decentralized ownership of AI and the AI supply chain (data), you can do so in the following ways!
The easiest way to help our community is just by starring the GitHub repos! This helps raise awareness of the cool tools we're building.
The best way to keep up to date on the latest advancements is to join our community! You can do so by filling out the form at http://slack.openmined.org
The best way to contribute to our community is to become a code contributor! At any time you can go to PySyft GitHub Issues page and filter for "Projects". This will show you all the top level Tickets giving an overview of what projects you can join! If you don't want to join a project, but you would like to do a bit of coding, you can also look for more "one off" mini-projects by searching for GitHub issues marked "good first issue".
If you don't have time to contribute to our codebase, but would still like to lend support, you can also become a Backer on our Open Collective. All donations go toward our web hosting and other community expenses such as hackathons and meetups!