Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

75 lines (65 sloc) 2.3 KB
"""
DeepSEA architecture (Zhou & Troyanskaya, 2015).
"""
import numpy as np
import torch
import torch.nn as nn
class DeepSEA(nn.Module):
def __init__(self, sequence_length, n_genomic_features):
"""
Parameters
----------
sequence_length : int
n_genomic_features : int
"""
super(DeepSEA, self).__init__()
conv_kernel_size = 8
pool_kernel_size = 4
self.conv_net = nn.Sequential(
nn.Conv1d(4, 320, kernel_size=conv_kernel_size),
nn.ReLU(inplace=True),
nn.MaxPool1d(
kernel_size=pool_kernel_size, stride=pool_kernel_size),
nn.Dropout(p=0.2),
nn.Conv1d(320, 480, kernel_size=conv_kernel_size),
nn.ReLU(inplace=True),
nn.MaxPool1d(
kernel_size=pool_kernel_size, stride=pool_kernel_size),
nn.Dropout(p=0.2),
nn.Conv1d(480, 960, kernel_size=conv_kernel_size),
nn.ReLU(inplace=True),
nn.Dropout(p=0.5))
reduce_by = conv_kernel_size - 1
pool_kernel_size = float(pool_kernel_size)
self.n_channels = int(
np.floor(
(np.floor(
(sequence_length - reduce_by) / pool_kernel_size)
- reduce_by) / pool_kernel_size)
- reduce_by)
self.classifier = nn.Sequential(
nn.Linear(960 * self.n_channels, n_genomic_features),
nn.ReLU(inplace=True),
nn.Linear(n_genomic_features, n_genomic_features),
nn.Sigmoid())
def forward(self, x):
"""Forward propagation of a batch.
"""
out = self.conv_net(x)
reshape_out = out.view(out.size(0), 960 * self.n_channels)
predict = self.classifier(reshape_out)
return predict
def criterion():
"""
The criterion the model aims to minimize.
"""
return nn.BCELoss()
def get_optimizer(lr):
"""
The optimizer and the parameters with which to initialize the optimizer.
At a later time, we initialize the optimizer by also passing in the model
parameters (`model.parameters()`). We cannot initialize the optimizer
until the model has been initialized.
"""
return (torch.optim.SGD,
{"lr": lr, "weight_decay": 1e-6, "momentum": 0.9})
You can’t perform that action at this time.