Using mxnet 1.1,
When I try to run net(data) on the following network:
net = gluon.nn.HybridSequential()
with net.name_scope():
net.add(gluon.nn.Embedding(input_dim=MAX_EVENT_INDEX + 1, output_dim=EMBEDDING_VECTOR_LENGTH))
net.add(gluon.nn.Conv1D(channels=conv1D_filters, kernel_size=conv1D_kernel_size, activation='relu'))
net.add(gluon.nn.MaxPool1D(pool_size=max_pool_size, strides=2))
net.add(gluon.rnn.LSTMCell(100))
net.add(gluon.rnn.DropoutCell(dropout_rate))
net.add(gluon.rnn.LSTMCell(100))
net.add(gluon.rnn.DropoutCell(dropout_rate))
net.add(gluon.rnn.LSTMCell(100))
net.add(gluon.rnn.DropoutCell(dropout_rate))
net.add(gluon.nn.Flatten())
net.add(gluon.nn.Dense(1, activation="sigmoid"))
net.hybridize()
Error: forward() missing 1 required positional argument: 'states'
Everything works when I use gluon.nn.Sequential() with net.add(gluon.rnn.LSTM(100, dropout=dropout_rate))
Thanks
If you look into implementation of LSTMCell you would notice, that hybrid_forward requires explicit states argument. LSTM class, using its base class implementation doesn't require states parameter (it can be None). So switching from one to another will definitely help you.
LSTM class is more than LSTMCell. It actually uses LSTMCell internally, but it also adds extra functionality on top of it. For example, you can specify LSTM to be multilayered or bidirectional, where LSTMCell is essentially just a bunch of LSTM-related formulas for calculating gates, c and h.
Related
My question is: is there any algorithm that can convert a SMILES structure into a topological fingerprint? For example if glycerol is the input the answer would be 3 x -OH , 2x -CH2 and 1x -CH.
I'm trying to build a python script that can predict the density of a mixture using an artificial neural network. As an input I want to have the structure/fingerprint of my molecules starting from the SMILES structure.
I'm already familiar with -rdkit and the morganfingerprint but that is not what i'm looking for. I'm also aware that I can use the 'matching substructure' search in rdkit, but then I would have to define all the different subgroups. Is there any more convenient/shorter way?
For most of the structures, there's no existing option to find the fragments. However, there's a module in rdkit that can provide you the number of fragments especially when it's a function group. Check it out here. As an example, let's say you want to find the number of aliphatic -OH groups in your molecule. You can simply call the following function to do that
from rdkit.Chem.Fragments import fr_Al_OH
fr_Al_OH(mol)
or the following would return the number of aromatic -OH groups:
from rdkit.Chem.Fragments import fr_Ar_OH
fr_Ar_OH(mol)
Similarly, there are 83 more functions available. Some of them would be useful for your task. For the ones, you don't get the pre-written function, you can always go to the source code of these rdkit modules, figure out how they did it, and then implement them for your features. But as you already mentioned, the way would be to define a SMARTS string and then fragment matching. The fragment matching module can be found here.
If you want to predict densities of pure components before predicting the mixtures I recommend the following paper:
https://pubs.acs.org/doi/abs/10.1021/acs.iecr.6b03809
You can use the fragments specified by rdkit as mnis proposes. Or you could specify the groups as SMARTS patterns and look for them yourself using GetSubstructMatches as you proposed yourself.
Dissecting a molecule into specific groups is not as straightforward as it might appear in the first place. You could also use an algorithm I published a while ago:
https://jcheminf.biomedcentral.com/articles/10.1186/s13321-019-0382-3
It includes a list of SMARTS for the UNIFAC model, but you could also use them for other things, like density prediction.
I had the following code, which defines a simple function taking two real variables as arguments and returning a complex number. The function call would not return in a minute's time. I determined the cause was inappropriate us of sympify (see below)
%%time
from sympy import *
x,t=symbols('x t')
e_psi_sw=sin(2*pi*x) + exp(1j*t)*sin(pi*x)
pdf=conjugate(e_psi_sw)*e_psi_sw
integrate(pdf*x,(x,0,1))
It's faster if you use sympy's I instead of the complex Python float 1j. It is generally best to avoid using floats unnecessarily in sympy.
Also declaring the symbols x and t to be real results in a simpler integrand that can be integrated more easily.
I was calling sympify with a string rather than a bare expression. When I removed the quotation marks, the integral ran quickly and the other issues I cited here were also resolved.
I did change j to I also...
Here is a question related to the algorithm of constructing the call graph for Java bytecode using CHA.
As there is no concrete method implementation for methods in abstract classes, adding a call edge to such methods might be a bit misleading.
take junit-4.12.jar for instance. runFailed has been defined in junit.runner.BaseTestRunner which is an abstract class. Besides, there are calls to runFailed in method getTest which also defined in junit.runner.BaseTestRunner
While in "Assumption Hierarchy for a CHA Call Graph Construction Algorithm"(Jason&Atanas), it is said that
"given a call site x.m(), where the declared type of x is C, the
possible runtime type of x must be a non-abstract subtype of C."
As far as i'm considered, without add a call edge(Calledge1) from junit.runner.BaseTestRunner getTest to junit.runner.BaseTestRunner runFailed, it is more reasonable to add a call edge(Calledge2) from junit.runner.BaseTestRunner getTest to junit/textui/TestRunner runFailed as TestRunner extends BaseTestRunner.
While after running test code to get the result of CallGraph.calledByStatistics(), only Calledge1 has been found. Calledge2 is missing.
Is there anybody can do me a favor to confirm this?
Thank you in advance.
Regards,
Jiang
I found OPAL offers two views of call graph. The second one won't add a "library-call" edge into call edge.
In CallGraph.calledByStatistics()
The binding is between Callsite (PC) to caller.method
for example: between “INVOKEVIRTUAL(junit.runner.BaseTestRunner{ void runFailed(java.lang.String) })” and
junit/runner/BaseTestRunner.public junit.framework.Test getTest(java.lang.String)
In CallGraph.callsStatistics()
The binding is between subtype.method to caller.method
for example:
between "junit/textui/TestRunner.protected void runFailed(java.lang.String)” and “junit/runner/BaseTestRunner.public junit.framework.Test getTest(java.lang.String)”
I am new to theano, can anyone help me defining a theano function like this:
Basically, I have a network model looks like this:
y_hat, cost, mu, output_hiddens, cells = nn_f(x, y, in_size, out_size, hidden_size, layer_models, 'MDN', training=False)
here the input x is a tensor:
x = tensor.tensor3('features', dtype=theano.config.floatX)
I want to define two theano functions for later use:
f_x_hidden = theano.function([x], [output_hiddens])
f_hidden_mu = theano.function([output_hiddens], [mu], on_unused_input = 'warn')
the first one is fine. for the second one, the problem is both the input and the output are output of the original function. it gives me error:
theano.gof.fg.MissingInputError: An input of the graph, used to compute Elemwise{identity}(features), was not provided and not given a value.
my understanding is, both of [output_hiddens] and [mu] are related to the input [x], there should be an relation between them. I tried define another theano function from [x] to [mu] like:
f_x_mu = theano.function([x], [mu]),
then
f_hidden_mu = theano.function(f_x_hidden, f_x_mu),
but it still does not work. Does anyone can help me? Thanks.
The simple answer is NO WAY. In here
Because in Theano you first express everything symbolically and afterwards compile this expression to get functions, ...
You can't use the output of theano.function as input/output for another theano.function since they are already a compiled graph/function.
You should pass the symbolic variables, such as x in your example code for f_x_hidden, to build the model.
I think I've been using these terms interchangably / wrongly!
Iain, this is basically a terminology question and is, despite the "language-agnostic" tag associated with this question, very language/environment related.
For design discussions sake, property and instance variable can be used interchangeably, since the idea is that a property is a data item describing an object.
When talking about a specific language these two can be different. For example, in C# a property is actually a function that returns an object, while an instance variable is a non-static member variable of a class.
Hershi is right about this being language specific. But to add to the trail of language specific answers:
In python, an instance variable is an attribute of an instance, (generally) something that is referred to in the instance's dictionary. This is analogous to members or instance variables in Java, except everything is public.
Properties are shortcuts to getter/setter methods that look just like an instance variable. Thus, in the following class definition (modified from Guido's new style object manifesto):
class C(object):
def __init__(self):
self.y = 0
def getx(self):
if self.y < 0: return 0
else: return self.y
def setx(self, x):
self.y = x
x = property(getx, setx)
>>> z = C()
>>> z.x = -3
>>> print z.x
0
>>> print z.y
-3
>>> z.x = 5
>>> print z.x
5
>>> print z.y
5
y is an instance variable of z, x is a property. (In general, where a property is defined, there are some techniques used to obscure the associated instance variable so that other code doesn't directly access it.) The benefit of properties in python is that a designer doesn't have to go around pre-emptively encapsulating all instance variables, since future encapsulation by converting an instance variable to a property should not break any existing code (unless the code is taking advantage of loopholes your encapsulation is trying to fix, or relying on class inspection or some other meta-programming technique).
All this is a very long answer to say that at the design level, it's good to talk about properties. It is agnostic as to what type of encapsulation you may need to perform. I guess this principle isn't language agnostic, but does apply to languages beside python.
In objective c, a property is an instance variable which can take advantage of an overloaded dot operator to call its setter and getter. So my.food = "cheeseburger" is actually interpreted as [my setFood:"cheeseburger"]. This is another case where the definition is definitely not language agnostic because objective-c defines the #property keyword.
code example done in C#
public class ClassName
{
private string variable;
public string property
{
get{ return variable; }
set { variable = value; }
}
}
Maybe thats because you first came from C++ right?!
In my school days I had professors that said class properties or class atributes all the time. Since I moved to the Java C# world, I started hearing about members. Class members, instance members...
And then Properties apear! in Java and .NET. So I think its better for you to call it members. Wheather they are instance members (or as you called it instance variable) or class Members....
Cheers!
A property can, and I suppose mostly does, return an instance variable but it can do more. You could put logic in a property, aggregate values or update other instance variables etc. I think it is best to avoid doing so however. Logic should go into methods.
In Java we have something called JavaBeans Properties, but that is basically a instance variable that follows a certain naming pattern for its getter and setter.
At add to what has been said, in a langauge like C#, a property is essentially a get and set function. As a result, it can have custom logic that runs in addition to the getting/setting. An instance variable cannot do this.
A property is some sort of data associated with an object. For instance, a property of a circle is its diameter, and another is its area.
An instance variable is a piece of data that is stored within an object. It doesn't necessarily need to correspond directly with a property. For instance (heh), a circle may store its radius in an instance variable, and calculate its diameter and area based on that radius. All three are still properties, but only the radius is stored in an instance variable.
Some languages have the concept of "first class" properties. This means that to a client application, the property looks and is used like an instance variable. That is, instead of writing something like circle.getDiameter(), you would write circle.diameter, and instead of circle.setRadius(5), you would write circle.radius = 5.
In contrast to the other answers given, I do think that there is a useful distinction between member variables and properties that is language-agnostic.
The distinction is most apparent in component-oriented programming, which is useful anywhere, but easiest to understand in a graphical UI. In that context, I tend to think of the design-time configuration of a component as manipulating the "properties" of an object. For example, I choose the foreground and background colors, the border style, and font of a text input field by setting its properties. While these properties could be changed at runtime, they typically aren't. At runtime, a different set of variables, representing the content of the field, are much more likely to be read and written. I think of this information as the "state" of the component.
Why is this distinction useful? When creating an abstraction for wiring components together, usually only the "state" variables need to be exposed. Going back to the text field example, you might declare an interface that provides access to the current content. But the "properties" that control the look and feel of the component are only defined on a concrete implementation class.