Пример #1
0
 def testRemoveUnlikelyPredictionsLikelihoodThresholds(self):
   result = CLAModel._removeUnlikelyPredictions({1: 0.1, 2: 0.001}, 0.01, 3)
   self.assertDictEqual(result, {1: 0.1})
   result = CLAModel._removeUnlikelyPredictions({1: 0.001, 2: 0.002}, 0.01, 3)
   self.assertDictEqual(result, {2: 0.002})
   result = CLAModel._removeUnlikelyPredictions({1: 0.002, 2: 0.001}, 0.01, 3)
   self.assertDictEqual(result, {1: 0.002})
Пример #2
0
 def testRemoveUnlikelyPredictionsMaxPredictions(self):
   result = CLAModel._removeUnlikelyPredictions({1: 0.1, 2: 0.2, 3: 0.3},
                                                0.01, 3)
   self.assertDictEqual(result, {1: 0.1, 2: 0.2, 3: 0.3})
   result = CLAModel._removeUnlikelyPredictions(
       {1: 0.1, 2: 0.2, 3: 0.3, 4: 0.4}, 0.01, 3)
   self.assertDictEqual(result, {2: 0.2, 3: 0.3, 4: 0.4})
Пример #3
0
 def imagine(self, func_list):
     """
     Imagines (predicts) the consequences of applying a given function to the model.
 
     The method accepts a set of functions, to permit a number of alternatives to be
     simultaneously assessed.  A given function is expected to mutate the model then use it
     to make a prediction.  The imagination class forks the model for each function invocation,
     providing a ephemeral/hypothetical model to the function.
 
     """
     # fork the model, then apply the sets of input sequences
     temp_path = tempfile.mkdtemp(prefix='nupic')
     shutil.rmtree(temp_path)
     self.model.save(temp_path)
     
     results = []
     for func in func_list:
         model_fork = CLAModel.load(temp_path)
         result = func(model_fork) # a list of predictions (one for each run)
         results.append(result)
     
     shutil.rmtree(temp_path)
     
     return results
     
Пример #4
0
 def testRemoveUnlikelyPredictionsSingleValues(self):
   result = CLAModel._removeUnlikelyPredictions({1: 0.1}, 0.01, 3)
   self.assertDictEqual(result, {1: 0.1})
   result = CLAModel._removeUnlikelyPredictions({1: 0.001}, 0.01, 3)
   self.assertDictEqual(result, {1: 0.001})
Пример #5
0
 def testRemoveUnlikelyPredictionsEmpty(self):
   result = CLAModel._removeUnlikelyPredictions({}, 0.01, 3)
   self.assertDictEqual(result, {})
Пример #6
0
 def testRemoveUnlikelyPredictionsSingleValues(self):
     result = CLAModel._removeUnlikelyPredictions({1: 0.1}, 0.01, 3)
     self.assertDictEqual(result, {1: 0.1})
     result = CLAModel._removeUnlikelyPredictions({1: 0.001}, 0.01, 3)
     self.assertDictEqual(result, {1: 0.001})
Пример #7
0
 def testRemoveUnlikelyPredictionsEmpty(self):
     result = CLAModel._removeUnlikelyPredictions({}, 0.01, 3)
     self.assertDictEqual(result, {})