日期:2014-05-18 浏览次数:20680 次
public class DrpcClient {
/****************************************
* by CSDN 撸大湿 Email : tntzhou@hotmail.com
****************************************/
public static void main(String[] args) throws Exception {
int InputHideCount = 32; /* Input Hide输入数量 */
int HideOutCount = 10; /* Hide Bolt输出数量,等于是Out Bolt的输入数量 */
int OutCount = 4; /* Out输出数量,等于Real的数量 */
TopologyBuilder builder = new TopologyBuilder();
DRPCSpout drpcSpout = new DRPCSpout("BPTrain");
builder.setSpout("drpcSpout", drpcSpout, 1);
builder.setBolt("hide", new HideBolt(), HideOutCount).allGrouping("drpcSpout");
// OutBolt的传参 必须等于 HideBolt的个数
builder.setBolt("out", new OutBolt(HideOutCount), OutCount).allGrouping("hide");
// TrainBPFinsh的传参 必须等于 OutBolt的个数
builder.setBolt("finsh", new TrainBPFinsh(OutCount), 1).allGrouping("out");
builder.setBolt("return", new ReturnResults(), 1).allGrouping("finsh");
Config conf = new Config();
conf.setNumWorkers(Integer.parseInt(args[1]));
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
String hideweight = getWeightStr(InputHideCount + 1, HideOutCount); // 隐藏层的权重
String outweight = getWeightStr(HideOutCount + 1, OutCount);// 输出层的权重
DRPCClient client = new DRPCClient("mynode001", 3772);
int[] ranInt = new int[1000];
for (int i = 0; i < ranInt.length; i++) {
ranInt[i] = new java.util.Random().nextInt();
}
int Num = 0;
System.out.println("开始训练");
for (int i = 0; i < 2000; i++) {
double r = 0d;
for (int j = 0; j < ranInt.length; j++) {//
RandomNum MyRandom = new RandomNum(ranInt[j]);
String input = MyRandom.getInputDataStr();
String real = MyRandom.getRealDataStr();
String[] result = client.execute(
"BPTrain",
String.valueOf(Num) + "::" + input + "::" + real + "::" + hideweight + "::"
+ outweight).split("::");
// 参数传入全部靠一个字符串,收取也是字符串,最基本的DRPC Client调用