-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathleak_prediction.py
62 lines (45 loc) · 2.08 KB
/
leak_prediction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'''
Inputs:
Pressure tolerance in each pipe
Temperature tolerance in each pipe
History of pressures and temperatures
Where current leaks are
Low pressure could mean a leak
Output predictions for pressure and temperature of the system for each day of the next week
Take average pressure and minimum temperature
1. Use linear regression to find projection of data
2. Use projected data in linear regression to find
'''
import numpy
from random_network import RandomWaterDistributionNetwork
from random_network_properties import random_properties_for_network
from sklearn import linear_model
class LeakPredictor:
def __init__(self, adjacency_matrix: numpy.ndarray, pipe_properties_over_time: numpy.ndarray) -> None:
self.adjacency = adjacency_matrix
self.pipe_properties_over_time = pipe_properties_over_time
def temperature_change_to_break(self, edge_index: int):
# defining feature matrix(X) and response vector(y)
coldestTemps = self.pipe_properties_over_time[edge_index, :, 0]
averagePressures = self.pipe_properties_over_time[edge_index, :, 2]
X = numpy.column_stack((coldestTemps, averagePressures))
y = self.pipe_properties_over_time[edge_index, :, 1]
# create linear regression object
reg = linear_model.LinearRegression()
# train model using training sets
reg.fit(X, y)
# regression coefficients
# print('Coefficients', reg.coef_)
# y-intercept
return reg.intercept_
def rank_pipes_by_break_nearity(self):
pipes = [(index, self.temperature_change_to_break(index)) for index in range(self.pipe_properties_over_time.shape[0])]
ranked_pipes = sorted(pipes, key=lambda pipe: pipe[1], reverse=True)
return ranked_pipes
if __name__ == "__main__":
random_network_maker = RandomWaterDistributionNetwork()
network = random_network_maker.random_network(10, 0, 0)
adjacency, pipe_props = random_properties_for_network(network)
predictor = LeakPredictor(adjacency, pipe_props)
results = predictor.rank_pipes_by_break_nearity()
print(results)