Rubix changes

This commit is contained in:
Paul Schaub 2018-09-12 17:52:05 +02:00
parent f668ceaf6a
commit 70edcea2ca
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
5 changed files with 12 additions and 25 deletions

View File

@ -34,21 +34,14 @@ class Result(Model):
def rows_to_df(indices): def rows_to_df(indices):
temps = []
dcs = [] dcs = []
winds = []
db.connect() db.connect()
for result in Result.select().where(Result.id << indices): for result in Result.select().where(Result.id << indices):
temps += result.temperature
dcs += result.dc_output dcs += result.dc_output
winds += result.wind_speed
db.close() db.close()
return pd.DataFrame( return pd.DataFrame(
{'temp': temps, {'dc': dcs})
'dc': dcs,
'wind': winds
})

View File

@ -4,13 +4,13 @@ from pywatts.routines import *
from pywatts import kcross from pywatts import kcross
NUM_STATIONS_FROM_DB = 75 NUM_STATIONS_FROM_DB = 75
K = 2 K = 10
NUM_EVAL_STATIONS = 40 NUM_EVAL_STATIONS = 40
TRAIN = True TRAIN = True
PLOT = True PLOT = True
TRAIN_STEPS = 1 TRAIN_STEPS = 10
TOTAL_STEPS = 2 TOTAL_STEPS = 6
NUM_QUERIES = 1 NUM_QUERIES = 5
PREDICT_QUERY = "query-sample_24hour.json" PREDICT_QUERY = "query-sample_24hour.json"
PREDICT_RESULT = PREDICT_QUERY.replace("query", "result") PREDICT_RESULT = PREDICT_QUERY.replace("query", "result")
FIGURE_OUTPUT_DIR = "../figures/" FIGURE_OUTPUT_DIR = "../figures/"

View File

@ -30,11 +30,11 @@ def pywatts_input_fn(X, y=None, num_epochs=None, shuffle=True, batch_size=1):
class Net: class Net:
__regressor = None __regressor = None
__feature_cols = [tf.feature_column.numeric_column(col) for col in ['dc', 'temp', 'wind']] __feature_cols = [tf.feature_column.numeric_column(col) for col in ['dc']]
def __init__(self, feature_cols=__feature_cols): def __init__(self, feature_cols=__feature_cols):
self.__regressor = tf.estimator.DNNRegressor(feature_columns=feature_cols, self.__regressor = tf.estimator.DNNRegressor(feature_columns=feature_cols,
hidden_units=[128, 512, 128], hidden_units=[64, 128, 64],
model_dir='tf_pywatts_model') model_dir='tf_pywatts_model')
def train(self, training_data, training_results, batch_size, steps): def train(self, training_data, training_results, batch_size, steps):

View File

@ -10,7 +10,7 @@ from pywatts.routines import *
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
if len(sys.argv) != 2: if len(sys.argv) != 2:
print("Usage: python photovoltaic_gruppe1.py <file.json>") print("Usage: python photovoltaic_gruppe4.py <file.json>")
exit(1) exit(1)
json_file = sys.argv[1] # json file json_file = sys.argv[1] # json file

View File

@ -9,7 +9,7 @@ from random import randint
def train_split(data, size): def train_split(data, size):
used_idxs = [] used_idxs = []
X_values = {'dc': [], 'temp': [], 'wind': []} X_values = {'dc': []}
y_values = [] y_values = []
for i in range(size): for i in range(size):
rnd_idx = randint(0, data.size / data.shape[1] - 337) rnd_idx = randint(0, data.size / data.shape[1] - 337)
@ -20,8 +20,6 @@ def train_split(data, size):
used_idxs.append(rnd_idx) used_idxs.append(rnd_idx)
X_values['dc'].extend(data['dc'][rnd_idx:rnd_idx + 336].tolist()) X_values['dc'].extend(data['dc'][rnd_idx:rnd_idx + 336].tolist())
X_values['temp'].extend(data['temp'][rnd_idx:rnd_idx + 336].tolist())
X_values['wind'].extend(data['wind'][rnd_idx:rnd_idx + 336].tolist())
y_values.append(data['dc'][rnd_idx + 337].tolist()) y_values.append(data['dc'][rnd_idx + 337].tolist())
return pandas.DataFrame.from_dict(X_values), pandas.DataFrame.from_dict({'dc': y_values}) return pandas.DataFrame.from_dict(X_values), pandas.DataFrame.from_dict({'dc': y_values})
@ -31,9 +29,7 @@ def input_query(json_str, idx=0):
tmp_df = pandas.read_json(json_str) tmp_df = pandas.read_json(json_str)
return pandas.DataFrame.from_dict( return pandas.DataFrame.from_dict(
{'dc': tmp_df['dc'][idx], {'dc': tmp_df['dc'][idx]}
'temp': tmp_df['temp'][idx],
'wind': tmp_df['wind'][idx]}
) )
def input_queries(json_str): def input_queries(json_str):
@ -48,9 +44,7 @@ def input_queries(json_str):
queries = [] queries = []
for i in range(len(tmp_df)): for i in range(len(tmp_df)):
queries.append(pandas.DataFrame.from_dict( queries.append(pandas.DataFrame.from_dict(
{'dc': tmp_df['dc'][i], {'dc': tmp_df['dc'][i]}
'temp': tmp_df['temp'][i],
'wind': tmp_df['wind'][i]}
)) ))
return oneH, queries return oneH, queries
@ -85,7 +79,7 @@ def plot_training(evaluation):
def predict(nn, X_pred): def predict(nn, X_pred):
pred = nn.predict1h(X_pred) pred = nn.predict1h(X_pred)
# Cap results to 0 # Cap results to 0
predictions = np.array([max(p['predictions'], 0) for p in pred]) predictions = np.array([max(p['predictions'], [0]) for p in pred])
return predictions return predictions