Error on applying Matlab activations function on Siamese network - matlab

Happy new year
For a sample Siamese network (for instance refer to Matlab example: Train a Siamese Network to Compare Images(https://www.mathworks.com/help/deeplearning/ug/train-a-siamese-network-to-compare-images.html)), I need to compute deep learning network layer activations (refer again to Matlab activations function (https://www.mathworks.com/help/deeplearning/ref/seriesnetwork.activations.html)) for a specific layer. I faced an error and I have no idea to solve it. The code is as below:
**sample code to test Matlab activations function:
**
inp = 255*rand(105,105,1);
inp = dlarray(inp,"SSCB");
f = activations(net,inp,"maxpool_1");
**Matlab error:
**Incorrect number or types of inputs or outputs for function 'activations'.
I tried to apply Matlab activations function on neural network object.
It work fine on pre-trained networks. But It failed on Siamese.

Related

How to calculate gradients for a neural network with theano when using Q-Learning

I am trying to use a standard fully-connected neural net as the basis for action values in Q-Learning. I am using http://deeplearning.net/tutorial/mlp.html#mlp as a reference specifically this line:
gparams = [T.grad(cost, param) for param in classifier.params]
I would like to calculate the error for my output unit associated with the last action using the Q-Learning policy control method (as described in http://webdocs.cs.ualberta.ca/~sutton/book/ebook/node65.html) and set the other output errors to zero.
How can I use Theano's grad function to back-propagate the errors to the rest of the neural network?
Neural nets are just one possible way of parametrizing your Q-function. The way you perform gradient descent in this case is explained in this section of Sutton and Barto's book. Just treat the weights of your neural net as a vector of parameters.

How do you make a prediction (forecast) from a trained network for a given input in Matlab?

I am using the neural network toolbox that Matlab provides. I trained a NARX neural network for time series problems. I am trying to predict future values using the inputs I am giving to the neural network.
I am able to see the error graphs and the response for the testing and validation samples, but how do I test new samples? How can I make a prediction using the trained neural network? I could not find any documentation.
This was my attempt
>> net(input2')
ans =
[917.9814]
But no matter what the inputs are, I am getting the exact same output always....

Non-linear regression using custom neural network in MatLab

I am very new to MatLab. I got a task for modelling non-linear regression using neural network in MatLab.
I need to create a two-layer neural network where:
The first layer is N neurons with sigmoid activation function.
The second layer is layer with one neuron and a linear activation
function.
Here is how I implemented the network:
net = network(N, 2);
net.layers{1}.transferFcn = 'logsig';
net.layers{1}.size = N
net.layers{2}.size = 1;
Is this implementation correct? How should I assign the linear activation function to the second layer?
A quick reading of the Matlab help on the nntransfer function gives you the list of all possible transfer functions you can use. In your case I think you should either try the poslin (positive linear) or the purelin one (pure linear).
When you have such questions, the best way is actually to 'ask' Matlab the possibilities you have.
In this case, I just typed net.layers{2} in the Matlab console window. This displays the list of the parameters of the 2nd layer. Then, you just click on the link TransferFcn and the Matlab help with the possible options for this parameter value automatically opens. This works for any parameter of your neural network ;)
You didn't determine the transfer function for the second layer.
net.layers{2}.transferFcn='pureline'
The rest is OK.

MATLAB neural network weight and bias initializaiton

I'm creating a neural network in one part of my program and using it's weights and biases for another neural network in other part so I have the following code:
net_b = patternnet(10);
net_b = configure(net,INPUT,Target);
Weights = getwb(net);
I will use this neural network weights and biases for creating another neural network as below:
net = patternnet(10);
net = configure(net,INPUT,Target);
net = setwb(net,Weights);
Everything was good until this stage, but then I wanted to disable pre-processing from the neural network (because I did it in a stage of the program before inserting the data to the neural network), so I used these functions:
net.inputs{1}.processFcns={};
net.outputs{2}.processFcns={};
When I used the above two functions and checked the weights in the input layer or biases in the output layer, everything is removed and I have an empty matrix, but in the hidden layer everything is normal. How can I do these without removing my weights and biases?

In Matlab, How to use already trained neural network on real time values?

Using nntool(Neural Network Manager) in Matlab, we have created a neural network named network1, the network type is Feed Forward backprop. Training function is TRAINLM, learning function is LEARNGDM, performance function is MSE. No. of layers are 2 and transfer function is TRANSIG. No. of Inputs is 2.
We have trained it using known datasets.
Now, we want to use this trained Neural Network on real time values(dynamically one by one) to get the output.
We are unable to use the network on real time values.
So, please guide us through the steps to use trained neural network on real time values.
if you created a ann via
network1 = feedforwardnet;
or something of that kind and then trained it with your known data, you should be able to use said net via
outputs = network1(inputs);
You can create a function from the neural network that you have trained and use it as regular MATLAB functions.
You can either create it with genFun command or using the GUI in neural network toolbox.
genFunction(net,pathname)
If you want the function to accept only matrix elements you should use this command:
genFunction(net,pathname,'MatrixOnly','yes')