Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: '3.10'

- name: Build
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/latest-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: '3.10'
- name: Install package
run: |
pip install --upgrade pip
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.8]
python-version: ['3.10']
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v1
Expand All @@ -32,7 +32,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v1
Expand All @@ -50,7 +50,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v1
Expand All @@ -68,7 +68,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v1
Expand Down Expand Up @@ -105,8 +105,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.8']
os: [macos-13]
python-version: ['3.9']
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -115,7 +115,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install package and dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade 'pip<=24.1'
python -m pip install invoke .[test]
- name: invoke minimum
run: invoke minimum
Expand All @@ -125,7 +125,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- os: windows-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</p>

[![Development Status](https://img.shields.io/badge/Development%20Status-2%20--%20Pre--Alpha-yellow)](https://pypi.org/search/?c=Development+Status+%3A%3A+2+-+Pre-Alpha)
[![Python](https://img.shields.io/badge/Python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue)](https://badge.fury.io/py/orion-ml)
[![Python](https://img.shields.io/badge/Python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)](https://badge.fury.io/py/orion-ml)
[![PyPi Shield](https://img.shields.io/pypi/v/orion-ml.svg)](https://pypi.python.org/pypi/orion-ml)
[![Tests](https://github.com/sintel-dev/Orion/workflows/Run%20Tests/badge.svg)](https://github.com/sintel-dev/Orion/actions?query=workflow%3A%22Run+Tests%22+branch%3Amaster)
[![Downloads](https://pepy.tech/badge/orion-ml)](https://pepy.tech/project/orion-ml)
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'm2r2',
'nbsphinx',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
Expand Down Expand Up @@ -96,7 +95,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ argument type description
``input_shape`` ``tuple`` tuple denoting the shape of an input sample
``target_shape`` ``tuple`` tuple denoting the shape of an output sample
``optimizer`` ``str`` string (name of optimizer) or optimizer instance. Default is ``keras.optimizers.Adam``
``loss`` ``str`` string (name of the objective function) or an objective function instance. Default is ``keras.losses.mean_squared_error``
``loss`` ``str`` string (name of the objective function) or an objective function instance. Default is ``tensorflow.losses.mse``
``metrics`` ``list`` list of metrics to be evaluated by the model during training and testing. Default is ["mse"]
``return_seqeunces`` ``bool`` whether to return the last output in the output sequence, or the full sequence. Default is False
``layers`` ``list`` list of keras layers which are the basic building blocks of a neural network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ argument type description
``input_shape`` ``tuple`` tuple denoting the shape of an input sample
``target_shape`` ``tuple`` tuple denoting the shape of an output sample
``optimizer`` ``str`` string (name of optimizer) or optimizer instance. Default is ``keras.optimizers.Adam``
``loss`` ``str`` string (name of the objective function) or an objective function instance. Default is ``keras.losses.mean_squared_error``
``loss`` ``str`` string (name of the objective function) or an objective function instance. Default is ``tensorflow.losses.mse``
``metrics`` ``list`` list of metrics to be evaluated by the model during training and testing. Default is ["mse"]
``return_seqeunces`` ``bool`` whether to return the last output in the output sequence, or the full sequence. Default is False
``layers`` ``list`` list of keras layers which are the basic building blocks of a neural network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ argument type description
``input_shape`` ``tuple`` tuple denoting the shape of an input sample
``dense_units`` ``int`` number of values ahead to predict (target size). Default is 1.
``optimizer`` ``str`` string (name of optimizer) or optimizer instance. Default is ``keras.optimizers.Adam``
``loss`` ``str`` string (name of the objective function) or an objective function instance. Default is ``keras.losses.mean_squared_error``
``loss`` ``str`` string (name of the objective function) or an objective function instance. Default is ``tensorflow.losses.mse``
``metrics`` ``list`` list of metrics to be evaluated by the model during training and testing. Default is ["mse"]
``return_seqeunces`` ``bool`` whether to return the last output in the output sequence, or the full sequence. Default is False
``layers`` ``list`` list of keras layers which are the basic building blocks of a neural network
Expand All @@ -53,7 +53,7 @@ argument type description
X = np.array([1] * 100).reshape(1, -1, 1)
y = np.array([[1]])
primitive = load_primitive('keras.Sequential.LSTMTimeSeriesRegressor',
arguments={"X": X, "y": y, "input_shape":(100, 1), "batch_size": 1, "validation_split": 0})
arguments={"X": X, "y": y, "input_shape":(100, 1), "batch_size": 1, "validation_split": 0, "loss": "tensorflow.losses.mse"})

primitive.fit()
primitive.produce(X=X)
9 changes: 0 additions & 9 deletions orion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import logging
import warnings

import tabulate

from orion.analysis import get_available_templates
from orion.benchmark import benchmark
from orion.evaluation import CONTEXTUAL_METRICS as METRICS
Expand All @@ -27,13 +25,6 @@ def _evaluate(args):
print('Writing results in {}'.format(args.output))
scores.to_csv(args.output, index=False)

print(tabulate.tabulate(
scores,
showindex=False,
tablefmt='github',
headers=scores.columns
))


def get_parser():

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"window_size": 250
},
"keras.Sequential.LSTMTimeSeriesRegressor": {
"epochs": 35
"epochs": 35,
"loss": "tensorflow.losses.mse"
},
"orion.primitives.timeseries_anomalies.find_anomalies#1": {
"window_size_portion": 0.33,
Expand Down
2 changes: 1 addition & 1 deletion orion/primitives/adapters/ncps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def build_layer(layer, hyperparameters):
layer_class = import_object(layer['class'])
layer_kwargs = layer['parameters'].copy()
if issubclass(layer_class, tf.keras.layers.Wrapper):
if issubclass(layer_class, tf.keras.layers.Layer) and 'layer' in layer_kwargs:
layer_kwargs['layer'] = build_layer(layer_kwargs['layer'], hyperparameters)
elif issubclass(layer_class, tf.keras.layers.RNN) and isinstance(layer_kwargs['units'], dict):
layer_kwargs['units'] = build_layer(layer_kwargs['units'], hyperparameters)
Expand Down
13 changes: 1 addition & 12 deletions orion/primitives/aer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,11 @@
from tensorflow.keras.models import Model

from orion.primitives.timeseries_errors import reconstruction_errors, regression_errors
from orion.primitives.utils import build_layer

LOGGER = logging.getLogger(__name__)


def build_layer(layer: dict, hyperparameters: dict):
layer_class = import_object(layer['class'])
layer_kwargs = layer['parameters'].copy()
# TODO: Upgrade to using tf.keras.layers.Wrapper in mlprimitives.
if issubclass(layer_class, tf.keras.layers.Wrapper):
layer_kwargs['layer'] = build_layer(layer_kwargs['layer'], hyperparameters)
for key, value in layer_kwargs.items():
if isinstance(value, str):
layer_kwargs[key] = hyperparameters.get(value, value)
return layer_class(**layer_kwargs)


class AER(object):
"""Autoencoder with bi-directional regression for time series anomaly detection.

Expand Down
2 changes: 1 addition & 1 deletion orion/primitives/jsons/keras.Sequential.DenseSeq2Seq.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
},
"loss": {
"type": "str",
"default": "tensorflow.keras.losses.mean_squared_error"
"default": "tensorflow.losses.mse"
},
"metrics": {
"type": "list",
Expand Down
2 changes: 1 addition & 1 deletion orion/primitives/jsons/keras.Sequential.LSTMSeq2Seq.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
},
"loss": {
"type": "str",
"default": "tensorflow.keras.losses.mean_squared_error"
"default": "tensorflow.losses.mse"
},
"metrics": {
"type": "list",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
},
"loss": {
"type": "str",
"default": "tensorflow.keras.losses.mean_squared_error"
"default": "tensorflow.losses.mse"
},
"metrics": {
"type": "list",
Expand Down Expand Up @@ -149,7 +149,7 @@
}
},
{
"class": "ncps.tf.LTC",
"class": "ncps.keras.LTC",
"parameters": {
"units": {
"class": "ncps.wirings.AutoNCP",
Expand Down
15 changes: 1 addition & 14 deletions orion/primitives/tadgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from tensorflow.keras import Model

from orion.primitives.timeseries_errors import reconstruction_errors
from orion.primitives.utils import build_layer

LOGGER = logging.getLogger(__name__)
tf.keras.backend.set_floatx('float64')
Expand All @@ -25,20 +26,6 @@
]


def build_layer(layer: dict, hyperparameters: dict):
layer_class = import_object(layer['class'])
layer_kwargs = layer['parameters'].copy()
# TODO: Upgrade to using tf.keras.layers.Wrapper in mlprimitives.
if issubclass(layer_class, tf.keras.layers.Wrapper):
layer_kwargs['layer'] = build_layer(layer_kwargs['layer'], hyperparameters)

for key, value in layer_kwargs.items():
if isinstance(value, str):
layer_kwargs[key] = hyperparameters.get(value, value)

return layer_class(**layer_kwargs)


class TadGAN:
"""TadGAN model for time series reconstruction.

Expand Down
2 changes: 1 addition & 1 deletion orion/primitives/timeseries_anomalies.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _find_sequences(errors, epsilon, anomaly_padding):
for idx in index_above.flatten():
above[max(0, idx - anomaly_padding):min(idx + anomaly_padding + 1, len(above))] = True

shift = above.shift(1).fillna(False)
shift = above.shift(1).astype('boolean').fillna(False)
change = above != shift

if above.all():
Expand Down
4 changes: 2 additions & 2 deletions orion/primitives/timeseries_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def _area_error(y, y_hat, score_window=10):
An array of area error.
"""
smooth_y = pd.Series(y).rolling(
score_window, center=True, min_periods=score_window // 2).apply(integrate.trapz)
score_window, center=True, min_periods=score_window // 2).apply(integrate.trapezoid)
smooth_y_hat = pd.Series(y_hat).rolling(
score_window, center=True, min_periods=score_window // 2).apply(integrate.trapz)
score_window, center=True, min_periods=score_window // 2).apply(integrate.trapezoid)

errors = abs(smooth_y - smooth_y_hat)

Expand Down
16 changes: 16 additions & 0 deletions orion/primitives/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-

import tensorflow as tf
from mlstars.utils import import_object


def build_layer(layer: dict, hyperparameters: dict):
layer_class = import_object(layer['class'])
layer_kwargs = layer['parameters'].copy()
# TODO: tf.keras.layers.Wrapper deprecated, Bidirectional inheret from Layer
if issubclass(layer_class, tf.keras.layers.Layer) and 'layer' in layer_kwargs:
layer_kwargs['layer'] = build_layer(layer_kwargs['layer'], hyperparameters)
for key, value in layer_kwargs.items():
if isinstance(value, str):
layer_kwargs[key] = hyperparameters.get(value, value)
return layer_class(**layer_kwargs)
24 changes: 11 additions & 13 deletions orion/primitives/vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@
from tensorflow.keras.layers import Input
from tensorflow.keras.models import Model

from orion.primitives.utils import build_layer

LOGGER = logging.getLogger(__name__)


def build_layer(layer: dict, hyperparameters: dict):
layer_class = import_object(layer['class'])
layer_kwargs = layer['parameters'].copy()
# TODO: Upgrade to using tf.keras.layers.Wrapper in mlprimitives.
if issubclass(layer_class, tf.keras.layers.Wrapper):
layer_kwargs['layer'] = build_layer(layer_kwargs['layer'], hyperparameters)
for key, value in layer_kwargs.items():
if isinstance(value, str):
layer_kwargs[key] = hyperparameters.get(value, value)
return layer_class(**layer_kwargs)
class KLDivergenceLoss(tf.keras.layers.Layer):
def call(self, inputs):
z_log_sigma, z_mean = inputs
kl_loss = -0.5 * K.mean(1 + z_log_sigma - K.square(z_mean) - K.exp(z_log_sigma), axis=-1)
self.add_loss(kl_loss)
return inputs


class VAE(object):
Expand Down Expand Up @@ -180,13 +178,13 @@ def _build_vae(self, **kwargs):
h = self.encoder(x)
z_mean = tf.keras.layers.Dense(self.latent_dim)(h)
z_log_sigma = tf.keras.layers.Dense(self.latent_dim)(h)
KLDivergenceLoss()([z_log_sigma, z_mean]) # kl loss
z = tf.keras.layers.Lambda(self._sampling)([z_mean, z_log_sigma])

y_ = self.generator(z)

self.vae_model = Model([x, y], y_)
self.vae_model.add_loss(self._vae_loss(y, y_, z_log_sigma, z_mean))
self.vae_model.compile(optimizer=self.optimizer)
self.vae_model.compile(loss='mse', optimizer=self.optimizer)

def fit(self, X: np.ndarray, y: np.ndarray, **kwargs):
"""Fit the model.
Expand All @@ -211,7 +209,7 @@ def fit(self, X: np.ndarray, y: np.ndarray, **kwargs):
for callback in self.callbacks
]

self.fit_history = self.vae_model.fit((X, y),
self.fit_history = self.vae_model.fit((X, y), y,
batch_size=self.batch_size,
epochs=self.epochs,
shuffle=self.shuffle,
Expand Down
Loading