Neural network from scratch in R [closed]












-1














I am writing a neural network from scratch in r programming language and apply it on iris dataset.
here



d1f is a matrix of propagation error of output layer



d2f is a matrix of propagation error of hidden layer



a1,a2,a3,a4 are activation output of hidden layer



o1,o2,o3 are activation output of output layer



w1b & w2b are the matrix of weights of hidden layer and output layer respectively



j is used to store cost of each observation



till now I had written it for only single pass through the whole dataset. So only propagation error is calculated but weights will not get updated.
whenever I run this code I got an error



Error in a1(1 - a1) : could not find function "a1"



bt after termination i can see the value of a1 on the right side of R-Studio.
It seems like is d2f is not calculated even.so what i am doing wrong.



here is the code



library(datasets)
library("phonTools", lib.loc="~/R/win-library/3.5")
iris.df =data(iris)
data(iris)
data("iris")
iris.df=iris

J = vector(mode = "numeric" , length = nrow(iris.df) )

attach(iris.df)

iris.df$y1 = 0

iris.df$y2 = 0

iris.df$y3 = 0

iris.df$y1[iris.df$Species =="setosa"] = 1

iris.df$y2[iris.df$Species =="versicolor"] = 1

iris.df$y3[iris.df$Species =="virginica"] = 1

w1b = matrix(rexp(20, rate=.1), ncol=5) #Declaring weights between 1st layer

w1b = wb1*0.24 - 0.12

q = c(1,1,1,1)

#w1b = cbind(q,w1b)

w2b = matrix(rexp(12, rate=.1), ncol=4)

w2b = w2b*0.24 - 0.12

q = c(1,1,1)

#w2b = cbind(q,w2b)

d1f = zeros(3,4)

d2f = zeros(4,5)

sigmoid = function(z)
{
sig = 1/( 1 + exp(-z) )

return(sig)
}

for (i in 1:150) {


# Forward Propagation For First Layer

a1 = sigmoid( 1*w1b[1,1] + iris.df$Sepal.Length[i]*w1b[1,2] + iris.df$Sepal.Width[i]*w1b[1,3] + iris.df$Petal.Length[i]*w1b[1,4] + iris.df$Petal.Width[i]*w1b[1,5] )

a2 = sigmoid( 1*w1b[2,1] + iris.df$Sepal.Length[i]*w1b[2,2] + iris.df$Sepal.Width[i]*w1b[2,3] + iris.df$Petal.Length[i]*w1b[2,4] + iris.df$Petal.Width[i]*w1b[2,5] )

a3 = sigmoid( 1*w1b[3,1] + iris.df$Sepal.Length[i]*w1b[3,2] + iris.df$Sepal.Width[i]*w1b[3,3] + iris.df$Petal.Length[i]*w1b[3,4] + iris.df$Petal.Width[i]*w1b[3,5] )

a4 = sigmoid( 1*w1b[4,1] + iris.df$Sepal.Length[i]*w1b[4,2] + iris.df$Sepal.Width[i]*w1b[4,3] + iris.df$Petal.Length[i]*w1b[4,4] + iris.df$Petal.Width[i]*w1b[4,5] )

#Forward Propagation For Second Layer

o1 = sigmoid( 1*w2b[1,1] + a1*w2b[1,2] + a1*w2b[1,3] + a1*w2b[1,4] )

o2 = sigmoid( 1*w2b[2,1] + a2*w2b[2,2] + a2*w2b[2,3] + a2*w2b[2,4] )

o3 = sigmoid( 1*w2b[3,1] + a3*w2b[3,2] + a3*w2b[3,3] + a3*w2b[3,4] )




#Backward Propagation For First Layer

d1f[1,1] = d1f[1,1] + o1*(1-o1) *(o1-y1[i]) #For Baised Node

d1f[2,1] = d1f[2,1] + o2*(1-o2) *(o2-y2[i]) #For Baised Node

d1f[3,1] = d1f[3,1] + o3*(1-o3) *(o3-y3[i]) #For Baised Node



d1f[1,2] = d1f[1,2] + a1*o1*(1-o1)*(o1-y1[i])

d1f[2,2] = d1f[2,2] + a1*o2*(1-o2)*(o2-y2[i])

d1f[3,2] = d1f[3,2] + a1*o3*(1-o3)*(o3-y3[i])




d1f[1,3] = d1f[1,3] + a2*o1*(1-o1)*(o1-y1[i])

d1f[2,3] = d1f[2,3] + a2*o2*(1-o2)*(o2-y2[i])

d1f[3,3] = d1f[3,3] + a2*o3*(1-o3)*(o3-y3[i])




d1f[1,4] = d1f[1,4] + a3*o1*(1-o1)*(o1-y1[i])

d1f[2,4] = d1f[2,4] + a3*o2*(1-o2)*(o2-y2[i])

d1f[3,4] = d1f[3,4] + a3*o3*(1-o3)*(o3-y3[i])



#Backward Propagation For Second Layer

d2f[1,2] = d2f[1,2] + iris.df$Sepal.Length[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[1,3] = d2f[1,3] + iris.df$Sepal.Width[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[1,4] = d2f[1,4] + iris.df$Petal.Length[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[1,5] = d2f[1,5] + iris.df$Petal.Width[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )


###########

d2f[1,1] = d2f[1,1] + a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

d2f[2,1] = d2f[2,1] + a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

d2f[3,1] = d2f[3,1] + a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

d2f[4,1] = d2f[4,1] + a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node





d2f[2,2] = d2f[2,2] + iris.df$Sepal.Length[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[2,3] = d2f[2,3] + iris.df$Sepal.Width[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[2,4] = d2f[2,4] + iris.df$Petal.Length[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[2,5] = d2f[2,5] + iris.df$Petal.Width[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




d2f[3,2] = d2f[3,2] + iris.df$Sepal.Length[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[3,3] = d2f[3,3] + iris.df$Sepal.Width[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[3,4] = d2f[3,4] + iris.df$Petal.Length[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[3][5] = d2f[3,5] + iris.df$Petal.Width[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




d2f[4,2] = d2f[4,2] + iris.df$Sepal.Length[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[4][3] = d2f[4,3] + iris.df$Sepal.Width[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[4,4] = d2f[4,4] + iris.df$Petal.Length[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

d2f[4,5] = d2f[4,5] + iris.df$Petal.Width[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




cost = ( iris.df$y1[i] * log(o1) + (1-y1[i]) * log(1-o1) + iris.df$y2[i] * log(o2) + (1-y2[i]) * log(1-o2) + iris.df$y3[i] * log(o3) + (1-y3[i]) * log(1-o3) )/nrow(iris.df)

j[i] = cost
}









share|improve this question















closed as off-topic by desertnaut, Rui Barradas, AkselA, blue-phoenox, Rob Nov 24 '18 at 2:12


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – desertnaut, Rui Barradas, Rob

If this question can be reworded to fit the rules in the help center, please edit the question.


















    -1














    I am writing a neural network from scratch in r programming language and apply it on iris dataset.
    here



    d1f is a matrix of propagation error of output layer



    d2f is a matrix of propagation error of hidden layer



    a1,a2,a3,a4 are activation output of hidden layer



    o1,o2,o3 are activation output of output layer



    w1b & w2b are the matrix of weights of hidden layer and output layer respectively



    j is used to store cost of each observation



    till now I had written it for only single pass through the whole dataset. So only propagation error is calculated but weights will not get updated.
    whenever I run this code I got an error



    Error in a1(1 - a1) : could not find function "a1"



    bt after termination i can see the value of a1 on the right side of R-Studio.
    It seems like is d2f is not calculated even.so what i am doing wrong.



    here is the code



    library(datasets)
    library("phonTools", lib.loc="~/R/win-library/3.5")
    iris.df =data(iris)
    data(iris)
    data("iris")
    iris.df=iris

    J = vector(mode = "numeric" , length = nrow(iris.df) )

    attach(iris.df)

    iris.df$y1 = 0

    iris.df$y2 = 0

    iris.df$y3 = 0

    iris.df$y1[iris.df$Species =="setosa"] = 1

    iris.df$y2[iris.df$Species =="versicolor"] = 1

    iris.df$y3[iris.df$Species =="virginica"] = 1

    w1b = matrix(rexp(20, rate=.1), ncol=5) #Declaring weights between 1st layer

    w1b = wb1*0.24 - 0.12

    q = c(1,1,1,1)

    #w1b = cbind(q,w1b)

    w2b = matrix(rexp(12, rate=.1), ncol=4)

    w2b = w2b*0.24 - 0.12

    q = c(1,1,1)

    #w2b = cbind(q,w2b)

    d1f = zeros(3,4)

    d2f = zeros(4,5)

    sigmoid = function(z)
    {
    sig = 1/( 1 + exp(-z) )

    return(sig)
    }

    for (i in 1:150) {


    # Forward Propagation For First Layer

    a1 = sigmoid( 1*w1b[1,1] + iris.df$Sepal.Length[i]*w1b[1,2] + iris.df$Sepal.Width[i]*w1b[1,3] + iris.df$Petal.Length[i]*w1b[1,4] + iris.df$Petal.Width[i]*w1b[1,5] )

    a2 = sigmoid( 1*w1b[2,1] + iris.df$Sepal.Length[i]*w1b[2,2] + iris.df$Sepal.Width[i]*w1b[2,3] + iris.df$Petal.Length[i]*w1b[2,4] + iris.df$Petal.Width[i]*w1b[2,5] )

    a3 = sigmoid( 1*w1b[3,1] + iris.df$Sepal.Length[i]*w1b[3,2] + iris.df$Sepal.Width[i]*w1b[3,3] + iris.df$Petal.Length[i]*w1b[3,4] + iris.df$Petal.Width[i]*w1b[3,5] )

    a4 = sigmoid( 1*w1b[4,1] + iris.df$Sepal.Length[i]*w1b[4,2] + iris.df$Sepal.Width[i]*w1b[4,3] + iris.df$Petal.Length[i]*w1b[4,4] + iris.df$Petal.Width[i]*w1b[4,5] )

    #Forward Propagation For Second Layer

    o1 = sigmoid( 1*w2b[1,1] + a1*w2b[1,2] + a1*w2b[1,3] + a1*w2b[1,4] )

    o2 = sigmoid( 1*w2b[2,1] + a2*w2b[2,2] + a2*w2b[2,3] + a2*w2b[2,4] )

    o3 = sigmoid( 1*w2b[3,1] + a3*w2b[3,2] + a3*w2b[3,3] + a3*w2b[3,4] )




    #Backward Propagation For First Layer

    d1f[1,1] = d1f[1,1] + o1*(1-o1) *(o1-y1[i]) #For Baised Node

    d1f[2,1] = d1f[2,1] + o2*(1-o2) *(o2-y2[i]) #For Baised Node

    d1f[3,1] = d1f[3,1] + o3*(1-o3) *(o3-y3[i]) #For Baised Node



    d1f[1,2] = d1f[1,2] + a1*o1*(1-o1)*(o1-y1[i])

    d1f[2,2] = d1f[2,2] + a1*o2*(1-o2)*(o2-y2[i])

    d1f[3,2] = d1f[3,2] + a1*o3*(1-o3)*(o3-y3[i])




    d1f[1,3] = d1f[1,3] + a2*o1*(1-o1)*(o1-y1[i])

    d1f[2,3] = d1f[2,3] + a2*o2*(1-o2)*(o2-y2[i])

    d1f[3,3] = d1f[3,3] + a2*o3*(1-o3)*(o3-y3[i])




    d1f[1,4] = d1f[1,4] + a3*o1*(1-o1)*(o1-y1[i])

    d1f[2,4] = d1f[2,4] + a3*o2*(1-o2)*(o2-y2[i])

    d1f[3,4] = d1f[3,4] + a3*o3*(1-o3)*(o3-y3[i])



    #Backward Propagation For Second Layer

    d2f[1,2] = d2f[1,2] + iris.df$Sepal.Length[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[1,3] = d2f[1,3] + iris.df$Sepal.Width[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[1,4] = d2f[1,4] + iris.df$Petal.Length[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[1,5] = d2f[1,5] + iris.df$Petal.Width[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )


    ###########

    d2f[1,1] = d2f[1,1] + a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

    d2f[2,1] = d2f[2,1] + a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

    d2f[3,1] = d2f[3,1] + a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

    d2f[4,1] = d2f[4,1] + a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node





    d2f[2,2] = d2f[2,2] + iris.df$Sepal.Length[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[2,3] = d2f[2,3] + iris.df$Sepal.Width[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[2,4] = d2f[2,4] + iris.df$Petal.Length[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[2,5] = d2f[2,5] + iris.df$Petal.Width[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




    d2f[3,2] = d2f[3,2] + iris.df$Sepal.Length[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[3,3] = d2f[3,3] + iris.df$Sepal.Width[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[3,4] = d2f[3,4] + iris.df$Petal.Length[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[3][5] = d2f[3,5] + iris.df$Petal.Width[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




    d2f[4,2] = d2f[4,2] + iris.df$Sepal.Length[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[4][3] = d2f[4,3] + iris.df$Sepal.Width[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[4,4] = d2f[4,4] + iris.df$Petal.Length[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

    d2f[4,5] = d2f[4,5] + iris.df$Petal.Width[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




    cost = ( iris.df$y1[i] * log(o1) + (1-y1[i]) * log(1-o1) + iris.df$y2[i] * log(o2) + (1-y2[i]) * log(1-o2) + iris.df$y3[i] * log(o3) + (1-y3[i]) * log(1-o3) )/nrow(iris.df)

    j[i] = cost
    }









    share|improve this question















    closed as off-topic by desertnaut, Rui Barradas, AkselA, blue-phoenox, Rob Nov 24 '18 at 2:12


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – desertnaut, Rui Barradas, Rob

    If this question can be reworded to fit the rules in the help center, please edit the question.
















      -1












      -1








      -1







      I am writing a neural network from scratch in r programming language and apply it on iris dataset.
      here



      d1f is a matrix of propagation error of output layer



      d2f is a matrix of propagation error of hidden layer



      a1,a2,a3,a4 are activation output of hidden layer



      o1,o2,o3 are activation output of output layer



      w1b & w2b are the matrix of weights of hidden layer and output layer respectively



      j is used to store cost of each observation



      till now I had written it for only single pass through the whole dataset. So only propagation error is calculated but weights will not get updated.
      whenever I run this code I got an error



      Error in a1(1 - a1) : could not find function "a1"



      bt after termination i can see the value of a1 on the right side of R-Studio.
      It seems like is d2f is not calculated even.so what i am doing wrong.



      here is the code



      library(datasets)
      library("phonTools", lib.loc="~/R/win-library/3.5")
      iris.df =data(iris)
      data(iris)
      data("iris")
      iris.df=iris

      J = vector(mode = "numeric" , length = nrow(iris.df) )

      attach(iris.df)

      iris.df$y1 = 0

      iris.df$y2 = 0

      iris.df$y3 = 0

      iris.df$y1[iris.df$Species =="setosa"] = 1

      iris.df$y2[iris.df$Species =="versicolor"] = 1

      iris.df$y3[iris.df$Species =="virginica"] = 1

      w1b = matrix(rexp(20, rate=.1), ncol=5) #Declaring weights between 1st layer

      w1b = wb1*0.24 - 0.12

      q = c(1,1,1,1)

      #w1b = cbind(q,w1b)

      w2b = matrix(rexp(12, rate=.1), ncol=4)

      w2b = w2b*0.24 - 0.12

      q = c(1,1,1)

      #w2b = cbind(q,w2b)

      d1f = zeros(3,4)

      d2f = zeros(4,5)

      sigmoid = function(z)
      {
      sig = 1/( 1 + exp(-z) )

      return(sig)
      }

      for (i in 1:150) {


      # Forward Propagation For First Layer

      a1 = sigmoid( 1*w1b[1,1] + iris.df$Sepal.Length[i]*w1b[1,2] + iris.df$Sepal.Width[i]*w1b[1,3] + iris.df$Petal.Length[i]*w1b[1,4] + iris.df$Petal.Width[i]*w1b[1,5] )

      a2 = sigmoid( 1*w1b[2,1] + iris.df$Sepal.Length[i]*w1b[2,2] + iris.df$Sepal.Width[i]*w1b[2,3] + iris.df$Petal.Length[i]*w1b[2,4] + iris.df$Petal.Width[i]*w1b[2,5] )

      a3 = sigmoid( 1*w1b[3,1] + iris.df$Sepal.Length[i]*w1b[3,2] + iris.df$Sepal.Width[i]*w1b[3,3] + iris.df$Petal.Length[i]*w1b[3,4] + iris.df$Petal.Width[i]*w1b[3,5] )

      a4 = sigmoid( 1*w1b[4,1] + iris.df$Sepal.Length[i]*w1b[4,2] + iris.df$Sepal.Width[i]*w1b[4,3] + iris.df$Petal.Length[i]*w1b[4,4] + iris.df$Petal.Width[i]*w1b[4,5] )

      #Forward Propagation For Second Layer

      o1 = sigmoid( 1*w2b[1,1] + a1*w2b[1,2] + a1*w2b[1,3] + a1*w2b[1,4] )

      o2 = sigmoid( 1*w2b[2,1] + a2*w2b[2,2] + a2*w2b[2,3] + a2*w2b[2,4] )

      o3 = sigmoid( 1*w2b[3,1] + a3*w2b[3,2] + a3*w2b[3,3] + a3*w2b[3,4] )




      #Backward Propagation For First Layer

      d1f[1,1] = d1f[1,1] + o1*(1-o1) *(o1-y1[i]) #For Baised Node

      d1f[2,1] = d1f[2,1] + o2*(1-o2) *(o2-y2[i]) #For Baised Node

      d1f[3,1] = d1f[3,1] + o3*(1-o3) *(o3-y3[i]) #For Baised Node



      d1f[1,2] = d1f[1,2] + a1*o1*(1-o1)*(o1-y1[i])

      d1f[2,2] = d1f[2,2] + a1*o2*(1-o2)*(o2-y2[i])

      d1f[3,2] = d1f[3,2] + a1*o3*(1-o3)*(o3-y3[i])




      d1f[1,3] = d1f[1,3] + a2*o1*(1-o1)*(o1-y1[i])

      d1f[2,3] = d1f[2,3] + a2*o2*(1-o2)*(o2-y2[i])

      d1f[3,3] = d1f[3,3] + a2*o3*(1-o3)*(o3-y3[i])




      d1f[1,4] = d1f[1,4] + a3*o1*(1-o1)*(o1-y1[i])

      d1f[2,4] = d1f[2,4] + a3*o2*(1-o2)*(o2-y2[i])

      d1f[3,4] = d1f[3,4] + a3*o3*(1-o3)*(o3-y3[i])



      #Backward Propagation For Second Layer

      d2f[1,2] = d2f[1,2] + iris.df$Sepal.Length[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[1,3] = d2f[1,3] + iris.df$Sepal.Width[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[1,4] = d2f[1,4] + iris.df$Petal.Length[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[1,5] = d2f[1,5] + iris.df$Petal.Width[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )


      ###########

      d2f[1,1] = d2f[1,1] + a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

      d2f[2,1] = d2f[2,1] + a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

      d2f[3,1] = d2f[3,1] + a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

      d2f[4,1] = d2f[4,1] + a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node





      d2f[2,2] = d2f[2,2] + iris.df$Sepal.Length[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[2,3] = d2f[2,3] + iris.df$Sepal.Width[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[2,4] = d2f[2,4] + iris.df$Petal.Length[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[2,5] = d2f[2,5] + iris.df$Petal.Width[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




      d2f[3,2] = d2f[3,2] + iris.df$Sepal.Length[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[3,3] = d2f[3,3] + iris.df$Sepal.Width[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[3,4] = d2f[3,4] + iris.df$Petal.Length[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[3][5] = d2f[3,5] + iris.df$Petal.Width[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




      d2f[4,2] = d2f[4,2] + iris.df$Sepal.Length[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[4][3] = d2f[4,3] + iris.df$Sepal.Width[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[4,4] = d2f[4,4] + iris.df$Petal.Length[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[4,5] = d2f[4,5] + iris.df$Petal.Width[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




      cost = ( iris.df$y1[i] * log(o1) + (1-y1[i]) * log(1-o1) + iris.df$y2[i] * log(o2) + (1-y2[i]) * log(1-o2) + iris.df$y3[i] * log(o3) + (1-y3[i]) * log(1-o3) )/nrow(iris.df)

      j[i] = cost
      }









      share|improve this question















      I am writing a neural network from scratch in r programming language and apply it on iris dataset.
      here



      d1f is a matrix of propagation error of output layer



      d2f is a matrix of propagation error of hidden layer



      a1,a2,a3,a4 are activation output of hidden layer



      o1,o2,o3 are activation output of output layer



      w1b & w2b are the matrix of weights of hidden layer and output layer respectively



      j is used to store cost of each observation



      till now I had written it for only single pass through the whole dataset. So only propagation error is calculated but weights will not get updated.
      whenever I run this code I got an error



      Error in a1(1 - a1) : could not find function "a1"



      bt after termination i can see the value of a1 on the right side of R-Studio.
      It seems like is d2f is not calculated even.so what i am doing wrong.



      here is the code



      library(datasets)
      library("phonTools", lib.loc="~/R/win-library/3.5")
      iris.df =data(iris)
      data(iris)
      data("iris")
      iris.df=iris

      J = vector(mode = "numeric" , length = nrow(iris.df) )

      attach(iris.df)

      iris.df$y1 = 0

      iris.df$y2 = 0

      iris.df$y3 = 0

      iris.df$y1[iris.df$Species =="setosa"] = 1

      iris.df$y2[iris.df$Species =="versicolor"] = 1

      iris.df$y3[iris.df$Species =="virginica"] = 1

      w1b = matrix(rexp(20, rate=.1), ncol=5) #Declaring weights between 1st layer

      w1b = wb1*0.24 - 0.12

      q = c(1,1,1,1)

      #w1b = cbind(q,w1b)

      w2b = matrix(rexp(12, rate=.1), ncol=4)

      w2b = w2b*0.24 - 0.12

      q = c(1,1,1)

      #w2b = cbind(q,w2b)

      d1f = zeros(3,4)

      d2f = zeros(4,5)

      sigmoid = function(z)
      {
      sig = 1/( 1 + exp(-z) )

      return(sig)
      }

      for (i in 1:150) {


      # Forward Propagation For First Layer

      a1 = sigmoid( 1*w1b[1,1] + iris.df$Sepal.Length[i]*w1b[1,2] + iris.df$Sepal.Width[i]*w1b[1,3] + iris.df$Petal.Length[i]*w1b[1,4] + iris.df$Petal.Width[i]*w1b[1,5] )

      a2 = sigmoid( 1*w1b[2,1] + iris.df$Sepal.Length[i]*w1b[2,2] + iris.df$Sepal.Width[i]*w1b[2,3] + iris.df$Petal.Length[i]*w1b[2,4] + iris.df$Petal.Width[i]*w1b[2,5] )

      a3 = sigmoid( 1*w1b[3,1] + iris.df$Sepal.Length[i]*w1b[3,2] + iris.df$Sepal.Width[i]*w1b[3,3] + iris.df$Petal.Length[i]*w1b[3,4] + iris.df$Petal.Width[i]*w1b[3,5] )

      a4 = sigmoid( 1*w1b[4,1] + iris.df$Sepal.Length[i]*w1b[4,2] + iris.df$Sepal.Width[i]*w1b[4,3] + iris.df$Petal.Length[i]*w1b[4,4] + iris.df$Petal.Width[i]*w1b[4,5] )

      #Forward Propagation For Second Layer

      o1 = sigmoid( 1*w2b[1,1] + a1*w2b[1,2] + a1*w2b[1,3] + a1*w2b[1,4] )

      o2 = sigmoid( 1*w2b[2,1] + a2*w2b[2,2] + a2*w2b[2,3] + a2*w2b[2,4] )

      o3 = sigmoid( 1*w2b[3,1] + a3*w2b[3,2] + a3*w2b[3,3] + a3*w2b[3,4] )




      #Backward Propagation For First Layer

      d1f[1,1] = d1f[1,1] + o1*(1-o1) *(o1-y1[i]) #For Baised Node

      d1f[2,1] = d1f[2,1] + o2*(1-o2) *(o2-y2[i]) #For Baised Node

      d1f[3,1] = d1f[3,1] + o3*(1-o3) *(o3-y3[i]) #For Baised Node



      d1f[1,2] = d1f[1,2] + a1*o1*(1-o1)*(o1-y1[i])

      d1f[2,2] = d1f[2,2] + a1*o2*(1-o2)*(o2-y2[i])

      d1f[3,2] = d1f[3,2] + a1*o3*(1-o3)*(o3-y3[i])




      d1f[1,3] = d1f[1,3] + a2*o1*(1-o1)*(o1-y1[i])

      d1f[2,3] = d1f[2,3] + a2*o2*(1-o2)*(o2-y2[i])

      d1f[3,3] = d1f[3,3] + a2*o3*(1-o3)*(o3-y3[i])




      d1f[1,4] = d1f[1,4] + a3*o1*(1-o1)*(o1-y1[i])

      d1f[2,4] = d1f[2,4] + a3*o2*(1-o2)*(o2-y2[i])

      d1f[3,4] = d1f[3,4] + a3*o3*(1-o3)*(o3-y3[i])



      #Backward Propagation For Second Layer

      d2f[1,2] = d2f[1,2] + iris.df$Sepal.Length[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[1,3] = d2f[1,3] + iris.df$Sepal.Width[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[1,4] = d2f[1,4] + iris.df$Petal.Length[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[1,5] = d2f[1,5] + iris.df$Petal.Width[i] * a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )


      ###########

      d2f[1,1] = d2f[1,1] + a1(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

      d2f[2,1] = d2f[2,1] + a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

      d2f[3,1] = d2f[3,1] + a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node

      d2f[4,1] = d2f[4,1] + a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] ) #For Biased Node





      d2f[2,2] = d2f[2,2] + iris.df$Sepal.Length[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[2,3] = d2f[2,3] + iris.df$Sepal.Width[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[2,4] = d2f[2,4] + iris.df$Petal.Length[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[2,5] = d2f[2,5] + iris.df$Petal.Width[i] * a2(1-a2) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




      d2f[3,2] = d2f[3,2] + iris.df$Sepal.Length[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[3,3] = d2f[3,3] + iris.df$Sepal.Width[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[3,4] = d2f[3,4] + iris.df$Petal.Length[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[3][5] = d2f[3,5] + iris.df$Petal.Width[i] * a3(1-a3) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




      d2f[4,2] = d2f[4,2] + iris.df$Sepal.Length[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[4][3] = d2f[4,3] + iris.df$Sepal.Width[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[4,4] = d2f[4,4] + iris.df$Petal.Length[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )

      d2f[4,5] = d2f[4,5] + iris.df$Petal.Width[i] * a4(1-a4) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )




      cost = ( iris.df$y1[i] * log(o1) + (1-y1[i]) * log(1-o1) + iris.df$y2[i] * log(o2) + (1-y2[i]) * log(1-o2) + iris.df$y3[i] * log(o3) + (1-y3[i]) * log(1-o3) )/nrow(iris.df)

      j[i] = cost
      }






      r machine-learning neural-network






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 11:46









      desertnaut

      16.4k63566




      16.4k63566










      asked Nov 23 '18 at 5:41









      Siddhant Vats

      31




      31




      closed as off-topic by desertnaut, Rui Barradas, AkselA, blue-phoenox, Rob Nov 24 '18 at 2:12


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – desertnaut, Rui Barradas, Rob

      If this question can be reworded to fit the rules in the help center, please edit the question.




      closed as off-topic by desertnaut, Rui Barradas, AkselA, blue-phoenox, Rob Nov 24 '18 at 2:12


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – desertnaut, Rui Barradas, Rob

      If this question can be reworded to fit the rules in the help center, please edit the question.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          If you want to get the product of a1 and 1-a1, you explicitly have to write the '*' in between.



          d2f[1,2] = d2f[1,2] + iris.df$Sepal.Length[i] * a1*(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )


          If you open parentheses after a1, r thinks youre referring to a function called a1, because thats the syntax for functions. The same problem is in multiple occasions of your code. You should always state the arithmetic operators you want to use.






          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            If you want to get the product of a1 and 1-a1, you explicitly have to write the '*' in between.



            d2f[1,2] = d2f[1,2] + iris.df$Sepal.Length[i] * a1*(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )


            If you open parentheses after a1, r thinks youre referring to a function called a1, because thats the syntax for functions. The same problem is in multiple occasions of your code. You should always state the arithmetic operators you want to use.






            share|improve this answer




























              0














              If you want to get the product of a1 and 1-a1, you explicitly have to write the '*' in between.



              d2f[1,2] = d2f[1,2] + iris.df$Sepal.Length[i] * a1*(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )


              If you open parentheses after a1, r thinks youre referring to a function called a1, because thats the syntax for functions. The same problem is in multiple occasions of your code. You should always state the arithmetic operators you want to use.






              share|improve this answer


























                0












                0








                0






                If you want to get the product of a1 and 1-a1, you explicitly have to write the '*' in between.



                d2f[1,2] = d2f[1,2] + iris.df$Sepal.Length[i] * a1*(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )


                If you open parentheses after a1, r thinks youre referring to a function called a1, because thats the syntax for functions. The same problem is in multiple occasions of your code. You should always state the arithmetic operators you want to use.






                share|improve this answer














                If you want to get the product of a1 and 1-a1, you explicitly have to write the '*' in between.



                d2f[1,2] = d2f[1,2] + iris.df$Sepal.Length[i] * a1*(1-a1) * ( (o1-y1[i])*o1*(1-o1)*w2b[1,2] + (o2-y2[i])*o2*(1-o2)*w2b[2,2] + (o3-y3[i])*o3*(1-o3)*w2b[3,2] )


                If you open parentheses after a1, r thinks youre referring to a function called a1, because thats the syntax for functions. The same problem is in multiple occasions of your code. You should always state the arithmetic operators you want to use.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 23 '18 at 7:30

























                answered Nov 23 '18 at 7:25









                marsh

                161




                161















                    Popular posts from this blog

                    Berounka

                    Sphinx de Gizeh

                    Different font size/position of beamer's navigation symbols template's content depending on regular/plain...