CNTK always return errorRate is 0 - cntk

I am new to CNTK, I am trying to write a cntk to train data for texas holdem playing action. However, no matter how I changed my cntk config file, I am getting the same output for every training data.
Here is my cntk file:
# CNTK Configuration File for creating a slot tagger and an intent tagger.
command = Train:Output:Test
makeMode = false ; traceLevel = 0 ; deviceId = -1
rootDir = "." ; dataDir = "$rootDir$" ; modelDir = "$rootDir$/Models"
modelPath = "$modelDir$/slu.lstm"
# The command to train the LSTM model
Train = {
action = "train"
BrainScriptNetworkBuilder = {
featDim = 22 # contextual words are used as features: previous word, current word, next word.
hiddenDim = 300
maxLayer = 1
initScale = 1
labelDim = 1
# inputs
HandPercentage = Input {1}
NoOfPlayersInPlay = Input {1}
HeroPosition = Input {1}
Pot = Input {1}
PlayerPosition0 = Input {1}
PlayerBettingSize0 = Input {1}
PlayerChips0 = Input {1}
PlayerPosition1 = Input {1}
PlayerBettingSize1 = Input {1}
PlayerChips1 = Input {1}
PlayerPosition2 = Input {1}
PlayerBettingSize2 = Input {1}
PlayerChips2 = Input {1}
PlayerPosition3 = Input {1}
PlayerBettingSize3 = Input {1}
PlayerChips3 = Input {1}
PlayerPosition4 = Input {1}
PlayerBettingSize4 = Input {1}
PlayerChips4 = Input {1}
PlayerPosition5 = Input {1}
PlayerBettingSize5 = Input {1}
PlayerChips5 = Input {1}
features = RowStack(
HandPercentage:
NoOfPlayersInPlay:
HeroPosition:
Pot:
PlayerPosition0:
PlayerBettingSize0:
PlayerChips0:
PlayerPosition1:
PlayerBettingSize1:
PlayerChips1:
PlayerPosition2:
PlayerBettingSize2:
PlayerChips2:
PlayerPosition3:
PlayerBettingSize3:
PlayerChips3:
PlayerPosition4:
PlayerBettingSize4:
PlayerChips4:
PlayerPosition5:
PlayerBettingSize5:
PlayerChips5
)
labels = Input {labelDim}
# build the LSTM stack
# lstmDims[i:0..maxLayer-1] = hiddenDim
# NoAuxInputHook (input, lstmState) = BS.Constants.None
# lstmStack = BS.RNNs.RecurrentLSTMPStack (lstmDims,
# cellDims=lstmDims,
# features,
# inputDim=featDim,
# previousHook=BS.RNNs.PreviousHC,
# augmentInputHook=BS.RNNs.NoAuxInputHook,
# augmentInputDim=0,
# enableSelfStabilization=false)
#
# lstmOutputLayer = Length (lstmStack)-1
# LSTMoutput = lstmStack[lstmOutputLayer].h
#
# W = Parameter(labelDim, hiddenDim, init = "uniform", initValueScale=initScale)
# b = Parameter(labelDim, 1, init = "fixedValue", value=0)
# outputs = W * LSTMoutput + b
model = Sequential (
RecurrentLSTMLayer {hiddenDim, goBackwards=false} : # LSTM
DenseLayer {labelDim} # output layer
)
# model application
outputs = model (features)
cr = CrossEntropyWithSoftmax(labels, outputs)
errs = ClassificationError(labels, outputs)
featureNodes = (HandPercentage:
NoOfPlayersInPlay:
HeroPosition:
Pot:
PlayerPosition0:
PlayerBettingSize0:
PlayerChips0:
PlayerPosition1:
PlayerBettingSize1:
PlayerChips1:
PlayerPosition2:
PlayerBettingSize2:
PlayerChips2:
PlayerPosition3:
PlayerBettingSize3:
PlayerChips3:
PlayerPosition4:
PlayerBettingSize4:
PlayerChips4:
PlayerPosition5:
PlayerBettingSize5:
PlayerChips5)
labelNodes = (labels)
criterionNodes = (cr)
evaluationNodes = (errs)
outputNodes = (outputs)
}
SGD = {
maxEpochs = 10 ; epochSize = 5000
minibatchSize = 70
learningRatesPerSample = 1
gradUpdateType = "fsAdaGrad"
}
reader = {
readerType = "CNTKTextFormatReader"
file = "preflopData.txt"
randomize = true
input = [
#|HandPercentage 0.5958
HandPercentage = [
dim = 1
format = "dense"
]
#|NoOfPlayersInPlay 2
NoOfPlayersInPlay = [
dim = 1
format = "dense"
]
#|HeroPosition 5
HeroPosition = [
dim = 1
format = "dense"
]
#|Pot 1.0000
Pot = [
dim = 1
format = "dense"
]
#|PlayerPosition0 0
PlayerPosition0 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize0 0.00
PlayerBettingSize0 = [
dim = 1
format = "dense"
]
#|PlayerChips0 100.00
PlayerChips0 = [
dim = 1
format = "dense"
]
#|PlayerPosition1 1
PlayerPosition1 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize1 0.00
PlayerBettingSize1 = [
dim = 1
format = "dense"
]
#|PlayerChips1 100.00
PlayerChips1 = [
dim = 1
format = "dense"
]
#|PlayerPosition2 2
PlayerPosition2 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize2 0.00
PlayerBettingSize2 = [
dim = 1
format = "dense"
]
#|PlayerChips2 100.00
PlayerChips2 = [
dim = 1
format = "dense"
]
#|PlayerPosition3 3
PlayerPosition3 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize3 0.00
PlayerBettingSize3 = [
dim = 1
format = "dense"
]
#|PlayerChips3 100.00
PlayerChips3 = [
dim = 1
format = "dense"
]
#|PlayerPosition4 4
PlayerPosition4 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize4 1.00
PlayerBettingSize4 = [
dim = 1
format = "dense"
]
#|PlayerChips4 99.00
PlayerChips4 = [
dim = 1
format = "dense"
]
#|PlayerPosition5 5
PlayerPosition5 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize5 0.00
PlayerBettingSize5 = [
dim = 1
format = "dense"
]
#|PlayerChips5 100.00
PlayerChips5 = [
dim = 1
format = "dense"
]
#|Action 1
labels = [
alias = "Action"
dim = 1
format = "dense"
]
]
}
}
# Test the model's accuracy (as an error count)
Test = {
action = "test"
traceLevel = 1
epochSize = 0
defaultHiddenActivity = 0.1
BrainScriptNetworkBuilder = [
labels = Input(1, tag = "label")
modelAsTrained = BS.Network.Load ("$modelPath$")
final = modelAsTrained.outputs
errorRate = ClassificationError(labels, final, tag='evaluation')
]
evalNodeNames = errorRate
reader = {
readerType = "CNTKTextFormatReader"
file = "preflopData.txt"
randomize = false
input = [
#|HandPercentage 0.5958
HandPercentage = [
dim = 1
format = "dense"
]
#|NoOfPlayersInPlay 2
NoOfPlayersInPlay = [
dim = 1
format = "dense"
]
#|HeroPosition 5
HeroPosition = [
dim = 1
format = "dense"
]
#|Pot 1.0000
Pot = [
dim = 1
format = "dense"
]
#|PlayerPosition0 0
PlayerPosition0 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize0 0.00
PlayerBettingSize0 = [
dim = 1
format = "dense"
]
#|PlayerChips0 100.00
PlayerChips0 = [
dim = 1
format = "dense"
]
#|PlayerPosition1 1
PlayerPosition1 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize1 0.00
PlayerBettingSize1 = [
dim = 1
format = "dense"
]
#|PlayerChips1 100.00
PlayerChips1 = [
dim = 1
format = "dense"
]
#|PlayerPosition2 2
PlayerPosition2 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize2 0.00
PlayerBettingSize2 = [
dim = 1
format = "dense"
]
#|PlayerChips2 100.00
PlayerChips2 = [
dim = 1
format = "dense"
]
#|PlayerPosition3 3
PlayerPosition3 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize3 0.00
PlayerBettingSize3 = [
dim = 1
format = "dense"
]
#|PlayerChips3 100.00
PlayerChips3 = [
dim = 1
format = "dense"
]
#|PlayerPosition4 4
PlayerPosition4 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize4 1.00
PlayerBettingSize4 = [
dim = 1
format = "dense"
]
#|PlayerChips4 99.00
PlayerChips4 = [
dim = 1
format = "dense"
]
#|PlayerPosition5 5
PlayerPosition5 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize5 0.00
PlayerBettingSize5 = [
dim = 1
format = "dense"
]
#|PlayerChips5 100.00
PlayerChips5 = [
dim = 1
format = "dense"
]
#|Action 1
labels = [
alias = "Action"
dim = 1
format = "dense"
]
]
}
}
# output the results
Output = [
action = "write"
traceLevel = 1
epochSize = 0
defaultHiddenActivity = 0.1
BrainScriptNetworkBuilder = [
modelAsTrained = BS.Network.Load ("$modelPath$")
final = modelAsTrained.outputs
]
outputNodeNames = final
reader = [
readerType = "CNTKTextFormatReader"
file = "preflopData.txt"
randomize = false
input = [
#|HandPercentage 0.5958
HandPercentage = [
dim = 1
format = "dense"
]
#|NoOfPlayersInPlay 2
NoOfPlayersInPlay = [
dim = 1
format = "dense"
]
#|HeroPosition 5
HeroPosition = [
dim = 1
format = "dense"
]
#|Pot 1.0000
Pot = [
dim = 1
format = "dense"
]
#|PlayerPosition0 0
PlayerPosition0 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize0 0.00
PlayerBettingSize0 = [
dim = 1
format = "dense"
]
#|PlayerChips0 100.00
PlayerChips0 = [
dim = 1
format = "dense"
]
#|PlayerPosition1 1
PlayerPosition1 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize1 0.00
PlayerBettingSize1 = [
dim = 1
format = "dense"
]
#|PlayerChips1 100.00
PlayerChips1 = [
dim = 1
format = "dense"
]
#|PlayerPosition2 2
PlayerPosition2 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize2 0.00
PlayerBettingSize2 = [
dim = 1
format = "dense"
]
#|PlayerChips2 100.00
PlayerChips2 = [
dim = 1
format = "dense"
]
#|PlayerPosition3 3
PlayerPosition3 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize3 0.00
PlayerBettingSize3 = [
dim = 1
format = "dense"
]
#|PlayerChips3 100.00
PlayerChips3 = [
dim = 1
format = "dense"
]
#|PlayerPosition4 4
PlayerPosition4 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize4 1.00
PlayerBettingSize4 = [
dim = 1
format = "dense"
]
#|PlayerChips4 99.00
PlayerChips4 = [
dim = 1
format = "dense"
]
#|PlayerPosition5 5
PlayerPosition5 = [
dim = 1
format = "dense"
]
#|PlayerBettingSize5 0.00
PlayerBettingSize5 = [
dim = 1
format = "dense"
]
#|PlayerChips5 100.00
PlayerChips5 = [
dim = 1
format = "dense"
]
#|Action 1
labels = [
alias = "Action"
dim = 1
format = "dense"
]
]
]
outputPath = "Preflop_Result.txt" # dump the output to this text file
]
And the data in the training file is like below:
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 1.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 1.00 |PlayerChips4 99.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 2
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 2.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 2.00 |PlayerChips4 98.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 3.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 3.00 |PlayerChips4 97.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 4.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 4.00 |PlayerChips4 96.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 5.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 5.00 |PlayerChips4 95.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 6.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 6.00 |PlayerChips4 94.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 7.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 7.00 |PlayerChips4 93.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 8.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 8.00 |PlayerChips4 92.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 9.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 9.00 |PlayerChips4 91.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 100.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 100.00 |PlayerChips4 0.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 10.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 10.00 |PlayerChips4 90.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 15.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 15.00 |PlayerChips4 85.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 20.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 20.00 |PlayerChips4 80.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 30.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 30.00 |PlayerChips4 70.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
|HandPercentage 0.5958 |NoOfPlayersInPlay 2 |HeroPosition 5 |Pot 40.00 |PlayerPosition0 0 |PlayerBettingSize0 0.00 |PlayerChips0 100.00 |PlayerPosition1 1 |PlayerBettingSize1 0.00 |PlayerChips1 100.00 |PlayerPosition2 2 |PlayerBettingSize2 0.00 |PlayerChips2 100.00 |PlayerPosition3 3 |PlayerBettingSize3 0.00 |PlayerChips3 100.00 |PlayerPosition4 4 |PlayerBettingSize4 40.00 |PlayerChips4 60.00 |PlayerPosition5 5 |PlayerBettingSize5 0.00 |PlayerChips5 100.00 |Action 1
However the output is always like below:
Finished Epoch[ 1 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 5000; learningRatePerSample = 1; epochTime=0.784258s
Finished Epoch[ 2 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 10000; learningRatePerSample = 1; epochTime=0.517457s
Finished Epoch[ 3 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 15000; learningRatePerSample = 1; epochTime=0.50032s
Finished Epoch[ 4 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 20000; learningRatePerSample = 1; epochTime=0.508821s
Finished Epoch[ 5 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 25000; learningRatePerSample = 1; epochTime=0.519995s
Finished Epoch[ 6 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 30000; learningRatePerSample = 1; epochTime=0.511545s
Finished Epoch[ 7 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 35000; learningRatePerSample = 1; epochTime=0.524342s
Finished Epoch[ 8 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 40000; learningRatePerSample = 1; epochTime=0.517396s
Finished Epoch[ 9 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 45000; learningRatePerSample = 1; epochTime=0.527745s
Finished Epoch[10 of 10]: [Training] cr = -0.00000000 * 5000; errs = 0.000% * 5000; totalSamplesSeen = 50000; learningRatePerSample = 1; epochTime=0.552185s
Can anyone help to tell me where possible my cntk is wrong?

You are getting this result because you are using CrossEntropyWithSoftmax on a binary label. There are two solutions to your problem. One solution is to have a two dimensional output and a label that is either 1 0 or 0 1. The other solution is to pass your final output through a sigmoid and use the Logistic operation.

Related

Display commend in ampl

I have a 2 dimension variable in ampl and I want to display it. I want to change the order of the indices but I do not know how to do that! I put my code , data and out put I described what kind of out put I want to have.
Here is my code:
param n;
param t;
param w;
param p;
set Var, default{1..n};
set Ind, default{1..t};
set mode, default{1..w};
var E{mode, Ind};
var B{mode,Var};
var C{mode,Ind};
param X{mode,Var,Ind};
var H{Ind};
minimize obj: sum{m in mode,i in Ind}E[m,i];
s.t. a1{m in mode, i in Ind}: sum{j in Var} X[m,j,i]*B[m,j] -C[m,i] <=E[m,i];
solve;
display C;
data;
param w:=4;
param n:=9;
param t:=2;
param X:=
[*,*,1]: 1 2 3 4 5 6 7 8 9 :=
1 69 59 100 70 35 1 1 0 0
2 34 31 372 71 35 1 0 1 0
3 35 25 417 70 35 1 0 0 1
4 0 10 180 30 35 1 0 0 0
[*,*,2]: 1 2 3 4 5 6 7 8 9 :=
1 64 58 68 68 30 2 1 0 0
2 44 31 354 84 30 2 0 1 0
3 53 25 399 85 30 2 0 0 1
4 0 11 255 50 30 2 0 0 0
The output of this code using glpksol is like tis:
C[1,1].val = -1.11111111111111
C[1,2].val = -1.11111111111111
C[2,1].val = -0.858585858585859
C[2,2].val = -1.11111111111111
C[3,1].val = -0.915032679738562
C[3,2].val = -1.11111111111111
C[4,1].val = 0.141414141414141
C[4,2].val = 0.2003367003367
but I want the result to be like this:
C[1,1].val = -1.11111111111111
C[2,1].val = -0.858585858585859
C[3,1].val = -0.915032679738562
C[4,1].val = 0.141414141414141
C[1,2].val = -1.11111111111111
C[2,2].val = -1.11111111111111
C[3,2].val = -1.11111111111111
C[4,2].val = 0.2003367003367
any idea?
You can use for loops and printf commands in your .run file:
for {i in Ind}
for {m in mode}
printf "C[%d,%d] = %.4f\n", m, i, C[m,i];
or even:
printf {i in Ind, m in mode} "C[%d,%d] = %.4f\n", m, i, C[m,i];
I don't get the same numerical results as you, but anyway the output works:
C[1,1] = 0.0000
C[2,1] = 0.0000
C[3,1] = 0.0000
C[4,1] = 0.0000
C[1,2] = 0.0000
C[2,2] = 0.0000
C[3,2] = 0.0000
C[4,2] = 0.0000

How To Loop Nested If-Then Statements in VBA

I am going to try to simplify my objective as well as add all of my vba as my OP was not clear.
I am writing a macro that is to be used to determine a commissions percentage based on a particular strategies (Tier1, Tier2, BPO or Enterprise), a Gross Margin range and contract year. This will need to be looped through about 5,000 rows of data in the final product. I have been trying to nest multiple If-Then statements to achieve my goal however it is not working.
Below is the table for the commissions rates that apply to each of the strategies and then the code that I wrote for this nested If-Then statement.
Looking to try to make this simpler and loop it through the entirety of the rows with data. Goal is to have each cell in column J return a Commission rate determined by the strategy in column i, year in column D and GM in column Z. The strategy has the potential to vary each row down the page.
Would I be better off creating a custom Function?
Kinda crazy task for a first time macro writer. Appreciate all the feedback I have gotten already and look forward to any other ideas to come.
enter image description here
enter image description here
enter image description here
My Code:
Where Column I = Strategy
Where Column D = Year
Where Column Z = Gross Margin
Where Column J = Result of If-Then
where Column C is a defined data set which determines the number of rows in the workbook.
Sub Define_Comm_Rate
Dim LastRow As Long
LastRow = Range("C" & Rows.Count).End(xlUp).Row
If Sheet1.Range("I2") = "BPO" And Sheet1.Range("Z2") >= 0.24 Then
If Sheet1.Range("D2") = 1 Then
Sheet1.Range("J2") = 0.4
Else
If Sheet1.Range("D2") = 2 Then
Sheet1.Range("J2") = 0.3
Else: Sheet1.Range("J2") = 0.15
End If
End If
End If
If Sheet1.Range("I2") = "BPO" And Sheet1.Range("Z2") >= 0.21 And Sheet1.Range("Z2") < 0.24 Then
If Sheet1.Range("D2") = 1 Then
Sheet1.Range("J2") = 0.35
Else
If Sheet1.Range("D2") = 2 Then
Sheet1.Range("J2") = 0.25
Else: Sheet1.Range("J2") = 0.1
End If
End If
End If
If Sheet1.Range("I2") = "BPO" And Sheet1.Range("Z2") >= 0.18 And Sheet1.Range("Z2") < 0.21 Then
If Sheet1.Range("D2") = 1 Then
Sheet1.Range("J2") = 0.3
Else
If Sheet1.Range("D2") = 2 Then
Sheet1.Range("J2") = 0.2
Else: Sheet1.Range("J2") = 0.05
End If
End If
End If
If Sheet1.Range("I2") = "BPO" And Sheet1.Range("Z2") < 0.18 Then
If Sheet1.Range("D2") = 1 Then
Sheet1.Range("J2") = 0.25
Else
If Sheet1.Range("D2") = 2 Then
Sheet1.Range("J2") = 0.15
Else: Sheet1.Range("J2") = 0.05
End If
End If
End If
If Sheet1.Range("I2") = "Enterprise24" Then
If Sheet1.Range("D2") = "1" Then
Sheet1.Range("J2") = 0.4
Else
If Sheet1.Range("D2") = 2 Then
Sheet1.Range("J2") = 0.3
Else: Sheet1.Range("J2") = 0.15
End If
End If
End If
If Sheet1.Range("I2") = "Enterprise21" Then
If Sheet1.Range("D2") = 1 Then
Sheet1.Range("J2") = 0.35
Else
If Sheet1.Range("D2") = 2 Then
Sheet1.Range("J2") = 0.25
Else: Sheet1.Range("J2") = 0.1
End If
End If
End If
If Sheet1.Range("I2") = "Enterprise18" Then
If Sheet1.Range("D2") = 1 Then
Sheet1.Range("J2") = 0.3
Else
If Sheet1.Range("D2") = 2 Then
Sheet1.Range("J2") = 0.2
Else: Sheet1.Range("J2") = 0.05
End If
End If
End If
If Sheet1.Range("I2") = "Enterprise00" Then
If Sheet1.Range("D2") = 1 Then
Sheet1.Range("J2") = 0.25
Else
If Sheet1.Range("D2") = 2 Then
Sheet1.Range("J2") = 0.15
Else: Sheet1.Range("J2") = 0.05
End If
End If
End If
If Sheet1.Range("I2") = "Tier1" Then
If Sheet1.Range("Z2") > 0.4 Then
Sheet1.Range("J2") = 0.5
Else
If Sheet1.Range("Z2") <= 0.4 And Sheet1.Range("Z2") > 0.25 Then
Sheet1.Range("J2") = (1 * Sheet1.Range("Z2")) + 0.1
Else
If Sheet1.Range("Z2") <= 0.25 And Sheet1.Range("Z2") > 0.075 Then
Sheet1.Range("J2") = (2 * Sheet1.Range("Z2")) - 0.15
Else
If Sheet1.Range("Z2") <= 0.075 And Sheet1.Range("Z2") > 0 Then
Sheet1.Range("J2") = 0
Else: Sheet1.Range("J2") = 0.5
End If
End If
End If
End If
End If
If Sheet1.Range("I2") = "Tier1-100" Then
If Sheet1.Range("Z2") > 0.4 Then
Sheet1.Range("J2") = 0.5
Else
If Sheet1.Range("Z2") <= 0.4 And Sheet1.Range("Z2") > 0.25 Then
Sheet1.Range("J2") = (1 * Sheet1.Range("Z2")) + 0.1
Else
If Sheet1.Range("Z2") <= 0.25 And Sheet1.Range("Z2") > 0.075 Then
Sheet1.Range("J2") = (2 * Sheet1.Range("Z2")) - 0.15
Else
If Sheet1.Range("Z2") <= 0.075 And Sheet1.Range("Z2") > 0 Then
Sheet1.Range("J2") = 0
Else: Sheet1.Range("J2") = 0.5
End If
End If
End If
End If
End If
If Sheet1.Range("I2") = "Tier2" Then
If Sheet1.Range("Z2") > 0.35 Then
Sheet1.Range("J2") = 0.5
Else
If Sheet1.Range("Z2") <= 0.35 And Sheet1.Range("Z2") > 0.25 Then
Sheet1.Range("J2") = (1 * Sheet1.Range("Z2")) + 0.15
Else
If Sheet1.Range("Z2") <= 0.25 And Sheet1.Range("Z2") > 0.05 Then
Sheet1.Range("J2") = (2 * Sheet1.Range("Z2")) - 0.1
Else
If Sheet1.Range("Z2") <= 0.05 And Sheet1.Range("Z2") > 0 Then
Sheet1.Range("J2") = 0
Else: Sheet1.Range("J2") = 0.5
End If
End If
End If
End If
End If
If Sheet1.Range("I2") = "Tier2-100" Then
If Sheet1.Range("Z2") > 0.35 Then
Sheet1.Range("J2") = 0.5
Else
If Sheet1.Range("Z2") <= 0.35 And Sheet1.Range("Z2") > 0.25 Then
Sheet1.Range("J2") = (1 * Sheet1.Range("Z2")) + 0.15
Else
If Sheet1.Range("Z2") <= 0.25 And Sheet1.Range("Z2") > 0.05 Then
Sheet1.Range("J2") = (2 * Sheet1.Range("Z2")) - 0.1
Else
If Sheet1.Range("Z2") <= 0.05 And Sheet1.Range("Z2") > 0 Then
Sheet1.Range("J2") = 0
Else: Sheet1.Range("J2") = 0.5
End If
End If
End If
End If
End If
Sheet1.Range("J2").AutoFill Destination:=Sheet1.Range("J2:J" & LastRow)
Application.Calculate
End Sub
I'm going to offer a non-VBA approach to this using INDIRECT, INDEX, MATCH, and a few tables. My thought is that instead of coding lots of nested IF's, with hard-coded values, in VBA, you should be able to do this with lookup tables. (Disclaimer: this was also a fun intellectual exercise.)
First, create a table similar to the Commissions Table you already have and name it your specific strategy, e.g. "BPO", under Formulas > Name Manager. I created mine on a separate sheet named "Tables". Note that I used 1 in row 1 as your max (and unrealistic) gross margin. I also added 1, 2, and 3 in cells B1, C1, and D1 respectively. You'd need to create similar tables for your other strategies, and put them under the BPO table.
Then in column J on your data tab, enter this formula: =INDEX(INDIRECT(I2),MATCH(Z2,INDIRECT(I2&"["&Z$1&"]"),-1),MATCH(D2,Tables!$A$1:$D$1,1))
This INDEX formula has 3 main parts:
INDIRECT(I2) - this returns the array comprising the table you have named "BPO" - so you know you're looking at the table appropriate to that particular strategy.
MATCH(Z2,INDIRECT(I2&"["&Z$1&"]"),-1) - this looks up your gross margin in column Z against the table (BPO), looking in the column[Gross Margin]. The last argument of MATCH (match type) is -1, meaning that it finds the smallest value that is greater than or equal to your gross margin (note that in the table, Gross Margin is sorted in descending order). So for example, if your Gross Margin is 0.22, the MATCH will return 0.2399.
MATCH(D2,Tables!$A$1:$D$1,1) - This looks up the year, and tries to find the largest value that is less than or equal to it. So if the year is 1, 2, or 3, the MATCH will return 1, 2, or 3, respectively, but if the year is greater than 3, the MATCH returns 3.
Columns AB and AC in the second screenshot are just the results of 2. and 3. above, included to show that the correct commission value is being returned. Note that the "Year Column" is not Year 2 or Year 3, but the 2nd or 3rd column in the BPO table, i.e. Year 1 or Year 2 respectively.
Thanks for all the input/feedback.
Due to added complexity of additional sales plans needing to be incorporated as well as needing the flexibility to add/remove sales plans at any time, I ended up writing a custom Function.
Function Commissions(Strategy As String, GM As Variant, YR As Variant) As Variant
If Strategy = "BPO" And GM >= 0.24 And YR = 1 Then
Commissions = 0.4
ElseIf Strategy = "BPO" And GM >= 0.24 And YR = 2 Then
Commissions = 0.3
ElseIf Strategy = "BPO" And GM >= 0.24 And YR >= 3 Then
Commissions = 0.15
ElseIf Strategy = "BPO" And GM >= 0.21 And GM < 0.24 And YR = 1 Then
Commissions = 0.35
ElseIf Strategy = "BPO" And GM >= 0.21 And GM < 0.24 And YR = 2 Then
Commissions = 0.25
ElseIf Strategy = "BPO" And GM >= 0.21 And GM < 0.24 And YR >= 3 Then
Commissions = 0.1
ElseIf Strategy = "BPO" And GM >= 0.18 And GM < 0.21 And YR = 1 Then
Commissions = 0.3
ElseIf Strategy = "BPO" And GM >= 0.18 And GM < 0.21 And YR = 2 Then
Commissions = 0.2
ElseIf Strategy = "BPO" And GM >= 0.18 And GM < 0.21 And YR >= 3 Then
Commissions = 0.05
ElseIf Strategy = "BPO" And GM < 0.18 And YR = 1 Then
Commissions = 0.25
ElseIf Strategy = "BPO" And GM < 0.18 And YR = 2 Then
Commissions = 0.15
ElseIf Strategy = "BPO" And GM < 0.18 And YR >= 3 Then
Commissions = 0.05
''all other strategies continued below....''
End If
End Function

Rounding up decimal number with condition in T-SQL

I have a ASP function as below for rounding up the amount:
function GetRoundedVal(amount)
NoOfRight = right(formatnumber(amount,2),1)
if NoOfRight = 0 then
roundedAmount = amount
elseif NoOfRight = 1 then
roundedAmount = amount - 0.01
elseif NoOfRight = 2 then
roundedAmount = amount - 0.02
elseif NoOfRight = 3 then
roundedAmount = amount + 0.02
elseif NoOfRight = 4 then
roundedAmount = amount + 0.01
elseif NoOfRight = 5 then
roundedAmount = amount
elseif NoOfRight = 6 then
roundedAmount = amount - 0.01
elseif NoOfRight = 7 then
roundedAmount = amount - 0.02
elseif NoOfRight = 8 then
roundedAmount = amount + 0.02
elseif NoOfRight = 9 then
roundedAmount = amount + 0.01
else
end if
GetRoundedVal = roundedAmount
end function
The result should be like this:
+----------------+--------+
| Original Value | Result |
+----------------+--------+
| 19.91 | 19.90 | Original Value - 0.01
| 19.92 | 19.90 | Original Value - 0.02
| 19.93 | 19.95 | Original Value + 0.02
| 19.94 | 19.95 | Original Value + 0.01
| 19.95 | 19.95 |
| 19.96 | 19.95 | Original Value - 0.01
| 19.97 | 19.95 | Original Value - 0.02
| 19.98 | 20.00 | Original Value + 0.02
| 19.99 | 20.00 | Original Value + 0.01
+----------------+--------+
The question is can we do this directly on T-SQL?
SQL Server V14.
If it even possible.
Thanks.
You can try this.
DECLARE #MyTable TABLE(OriginalValue DECIMAL(18,2))
INSERT INTO #MyTable VALUES (19.91), (19.92), (19.93), (19.94), (19.95), (19.96), (19.97), (19.98), (19.99)
SELECT
OriginalValue,
ROUND( ( OriginalValue / 0.05 ), 0, 0 ) * 0.05 Result
FROM #MyTable
Result:
OriginalValue Result
--------------------------------------- ---------------------------------------
19.91 19.90000000
19.92 19.90000000
19.93 19.95000000
19.94 19.95000000
19.95 19.95000000
19.96 19.95000000
19.97 19.95000000
19.98 20.00000000
19.99 20.00000000
try This
DECLARE #Inp TABLE
(
Org DECIMAL(10,4),
Res DECIMAL(10,2)
)
INSERT INTO #Inp
(
Org
)
VALUES(19.91),
(19.92),
(19.93),
(19.94),
(19.95),
(19.96),
(19.97),
(19.98),
(19.99)
SELECT
*,
Result = CAST(
Org +
CASE RIGHT(CAST(Org AS DECIMAL(10,2)),1)
WHEN 1 THEN -0.01
WHEN 2 THEN -0.02
WHEN 3 THEN 0.02
WHEN 4 THEN 0.01
WHEN 5 THEN 0
WHEN 6 THEN -0.01
WHEN 7 THEN -0.02
WHEN 8 THEN 0.02
WHEN 9 THEN 0.01
ELSE 0 END
AS DECIMAL(10,2))
FROM #Inp
----------

Dataframe tranposition and mapping

I need to perform two sample t-test, for which I have to transpose my sample file and map values from another csv file to the sample file. I am new to python, so far I have tried this:
with open('project.csv') as f_project:
df = pd.read_csv('project.csv', delimiter = ',', dtype= 'unicode',
error_bad_lines=False)
df.set_index('TaxID', inplace=True)
df_kraken = df.T
df_meta = pd.read_csv('Meta3251.csv', delimiter = ',', dtype= 'unicode',
error_bad_lines=False, usecols = ['SRA ID', '(0/1)'])
df_kraken['Meta'] = df_kraken['TaxID'].map(df_meta.set_index('SRA ID')
['(0/1)'])
My sample file dataframe after transposition looks like this:
333046 1049 337090
PRJEB3251_ERR169499 0.05 0.03 0.01
PRJEB3251_ERR169500 0 0 0
PRJEB3251_ERR169501 0 0 0
PRJEB3251_ERR169502 0.05 0 0
PRJEB3251_ERR169503 0.03 1.9 0
PRJEB3251_ERR169507 0.01 0 0
PRJEB3251_ERR169508 0 0.1 0
PRJEB3251_ERR169509 0 0.05 0
The index is not been set as TaxID.
I have another csv file which T have taken as another dataframe so that I can map the values. It looks like
SRA ID (0/1)
ERR169611 1
ERR169610 1
ERR169609 1
ERR169608 1
ERR169607 0
ERR169606 0
ERR169605 1
ERR169604 1
ERR169484 0
I need to map the zero one values to the first column of 1st dataframe. Im stuck with the error : KeyError: 'TaxID'
Any hepl regarding this will be highly appreciated.
After you suggestion I have this :
import pandas as pd
df = pd.read_csv('project.csv').set_index('ID').T
df = df.reset_index().rename(columns={'index': 'Project ID'})
df_meta = pd.read_csv('Meta3251.csv', delimiter = ',', dtype= 'unicode',
error_bad_lines=False, usecols = ['SRA ID', '(0/1)'])
df['KEY'] = df['Project ID'].str.split('_').str[1]
df['Meta ID'] = df['KEY'].replace(dict(zip(df_meta['SRA ID'], df['(Project
ID)'])))
df.to_csv('R.csv')
After this I have the following result:
Project ID 333046 1049 KEY Meta ID
0 PRJEB3251_ERR169499 0.05 0.03 ERR169499 PRJEB3251_ERR169636
1 PRJEB3251_ERR169500 0 0 ERR169500 PRJEB3251_ERR169635
2 PRJEB3251_ERR169501 0 0 ERR169501 PRJEB3251_ERR169626
3 PRJEB3251_ERR169502 0.05 0 ERR169502 PRJEB3251_ERR169625
I have the index but the good part is now im able to rename my column, the mapping is not working though.
Here a solution that could work:
df = pd.read_csv('project.csv', delimiter = ',', dtype= 'unicode', error_bad_lines=False)
df.set_index('TaxID', inplace=True)
df_kraken = df.T.reset_index() # Make sure 'TaxID' is a column
df_meta = pd.read_csv('Meta3251.csv', delimiter = ',', dtype= 'unicode', error_bad_lines=False, usecols = ['SRA ID', '(0/1)'])
# In your example the second dataframe only matches what's after the '_'
# so you can isolate that part
df_kraken['KEY'] = df_kraken['TaxID'].str.split('_').str[1]
df_kraken['Meta'] = df_kraken['KEY'].replace(dict(zip(meta['SRA'], meta['ID'])))
EDIT
The question has been edited.
After read_csv() (first line):
TaxID PRJEB3251_ERR169499 PRJEB3251_ERR169500 PRJEB3251_ERR169501
0 333046 0.05 0 0
1 1049 0.03 0 0
2 337090 0.01 0 0
3 288681 3.6 0 0
4 267889 0.02 0 0
...
Then
df = df.set_index('TaxID').T
print(df)
TaxID 333046 1049 337090
PRJEB3251_ERR169499 0.05 0.03 0.01
PRJEB3251_ERR169500 0.00 0.00 0.00
PRJEB3251_ERR169501 0.00 0.00 0.00
Note that at this point TaxID is the name of the columns index, not of the row index. If you want to have TaxID as a column:
df = df.reset_index().rename(columns={'index': 'TaxID'})
To avoid confusion you can remove TaxID from the column name:
df.columns.name = None

Having a key error when using group and sum in a dataframe

I would like to use groupby and sum a csv file
a b c d
1111 0.1 1 1
1111 0 1 0
2222 0.2 1 1
1111 0.2 2 1
2222 1 1
1111 0.3 2 0
3333 0.4 1 1
3333 0.5 2 1
1111 0.6 2 1
e: # if b < 0.2, group column a and sum of column c
f: # If b >= 0.2 group column a and sum of column c
g: # If d = 1, and b >= 0.2, g is sum of c
h: # If d = 0 and b < 0.2, h is sum of c
expected output:
e f g h
1111 2 6 4 1
2222 1 1
3333 3 3
I try:
df1 = df[(df['d'] == 1) & (df['b'] >= 0.2)]
df1.groupby('a')['c'].sum()
However, I got key error in a large file:
pandas.index.IndexEngine.get_loc, pandas.hastable.PobjectHashTable.get_item in column a.
Maybe you can try different approach:
First create conditions columns - e to h and then use mul for filling this mask with values of column c. Last use GroupBy.sum:
df['e'] = df['b'] < 0.2
df['f'] = df['b'] >= 0.2
df['g'] = (df['d'] == 1) & (df['b'] >= 0.2)
df['h'] = (df['d'] == 0) & (df['b'] < 0.2)
print df
a b c d e f g h
0 1111 0.1 1 1 True False False False
1 1111 0.0 1 0 True False False True
2 2222 0.2 1 1 False True True False
3 1111 0.2 2 1 False True True False
4 2222 NaN 1 1 False False False False
5 1111 0.3 2 0 False True False False
6 3333 0.4 1 1 False True True False
7 3333 0.5 2 1 False True True False
8 1111 0.6 2 1 False True True False
df.loc[:, ['e','f','g','h']]= df.loc[:, ['e','f','g','h']].mul(df.c, axis=0)
print df
a b c d e f g h
0 1111 0.1 1 1 1 0 0 0
1 1111 0.0 1 0 1 0 0 1
2 2222 0.2 1 1 0 1 1 0
3 1111 0.2 2 1 0 2 2 0
4 2222 NaN 1 1 0 0 0 0
5 1111 0.3 2 0 0 2 0 0
6 3333 0.4 1 1 0 1 1 0
7 3333 0.5 2 1 0 2 2 0
8 1111 0.6 2 1 0 2 2 0
df1 = df.groupby('a').sum()
print df1[['e','f','g','h']]
e f g h
a
1111 2 6 4 1
2222 0 1 1 0
3333 0 3 3 0