示例#1
0
 def newModel(self, event):
     '''Callback for creating a new (meta-, view-) model.'''
     self.clearModels()
     self.clearViewer()
     root = None
     if self.editor_mode == 'Model':
         fname = QtGui.QFileDialog.getOpenFileName(
             self,
             'Select Meta Model',
             '',
             'Meta Model Files (*.meta)',
             options=QtGui.QFileDialog.Options()
         )
         if fname:
             self.open_meta(fname)
             uuid_dict = OrderedDict()
             base = MetaModel.fromMeta(self.META['__ROOT__'][0], uuid_dict)
             roots = [
                 MetaModel.fromMeta(r, uuid_dict)()
                 for r in self.META['__ROOT__']
             ]
     elif self.editor_mode == 'Meta Model':
         self.open_meta('MetaMetaModel.meta')
         roots = [MetaModel()]
     elif self.editor_mode == 'View Model':
         # TODO: Replace this with view_model code
         self.open_meta('MetaViewModel.meta')
         roots = [ViewModel()]
     if roots:
         self.load_model(roots)
示例#2
0
    def summary(self) -> None:
        for island in self.islands:
            print(f"{island.name}")
            print('-' * len(island.model_group))
            print('')
            island.model_group.report()
            print('')

        archipelago = MetaModel(-1, self.groups)
        archipelago.summary()
        print('-' * 80)
示例#3
0
文件: test_meta.py 项目: sarocu/smpc
def test_ridge(data):
    model = MetaModel().readCSV(data)
    model.setResponse("Electricity:Facility [J](Hourly)")
    model.addPredictor("Environment:Site Outdoor Air Drybulb Temperature [C](Hourly)")
    model.addPredictor("Environment:Site Outdoor Air Humidity Ratio [kgWater/kgDryAir](Hourly)")

    model.bayesRidge().getScores()
    print(model.scores)
示例#4
0
 def saveModel(self, event):
     '''Saves a model according to the current mode of the editor.'''
     ftype = '{}'.format(self.editor_mode.lower().split()[0])
     fname = QtGui.QFileDialog.getSaveFileName(
         self,
         'Save {}'.format(self.editor_mode),
         '',
         '{} Files (*.{})'.format(self.editor_mode, ftype),
         options=QtGui.QFileDialog.Options()
     )
     fname = str(fname)
     if fname:
         if fname[-len(ftype):] != ftype:
             fname += '.{}'.format(ftype)
         root = self.model.getModel(QtCore.QModelIndex())
         # the actual root is not displayed and is always a Model()
         rootDict = [MetaModel.toDict(c) for c in root.children]
         modelDict = OrderedDict()
         modelDict['Name'] = fname.split('/')[-1].split('.')[-2]
         modelDict['MD5'] = hashlib.md5(str(rootDict)).hexdigest()
         modelDict['__META__'] = {
             'Name': self.META['Name'],
             'MD5': self.META['MD5']
         }
         modelDict['__ROOT__'] = rootDict
         dictStr = json.dumps(modelDict, indent=4)
         with open(fname, 'w') as f:
             f.write(dictStr)
         return 0
示例#5
0
    def load_model(self, roots):
        '''
        :param in model: the root object of a model, which is loaded into
            the tree-viewer and proxy models
        '''

        # Set up the hidden Root model, with the 'model' object as its
        # only child

        # TODO: Figure out how to allow different roots and multiple
        #       child objects.
        root = MetaModel()
        for r in roots:
            root.children.set_cardinality({r.__class__: '1..*'})
            root.add_child(r)

        # Set up the proxy model for sorting/filtering
        self.proxy_model = SortFilterProxyModel(self)
        self.proxy_model.setDynamicSortFilter(True)
        self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive)
        self.proxy_model.setSortRole(ItemModel.sort_role)
        self.proxy_model.setFilterRole(self.filter_role)
        self.proxy_model.setFilterKeyColumn(0)

        # the model stores the reference to the model that is
        # currently being edited/viewed; this can be a regular model,
        # a view model, or even a meta-model.  All these models
        # inherit from the meta-metamodel so have the same interfaces
        # and can be interacted with in the same way
        self.model = ItemModel(root)
        self.model.setMeta(self.META)
        self.model.rowsAboutToBeRemoved.connect(self.modelRowsAboutToBeRemoved)

        # Link the actual model and the proxy model
        self.proxy_model.setSourceModel(self.model)
        self.filter_edit.textChanged.connect(self.proxy_model.setFilterRegExp)
        self.tree_view.setModel(self.proxy_model)
        self.tree_view.expandAll()
示例#6
0
 def open_meta(self, fname):
     '''Decodes a saved meta-model file and loads it into the editor.'''
     with open(fname, 'r') as f:
         meta_dict = json.loads(f.read())
         print 'Loaded meta-model {}'.format(fname)
         # uuid_dict = {}
         # base = MetaModel.fromMeta(meta_dict['__ROOT__'], uuid_dict)
         # TODO: create meta_dict from loaded meta-model
         # TODO: Probably will need to resolve UUID referencce problems here
         uuid_dict = {}
         unresolved_keys = {}
         for r in meta_dict['__ROOT__']:
             a = MetaModel.fromDict(r, uuid_dict, unresolved_keys)
             buildMeta(meta_dict, r, uuid_dict)
         self.META = meta_dict
示例#7
0
    def process(self) -> None:
        logging.info(f" == {self.name} island == ")

        base = self._data.base_price
        self._models = MetaModel.blank(base)

        logging.info(f"  (%d models)  ", len(self._models))

        for time, price in self._data.timeline.items():
            if price is None:
                continue
            if time.value < TimePeriod.Monday_AM.value:
                continue
            logging.info(f"[{time.name}]: fixing price @ {price}")
            self._models.fix_price(time, price)
示例#8
0
文件: test_meta.py 项目: sarocu/smpc
def test_addPredictor():
    model = MetaModel()
    model.addPredictor("temperature")
    print(model.predictors)
示例#9
0
文件: test_meta.py 项目: sarocu/smpc
def test_all(data):
    model = MetaModel().readCSV(data)
    model.setResponse("Electricity:Facility [J](Hourly)")
    model.addPredictor("Environment:Site Outdoor Air Drybulb Temperature [C](Hourly)")
    model.addPredictor("Environment:Site Outdoor Air Humidity Ratio [kgWater/kgDryAir](Hourly)")
    model.addPredictor("BASEMENT:Zone Thermostat Heating Setpoint Temperature [C](Hourly)")
    model.addPredictor("CORE_MID:Zone Thermostat Heating Setpoint Temperature [C](Hourly)")
    model.addPredictor("CORE_TOP:Zone Thermostat Cooling Setpoint Temperature [C](Hourly)")

    model.bayesRidge().fitSVR(cost=10, epsilon=0.2).trees(numberOfTrees=300).getScores()
    print(model.scores)
    model.fit(model.SVR)
    model.persistMeta('../../data/demoMeta.p')
示例#10
0
文件: test_meta.py 项目: sarocu/smpc
def test_readCSV(data):
    model = MetaModel()
    model.readCSV(data)
    print(model.dataBox[:3])
示例#11
0
文件: test_meta.py 项目: sarocu/smpc
def test_persist(data):
    model = MetaModel().readCSV(data)
    model.setResponse("Electricity:Facility [J](Hourly)")
    model.addPredictor("Environment:Site Outdoor Air Drybulb Temperature [C](Hourly)")
    model.addPredictor("Environment:Site Outdoor Air Humidity Ratio [kgWater/kgDryAir](Hourly)")

    model.fitSVR(cost=10, epsilon=0.2).getScores()

    model.persistMeta('testPickle.p')
    newModel = pickle.load(open('testPickle.p', 'rb'))
    print(newModel.scores)
示例#12
0
文件: test_meta.py 项目: sarocu/smpc
def test_setResponse():
    model = MetaModel()
    model.setResponse("energy")
    print (model.response)