I have a matrix that is outputted like this:
maximums =
[ -9.9043877608991468201413092380493, 426.34796945271797204125533010993]
[ 9.3758615553048990076305298649689, 441.87005169359418197397861057075]
But when I try and run any commands on it, I get an error saying that this matrix is still symbolic. I don't understand since it's just numeric values. Is there anyway of making this matrix outputted used by normal functions of Matlab?
To get this matrix, I did calculate derivatives of a symbolic equation and then evaluate. But I'd like to run functions on this output.
Thanks!
EDIT (Here's an example of the command/error):
[maxValue, rowIdx] = max(maximums(:,2),[],2)
Undefined function 'max' for input arguments of type 'sym'.
Since your matrix is symbolic, you have to convert it to numeric first:
maximums = double(maximums)
You have to convert it:
maximus=double(maximus)
Related
I am trying to understand how word embeddings are generated, I've been reading that 1-hot encoded vector is used and it servers as a lookup table but, I want to print that and see, how can I do that. When I am doing the following:
self.embeddings = nn.Embedding(vocab_size, dim)
print('embed',self.embeddings.weight)
I am getting different results when I re-run the code for same input string/vocab_size and same dim.
I want to know why this happens and how are those weight values calulated? What equation/fucntions is used to get these values? Is any function like softmax etc used to get the weights?
I have a function where I want to solve for many variables separately, do I have to write down the function every time in terms of the other variable?
x,xG,xR
y = e.^tan(x.^2)+cos.^2(x);
yG = e.^tan(xG.^2)+cos.^2(xG);
First you cannot write an expression like cos.^2(x). If x is a single variable (ie x=pi) you could write either cos(x)^2 or cos(x^2). If x is a vector (a column vector might be x=[3;4;pi] and a row vector might be x=[3,4,pi], then you might write cos(x).^2 or cos(x.^2). The role of the period (.) in octave is explained here: https://octave.org/doc/v4.0.3/Arithmetic-Ops.html
Another issue has to do with understanding the difference between an expression: x=e^tanh(y); and a function. The later is a separate chunk of code that can be invoked from anywhere in your program.
Consider this simple example
1;
function y=myfunc(x)
y=exp(tanh(x));
endfunction
## main program
xxx=pi/3;
yyy=myfunc(xxx);
printf('%7.3f %7.3f\n',xxx,yyy)
y=exp(tanh(pi/3))
comments: The '1' in the first line tells Octave that there is more to the script than just the following function: the main program has to be interpreted as well. The function line specifies that inside the function, the input will be called x and the output y, so when my function is called from main, the input is xxx(=pi/2) and the output is yyy. The last line in this tiny script is an expression that does the same thing as the function. Note that since I didn't include a semi-colon at the end of that line the result is printed out
I suggest you play with this for a while, then if you have more questions, ask them in a new question.
Im using maple Im in worksheetmode I tried using Maple Input and 2D Input and I want to transpose my Matrix A:
A := `<|>`(`<,>`(1, .5, -2), `<,>`(.5, 9/4+b, 5+3*b), `<,>`(-2, 5+3*b, 18+9*b+4*a));
B:= Transpose(A);
When I exectute the sheet I dont get the translated values, there are the same as the input. So my matrix looks like the same as my input matrix plus the function term.
You can see a picture in the following link: Why arent the functions executed?
Meanwhile B:=A^+ is doing it the right way and I get a transposed Matrix. But also other functions only return the function body instead the needed values...
If you are using 2D Input mode (the default) then the extra space you've got between Transpose and the bracketed (B) is interpreted as multiplcation. Get rid of such a space.
Also, either load the package at the start of your document like,
with(LinearAlgebra):
before calling the Transpose command from that package, or call it with it's full name like,
LinearAlgebra:-Transpose(B);
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'm trying to get the max indexes by row from a matrix. To do this, I'm doing:
[throwaway, indexes] = max(blah, [], 2);
The variable "throwaway," would store values I don't want anymore and would never use, and I don't want to waste memory on it. Is there some way to indicate I don't want anything put into that throwaway variable? Something like undef in Perl, perhaps?
Yes, you can throw away return arguments with ~ for examples if func returns two arguments only v will be available after the following [~, v] = func()