-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinput_data.py
More file actions
144 lines (109 loc) · 4.07 KB
/
input_data.py
File metadata and controls
144 lines (109 loc) · 4.07 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Functions for downloading and reading MNIST data."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from scipy.io import loadmat
import math
import numpy
import tensorflow as tf
class WindDataSet():
def __init__(self, inputs, outputs, fake_data=False, one_hot=False,
dtype=tf.float32):
dtype = tf.as_dtype(dtype).base_dtype
assert inputs.shape[0] == outputs.shape[0], (
'inputs.shape: %s outputs.shape: %s' % (inputs.shape,
outputs.shape))
self._num_examples = inputs.shape[0]
self._inputs = inputs
self._outputs = outputs
self._epochs_completed = 0
self._index_in_epoch = 0
@property
def inputs(self):
return self._inputs
@property
def outputs(self):
return self._outputs
@property
def num_examples(self):
return self._num_examples
@property
def epochs_completed(self):
return self._epochs_completed
def next_batch(self, batch_size, fake_data=False):
"""Return the next `batch_size` examples from this data set."""
start = self._index_in_epoch
self._index_in_epoch += batch_size
if self._index_in_epoch > self._num_examples:
# Finished epoch
self._epochs_completed += 1
print ("next_batch: Epochs_completed: %d" % self._epochs_completed)
# Shuffle the data
perm = numpy.arange(self._num_examples)
numpy.random.shuffle(perm)
self._inputs = self._inputs[perm]
self._outputs = self._outputs[perm]
# Start next epoch
start = 0
self._index_in_epoch = batch_size
assert batch_size <= self._num_examples
end = self._index_in_epoch
return self._inputs[start:end], self._outputs[start:end]
def read_wind_data_sets(dtype=tf.float32):
class DataSets():
pass
data_sets = DataSets()
datos = loadmat('wind_data_set_wStart10_wEnd50_h24.mat')
entradas = datos ['k_10_inputs']
salidas = datos['k_10_outputs']
salidas = salidas[0]
entradas = entradas.transpose()
#salidas = salidas.transpose()
import numpy as np
tmp = ~np.isnan(entradas).any(axis=1)
entradas = entradas[tmp]
salidas = salidas[tmp]
tmp = ~np.isnan(salidas)
entradas = entradas[tmp]
salidas = salidas[tmp]
windowSize = entradas.shape[1]
nwindows = entradas.shape[0]
trainSize = math.trunc(nwindows*0.7)
validationSize = math.trunc(nwindows*0.15)
testSize = validationSize
# trainSet_x = entradas[:,0:trainSize-1]
# validationSet_x=entradas[:,trainSize:trainSize+validationSize]
# testSet_x = entradas[:,trainSize+validationSize+1:-1]
trainSet_x = entradas[0:trainSize-1]
validationSet_x=entradas[trainSize:trainSize+validationSize]
testSet_x = entradas[trainSize+validationSize+1:-1]
# trainSet_y = salidas[0:trainSize-1]
# validationSet_y = salidas[trainSize:trainSize+validationSize]
# testSet_y = salidas[trainSize+validationSize+1:-1]
trainSet_y = salidas[0:trainSize-1]
validationSet_y = salidas[trainSize:trainSize+validationSize]
testSet_y = salidas[trainSize+validationSize+1:-1]
train_x = trainSet_x
train_y = trainSet_y
valid_x = validationSet_x
valid_y = validationSet_y
test_x = testSet_x
test_y = testSet_y
data_sets.train = WindDataSet(train_x, train_y, dtype=dtype)
data_sets.validation = WindDataSet(valid_x, valid_y,dtype=dtype)
data_sets.test = WindDataSet(test_x, test_y, dtype=dtype)
return data_sets