nilmtk.disaggregate package

Submodules

nilmtk.disaggregate.combinatorial_optimisation module

class nilmtk.disaggregate.combinatorial_optimisation.CombinatorialOptimisation[source]

Bases: object

1 dimensional combinatorial optimisation NILM algorithm.

Attributes

model (list of dicts) Each dict has these keys: states : list of ints (the power (Watts) used in different states) training_metadata : ElecMeter or MeterGroup object used for training this set of states. We need this information because we need the appliance type (and perhaps some other metadata) for each model.
disaggregate(mains, output_datastore, **load_kwargs)[source]

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.

output_name : string, optional

The name to use in the metadata for the output_datastore. e.g. some sort of name for this experiment. Defaults to “NILMTK_CO_<date>”

resample_seconds : number, optional

The desired sample period in seconds.

**load_kwargs : key word arguments

Passed to mains.power_series(**kwargs)

train(metergroup, **load_kwargs)[source]

Train using 1D CO. Places the learnt model in the model attribute.

Parameters:metergroup : a nilmtk.MeterGroup object

Notes

  • only uses first chunk for each meter (TODO: handle all chunks).

nilmtk.disaggregate.disaggregator module

class nilmtk.disaggregate.disaggregator.Disaggregator[source]

Bases: object

Provides a common interface to all disaggregation classes. See https://github.com/nilmtk/nilmtk/issues/271 for discussion.

Attributes

Each subclass should internally store models learned from training.  
disaggregate(mains, output_datastore)[source]

Passes each chunk from mains generator to disaggregate_chunk() and passes the output to _write_disaggregated_chunk_to_datastore() Will have a default implementation in super class. Can be overridden for more simple in-memory disaggregation, or more complex out-of-core disaggregation.

Parameters:

mains : nilmtk.ElecMeter (single-phase) or nilmtk.MeterGroup (multi-phase)

output_datastore : instance of nilmtk.DataStore or str of datastore location

disaggregate_chunk(chunk)[source]

Loads all of a DataFrame from disk.

Parameters:chunk : pd.DataFrame (in NILMTK format)
Returns:chunk : pd.DataFrame where each column represents a disaggregated appliance
export_model(filename)[source]

Saves learned model to file. Required to be overridden for learned models to persist.

Parameters:filename : str path to file to save model to
import_model(filename)[source]

Loads learned model from file. Required to be overridden for learned models to persist.

Parameters:filename : str path to file to load model from
train(metergroup)[source]

Trains the model given a metergroup containing a appliance meters (supervised) or a site meter (unsupervised). Will have a default implementation in super class. Can be overridden for simpler in-memory training, or more complex out-of-core training.

Parameters:metergroup : a nilmtk.MeterGroup object
train_on_chunk(chunk, identifier)[source]

Signature is fine for site meter dataframes (unsupervised learning). Would need to be called for each appliance meter along with appliance identifier for supervised learning. Required to be overridden to provide out-of-core disaggregation.

Parameters:

chunk : pd.DataFrame where each column represents a disaggregated appliance

identifier : tuple of (nilmtk.appliance, int) representing instance of that appliance for this chunk

nilmtk.disaggregate.fhmm_exact module

class nilmtk.disaggregate.fhmm_exact.FHMM[source]

Bases: object

disaggregate(mains, output_datastore, **load_kwargs)[source]

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.

output_name : string, optional

The name to use in the metadata for the output_datastore. e.g. some sort of name for this experiment. Defaults to “NILMTK_FHMM_<date>”

resample_seconds : number, optional

The desired sample period in seconds.

**load_kwargs : key word arguments

Passed to mains.power_series(**kwargs)

disaggregate_chunk(test_mains)[source]

Disaggregate the test data according to the model learnt previously Performs 1D FHMM disaggregation.

For now assuming there is no missing data at this stage.

train(metergroup, **load_kwargs)[source]

Train using 1d FHMM. Places the learnt model in model attribute The current version performs training ONLY on the first chunk. Online HMMs are welcome if someone can contribute :) Assumes all pre-processing has been done.

nilmtk.disaggregate.fhmm_exact.compute_A_fhmm(list_A)[source]
Parameters:list_pi : List of PI’s of individual learnt HMMs
Returns:result : Combined Pi for the FHMM
nilmtk.disaggregate.fhmm_exact.compute_means_fhmm(list_means)[source]
Returns:[mu, cov]
nilmtk.disaggregate.fhmm_exact.compute_pi_fhmm(list_pi)[source]
Parameters:list_pi : List of PI’s of individual learnt HMMs
Returns:result : Combined Pi for the FHMM
nilmtk.disaggregate.fhmm_exact.create_combined_hmm(model)[source]
nilmtk.disaggregate.fhmm_exact.decode_hmm(length_sequence, centroids, appliance_list, states)[source]

Decodes the HMM state sequence

nilmtk.disaggregate.fhmm_exact.return_sorting_mapping(means)[source]
nilmtk.disaggregate.fhmm_exact.sort_covars(mapping, covars)[source]
nilmtk.disaggregate.fhmm_exact.sort_learnt_parameters(startprob, means, covars, transmat)[source]
nilmtk.disaggregate.fhmm_exact.sort_startprob(mapping, startprob)[source]

Sort the startprob according to power means; as returned by mapping

nilmtk.disaggregate.fhmm_exact.sort_transition_matrix(mapping, A)[source]

Sorts the transition matrix according to increasing order of power means; as returned by mapping

Parameters:

mapping :

A : numpy.array of shape (k, k)

transition matrix

nilmtk.disaggregate.hart_85 module

class nilmtk.disaggregate.hart_85.Hart85[source]

Bases: object

1 or 2 dimensional Hart 1985 algorithm.

Attributes

model (dict) Each key is either the instance integer for an ElecMeter, or a tuple of instances for a MeterGroup. Each value is a sorted list of power in different states.
assign_power_from_states(states_chunk, prev)[source]
disaggregate(mains, output_datastore, **load_kwargs)[source]

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.

output_name : string, optional

The name to use in the metadata for the output_datastore. e.g. some sort of name for this experiment. Defaults to “NILMTK_Hart85_<date>”

resample_seconds : number, optional

The desired sample period in seconds.

**load_kwargs : key word arguments

Passed to mains.power_series(**kwargs)

hart85_disaggregate_single_chunk(chunk, prev, transients)[source]
pair(buffer_size, min_tolerance, percent_tolerance, large_transition)[source]
train(metergroup, cols=[('power', 'active')], buffer_size=20, noise_level=70, state_threshold=15, min_tolerance=100, percent_tolerance=0.035, large_transition=1000, **kwargs)[source]

Train using Hart85. Places the learnt model in model attribute.

Parameters:

metergroup : a nilmtk.MeterGroup object

cols: nilmtk.Measurement, should be one of the following

[(‘power’,’active’)] [(‘power’,’apparent’)] [(‘power’,’reactive’)] [(‘power’,’active’), (‘power’, ‘reactive’)]

buffer_size: int, optional

size of the buffer to use for finding edges

min_tolerance: int, optional

variance in power draw allowed for pairing a match

percent_tolerance: float, optional

if transition is greater than large_transition, then use percent of large_transition

large_transition: float, optional

power draw of a Large transition

class nilmtk.disaggregate.hart_85.MyDeque[source]

Bases: collections.deque

popmiddle(pos)[source]
class nilmtk.disaggregate.hart_85.PairBuffer(buffer_size, min_tolerance, percent_tolerance, large_transition, num_measurements)[source]

Bases: object

Attributes: * transitionList (list of tuples) * matchedPairs (dataframe containing matched pairs of transitions)

add_transition(transition)[source]
clean_buffer()[source]
pair_transitions()[source]

Hart 85, P 33. When searching the working buffer for pairs, the order in which entries are examined is very important. If an Appliance has on and off several times in succession, there can be many pairings between entries in the buffer. The algorithm must not allow an 0N transition to match an OFF which occurred at the end of a different cycle, so that only ON/OFF pairs which truly belong together are paired up. Otherwise the energy consumption of the appliance will be greatly overestimated. The most straightforward search procedures can make errors of this nature when faced with types of transition sequences.

Hart 85, P 32. For the two-state load monitor, a pair is defined as two entries which meet the following four conditions: (1) They are on the same leg, or are both 240 V, (2) They are both unmarked, (3) The earlier has a positive real power component, and (4) When added together, they result in a vector in which the absolute value of the real power component is less than 35 Watts (or 3.5% of the real power, if the transitions are over 1000 W) and the absolute value of the reactive power component is less than 35 VAR (or 3.5%).

... the correct way to search the buffer is to start by checking elements which are close together in the buffer, and gradually increase the distance. First, adjacent elements are checked for pairs which meet all four requirements above; if any are found they are processed and marked. Then elements two entries apart are checked, then three, and so on, until the first and last element are checked...

Module contents