How to get Elemwise{tanh,no_inplace}.0 value - input

I am using Deep learning Theano. How can I see the content of a variable like this: Elemwise{tanh,no_inplace}.0. It is the input data of logistic layer.

Suppose your variable is called t. Then you can evaluate it by calling t.eval(). This may fail if input data are needed. In that case you need to supply them by providing a dictionary like this t.eval({input_var1: value1, input_var2: value2}). This is the ad-hoc way of evaluating a theano-expression.
The way it works in real programs is to create a function taking the necessary input, for example: f = theano.function([input_var1, input_var2], t), will yield a function that takes two input variables, calculates t from them and outputs the result.

Right now, you don't seem to print values but operations. The output Elemwise{tanh,no_inplace}.0 means, that you have an element wise operation of tanh, that is not done in place. You still need to create a function that takes input and executes your operation. Then you need to call that function and print the result. You can read more about that in the graph-structure part of their tutorial.

Related

LabVIEW - How to clear an array after each iteration in a for loop

I'm trying to clear an array after each iteration of a for loop in LabVIEW, but the way I've implemented it has the values not going directly to what I want, but it changes with previous values in other parts of the array.
It isn't shown, but this code is inside of a for-loop that iterates through another numeric array.
I know that if I get the array to clear properly after each loop iteration, this should work. How do I do that? I'm a beginner at Labview but have been coding for awhile - help is appreciated!!!
[![labview add to array][2]][2]
It looks as if you're not quite used to how LabVIEW passes data around yet. There's no need to use lots of value property nodes for the same control or indicator within one structure; if you want to use the same data in more than one place, just branch the wire. Perhaps you're thinking that a LabVIEW control or indicator is equivalent to a variable in text languages, and you need to use a property node to get or set it. Instead, think of the wire as the variable. If you want to pass the output of one operation to the input of another, just wire the output to the input.
The indicators with terminals inside your loop will be updated with new values every loop iteration, and the code inside the loop should execute faster than a human can read those values, so once the loop has finished all the outputs except the final values will be lost. Is that what you intended, or do you want to accumulate or store them in some way?
I can see that in each loop iteration you're reading two values from a config file, and the section is specified by the string value of one element of the numeric array Array. You're displaying the two values in the indicators PICKERING and SUBUNIT. If you can describe in words (or pseudocode, or a text language you're used to) what manipulation of data you're actually trying to do in the rest of this code, we may be able to make more specific suggestions.
First of all, I'm assuming that the desired order of operations is the following:
Putting the value of Pickering into Array 2
Extracting from Array 2 the values to put in Pickering 1 and Pickering 2
Putting Array 2 back to its original value
If this is the case, with your current code you can't be sure that operation 1 will be executed be fore operation 2. In fact, the order of these operations can't be pre-determined. You must force the dataflow, for example by creating a sequence structure. You will put the code related to 1 in the first frame, then code related to operation 2 in the second.
Then, to put Array 2 back to it's original value I would add a third frame, where you force an empty array into the Value property node of Array 2 (the tool you use for pickering, but as input and not as output).
The sequence structure has to be inside the for loop.
I have never used the property node Reinit to default, so I can't help you with that.
Unfortunately I can't run Labview on this PC but I hope my explanation was clear enough, if not tell me and I will try to be more specific.

What is the lambda function doing in the info_dict parameter of the summary_col in this code?

I'm running summary statistics for a group of standard OLS regressions. The code was written by my professor and I'm trying to figure out what's going on specifically in a portion of the code.
summary_col(
[reg0,reg1,reg2,reg3],
stars=True,
float_format='%0.2f',
info_dict = {
'N':lambda x: "{0:d}".format(int(x.nobs)),
'R2':lambda x: "{:.2f}".format(x.rsquared)
})
I looked up lambda functions. I have a fairly decent understanding of how they work. Aspects of the code that I do understand:
info_dict is a dictionary of values that can be called if you wish to include them in your summary statistics
lambda function work by calling an anonymous function "lambda x" then you place the : and list what operation you want to take place (i.e. x + 5) and then if you already know what parameters you want it to run you can put in a list after a second ":".
{0:d} will round to integers which makes perfect sense for observations. Although I don't know why you can't just say {%.f}. Maybe it's because the former returns an explicit int and the latter returns a float that looks like an int.
{:.2f} will return a float with 2 decimal places
What I don't fully understand is what somestring.format() does. Somehow x is getting defined as the results from the regression I believe and x.nobs is the variable "number of observations". Similar for x.rsquared.
Could someone fill in the gaps for me about what's going on in the formula? What exactly about the lambda function is enabling it to fetch data for each individual regression?
Let's break this out a little bit to make it obvious what is happening:
summary_col(
[reg0,reg1,reg2,reg3],
stars=True,
float_format='%0.2f',
info_dict={
'N':lambda x: "{0:d}".format(int(x.nobs)),
'R2':lambda x: "{:.2f}".format(x.rsquared)
}
)
The summary_col object is taking in some input, the first argument being a list of regression objects, [reg0,reg1,reg2,reg3]. Then there are three named arguments, stars, float_format, and info_dict. When we pass in the list of regression objects as the first argument, I believe that the lambda function knows to apply the anonymous function to each object. So all info_dict is doing is creating a dictionary with two keys, N and R2 which map to strings. When the member x.nobs and x.rsquared are referenced in the lambda functions they are applied against the regression objects due to the context in which these are used.
If you try to use lambda in that line of code on something that does not exist in the regression objects, you'll almost certainly get an error. The key is in the context against which the lambda is applied.
A good example on the context of lambda functions is iterating over a dictionary and sorting by key and value.
# sort the dict by value first, and key second...
# x is inferred from the context (my_dict.items())
for key, value in sorted(my_dict.items(), key=lambda x: (x[1], x[0]):
print(key, value)

How to optimize a function existing as a embedded function block in simulink, part of MATLab, using fmincon?

function y = objfun(x)
sim('modelprototype.slx');
y = Y(1);
end
It is in simulink embedded func block.
Before that I ask for help, I will explain what I did and what I want;
I had a function as a script in matlab. Having entered the parameters to fmincon to optimize my fuction, It worked correctly. And iterated 9 times and lastly found the minimum value of my function;
But the problem is occured when I decided to write the function in a embedded function existing in simulink model. Like I did above I entered all parameters for fmincon it only iterates 3 times and the values are same. I could not find the minimum value.
Please help me to find a solution to optimize the function in simulink model like that same function written as ascript file in matlab.
I want to write the function indicated in that link in simulink embedded function block and optimize it;
You can find information from the link below;
-https://www.mathworks.com/help/optim/ug/output-functions.html
You can reach Code and File
-https://github.com/saibermehmet/MATLAB.git
I again indicate that I want to optimize the obj function when it is a embedded function block in simulink instead of a ordinary function m-file.

How to correctly pass initial value of transition_params in tensorflow linear chain CRF

I'm trying to use the linear chain CRF in my work. I took the help of the example usage code provided in -- https://github.com/tensorflow/tensorflow/tree/r1.0/tensorflow/contrib/crf
My question is how to supply some initial value of "transition_params" in "crf_log_likelihood()". For concreteness of the example, say, I want to initialize it with standard random normal distribution. In the api doc, I saw that "transition_params" can, in fact, be passed as an input argument. Inside the method I see that if no "transition_params" is passed, it is obtained by doing a "vs.get_variable()" with name = "transitions".
So should I do something similar to this, before creating the 'crf_log_likelihood' op? Something like -- transition_params = vs.get_variable("transitions", [num_tags, num_tags], initializer=tf.random_normal_initializer()) -- and then change the call of "crf_log_likelihood()" to "log_likelihood, transition_params = tf.contrib.crf.crf_log_likelihood(unary_scores, y_t, sequence_lengths_t, transition_params)"?
The get_variable() inside the definition of crf_log_likelihood() will create a fresh, randomly-initialized variable to represent the transition parameters, if you don't provide one yourself. You only need to provide an explicit transition_params if you don't want the default behavior.
To understand the behavior of get_variable(), see here:
https://www.tensorflow.org/api_docs/python/state_ops/sharing_variables#get_variable
Hope that helps!

cacti: Display how much % one data source item has of an other datasource item

I want to create a graph template in which it is displayed how much percentage a data source item has of another data source item.
I assumed I'd need to use CDEF functions for that and according to that question CDEF Function to find % value in Cacti it isn't even a difficult one.
However, I have no idea how to actually use the given CDEF function within the graph template web interface, how to choose which data source items should serve as input for the CDEF function, how to get the CDEF functions output as input for drawing a graph item of (e.g of type LINE1).
Nowhere does the documentation mentions such things, or if, I didn't find or get it.
The way to find out what datasource is what letter value is by going into Console -> Graph Management -> Pick the Graph you are working on -> Turn On Debug Mode
What you are looking for are the lines that start with DEF a=, b= etc.
From there you build the CDEF function using reverse polish notation as shown in my question you have referenced above.
To use the value in a graph eg a LINE add a new item in the graph template then just dont select a datasource and select your prebuilt CDEF function like below.
That should do exactly what you are looking for. In my example I used an AREA but that is just what was best suited for the graph in question.