htm-community / hitc

HTM In The Cloud
GNU Affero General Public License v3.0
7 stars 7 forks source link

Creating a custom model does not respect input model param field names #16

Closed rhyolight closed 8 years ago

rhyolight commented 8 years ago

The script below creates a new custom model with these model params, which declare the following fieldnames:

#!/usr/bin/env python
import requests
import json

DATE_FORMAT = "%m/%d/%y %H:%M"
desc = """
A test the shows created models do not return the right field names.
"""

URL = 'http://localhost:5000/'

def post(url, params=None):
    return requests.post(URL+url, data=params)

def get(url, params=None):
    return requests.get(URL+url, params=params)

def create_model(model_spec):
    r = post('models', model_spec).json()
    return r['guid']

def get_model(model):
    return get('models/'+model)

if __name__ == "__main__":
    from pprint import pprint
    print(desc)
    print ("Making prediction model from model_params.json")
    with open('model_params.json') as data_file:
        model_spec = data_file.read()
    custom_model = create_model(model_spec)
    pprint (get_model(custom_model).json())

However, the resulting model params used to create the model don't respect the input param field names, instead the fields c0 and c1 are created, as shown in this python dict representing the created model params:

{u'guid': u'cfa3bb3e-4769-41b0-9299-0fb903d4e820',
 u'last': None,
 u'params': {u'aggregationInfo': {u'days': 0,
                                  u'fields': [],
                                  u'hours': 0,
                                  u'microseconds': 0,
                                  u'milliseconds': 0,
                                  u'minutes': 0,
                                  u'months': 0,
                                  u'seconds': 0,
                                  u'weeks': 0,
                                  u'years': 0},
             u'model': u'CLA',
             u'modelParams': {u'anomalyParams': {u'anomalyCacheRecords': None,
                                                 u'autoDetectThreshold': None,
                                                 u'autoDetectWaitRecords': 5030},
                              u'clEnable': False,
                              u'clParams': {u'alpha': 0.035828933612158,
                                            u'clVerbosity': 0,
                                            u'regionName': u'CLAClassifierRegion',
                                            u'steps': u'1'},
                              u'inferenceType': u'TemporalAnomaly',
                              u'sensorParams': {u'encoders': {u'c0_dayOfWeek': None,
                                                              u'c0_timeOfDay': {u'fieldname': u'c0',
                                                                                u'name': u'c0',
                                                                                u'timeOfDay': [21,
                                                                                               9.49122334747737],
                                                                                u'type': u'DateEncoder'},
                                                              u'c0_weekend': None,
                                                              u'c1': {u'fieldname': u'c1',
                                                                      u'name': u'c1',
                                                                      u'resolution': 21,
                                                                      u'seed': 42,
                                                                      u'type': u'RandomDistributedScalarEncoder'}},
                                                u'sensorAutoReset': None,
                                                u'verbosity': 0},
                              u'spEnable': True,
                              u'spParams': {u'columnCount': 2048,
                                            u'globalInhibition': 1,
                                            u'inputWidth': 0,
                                            u'maxBoost': 1.0,
                                            u'numActiveColumnsPerInhArea': 40,
                                            u'potentialPct': 0.8,
                                            u'seed': 1956,
                                            u'spVerbosity': 0,
                                            u'spatialImp': u'cpp',
                                            u'synPermActiveInc': 0.0015,
                                            u'synPermConnected': 0.1,
                                            u'synPermInactiveDec': 0.0005},
                              u'tpEnable': True,
                              u'tpParams': {u'activationThreshold': 13,
                                            u'cellsPerColumn': 32,
                                            u'columnCount': 2048,
                                            u'globalDecay': 0.0,
                                            u'initialPerm': 0.21,
                                            u'inputWidth': 2048,
                                            u'maxAge': 0,
                                            u'maxSegmentsPerCell': 128,
                                            u'maxSynapsesPerSegment': 32,
                                            u'minThreshold': 10,
                                            u'newSynapseCount': 20,
                                            u'outputType': u'normal',
                                            u'pamLength': 3,
                                            u'permanenceDec': 0.1,
                                            u'permanenceInc': 0.1,
                                            u'seed': 1960,
                                            u'temporalImp': u'cpp',
                                            u'verbosity': 0},
                              u'trainSPNetOnlyIfRequested': False},
             u'predictAheadTime': None,
             u'version': 1},
 u'predicted_field': u'c1',
 u'seen': 0}