francesco-mannella / echo-state-networks Goto Github PK
View Code? Open in Web Editor NEWEcho State Networks with TensorFlow
Echo State Networks with TensorFlow
I have been trying to use this on the KDD99 dataset, where from my understanding it is going to be 1 input and 5 outputs, but when I try to train I get something that looks like this.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
50 try:
---> 51 return getattr(obj, method)(*args, **kwds)
52
~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
4375 return self[name]
-> 4376 return object.__getattribute__(self, name)
4377
AttributeError: 'Series' object has no attribute 'reshape'
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
<ipython-input-83-c189dc55e5ae> in <module>
----> 1 esn.fit(x_train, y_train)
~\Desktop\Machine Learning\pyESN.py in fit(self, inputs, outputs, inspect)
163 inputs = np.reshape(inputs, (len(inputs), -1))
164 if outputs.ndim < 2:
--> 165 outputs = np.reshape(outputs, (len(outputs), -1))
166 # transform input and teacher signal:
167 inputs_scaled = self._scale_inputs(inputs)
~\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in reshape(a, newshape, order)
277 [5, 6]])
278 """
--> 279 return _wrapfunc(a, 'reshape', newshape, order=order)
280
281
~\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
59 # a downstream library like 'pandas'.
60 except (AttributeError, TypeError):
---> 61 return _wrapit(obj, method, *args, **kwds)
62
63
~\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapit(obj, method, *args, **kwds)
43 if not isinstance(result, mu.ndarray):
44 result = asarray(result)
---> 45 result = wrap(result)
46 return result
47
~\Anaconda3\lib\site-packages\pandas\core\series.py in __array_wrap__(self, result, context)
646 """
647 return self._constructor(result, index=self.index,
--> 648 copy=False).__finalize__(self)
649
650 def __array_prepare__(self, result, context=None):
~\Anaconda3\lib\site-packages\pandas\core\series.py in __init__(self, data, index, dtype, name, copy, fastpath)
273 else:
274 data = _sanitize_array(data, index, dtype, copy,
--> 275 raise_cast_failure=True)
276
277 data = SingleBlockManager(data, index, fastpath=True)
~\Anaconda3\lib\site-packages\pandas\core\series.py in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
4163 elif subarr.ndim > 1:
4164 if isinstance(data, np.ndarray):
-> 4165 raise Exception('Data must be 1-dimensional')
4166 else:
4167 subarr = com._asarray_tuplesafe(data, dtype=dtype)
Exception: Data must be 1-dimensional
Is there anything I could do to make this work? Or is it saying that my training data has too many dimensions? I am not sure what to do.
Thanks!
Hi Francesco,
I tried to find a source (reasearch paper or else) for the dynamic rotation trick but have not been successful - do have any hints regarding theoretical foundations or empirical evidence?
Kind Regards
Arvin
Hello ! I am a student from China and I am learning about ESN recently. I have read your ESN code on github.But when I tried to reproduce the code myself(on tensorflow2), I found the following error. Could you tell me what the reason is?
filename:ESN-usage
code:
model = keras.models.Sequential()
model.add(recurrent_layer)
model.add(output)
TypeError: You are attempting to use Python control flow in a layer that was not declared to be dynamic. Pass dynamic=True
to the class constructor.
Encountered error:
"""
using a tf.Tensor
as a Python bool
is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
"""
Hello!
Thanks for posting this code online. Trying to use it, when I run the code of ESN-usage.ipynb I get the following error:
---------------------------------------------------------------------------
OperatorNotAllowedInGraphError Traceback (most recent call last)
<ipython-input-51-ec63cda2780d> in <module>
19 # put all together in a keras sequential model
20 model = keras.models.Sequential()
---> 21 model.add(recurrent_layer)
22 model.add(output)
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
515 self._self_setattr_tracking = False # pylint: disable=protected-access
516 try:
--> 517 result = method(self, *args, **kwargs)
518 finally:
519 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/engine/sequential.py in add(self, layer)
206 # and create the node connecting the current layer
207 # to the input layer we just created.
--> 208 layer(x)
209 set_inputs = True
210
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in __call__(self, inputs, initial_state, constants, **kwargs)
658
659 if initial_state is None and constants is None:
--> 660 return super(RNN, self).__call__(inputs, **kwargs)
661
662 # If any of `initial_state` or `constants` are specified and are Keras
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
949 # >> model = tf.keras.Model(inputs, outputs)
950 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
--> 951 return self._functional_construction_call(inputs, args, kwargs,
952 input_list)
953
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
1088 layer=self, inputs=inputs, build_graph=True, training=training_value):
1089 # Check input assumptions set after layer building, e.g. input shape.
-> 1090 outputs = self._keras_tensor_symbolic_call(
1091 inputs, input_masks, args, kwargs)
1092
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in _keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs)
820 return nest.map_structure(keras_tensor.KerasTensor, output_signature)
821 else:
--> 822 return self._infer_output_signature(inputs, args, kwargs, input_masks)
823
824 def _infer_output_signature(self, inputs, args, kwargs, input_masks):
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in _infer_output_signature(self, inputs, args, kwargs, input_masks)
861 # TODO(kaftan): do we maybe_build here, or have we already done it?
862 self._maybe_build(inputs)
--> 863 outputs = call_fn(inputs, *args, **kwargs)
864
865 self._handle_activity_regularization(inputs, outputs)
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in call(self, inputs, mask, training, initial_state, constants)
792 new_states = [new_states]
793 return output, new_states
--> 794 last_output, outputs, states = K.rnn(
795 step,
796 inputs,
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/backend.py in rnn(step_function, inputs, initial_states, go_backwards, mask, constants, unroll, input_length, time_major, zero_output_for_mask)
4346 # output_time_zero is used to determine the cell output shape and its dtype.
4347 # the value is discarded.
-> 4348 output_time_zero, _ = step_function(
4349 input_time_zero, tuple(initial_states) + tuple(constants))
4350 output_ta = tuple(
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in step(inputs, states)
788 def step(inputs, states):
789 states = states[0] if len(states) == 1 and is_tf_rnn_cell else states
--> 790 output, new_states = cell_call_fn(inputs, states, **kwargs)
791 if not nest.is_nested(new_states):
792 new_states = [new_states]
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
1010 with autocast_variable.enable_auto_cast_variables(
1011 self._compute_dtype_object):
-> 1012 outputs = call_fn(inputs, *args, **kwargs)
1013
1014 if self._activity_regularizer:
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs)
665 try:
666 with conversion_ctx:
--> 667 return converted_call(f, args, kwargs, options=options)
668 except Exception as e: # pylint:disable=broad-except
669 if hasattr(e, 'ag_error_metadata'):
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/autograph/impl/api.py in converted_call(f, args, kwargs, caller_fn_scope, options)
348 if conversion.is_in_allowlist_cache(f, options):
349 logging.log(2, 'Allowlisted %s: from cache', f)
--> 350 return _call_unconverted(f, args, kwargs, options, False)
351
352 if ag_ctx.control_status_ctx().status == ag_ctx.Status.DISABLED:
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/autograph/impl/api.py in _call_unconverted(f, args, kwargs, options, update_cache)
476
477 if kwargs is not None:
--> 478 return f(*args, **kwargs)
479 return f(*args)
480
/mnt/d/projects/recirculation/esn/ESN.py in call(self, inputs, states)
195
196 rkernel = self.setAlpha(self.recurrent_kernel_init)
--> 197 if self.alpha != self.alpha_store:
198 self.clip_variables()
199 self.echo_ratio.assign(self.echoStateRatio(rkernel))
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/framework/ops.py in __bool__(self)
883 `TypeError`.
884 """
--> 885 self._disallow_bool_casting()
886
887 def __nonzero__(self):
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/framework/ops.py in _disallow_bool_casting(self)
490 else:
491 # Default: V1-style Graph execution.
--> 492 self._disallow_in_graph_mode("using a `tf.Tensor` as a Python `bool`")
493
494 def _disallow_iteration(self):
~/software/miniconda3/envs/recirc/lib/python3.8/site-packages/tensorflow/python/framework/ops.py in _disallow_in_graph_mode(self, task)
477
478 def _disallow_in_graph_mode(self, task):
--> 479 raise errors.OperatorNotAllowedInGraphError(
480 "{} is not allowed in Graph execution. Use Eager execution or decorate"
481 " this function with @tf.function.".format(task))
OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
I tried running tf.executing_eagerly()
and it returns True. And I also tried to use @tf.function above call
function, but it still did not work.
Should I change the if self.alpha != self.alpha_store:
condition to something else using tf.cond? Thank you for your help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.