# Path: nilmtk/feature_detectors/cluster.py
# def hart85_means_shift_cluster(pair_buffer_df, columns):
# 
#     from sklearn.cluster import MeanShift
#     # Creating feature vector
#     cluster_df = pd.DataFrame()
#     power_types = [col[1] for col in columns]
# 
#     if 'active' in power_types:
#         cluster_df['active'] = pd.Series(
#             pair_buffer_df.apply(
#                 lambda row: (
#                     (np.fabs(
#                         row['T1 Active']) +
#                         np.fabs(
#                         row['T2 Active'])) /
#                     2),
#                 axis=1),
#             index=pair_buffer_df.index)
#     if 'reactive' in power_types:
#         cluster_df['reactive'] = pd.Series(
#             pair_buffer_df.apply(
#                 lambda row: (
#                     (np.fabs(
#                         row['T1 Reactive']) +
#                         np.fabs(
#                         row['T2 Reactive'])) /
#                     2),
#                 axis=1),
#             index=pair_buffer_df.index)
#     if 'apparent' in power_types:
#         cluster_df['apparent'] = pd.Series(
#             pair_buffer_df.apply(
#                 lambda row: (
#                     (np.fabs(
#                         row['T1 Apparent']) +
#                         np.fabs(
#                         row['T2 Apparent'])) /
#                     2),
#                 axis=1),
#             index=pair_buffer_df.index)
#     X = cluster_df.values.reshape((len(cluster_df.index), len(columns)))
#     ms = MeanShift(bin_seeding=True)
#     ms.fit(X)
#     labels = ms.labels_
#     cluster_centers = ms.cluster_centers_
#     labels_unique = np.unique(labels)
#     return pd.DataFrame(cluster_centers, columns=columns)
# 
# Path: nilmtk/feature_detectors/steady_states.py
# def find_steady_states_transients(metergroup, columns, noise_level,
#                                   state_threshold, **load_kwargs):
#     """
#     Returns
#     -------
#     steady_states, transients : pd.DataFrame
#     """
#     steady_states_list = []
#     transients_list = []
# 
#     for power_df in metergroup.load(columns=columns, **load_kwargs):
#         """
#         if len(power_df.columns) <= 2:
#             # Use whatever is available
#             power_dataframe = power_df
#         else:
#             # Active, reactive and apparent are available
#             power_dataframe = power_df[[('power', 'active'), ('power', 'reactive')]]
#         """
#         power_dataframe = power_df.dropna()
#         if power_dataframe.empty:
#             continue
# 
#         x, y = find_steady_states(
#             power_dataframe, noise_level=noise_level,
#             state_threshold=state_threshold)
#         steady_states_list.append(x)
#         transients_list.append(y)
#     return [pd.concat(steady_states_list), pd.concat(transients_list)]


import pickle
import numpy as np
import pandas as pd
from collections import OrderedDict, deque
from sklearn.metrics import mean_squared_error
from ...feature_detectors.cluster import hart85_means_shift_cluster
from ...feature_detectors.steady_states import find_steady_states_transients
from . import Disaggregator
                            power[i] = self.centroids.loc[appliance].values
                            i = i + 1

            di[appliance] = power
            # print(power.sum())
        return di

    def disaggregate(self, mains, output_datastore, **load_kwargs):
        """Disaggregate mains according to the model learnt previously.

        Parameters
        ----------
        mains : nilmtk.ElecMeter or nilmtk.MeterGroup
        output_datastore : instance of nilmtk.DataStore subclass
            For storing power predictions from disaggregation algorithm.
        sample_period : number, optional
            The desired sample period in seconds.
        **load_kwargs : key word arguments
            Passed to `mains.power_series(**kwargs)`
        """
        load_kwargs = self._pre_disaggregation_checks(load_kwargs)

        load_kwargs.setdefault('sample_period', 60)
        load_kwargs.setdefault('sections', mains.good_sections())

        timeframes = []
        building_path = '/building{}'.format(mains.building())
        mains_data_location = building_path + '/elec/meter1'
        data_is_available = False


# Path: nilmtk/feature_detectors/cluster.py
# def hart85_means_shift_cluster(pair_buffer_df, columns):
# 
#     from sklearn.cluster import MeanShift
#     # Creating feature vector
#     cluster_df = pd.DataFrame()
#     power_types = [col[1] for col in columns]
# 
#     if 'active' in power_types:
#         cluster_df['active'] = pd.Series(
#             pair_buffer_df.apply(
#                 lambda row: (
#                     (np.fabs(
#                         row['T1 Active']) +
#                         np.fabs(
#                         row['T2 Active'])) /
#                     2),
#                 axis=1),
#             index=pair_buffer_df.index)
#     if 'reactive' in power_types:
#         cluster_df['reactive'] = pd.Series(
#             pair_buffer_df.apply(
#                 lambda row: (
#                     (np.fabs(
#                         row['T1 Reactive']) +
#                         np.fabs(
#                         row['T2 Reactive'])) /
#                     2),
#                 axis=1),
#             index=pair_buffer_df.index)
#     if 'apparent' in power_types:
#         cluster_df['apparent'] = pd.Series(
#             pair_buffer_df.apply(
#                 lambda row: (
#                     (np.fabs(
#                         row['T1 Apparent']) +
#                         np.fabs(
#                         row['T2 Apparent'])) /
#                     2),
#                 axis=1),
#             index=pair_buffer_df.index)
#     X = cluster_df.values.reshape((len(cluster_df.index), len(columns)))
#     ms = MeanShift(bin_seeding=True)
#     ms.fit(X)
#     labels = ms.labels_
#     cluster_centers = ms.cluster_centers_
#     labels_unique = np.unique(labels)
#     return pd.DataFrame(cluster_centers, columns=columns)
# 
# Path: nilmtk/feature_detectors/steady_states.py
# def find_steady_states_transients(metergroup, columns, noise_level,
#                                   state_threshold, **load_kwargs):
#     """
#     Returns
#     -------
#     steady_states, transients : pd.DataFrame
#     """
#     steady_states_list = []
#     transients_list = []
# 
#     for power_df in metergroup.load(columns=columns, **load_kwargs):
#         """
#         if len(power_df.columns) <= 2:
#             # Use whatever is available
#             power_dataframe = power_df
#         else:
#             # Active, reactive and apparent are available
#             power_dataframe = power_df[[('power', 'active'), ('power', 'reactive')]]
#         """
#         power_dataframe = power_df.dropna()
#         if power_dataframe.empty:
#             continue
# 
#         x, y = find_steady_states(
#             power_dataframe, noise_level=noise_level,
#             state_threshold=state_threshold)
#         steady_states_list.append(x)
#         transients_list.append(y)
#     return [pd.concat(steady_states_list), pd.concat(transients_list)]


# Path: nilmtk/legacy/disaggregate/hart_85.py
import pickle
import numpy as np
import pandas as pd
from collections import OrderedDict, deque
from sklearn.metrics import mean_squared_error
from ...feature_detectors.cluster import hart85_means_shift_cluster
from ...feature_detectors.steady_states import find_steady_states_transients
from . import Disaggregator

                            power[i] = self.centroids.loc[appliance].values
                            i = i + 1

            di[appliance] = power
            # print(power.sum())
        return di

    def disaggregate(self, mains, output_datastore, **load_kwargs):
        """Disaggregate mains according to the model learnt previously.

        Parameters
        ----------
        mains : nilmtk.ElecMeter or nilmtk.MeterGroup
        output_datastore : instance of nilmtk.DataStore subclass
            For storing power predictions from disaggregation algorithm.
        sample_period : number, optional
            The desired sample period in seconds.
        **load_kwargs : key word arguments
            Passed to `mains.power_series(**kwargs)`
        """
        load_kwargs = self._pre_disaggregation_checks(load_kwargs)

        load_kwargs.setdefault('sample_period', 60)
        load_kwargs.setdefault('sections', mains.good_sections())

        timeframes = []
        building_path = '/building{}'.format(mains.building())
        mains_data_location = building_path + '/elec/meter1'
        data_is_available = False


        [_, transients] = find_steady_states_transients(