本文整理匯總了Python中hpelm.ELM.add_neurons方法的典型用法代碼示例。如果您正苦於以下問題:Python ELM.add_neurons方法的具體用法?Python ELM.add_neurons怎麽用?Python ELM.add_neurons使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類hpelm.ELM
的用法示例。
在下文中一共展示了ELM.add_neurons方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_CrossValidation_ReturnsError
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_CrossValidation_ReturnsError(self):
model = ELM(5, 2)
model.add_neurons(10, 'tanh')
X = np.random.rand(100, 5)
T = np.random.rand(100, 2)
err = model.train(X, T, 'CV', k=3)
self.assertIsNotNone(err)
示例2: HPELMNN
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
class HPELMNN(Classifier):
def __init__(self):
self.__hpelm = None
@staticmethod
def name():
return "hpelmnn"
def train(self, X, Y, class_number=-1):
class_count = max(np.unique(Y).size, class_number)
feature_count = X.shape[1]
self.__hpelm = ELM(feature_count, class_count, 'wc')
self.__hpelm.add_neurons(feature_count, "sigm")
Y_arr = Y.reshape(-1, 1)
enc = OneHotEncoder()
enc.fit(Y_arr)
Y_OHE = enc.transform(Y_arr).toarray()
out_fd = sys.stdout
sys.stdout = open(os.devnull, 'w')
self.__hpelm.train(X, Y_OHE)
sys.stdout = out_fd
def predict(self, X):
Y_predicted = self.__hpelm.predict(X)
return Y_predicted
示例3: test_MultiLabelClassification_Works
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_MultiLabelClassification_Works(self):
elm = ELM(1, 2)
X = np.array([1, 2, 3, 4, 5, 6])
T = np.array([[1, 1], [1, 0], [1, 0], [0, 1], [0, 1], [1, 1]])
elm.add_neurons(1, "lin")
elm.train(X, T, 'ml')
elm.train(X, T, 'mc')
示例4: test_ELM_SaveLoad
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_ELM_SaveLoad(self):
X = np.array([1, 2, 3, 1, 2, 3])
T = np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]])
elm = ELM(1, 2, precision='32', norm=0.02)
elm.add_neurons(1, "lin")
elm.add_neurons(2, "tanh")
elm.train(X, T, "wc", w=(0.7, 0.3))
B1 = elm.nnet.get_B()
try:
f, fname = tempfile.mkstemp()
elm.save(fname)
elm2 = ELM(3, 3)
elm2.load(fname)
finally:
os.close(f)
self.assertEqual(elm2.nnet.inputs, 1)
self.assertEqual(elm2.nnet.outputs, 2)
self.assertEqual(elm2.classification, "wc")
self.assertIs(elm.precision, np.float32)
self.assertIs(elm2.precision, np.float64) # precision has changed
np.testing.assert_allclose(np.array([0.7, 0.3]), elm2.wc)
np.testing.assert_allclose(0.02, elm2.nnet.norm)
np.testing.assert_allclose(B1, elm2.nnet.get_B())
self.assertEqual(elm2.nnet.get_neurons()[0][1], "lin")
self.assertEqual(elm2.nnet.get_neurons()[1][1], "tanh")
示例5: test_24_AddNeurons_InitDefault_BiasWNotZero
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_24_AddNeurons_InitDefault_BiasWNotZero(self):
elm = ELM(2, 1)
elm.add_neurons(3, "sigm")
W = elm.neurons[0][2]
bias = elm.neurons[0][3]
self.assertGreater(np.sum(np.abs(W)), 0.001)
self.assertGreater(np.sum(np.abs(bias)), 0.001)
示例6: test_TrainWithBatch_OverwritesBatch
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_TrainWithBatch_OverwritesBatch(self):
elm = ELM(1, 1, batch=123)
X = np.array([1, 2, 3])
T = np.array([1, 2, 3])
elm.add_neurons(1, "lin")
elm.train(X, T, batch=234)
self.assertEqual(234, elm.batch)
示例7: test_20_SLFN_AddTwoNeuronTypes_GotThem
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_20_SLFN_AddTwoNeuronTypes_GotThem(self):
elm = ELM(1, 1)
elm.add_neurons(1, "lin")
elm.add_neurons(1, "sigm")
self.assertEquals(2, len(elm.neurons))
ntypes = [nr[0] for nr in elm.neurons]
self.assertIn("lin", ntypes)
self.assertIn("sigm", ntypes)
示例8: test_MultiLabelClassError_Works
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_MultiLabelClassError_Works(self):
X = np.array([1, 2, 3])
T = np.array([[0, 1], [1, 1], [1, 0]])
Y = np.array([[0.4, 0.6], [0.8, 0.6], [1, 1]])
elm = ELM(1, 2, classification="ml")
elm.add_neurons(1, "lin")
e = elm.error(T, Y)
np.testing.assert_allclose(e, 1.0 / 6)
示例9: test_AddNeurons_WorksWithLongType
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_AddNeurons_WorksWithLongType(self):
if sys.version_info[0] == 2:
ltype = long
else:
ltype = int
model = ELM(3, 2)
L = ltype(10)
model.add_neurons(L, 'tanh')
示例10: test_WeightedClassError_Works
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_WeightedClassError_Works(self):
T = np.array([[0, 1], [0, 1], [1, 0]])
Y = np.array([[0, 1], [0.4, 0.6], [0, 1]])
# here class 0 is totally incorrect, and class 1 is totally correct
w = (9, 1)
elm = ELM(1, 2, classification="wc", w=w)
elm.add_neurons(1, "lin")
e = elm.error(T, Y)
np.testing.assert_allclose(e, 0.9)
示例11: test_Classification_WorksCorreclty
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_Classification_WorksCorreclty(self):
elm = ELM(1, 2)
X = np.array([-1, -0.6, -0.3, 0.3, 0.6, 1])
T = np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]])
elm.add_neurons(1, "lin")
elm.train(X, T, 'c')
Y = elm.predict(X)
self.assertGreater(Y[0, 0], Y[0, 1])
self.assertLess(Y[5, 0], Y[5, 1])
示例12: test_25_AddNeurons_InitTwiceBiasW_CorrectlyMerged
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_25_AddNeurons_InitTwiceBiasW_CorrectlyMerged(self):
elm = ELM(2, 1)
W1 = np.random.rand(2, 3)
W2 = np.random.rand(2, 4)
bias1 = np.random.rand(3,)
bias2 = np.random.rand(4,)
elm.add_neurons(3, "sigm", W1, bias1)
elm.add_neurons(4, "sigm", W2, bias2)
np.testing.assert_array_almost_equal(np.hstack((W1, W2)), elm.neurons[0][2])
np.testing.assert_array_almost_equal(np.hstack((bias1, bias2)), elm.neurons[0][3])
示例13: test_WeightedClassification_ClassWithLargerWeightWins
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_WeightedClassification_ClassWithLargerWeightWins(self):
elm = ELM(1, 2)
X = np.array([1, 2, 3, 1, 2, 3])
T = np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]])
elm.add_neurons(1, "lin")
elm.train(X, T, 'wc', w=(1, 0.1))
Y = elm.predict(X)
self.assertGreater(Y[0, 0], Y[0, 1])
self.assertGreater(Y[1, 0], Y[1, 1])
self.assertGreater(Y[2, 0], Y[2, 1])
示例14: build_ELM_encoder
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def build_ELM_encoder(xinput, target, num_neurons):
elm = ELM(xinput.shape[1], target.shape[1])
elm.add_neurons(num_neurons, "sigm")
elm.add_neurons(num_neurons, "lin")
#elm.add_neurons(num_neurons, "rbf_l1")
elm.train(xinput, target, "r")
ypred = elm.predict(xinput)
print "mse error", elm.error(ypred, target)
return elm, ypred
示例15: test_LOOandOP_CanSelectMoreThanOneNeuron
# 需要導入模塊: from hpelm import ELM [as 別名]
# 或者: from hpelm.ELM import add_neurons [as 別名]
def test_LOOandOP_CanSelectMoreThanOneNeuron(self):
X = np.random.rand(100, 5)
T = np.random.rand(100, 2)
for _ in range(10):
model = ELM(5, 2)
model.add_neurons(5, 'lin')
model.train(X, T, 'LOO', 'OP')
max2 = model.nnet.L
if max2 > 1:
break
self.assertGreater(max2, 1)