Skip to content

Commit 80c349e

Browse files
committed
add constrained SVD model
1 parent d78924e commit 80c349e

9 files changed

+65
-24
lines changed
254 KB
Binary file not shown.

datasets/dwelling_worm1_2.csv.gz

1.33 MB
Binary file not shown.

datasets/dwelling_worm2_2.csv.gz

1.33 MB
Binary file not shown.

datasets/roaming_worm2_2.csv.gz

1.35 MB
Binary file not shown.

demos.ipynb

+5-16
Large diffs are not rendered by default.

exploratory.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@
455455
"name": "python",
456456
"nbconvert_exporter": "python",
457457
"pygments_lexer": "ipython3",
458-
"version": "3.6.9"
458+
"version": "3.8.5"
459459
}
460460
},
461461
"nbformat": 4,

fnn/models.py

+14
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,20 @@ def transform(self, X, y=None):
510510
# **kwargs
511511
# )
512512

513+
class ETDConstrainedEmbedding(NeuralNetworkEmbedding):
514+
def __init__(
515+
self,
516+
*args,
517+
**kwargs
518+
):
519+
super().__init__(*args, **kwargs)
520+
kwargs.pop("time_window")
521+
self.model = ETDConstrained(
522+
self.n_latent,
523+
self.time_window,
524+
**kwargs
525+
)
526+
513527
class MLPEmbedding(NeuralNetworkEmbedding):
514528
def __init__(
515529
self,

fnn/networks.py

+44-1
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,47 @@ def __init__(
547547
def call(self, inputs, training=False):
548548
outputs = self.decoder(self.encoder(inputs))
549549
return outputs
550-
550+
551+
552+
class ETDConstrained(tf.keras.Model):
553+
"""
554+
A batchwise fully-connected eigen-time-delay embedding (linear autoencoder)
555+
"""
556+
def __init__(
557+
self,
558+
n_latent,
559+
time_window,
560+
n_features=1,
561+
latent_regularizer=None,
562+
rnn_opts=dict(),
563+
random_state=None,
564+
**kwargs
565+
):
566+
super(ETDConstrained, self).__init__()
567+
self.n_latent = n_latent
568+
self.time_window = time_window
569+
self.n_features = n_features
570+
571+
# Initialize state
572+
tf.random.set_seed(random_state)
573+
574+
# Encoder
575+
self.encoder = tf.keras.Sequential()
576+
self.encoder.add(tf.keras.layers.InputLayer(input_shape=(time_window, n_features)))
577+
self.encoder.add(tf.keras.layers.Flatten())
578+
self.encoder.add(tf.keras.layers.Dense(n_latent, activation=None, **rnn_opts))
579+
self.encoder.add(
580+
tf.keras.layers.Reshape(
581+
(n_latent,),
582+
activity_regularizer=latent_regularizer
583+
)
584+
)
585+
586+
self.decoder = tf.keras.Sequential()
587+
self.decoder.add(tf.keras.layers.Flatten())
588+
self.decoder.add(tf.keras.layers.Dense(time_window*n_features, activation=None, **rnn_opts))
589+
self.decoder.add(tf.keras.layers.Reshape((time_window, n_features)))
590+
591+
def call(self, inputs, training=False):
592+
outputs = self.decoder(self.encoder(inputs))
593+
return outputs

fnn/utils.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import numpy as np
22
import warnings
33

4-
import scipy
5-
from scipy.linalg import hankel, orthogonal_procrustes
6-
from scipy.signal import periodogram, argrelextrema, savgol_filter
7-
from scipy.spatial.distance import pdist, squareform, directed_hausdorff
8-
from scipy.spatial import procrustes
9-
4+
from scipy.linalg import hankel
105
import matplotlib.pyplot as plt
116

127
###------------------------------------###

0 commit comments

Comments
 (0)