Skip to content

Commit

Permalink
Merge pull request #203 from cchrewrite/dev
Browse files Browse the repository at this point in the history
Update new energy models. Update .pylintrc to be compatible with the latest version of pylint.
  • Loading branch information
cchrewrite committed Sep 28, 2022
2 parents 49b9442 + c272cd7 commit c481e7e
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 104 deletions.
178 changes: 93 additions & 85 deletions .pylintrc
Expand Up @@ -79,91 +79,99 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
deprecated-operator-function,
deprecated-urllib-function,
xreadlines-attribute,
deprecated-sys-function,
exception-escape,
import-error,
comprehension-escape,
too-many-function-args, # false positive on np.array([...])
not-an-iterable, # false positive on tensor.shape
unsubscriptable-object, # false positive on tensor.shape
no-name-in-module, # proto object available after compilation
access-member-before-definition # conv layer re-instantiate handle when batch number changed
disable=import-error,
unrecognized-option,
used-before-assignment,
no-name-in-module,
access-member-before-definition,
unsubscriptable-object

# disable=print-statement,
# parameter-unpacking,
# unpacking-in-except,
# old-raise-syntax,
# backtick,
# long-suffix,
# old-ne-operator,
# old-octal-literal,
# import-star-module-level,
# non-ascii-bytes-literal,
# raw-checker-failed,
# bad-inline-option,
# locally-disabled,
# file-ignored,
# suppressed-message,
# useless-suppression,
# deprecated-pragma,
# use-symbolic-message-instead,
# apply-builtin,
# basestring-builtin,
# buffer-builtin,
# cmp-builtin,
# coerce-builtin,
# execfile-builtin,
# file-builtin,
# long-builtin,
# raw_input-builtin,
# reduce-builtin,
# standarderror-builtin,
# unicode-builtin,
# xrange-builtin,
# coerce-method,
# delslice-method,
# getslice-method,
# setslice-method,
# no-absolute-import,
# old-division,
# dict-iter-method,
# dict-view-method,
# next-method-called,
# metaclass-assignment,
# indexing-exception,
# raising-string,
# reload-builtin,
# oct-method,
# hex-method,
# nonzero-method,
# cmp-method,
# input-builtin,
# round-builtin,
# intern-builtin,
# unichr-builtin,
# map-builtin-not-iterating,
# zip-builtin-not-iterating,
# range-builtin-not-iterating,
# filter-builtin-not-iterating,
# using-cmp-argument,
# eq-without-hash,
# div-method,
# idiv-method,
# rdiv-method,
# exception-message-attribute,
# invalid-str-codec,
# sys-max-int,
# bad-python3-import,
# deprecated-string-function,
# deprecated-str-translate-call,
# deprecated-itertools-function,
# deprecated-types-field,
# next-method-defined,
# dict-items-not-iterating,
# dict-keys-not-iterating,
# dict-values-not-iterating,
# deprecated-operator-function,
# deprecated-urllib-function,
# xreadlines-attribute,
# deprecated-sys-function,
# exception-escape,
# import-error,
# comprehension-escape,
# too-many-function-args, # false positive on np.array([...])
# not-an-iterable, # false positive on tensor.shape
# unsubscriptable-object, # false positive on tensor.shape
# no-name-in-module, # proto object available after compilation
# access-member-before-definition # conv layer re-instantiate handle when batch number changed


# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
Expand Up @@ -41,7 +41,8 @@ class MLPBatteryCapacityEstimator(BaseModel):
@staticmethod
def get_knob_config():
return {
'num_hid_layers': IntegerKnob(2, 4)
'num_hid_layers': IntegerKnob(2, 4),
'num_hid_units': IntegerKnob(64, 512)
}

def __init__(self, **knobs):
Expand All @@ -52,7 +53,8 @@ def __init__(self, **knobs):
self.time_length = 60

num_hid_layers = self._knobs.get("num_hid_layers")
hidden_layer_sizes = [256] * int(num_hid_layers)
num_hid_units = self._knobs.get("num_hid_units")
hidden_layer_sizes = [int(num_hid_units)] * int(num_hid_layers)

self._regr = MLPRegressor(random_state=1, max_iter=100000, hidden_layer_sizes = hidden_layer_sizes)

Expand Down Expand Up @@ -157,19 +159,23 @@ def read_discharge_data(self, data_file):
continue
if data_header == "":
data_header = x.split(",")
if not("Capacity" in data_header):
is_query = True
else:
is_query = False
continue

if x == "<Start of Discharging>":
if "<Start of Discharging>" in x:
data_matrix = []
continue

elif x == "<End of Discharging>":
elif "<End of Discharging>" in x:
data_matrix = np.asarray(data_matrix)
t = data_matrix[:,data_header.index("Time")]
if "Capacity" in data_header:
target = data_matrix[-1,data_header.index("Capacity")]
if is_query == True:
target = "Unknown"
else:
target = None
target = data_matrix[-1,data_header.index("Capacity")]
data_matrix_ali = []

for i in range(len(data_header)):
Expand All @@ -195,8 +201,6 @@ def read_discharge_data(self, data_file):
return data_header, feat_data, tgt_data




if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--train_path',
Expand All @@ -213,7 +217,7 @@ def read_discharge_data(self, data_file):
help='Path to test dataset')
parser.add_argument('--query_path',
type=str,
default='data/B0005_eval.csv,data/B0005_eval.csv',
default='data/B0005_query.csv,data/B0005_query.csv',
help='Path(s) to query image(s), delimited by commas')
(args, _) = parser.parse_known_args()

Expand All @@ -227,6 +231,6 @@ def read_discharge_data(self, data_file):
train_dataset_path=args.train_path,
val_dataset_path=args.val_path,
test_dataset_path=args.test_path,
budget={'MODEL_TRIAL_COUNT': 10, 'TIME_HOURS': 1.0},
queries=queries)


52 changes: 52 additions & 0 deletions examples/models/new_energy_analysis/battery/README.md
@@ -0,0 +1,52 @@
# Singa-Auto Demo - Battery Capacity Estimator.

This folder contains a number of models for estimating the capacity of rechargeable batteries in mobile phones, electric vehicles, etc.

## Dataset Preparation

The training and evaluation data should be compressed into a single .zip file. The zip file contains two CSV files: train.csv and valid.csv. Both CSV files are in the following format:

The first line is the header, which must be:

Time,Voltage_measured,Current_measured,Temperature_measured,Current_load,Voltage_load,Capacity

From the second line, the data is split into many blocks. Each block starts from a '\<Start of Discharging\>' line and ends at an '\<End of Discharging\>' line. Each block contains data during a single round of discharging. Each line is a data point. For example:

\<Start of Discharging\>
0.00,4.19,-0.000261,24.3,0.000600,0.00,1.36
9.37,4.19,0.000523,24.3,0.000800,4.21,1.36
19.51,3.97,-2.01,24.3,1.99,2.96,1.36
28.82,3.95,-2.01,24.4,1.99,2.95,1.36
...
2873.25,3.58,-0.003372,35.0,0.0006,0.00,1.36
2883.01,3.58,-0.002502,34.9,0.0006,0.00,1.36
\<End of Discharging\>

## Prediction/Inference

A query file is a CSV file that contains some historical discharging data. The first line is the header, which must be:

Time,Voltage_measured,Current_measured,Temperature_measured,Current_load,Voltage_load

From the second line, the data is split into many blocks. Each block starts from a '\<Start of Discharging\>' line and ends at an '\<End of Discharging\>' line. Each block contains data during a single round of discharging. Each line is a data point. For example:

\<Start of Discharging\>
0.00,4.19,-0.000261,24.3,0.000600,0.00
9.37,4.19,0.000523,24.3,0.000800,4.21
19.51,3.97,-2.01,24.3,1.99,2.96
28.82,3.95,-2.01,24.4,1.99,2.95
...
2873.25,3.58,-0.003372,35.0,0.0006,0.00
2883.01,3.58,-0.002502,34.9,0.0006,0.00
\<End of Discharging\>

Given a query CSV file, the model returns an estimated capacity.

## Model Description

There are two models:
1. RFBatteryCapacityEstimator.py, which is a random forest. It will perform auto parameter tuning on the maximum depth of decision trees, the number of estimators and feature selection criteria.
2. MLPBatteryCapacityEstimator.py, which is a feedforward neural network. It will perform auto parameter tuning on the number of hidden layers and hidden units.

Their usages are almost the same. However, the random forest is usually much faster, whereas the feedforward neural network is more robust.

0 comments on commit c481e7e

Please sign in to comment.