Ejemplo n.º 1
0
 def test20BitMP5000Iterations(self):
     dataPath = os.path.join(THIS_DIR, "test/DataSets/Real/Multiplexer20Modified.csv")
     converter = StringEnumerator(dataPath,"Class")
     headers, classLabel, dataFeatures, dataPhenotypes = converter.get_params()
     clf = XCS(learning_iterations=5000,N=2000,nu=10)
     clf.fit(dataFeatures,dataPhenotypes)
     answer = 0.6634
     #print("20 Bit 5000 Iter: "+str(clf.get_final_training_accuracy()))
     self.assertTrue(self.approxEqualOrBetter(0.2,clf.get_final_training_accuracy(),answer,True))
Ejemplo n.º 2
0
 def testContValues5000Iterations(self):
     dataPath = os.path.join(THIS_DIR, "test/DataSets/Real/ContinuousAndNonBinaryDiscreteAttributes.csv")
     converter = StringEnumerator(dataPath,"Class")
     headers, classLabel, dataFeatures, dataPhenotypes = converter.get_params()
     clf = XCS(learning_iterations=5000)
     clf.fit(dataFeatures,dataPhenotypes)
     answer = 0.64
     #print("Continuous Attributes 5000 Iter: "+str(clf.get_final_training_accuracy()))
     self.assertTrue(self.approxEqualOrBetter(0.2,clf.get_final_training_accuracy(),answer,True))
Ejemplo n.º 3
0
 def testPredictInvVar(self):
     dataPath = os.path.join(THIS_DIR,
                             "test/DataSets/Real/Multiplexer6Modified.csv")
     converter = StringEnumerator(dataPath, "Class")
     headers, classLabel, dataFeatures, dataPhenotypes = converter.get_params(
     )
     clf = XCS(learning_iterations=1000,
               N=500,
               nu=10,
               use_inverse_varinance=True,
               p_explore=0.5)
     clf.fit(dataFeatures, dataPhenotypes)
     print("kkkkkkkkkkkkkkkkkkkkkkkkkkk")
     print(clf.predict(clf.env.formatData.savedRawTrainingData[0]))
Ejemplo n.º 4
0
 def testInverseVariance(self):
     dataPath = os.path.join(THIS_DIR,
                             "test/DataSets/Real/Multiplexer11.csv")
     converter = StringEnumerator(dataPath, "class")
     headers, classLabel, dataFeatures, dataPhenotypes = converter.get_params(
     )
     clf = XCS(learning_iterations=5000,
               N=1000,
               mixing_method="inv-var-only-mixing")
     clf.fit(dataFeatures, dataPhenotypes)
     answer = 0.894
     score = clf.get_final_training_accuracy()
     print("#####################################\n6 Bit 1000 Iter: " +
           str(score))
Ejemplo n.º 5
0
    def testNew(self):
        #Use StringEnumerator to gather data
        converter = StringEnumerator("test/DataSets/Real/Multiplexer11.csv",
                                     "class")
        headers, actionLabel, dataFeatures, dataActions = converter.get_params(
        )

        #Shuffle data
        formatted = np.insert(dataFeatures, dataFeatures.shape[1], dataActions,
                              1)
        np.random.shuffle(formatted)
        dataFeatures = np.delete(formatted, -1, axis=1)
        dataActions = formatted[:, -1]

        #Initialize and train model

        clf_inv_var = XCS(learning_iterations=1000,
                          N=200,
                          use_inverse_varinance=True)
        clf_inv_var.fit(dataFeatures, dataActions)
        breakpoint()
Ejemplo n.º 6
0
    def testContValuesAndMissingTesting5000Iterations(self):
        dataPath = os.path.join(THIS_DIR, "test/DataSets/Real/ContinuousAndNonBinaryDiscreteAttributesMissing.csv")
        converter = StringEnumerator(dataPath, "Class")
        headers, classLabel, dataFeatures, dataPhenotypes = converter.get_params()
        formatted = np.insert(dataFeatures, dataFeatures.shape[1], dataPhenotypes, 1)
        np.random.shuffle(formatted)
        dataFeatures = np.delete(formatted, -1, axis=1)
        dataPhenotypes = formatted[:, -1]

        clf = XCS(learning_iterations=5000)
        score = np.mean(cross_val_score(clf, dataFeatures, dataPhenotypes, cv=3))

        answer = 0.5
        #print("Cont & Missing Testing 5000 Iter: " + str(score))
        self.assertTrue(self.approxEqualOrBetter(0.2, score, answer, True))
Ejemplo n.º 7
0
    def test6BitMPTesting1000Iterations(self):
        dataPath = os.path.join(THIS_DIR, "test/DataSets/Real/Multiplexer6Modified.csv")
        converter = StringEnumerator(dataPath,"Class")
        headers, classLabel, dataFeatures, dataPhenotypes = converter.get_params()
        formatted = np.insert(dataFeatures, dataFeatures.shape[1], dataPhenotypes, 1)
        np.random.shuffle(formatted)
        dataFeatures = np.delete(formatted, -1, axis=1)
        dataPhenotypes = formatted[:, -1]

        clf = XCS(learning_iterations=1000,N=500,nu=10)
        score = np.mean(cross_val_score(clf, dataFeatures, dataPhenotypes, cv=3))

        answer = 0.9
        #print("6 Bit Testing 1000 Iter: "+str(score))
        self.assertTrue(self.approxEqualOrBetter(0.2,score,answer,True))
Ejemplo n.º 8
0
 def testParamSpecAttrNonarray(self):
     with self.assertRaises(Exception) as context:
         clf = XCS(specified_attributes=2)
     self.assertTrue("specified_attributes param must be ndarray" in str(context.exception))
Ejemplo n.º 9
0
 def testParamSpecAttrInvalidNumeric2(self):
     with self.assertRaises(Exception) as context:
         clf = XCS(specified_attributes=np.array([2,100,-200,200]))
     self.assertTrue("All specified_attributes elements param must be nonnegative integers" in str(context.exception))
Ejemplo n.º 10
0
 def testParamP_GeneralInv3(self):
     with self.assertRaises(Exception) as context:
         clf = XCS(p_general=-1.2)
     self.assertTrue("p_general param must be float from 0 - 1" in str(context.exception))
Ejemplo n.º 11
0
 def testRebootFilename2(self):
     clf = XCS(reboot_filename=None)
     self.assertEqual(clf.reboot_filename,None)
Ejemplo n.º 12
0
 def testRebootFilenameInv2(self):
     with self.assertRaises(Exception) as context:
         clf = XCS(reboot_filename=True)
     self.assertTrue("reboot_filename param must be None or String from pickle" in str(context.exception))
Ejemplo n.º 13
0
 def testFitnessReduction3(self):
     clf = XCS(fitness_reduction = 1.2)
     self.assertEqual(clf.fitness_reduction,1.2)
Ejemplo n.º 14
0
 def testRandomSeed2(self):
     clf = XCS(random_state=200)
     self.assertEqual(clf.random_state,200)
Ejemplo n.º 15
0
 def testBeta3(self):
     clf = XCS(beta = 1.2)
     self.assertEqual(clf.beta,1.2)
Ejemplo n.º 16
0
 def testBeta1(self):
     clf = XCS(beta = -1)
     self.assertEqual(clf.beta,-1)
Ejemplo n.º 17
0
 def testParamP_General2(self):
     clf = XCS(p_general=0.3)
     self.assertEqual(clf.p_general,0.3)
Ejemplo n.º 18
0
 def testPredReduction2(self):
     clf = XCS(prediction_error_reduction = 3)
     self.assertEqual(clf.prediction_error_reduction,3)
Ejemplo n.º 19
0
 def testPredReduction1(self):
     clf = XCS(prediction_error_reduction = -1)
     self.assertEqual(clf.prediction_error_reduction,-1)
Ejemplo n.º 20
0
 def testPredReductionInv1(self):
     with self.assertRaises(Exception) as context:
         clf = XCS(prediction_error_reduction="hi")
     self.assertTrue("prediction_error_reduction param must be float" in str(context.exception))
Ejemplo n.º 21
0
 def testRandomSeed3(self):
     clf = XCS(random_state=None)
     self.assertEqual(clf.random_state,None)
Ejemplo n.º 22
0
 def testParamSpecAttr(self):
     clf = XCS(specified_attributes=np.array([2, 100, 200, 300]))
     self.assertTrue(np.array_equal(clf.specified_attributes,np.array([2, 100, 200, 300])))
Ejemplo n.º 23
0
 def testPredReduction3(self):
     clf = XCS(prediction_error_reduction = 1.2)
     self.assertEqual(clf.prediction_error_reduction,1.2)
Ejemplo n.º 24
0
 def testRandomSeedInv2(self):
     with self.assertRaises(Exception) as context:
         clf = XCS(random_state=1.2)
     self.assertTrue("random_state param must be integer or None" in str(context.exception))
Ejemplo n.º 25
0
 def testParamP_General3(self):
     clf = XCS(p_general=1)
     self.assertEqual(clf.p_general,1)
Ejemplo n.º 26
0
 def testFitnessReductionInv1(self):
     with self.assertRaises(Exception) as context:
         clf = XCS(fitness_reduction="hi")
     self.assertTrue("fitness_reduction param must be float" in str(context.exception))
Ejemplo n.º 27
0
 def testBeta2(self):
     clf = XCS(beta = 3)
     self.assertEqual(clf.beta,3)
Ejemplo n.º 28
0
 def testFitnessReduction1(self):
     clf = XCS(fitness_reduction = -1)
     self.assertEqual(clf.fitness_reduction,-1)
Ejemplo n.º 29
0
 def testAlphaInv1(self):
     with self.assertRaises(Exception) as context:
         clf = XCS(alpha="hi")
     self.assertTrue("alpha param must be float" in str(context.exception))
Ejemplo n.º 30
0
 def testFitnessReduction2(self):
     clf = XCS(fitness_reduction = 3)
     self.assertEqual(clf.fitness_reduction,3)