Python chainer.functions.Linear() Examples
The following are 12
code examples of chainer.functions.Linear().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
chainer.functions
, or try the search function
.
Example #1
Source File: run_tiger.py From Chimp with Apache License 2.0 | 5 votes |
def __init__(self): super(Linear, self).__init__( l1=F.Bilinear(settings["n_frames"], settings["n_frames"], 200), l2=F.Linear(200, 100, wscale=np.sqrt(2)), l3=F.Linear(100, 100, wscale=np.sqrt(2)), l4=F.Linear(100, 50, wscale=np.sqrt(2)), l5=F.Linear(50, simulator.n_actions, wscale = np.sqrt(2)) )
Example #2
Source File: mountain_car_test.py From Chimp with Apache License 2.0 | 5 votes |
def __init__(self): super(TestNet, self).__init__( l1=F.Linear(settings['model_dims'][1], 20, bias=0.0), l2=F.Linear(20, 10, bias=0.0), bn1=L.BatchNormalization(10), l3=F.Linear(10, 10), l4=F.Linear(10, 10), bn2=L.BatchNormalization(10), lout=F.Linear(10, simulator.n_actions) ) self.train = True # initialize avg_var to prevent divide by zero self.bn1.avg_var.fill(0.1), self.bn2.avg_var.fill(0.1),
Example #3
Source File: run_atari.py From Chimp with Apache License 2.0 | 5 votes |
def __init__(self): super(Convolution, self).__init__( l1=F.Convolution2D(settings['history_sizes'][0], 32, ksize=8, stride=4, nobias=False, wscale=np.sqrt(2)), l2=F.Convolution2D(32, 64, ksize=4, stride=2, nobias=False, wscale=np.sqrt(2)), l3=F.Convolution2D(64, 64, ksize=3, stride=1, nobias=False, wscale=np.sqrt(2)), l4=F.Linear(3136, 512, wscale = np.sqrt(2)), l5=F.Linear(512, simulator.n_actions, wscale = np.sqrt(2)), )
Example #4
Source File: run_mountain_car.py From Chimp with Apache License 2.0 | 5 votes |
def __init__(self): super(CarNet, self).__init__( l1=F.Linear(settings['model_dims'][1], 20, bias=0.0), l2=F.Linear(20, 10, bias=0.0), bn1=L.BatchNormalization(10), l3=F.Linear(10, 10), l4=F.Linear(10, 10), bn2=L.BatchNormalization(10), lout=F.Linear(10, simulator.n_actions) ) self.train = True # initialize avg_var to prevent divide by zero self.bn1.avg_var.fill(0.1), self.bn2.avg_var.fill(0.1),
Example #5
Source File: run_cartpole.py From Chimp with Apache License 2.0 | 5 votes |
def __init__(self): super(CartNet, self).__init__( l1=F.Linear(4, 20, bias=0.0), l2=F.Linear(20, 10, bias=0.0), bn1=L.BatchNormalization(10), l3=F.Linear(10, 10), l4=F.Linear(10, 10), bn2=L.BatchNormalization(10), lout=F.Linear(10, simulator.n_actions) ) self.train = True # initialize avg_var to prevent divide by zero self.bn1.avg_var.fill(0.1), self.bn2.avg_var.fill(0.1),
Example #6
Source File: agent_test.py From Chimp with Apache License 2.0 | 5 votes |
def __init__(self): super(TestNet, self).__init__( l1=F.Linear(settings['model_dims'][1], 20, bias=0.0), l2=F.Linear(20, 10, bias=0.0), bn1=L.BatchNormalization(10), l3=F.Linear(10, 10), l4=F.Linear(10, 10), bn2=L.BatchNormalization(10), lout=F.Linear(10, simulator.n_actions) ) self.train = True # initialize avg_var to prevent divide by zero self.bn1.avg_var.fill(0.1), self.bn2.avg_var.fill(0.1),
Example #7
Source File: confirm_dqn_env.py From techcircle_openai_handson with MIT License | 5 votes |
def __init__(self, action, other_action, size, epsilon=0.05, hidden=200): self.action = action self.other_action = other_action self.width = size * size self.epsilon = epsilon self.hidden = hidden super(ChainerAgent, self).__init__( l1=F.Linear(self.width, self.hidden, wscale=np.sqrt(2)), l2=F.Linear(self.hidden, 1, wscale=np.sqrt(2)), )
Example #8
Source File: dqn_agent.py From DQN-chainer with MIT License | 5 votes |
def __init__(self, n_history, n_act): super(ActionValue, self).__init__( l1=F.Convolution2D(n_history, 32, ksize=8, stride=4, nobias=False, wscale=np.sqrt(2)), l2=F.Convolution2D(32, 64, ksize=4, stride=2, nobias=False, wscale=np.sqrt(2)), l3=F.Convolution2D(64, 64, ksize=3, stride=1, nobias=False, wscale=np.sqrt(2)), l4=F.Linear(3136, 512, wscale=np.sqrt(2)), q_value=F.Linear(512, n_act, initialW=np.zeros((n_act, 512), dtype=np.float32)) )
Example #9
Source File: dqn_agent_cpu.py From DQN-chainer with MIT License | 5 votes |
def __init__(self, n_history, n_act): super(ActionValue, self).__init__( l1=F.Convolution2D(n_history, 32, ksize=8, stride=4, nobias=False, wscale=np.sqrt(2)), l2=F.Convolution2D(32, 64, ksize=4, stride=2, nobias=False, wscale=np.sqrt(2)), l3=F.Convolution2D(64, 64, ksize=3, stride=1, nobias=False, wscale=np.sqrt(2)), l4=F.Linear(3136, 512),#, wscale=np.sqrt(2)), q_value=F.Linear(512, n_act, initialW=0.0*np.random.randn(n_act, 512).astype(np.float32)) )
Example #10
Source File: dqn_agent_nips.py From DQN-chainer with MIT License | 5 votes |
def __init__(self, enable_controller=[0, 3, 4]): self.num_of_actions = len(enable_controller) self.enable_controller = enable_controller # Default setting : "Pong" print "Initializing DQN..." # Initialization for Chainer 1.1.0 or older. # print "CUDA init" # cuda.init() print "Model Building" self.model = FunctionSet( l1=F.Convolution2D(4, 16, ksize=8, stride=4, wscale=np.sqrt(2)), l2=F.Convolution2D(16, 32, ksize=4, stride=2, wscale=np.sqrt(2)), l3=F.Linear(2592, 256), q_value=F.Linear(256, self.num_of_actions, initialW=np.zeros((self.num_of_actions, 256), dtype=np.float32)) ).to_gpu() print "Initizlizing Optimizer" self.optimizer = optimizers.RMSpropGraves(lr=0.0002, alpha=0.3, momentum=0.2) self.optimizer.setup(self.model.collect_parameters()) # History Data : D=[s, a, r, s_dash, end_episode_flag] self.D = [np.zeros((self.data_size, 4, 84, 84), dtype=np.uint8), np.zeros(self.data_size, dtype=np.uint8), np.zeros((self.data_size, 1), dtype=np.int8), np.zeros((self.data_size, 4, 84, 84), dtype=np.uint8), np.zeros((self.data_size, 1), dtype=np.bool)]
Example #11
Source File: dqn_agent_nature.py From DQN-chainer with MIT License | 5 votes |
def __init__(self, enable_controller=[0, 3, 4]): self.num_of_actions = len(enable_controller) self.enable_controller = enable_controller # Default setting : "Pong" print "Initializing DQN..." # Initialization of Chainer 1.1.0 or older. # print "CUDA init" # cuda.init() print "Model Building" self.model = FunctionSet( l1=F.Convolution2D(4, 32, ksize=8, stride=4, nobias=False, wscale=np.sqrt(2)), l2=F.Convolution2D(32, 64, ksize=4, stride=2, nobias=False, wscale=np.sqrt(2)), l3=F.Convolution2D(64, 64, ksize=3, stride=1, nobias=False, wscale=np.sqrt(2)), l4=F.Linear(3136, 512, wscale=np.sqrt(2)), q_value=F.Linear(512, self.num_of_actions, initialW=np.zeros((self.num_of_actions, 512), dtype=np.float32)) ).to_gpu() self.model_target = copy.deepcopy(self.model) print "Initizlizing Optimizer" self.optimizer = optimizers.RMSpropGraves(lr=0.00025, alpha=0.95, momentum=0.95, eps=0.0001) self.optimizer.setup(self.model.collect_parameters()) # History Data : D=[s, a, r, s_dash, end_episode_flag] self.D = [np.zeros((self.data_size, 4, 84, 84), dtype=np.uint8), np.zeros(self.data_size, dtype=np.uint8), np.zeros((self.data_size, 1), dtype=np.int8), np.zeros((self.data_size, 4, 84, 84), dtype=np.uint8), np.zeros((self.data_size, 1), dtype=np.bool)]
Example #12
Source File: q_net.py From deel with MIT License | 5 votes |
def __init__(self, use_gpu, enable_controller, dim): self.use_gpu = use_gpu self.num_of_actions = len(enable_controller) self.enable_controller = enable_controller self.dim = dim print("Initializing Q-Network...") hidden_dim = 256 self.model = FunctionSet( l4=F.Linear(self.dim*self.hist_size, hidden_dim, wscale=np.sqrt(2)), q_value=F.Linear(hidden_dim, self.num_of_actions, initialW=np.zeros((self.num_of_actions, hidden_dim), dtype=np.float32)) ) if self.use_gpu >= 0: self.model.to_gpu() self.model_target = copy.deepcopy(self.model) self.optimizer = optimizers.RMSpropGraves(lr=0.00025, alpha=0.95, momentum=0.95, eps=0.0001) self.optimizer.setup(self.model.collect_parameters()) # History Data : D=[s, a, r, s_dash, end_episode_flag] self.d = [np.zeros((self.data_size, self.hist_size, self.dim), dtype=np.uint8), np.zeros(self.data_size, dtype=np.uint8), np.zeros((self.data_size, 1), dtype=np.int8), np.zeros((self.data_size, self.hist_size, self.dim), dtype=np.uint8), np.zeros((self.data_size, 1), dtype=np.bool)]