search for: sum_squares

Displaying 6 results from an estimated 6 matches for "sum_squares".

2024 Jun 16
2
slowness when I use a list comprehension
...- 70000 ## size of the second serie N2 <- 100 ## mock data set.seed(123) vec1 <- rnorm(N1) vec2 <- runif(N2) ## 1. with the "for" loops ## the square differences will be stored in a vector S_diff2 <- numeric((N1-(N2-1)*ratio_sampling)) tic() for( j in 1:length(S_diff2)){ ? sum_squares <- 0 ? for( i in 1:length(vec2)){ ??? sum_squares = sum_squares + ((vec1[(i-1)*ratio_sampling+j] - vec2[i])**2) ? } ? S_diff2[j] <- sum_squares } toc() ## 0.22 sec elapsed which.max(S_diff2) ## 7857 ## 2. with the lists comprehension tic() S_diff2 <- to_vec(for( j in 1:length(S_diff2...
2024 Jun 16
1
slowness when I use a list comprehension
...- 70000 ## size of the second serie N2 <- 100 ## mock data set.seed(123) vec1 <- rnorm(N1) vec2 <- runif(N2) ## 1. with the "for" loops ## the square differences will be stored in a vector S_diff2 <- numeric((N1-(N2-1)*ratio_sampling)) tic() for( j in 1:length(S_diff2)){ sum_squares <- 0 for( i in 1:length(vec2)){ sum_squares = sum_squares + ((vec1[(i-1)*ratio_sampling+j] - vec2[i])**2) } S_diff2[j] <- sum_squares } toc() ## 0.22 sec elapsed which.max(S_diff2) ## 7857 ## 2. with the lists comprehension tic() S_diff2 <- to_vec(for( j in 1:length(S_diff2...
2024 Jun 16
1
slowness when I use a list comprehension
...data > set.seed(123) > vec1 <- rnorm(N1) > vec2 <- runif(N2) > > > ## 1. with the "for" loops > > ## the square differences will be stored in a vector > S_diff2 <- numeric((N1-(N2-1)*ratio_sampling)) > tic() > for( j in 1:length(S_diff2)){ > sum_squares <- 0 > for( i in 1:length(vec2)){ > sum_squares = sum_squares + ((vec1[(i-1)*ratio_sampling+j] - > vec2[i])**2) > } > S_diff2[j] <- sum_squares > } > toc() > ## 0.22 sec elapsed > which.max(S_diff2) > ## 7857 > > ## 2. with the lists comprehen...
2024 Jun 16
1
slowness when I use a list comprehension
...the first serie N1 <- 70000 ## size of the second serie N2 <- 100 ## mock data set.seed(123) vec1 <- rnorm(N1) vec2 <- runif(N2) dloop <- function( N1, M2, ratio_sampling, vec1, vec2 ) { S_diff2 <- numeric( N1-(N2-1)*ratio_sampling ) for( j in 1:length(S_diff2) ) { sum_squares <- 0 for( i in 1:length(vec2)){ sum_squares <- ( sum_squares + ( vec1[ (i-1)*ratio_sampling+j ] - vec2[i] )**2 ) } S_diff2[j] <- sum_squares } S_diff2 } vloop <- function( N1, M2, ratio_sampling, vec1, vec2 ) { S...
2024 Jun 16
1
slowness when I use a list comprehension
...the first serie N1 <- 70000 ## size of the second serie N2 <- 100 ## mock data set.seed(123) vec1 <- rnorm(N1) vec2 <- runif(N2) dloop <- function( N1, M2, ratio_sampling, vec1, vec2 ) { S_diff2 <- numeric( N1-(N2-1)*ratio_sampling ) for( j in 1:length(S_diff2) ) { sum_squares <- 0 for( i in 1:length(vec2)){ sum_squares <- ( sum_squares + ( vec1[ (i-1)*ratio_sampling+j ] - vec2[i] )**2 ) } S_diff2[j] <- sum_squares } S_diff2 } vloop <- function( N1, M2, ratio_sampling, vec1, vec2 ) { S...
2009 Oct 01
1
Using optimize with array variables
Hello, I am trying to figure out how to use optimize() with array variables as inputs. I have a for loop in the function definition: SS <- function(int,slo,x,y){ for(i in 1:length(x)) ((int+slo*x[i])-y[i])^2->squares[i] sum(squares)->>sum_squares output_txt = c ("The sum of squares is", sum_squares) print(output_txt, quote=FALSE)} Even assuming I make x and y single-integer variables, for example: optimize(SS, c(0,1), tol = 0.0001, x=1, y=1, slo=1) I get the error: Error in optimize(SS, c(0, 1), tol = 1e-04, x = 1, y = 1, slo...