Thanks for your code, and it works.
But the problem occurs again when I want to add a Linear layer onto my net.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 10 10:04:34 2018

@author: apple
"""
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.autograd import Function

class Gaussian(nn.Module):
    def __init__(self,in_features,out_features):
        super(Gaussian,self).__init__()
        self.sigma=nn.Parameter(torch.Tensor(out_features))
        self.center=nn.Parameter(torch.Tensor(out_features,in_features))
    def forward(self,input):
        dist=self.center-input
        dist=torch.pow(dist,2)
        dist=torch.sum(dist,1)
        sigma=torch.pow(self.sigma,2)
        dist=-1/2*sigma*dist
        output=torch.exp(dist)
        return output

class RBF(nn.Module):
    def __init__(self,in_features,h_features,out_features):
        super(RBF,self).__init__()
        self.linear = nn.Linear(in_features,h_features,bias=False)
        self.Gaussian1 = Gaussian(h_features,out_features)
    
    def forward(self,x):
        x= self.linear(x)
        x = Gaussian(x)
        return x

def Weight_init(m):
    if isinstance(m,nn.Linear):
        m.weight= nn.Parameter(torch.Tensor([[1,2,3],[4,5,6]]))
def Gaussian_init(m):
    if isinstance(m, Gaussian):
        m.sigma=nn.Parameter(torch.Tensor([3]))
        m.center=nn.Parameter(torch.Tensor([[1,2]]))

model=RBF(3,2,1)
model.apply(Weight_init)
model.apply(Gaussian_init)

x=Variable(torch.Tensor([3,2]))
y=model(x)
print(y)  


The error message is:
" size mismatch, m1: [1 x 2], m2: [3 x 2] at /Users/soumith/code/builder/wheel/pytorch-src/torch/lib/TH/generic/THTensorMath.c:1416"
And I searched on http://pytorch.org/tutorials/beginner/pytorch_with_examples.html 1 ,  and it puzzled me a lot

Snipaste_2018-04-12_09-38-49.png1435×809 173 KB

In the Linear, we need to consider the batch size. My code is simple , but I want to use SGD later. Then, do I need to consider the batch_size when I define my own Gaussian layer?