<commit_before>from __future__ import print_function, division

# Stop matplotlib from drawing to X.
# Must be before importing matplotlib.pyplot or pylab!
import matplotlib
matplotlib.use('Agg')

from lasagne.layers import InputLayer, DenseLayer, ReshapeLayer

from neuralnilm.data.loadactivations import load_nilmtk_activations
from neuralnilm.data.syntheticaggregatesource import SyntheticAggregateSource
from neuralnilm.data.realaggregatesource import RealAggregateSource
from neuralnilm.data.stridesource import StrideSource
from neuralnilm.data.datapipeline import DataPipeline
from neuralnilm.data.processing import DivideBy, IndependentlyCenter
from neuralnilm.net import Net
from neuralnilm.trainer import Trainer
from neuralnilm.metrics import Metrics
from neuralnilm.consts import DATA_FOLD_NAMES


NILMTK_FILENAME = '/data/dk3810/ukdale.h5'
SAMPLE_PERIOD = 6
STRIDE = None
APPLIANCES = [
    'kettle', 'microwave', 'washing machine', 'dish washer', 'fridge']
WINDOWS = {
    'train': {
        1: ("2013-04-12", "2015-07-01"),
        2: ("2013-05-22", "2013-10-03 06:16:00"),
        3: ("2013-02-27", "2013-04-01 06:15:05"),
        4: ("2013-03-09", "2013-09-24 06:15:14")
    },
    'unseen_activations_of_seen_appliances': {
        1: ("2015-07-02", None),
        2: ("2013-10-03 06:16:00", None),
        3: ("2013-04-01 06:15:05", None),
        4: ("2013-09-24 06:15:14", None)
    },
    'unseen_appliances': {
        5: ("2014-06-29", None)
    }
}


def run(root_experiment_name):
    activations = load_nilmtk_activations(
        appliances=APPLIANCES,
        filename=NILMTK_FILENAME,
        sample_period=SAMPLE_PERIOD,
        windows=WINDOWS
    )

    for get_net in [ae]:
        for target_appliance in ['kettle']:
            pipeline = get_pipeline(target_appliance, activations)

            # Build net
            batch = pipeline.get_batch()
            net = get_net(batch)

            # Trainer
            trainer = Trainer(
                net=net,
                data_pipeline=pipeline,
                experiment_id=[
                    root_experiment_name, get_net.__name__, target_appliance],
                metrics=Metrics(state_boundaries=[3]),
                learning_rates={0: 1E-2},
                repeat_callbacks=[
                    (500, Trainer.validate),
                    (5000, Trainer.save_params),
                    (5000, Trainer.plot_estimates)
                ]
            )

            report = trainer.submit_report()
            print(report)

            # Run!
            trainer.fit(None)


# ----------------------  NETWORKS  -------------------------
def ae(batch):
    input_shape = batch.input.shape
    target_shape = batch.target.shape

    input_layer = InputLayer(
        shape=input_shape
    )

    # Dense layers
    dense_layer_0 = DenseLayer(
        input_layer,
        num_units=128
    )<commit_msg>only validated every 5000 updates<commit_after>from __future__ import print_function, division

# Stop matplotlib from drawing to X.
# Must be before importing matplotlib.pyplot or pylab!
import matplotlib
matplotlib.use('Agg')

from lasagne.layers import InputLayer, DenseLayer, ReshapeLayer

from neuralnilm.data.loadactivations import load_nilmtk_activations
from neuralnilm.data.syntheticaggregatesource import SyntheticAggregateSource
from neuralnilm.data.realaggregatesource import RealAggregateSource
from neuralnilm.data.stridesource import StrideSource
from neuralnilm.data.datapipeline import DataPipeline
from neuralnilm.data.processing import DivideBy, IndependentlyCenter
from neuralnilm.net import Net
from neuralnilm.trainer import Trainer
from neuralnilm.metrics import Metrics
from neuralnilm.consts import DATA_FOLD_NAMES


NILMTK_FILENAME = '/data/dk3810/ukdale.h5'
SAMPLE_PERIOD = 6
STRIDE = None
APPLIANCES = [
    'kettle', 'microwave', 'washing machine', 'dish washer', 'fridge']
WINDOWS = {
    'train': {
        1: ("2013-04-12", "2015-07-01"),
        2: ("2013-05-22", "2013-10-03 06:16:00"),
        3: ("2013-02-27", "2013-04-01 06:15:05"),
        4: ("2013-03-09", "2013-09-24 06:15:14")
    },
    'unseen_activations_of_seen_appliances': {
        1: ("2015-07-02", None),
        2: ("2013-10-03 06:16:00", None),
        3: ("2013-04-01 06:15:05", None),
        4: ("2013-09-24 06:15:14", None)
    },
    'unseen_appliances': {
        5: ("2014-06-29", None)
    }
}


def run(root_experiment_name):
    activations = load_nilmtk_activations(
        appliances=APPLIANCES,
        filename=NILMTK_FILENAME,
        sample_period=SAMPLE_PERIOD,
        windows=WINDOWS
    )

    for get_net in [ae]:
        for target_appliance in ['kettle']:
            pipeline = get_pipeline(target_appliance, activations)

            # Build net
            batch = pipeline.get_batch()
            net = get_net(batch)

            # Trainer
            trainer = Trainer(
                net=net,
                data_pipeline=pipeline,
                experiment_id=[
                    root_experiment_name, get_net.__name__, target_appliance],
                metrics=Metrics(state_boundaries=[3]),
                learning_rates={0: 1E-2},
                repeat_callbacks=[
                    (5000, Trainer.validate),
                    (5000, Trainer.save_params),
                    (5000, Trainer.plot_estimates)
                ]
            )

            report = trainer.submit_report()
            print(report)

            # Run!
            trainer.fit(None)


# ----------------------  NETWORKS  -------------------------
def ae(batch):
    input_shape = batch.input.shape
    target_shape = batch.target.shape

    input_layer = InputLayer(
        shape=input_shape
    )

    # Dense layers
    dense_layer_0 = DenseLayer(
        input_layer,
        num_units=128
    )
{'fraction_non_alphanumeric': 0.11722365038560412, 'fraction_numerical': 0.06049700085689803, 'mean_word_length': 2.321570859419465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5806535', 'n_tokens_mistral': 2093, 'n_tokens_neox': 1821, 'n_words': 372}