예제 #1
0
        // TODO this should take a IntTensor
        public override FloatTensor Forward(FloatTensor input)
        {
            FloatTensor output = _weights.emptyTensorCopy();

            var indices = new List <int>();

            foreach (var d in input.Data)
            {
                indices.Add((int)d);
            }

            if (input.Shape.Length == 1)
            {
                output = _weights.IndexSelect(indices, 0);
            }
            else
            {
                output = _weights.IndexSelect(indices, 0);

                int[] newShape = { input.Shape[0], input.Shape[1], _weights.Shape[1] };

                output = output.View(newShape);
            }

            return(output);
        }
예제 #2
0
        public IntTensor Sample(FloatTensor input, int dim = 1)
        {
            input.Autograd = true;

            FloatTensor pred = Forward(input);

            IntTensor   actions      = pred.Sample(dim);
            FloatTensor action_preds = pred.IndexSelect(actions, -1);

            history.Add(new FloatTensor[2] {
                action_preds, null
            });
            return(actions);
        }