请同时用C#和VB的亲们进来看下,关于数组和花括号的问题
直接把一个C#文件转为VB文件,但出现了这样的数组,请问这种连续两个 ()() 和 (){}是什么意思啊?
Dim trainInput As Double()() = New Double(trainNum - 1)() {}
Dim trainNum As Integer = 1000
Dim testNum As Integer = 100
Dim trainInput As Double()() = New Double(trainNum - 1)() {}
Dim trainOutput As Double()() = New Double(trainNum - 1)() {}
Dim max As Double() = New Double(6) {}
Dim min As Double() = New Double(6) {}
For i As Integer = 0 To 6
max(i) = Double.MinValue
min(i) = Double.MaxValue
Next
' 读取训练数据
Dim reader As New StreamReader("f:\example.txt")
For i As Integer = 0 To trainNum - 1
Dim value As String = reader.ReadLine()
Dim temp As String() = value.Split(ControlChars.Tab)
trainInput(i) = New Double(3) {}
trainOutput(i) = New Double(2) {}
For j As Integer = 0 To 6
trainInput(i)(j) = Double.Parse(temp(j))
If trainInput(i)(j) > max(j) Then
max(j) = trainInput(i)(j)
End If
If trainInput(i)(j) < min(j) Then
min(j) = trainInput(i)(j)
End If
Next
For j As Integer = 0 To 4
trainOutput(i)(j) = 0
Next
trainOutput(i)(Integer.Parse(temp(4)) - 1) = 1
Next
' 归一化
For i As Integer = 0 To trainNum - 1
For j As Integer = 0 To 6
trainInput(i)(j) = premnmx(trainInput(i)(j), min(j), max(j))
Next
Next
'训练网络
' create multi-layer neural network
'Dim network As New ActivationNetwork(New SigmoidFunction(3), 4, 5, 3)
Dim network As New ActivationNetwork(New SigmoidFunction(3), 7, 8, 5)
' create teacher
Dim teacher As New BackPropagationLearning(network)
' set learning rate and momentum
teacher.LearningRate = 0.1
teacher.Momentum = 0
Dim iteration As Integer = 1
While iteration < 500
teacher.RunEpoch(trainInput, trainOutput)
iteration += 1
End While
' 读取测试数据
Dim testInput As Double()() = New Double(testNum - 1)() {}
Dim testOutput As Double()() = New Double(testNum - 1)() {}
Dim reader1 As New StreamReader("f:\test.txt")
For i As Integer = 0 To testNum - 1
Dim value As String = reader1.ReadLine()
Dim temp As String() = value.Split(ControlChars.Tab)
testInput(i) = New Double(6) {}
For j As Integer = 0 To 6
testInput(i)(j) = Double.Parse(temp(j))
Next
For j As Integer = 0 To 4
testOutput(i)(j) = Integer.Parse(temp(4))
Next
Next
' 对测试数据进行分类, 并统计正确率
Dim hitNum As Integer = 0
For i As Integer = 0 To testNum - 1
Dim inp As Double() = New Double(3) {testInput(i)(0), testInput(i)(1), testInput(i)(2), testInput(i)(3)}
For j As Integer = 0 To 3
inp(j) = premnmx(inp(j), min(j), max(j))
Next
Dim t As Double() = {inp(0), inp(1), inp(2), inp(3)}
' 使用网络对训练样本计算输出
Dim result As Double() = network.Compute(t)
Dim m As Integer = 0
For j As Integer = 0 To 2
If result(j) > result(m) Then
m = j
End If
Next
If m + 1 = testOutput(i) Then
hitNum += 1
End If
Next
System.Console.WriteLine("分类正确率为 {0}% ", 100.0 * hitNum / testNum)
System.Console.Read()