mod.add_component("feeder", feeder) mod.add_component("svm", svm) mod.add_component("RFC", RFC) mod.add_component("SR", SR) # Setup scheduler and agent s = brica1.VirtualTimeSyncScheduler() a = brica1.Agent(s) a.add_submodule("mod", mod) # Test the classifier svm_result = [] RFC_result = [] svm_vs_RFC = [] for i in xrange(len(X)): feeder.set_state("out0", X[i]) # Set data feeder to training data i a.step() # Execute prediction svm_result.append(svm.get_out_port("out0").buffer[0]) RFC_result.append(RFC.get_out_port("out0").buffer[0]) a.step() svm_vs_RFC.append(SR.get_out_port("out0").buffer[0]) for i in xrange(len(X)): print "SVM: {}\tRFC: {}\tRESULT: {}".format(svm_result[i], RFC_result[i], svm_vs_RFC[i])
feeder = brica1.ConstantComponent() feeder.make_out_port("out0", 2) # Setup SVM component svm = SVMComponent(2) svm.fit(X, y) # Connect the components brica1.connect((feeder, "out0"), (svm, "in0")) # Add components to module mod = brica1.Module() mod.add_component("feeder", feeder) mod.add_component("svm", svm) # Setup scheduler and agent s = brica1.VirtualTimeSyncScheduler() a = brica1.Agent(s) a.add_submodule("mod", mod) # Test the classifier for i in xrange(len(X)): feeder.set_state("out0", X[i]) # Set data feeder to training data i a.step() # Execute prediction print "Actual: {}\tPrediction: {}\t{}".format( y[i], svm.get_out_port("out0").buffer[0], y[i] == svm.get_out_port("out0").buffer[0])
y = iris.target # Setup data feeder component feeder = brica1.ConstantComponent() feeder.make_out_port("out0", 2) # Setup SVM component svm = SVMComponent(2) svm.fit(X, y) # Connect the components brica1.connect((feeder, "out0"), (svm, "in0")) # Add components to module mod = brica1.Module() mod.add_component("feeder", feeder) mod.add_component("svm", svm) # Setup scheduler and agent s = brica1.VirtualTimeSyncScheduler() a = brica1.Agent(s) a.add_submodule("mod", mod) # Test the classifier for i in xrange(len(X)): feeder.set_state("out0", X[i]) # Set data feeder to training data i a.step() # Execute prediction print "Actual: {}\tPrediction: {}\t{}".format(y[i], svm.get_out_port("out0").buffer[0], y[i] == svm.get_out_port("out0").buffer[0])
mod = brica1.Module() mod.add_component("feeder", feeder) mod.add_component("svm", svm) mod.add_component("RFC",RFC) mod.add_component("SR", SR) # Setup scheduler and agent s = brica1.VirtualTimeSyncScheduler() a = brica1.Agent(s) a.add_submodule("mod", mod) # Test the classifier svm_result=[] RFC_result=[] svm_vs_RFC=[] for i in xrange(len(X)): feeder.set_state("out0", X[i]) # Set data feeder to training data i a.step() # Execute prediction svm_result.append(svm.get_out_port("out0").buffer[0]) RFC_result.append(RFC.get_out_port("out0").buffer[0]) a.step() svm_vs_RFC.append(SR.get_out_port("out0").buffer[0]) for i in xrange(len(X)): print "SVM: {}\tRFC: {}\tRESULT: {}".format(svm_result[i], RFC_result[i], svm_vs_RFC[i])