Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

may you do me a favor. i wanna transfer matlab function to python in pyarma #3

Closed
luyifanlu opened this issue Feb 10, 2021 · 6 comments

Comments

@luyifanlu
Copy link

luyifanlu commented Feb 10, 2021

matlab function
`
function output =NN_F(input)

layer_nodes_num=[200,200,150,150];
bias=0.00001;
%input=traindata(:,1);
pre_layer_nodes_num=length(input);
pre_layer_nodes_value=input'; % input
for l=1:length(layer_nodes_num)
> curr_layer_nodes_num=layer_nodes_num(l);

clear curr_layer_nodes_value;
for it=1:curr_layer_nodes_num
    curr_node_input_weight=randn(1,pre_layer_nodes_num);
    xx=sum(pre_layer_nodes_value.*curr_node_input_weight);
    curr_layer_nodes_value(it)=tanh(xx/2.5);
end
pre_layer_nodes_value=curr_layer_nodes_value;
pre_layer_nodes_num=curr_layer_nodes_num;

end
output=curr_layer_nodes_value;
end
`

@luyifanlu
Copy link
Author

luyifanlu commented Feb 10, 2021

my work ,but got error--NameError: name 'curr_layer_nodes_value' is not defined

`

from pyarma import *
import numpy as np
def out(inp):

layer_nodes_num=[200,210,150,150]

bias=0.00001
pre_layer_nodes_num=inp.n_rows
pre_layer_nodes_value=inp.t()
for l in range(len(layer_nodes_num)):
    curr_layer_nodes_num=layer_nodes_num[l]
    print(curr_layer_nodes_num)
    #curr_layer_nodes_value = mat(10,4,fill.zeros)
    for it in range(curr_layer_nodes_num):
        curr_node_input_weight=randn(1,pre_layer_nodes_num)
        xx=sum(pre_layer_nodes_value@curr_node_input_weight)
        curr_layer_nodes_value[it]= tanh(xx/2.5)
    pre_layer_nodes_value=curr_layer_nodes_value
    pre_layer_nodes_num=curr_layer_nodes_num
    #del curr_layer_nodes_value
return curr_layer_nodes_value

`

@terryyz
Copy link
Owner

terryyz commented Feb 10, 2021

Hi @luyifanlu, from my understanding, curr_layer_nodes_value will change its size per iteration. You may consider initialize curr_layer_nodes_value by using curr_layer_nodes_value = mat(). Then you may want to use .resize() to handle the assigned values and increased size of curr_layer_nodes_value per iteration.

@luyifanlu
Copy link
Author

luyifanlu commented Feb 11, 2021

Hi @luyifanlu, from my understanding, curr_layer_nodes_value will change its size per iteration. You may consider initialize curr_layer_nodes_value by using curr_layer_nodes_value = mat(). Then you may want to use .resize() to handle the assigned values and increased size of curr_layer_nodes_value per iteration.

Thank you . i got a question whether there are cell function in pyarma like matlab. if not, which one can instead of it

@terryyz
Copy link
Owner

terryyz commented Feb 11, 2021

Hi @luyifanlu, from my understanding, curr_layer_nodes_value will change its size per iteration. You may consider initialize curr_layer_nodes_value by using curr_layer_nodes_value = mat(). Then you may want to use .resize() to handle the assigned values and increased size of curr_layer_nodes_value per iteration.

Thank you . i got a question whether there are cell function in pyarma like matlab. if not, which one can instead of it

Hi @luyifanlu, if you mean cell() function in the matlab, then we don't have it as it is not implemented by Armadillo... (We may add extra features later. But we want to focus on implementing all functions of Armadillo into the PyArmadillo at this stage.). Feel free to check the PyArmadillo documentation in English. I'm still trying to find some time to work on the documentation translation.

And Happy Chinese New Year! 🥳

@luyifanlu
Copy link
Author

luyifanlu commented Feb 11, 2021

Hi @luyifanlu, from my understanding, curr_layer_nodes_value will change its size per iteration. You may consider initialize curr_layer_nodes_value by using curr_layer_nodes_value = mat(). Then you may want to use .resize() to handle the assigned values and increased size of curr_layer_nodes_value per iteration.

Thank you . i got a question whether there are cell function in pyarma like matlab. if not, which one can instead of it

Hi @luyifanlu, if you mean cell() function in the matlab, then we don't have it as it is not implemented by Armadillo... (We may add extra features later. But we want to focus on implementing all functions of Armadillo into the PyArmadillo at this stage.). Feel free to check the PyArmadillo documentation in English. I'm still trying to find some time to work on the documentation translation.

And Happy Chinese New Year!

ow ow, i see. How to get last row. i have tried in X[-1,:] and X[end,:],but both get error.

And Happy Chinese New Year!

@terryyz
Copy link
Owner

terryyz commented Feb 12, 2021

Hi @luyifanlu, from my understanding, curr_layer_nodes_value will change its size per iteration. You may consider initialize curr_layer_nodes_value by using curr_layer_nodes_value = mat(). Then you may want to use .resize() to handle the assigned values and increased size of curr_layer_nodes_value per iteration.

Thank you . i got a question whether there are cell function in pyarma like matlab. if not, which one can instead of it

Hi @luyifanlu, if you mean cell() function in the matlab, then we don't have it as it is not implemented by Armadillo... (We may add extra features later. But we want to focus on implementing all functions of Armadillo into the PyArmadillo at this stage.). Feel free to check the PyArmadillo documentation in English. I'm still trying to find some time to work on the documentation translation.
And Happy Chinese New Year!

ow ow, i see. How to get last row. i have tried in X[-1,:] and X[end,:],but both get error.

And Happy Chinese New Year!

Check this in the doc.

@terryyz terryyz closed this as completed Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants