Deep belief Network
3 Example
3.1 Test data
Follow the previous example data, or create a new image recognition data.
3.2 DBN Instances
Example 2 (reading a fixed sample: From the classical optimization algorithm test function sphere Model) ***********//
2 Reading Sample Data
Logger.getRootLogger.setLevel (Level.warn)
Valdata_path = "/user/huangmeiling/deeplearn/data1"
Valexamples =www.ycyc66.cn/sc.textfile (Data_path). Cache ()
Valtrain_d1 =www.zhenlyule.cn Examples.map {line =
Valf1 = Line.split ("\ t")
Valf =f1.map (f =>www.egouyule.cn f.todouble)
Valid =f (0)
Valy = Array (f (1))
Valx =f.slice (2,f.length)
(ID, new BDM (1,y.length,y), New BDM (1,x.length,x))
}
Valtrain_d =train_d1.www.zhenloyl88.cn map (f = (f._2, f._3))
valopts = Array (100.0,20.0,0.0)
3 Set up training parameters, establish DBN model
Valdbnmodel =new DBN ().
SetSize (Array (5, 7)).
Setlayer (2).
Setmomentum (0.1).
Setalpha (1.0).
Dbntrain (Train_d, opts)
4 DBN Model converted to NN model
Valmynn =dbnmodel.www.yghrcp88.cn dbnunfoldtonn (1)
valnnopts = Array (100.0,50.0,0.0)
Valnumexamples =train_d.count ()
println (S "Numexamples =www.huacairen88.cn $numExamples.")
println (mynn._2)
for (i <-0 tomynn._1.length-1) {
Print (Mynn._1 (i) + "\ T")
}
println ()
println ("Mynn_w1")
VALTMPW1 =mynn._3 (0)
for (i <-0 totmpw1www.jyz521.com/. rows-1) {
For (J <-0 totmpw1.cols-1) {
Print (TMPW1 (i,j) + "\ T")
}
println ()
}
Valnnmodel =new www.ludingyule66.cn neuralnet ().
SetSize (mynn._1).
Setlayer (mynn._2).
Setactivation_function ("Sigm").
Setoutput_function ("Sigm").
SETINITW (Mynn._3).
Nntrain (Train_d, nnopts)
5 NN model test
Valnnforecast =nnmodel.www.yyzx66.cn/predict (Train_d)
Valnnerror =nnmodel.loss (Nnforecast)
println (S "nnerror = $NNerror.")
VALPRINTF1 =nnforecast.map (f = (www.myqunliphoto.com/f.label.data (0), F.predict_label.data (0)). Take (200)
PRINTLN ("forecast result--Actual value: Predicted value: Error")
for (i <-0 untilprintf1.length)
println (PRINTF1 (i). _1 + "\ T" +PRINTF1 (i). _2 + "\ T" + (PRINTF1 (i). _2-PRINTF1 (i). _1))
Deep belief Network