• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

R code to Java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends...

can anybody tell me how to convert the R code into Java code? Or anybody can help me to convert the R code to Java code??
 
Marshal
Posts: 8960
646
Mac OS X Spring VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you understand the logic of R code, meaning what the R app is doing?
 
geethu th
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually its an R implementation of an algorithm. I have the algorithm, its R code and input data with me. But I don't know the R. Actually, I want the code in Java and so that, I can do my own modification in that code. Can you help me to convert the R code into Java.. or Suggest me somebody who knows both R and Java..

Thanks in advance.
 
Liutauras Vilda
Marshal
Posts: 8960
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds fuzzy.

If you were know the logic behind the algorithm, you could rewrite the algorithm in Java yourself (I assumed in R's code there is nothing R specifics what couldn't be achieved with Java and I imply you know Java).
But since you don't know what this algorithm is doing at all, hm... I know for sure we have some people here who know R fairly well. You can try to post this algorithm here and might somebody will be interested to research it.

I hope it isn't 15.000 lines of code. Don't post if that's the case or very similar to it.
 
geethu th
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its really a big code. Could you please give me any email id so that I can send the entire code and algorithm to you. Its really urgent...
 
Liutauras Vilda
Marshal
Posts: 8960
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

geethu th wrote:Its really a big code. Could you please give me any email id so that I can send the entire code and algorithm to you. Its really urgent...


Dude, I don't need that code. That's your task.

My suggestion is, find the person who knows the algorithm, ask him/her nicely to explain what it does, more better would be to get specification of it - and then based on your needs you can try to implement it in Java. Not sure why is that needed in the first place, but I'll leave that knowledge to you.

You can be almost certain, that no one is going sit down and do the task for you to convert some mystical algorithm from R to Java (if that's even possible).

We also have at least two useful tutorials to go through: [1] Ease Up, [2] Java Dudes Lament
 
Liutauras Vilda
Marshal
Posts: 8960
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe post a really small portion of it, so somebody could get a taste of the R code and see if that sounds doable to convert to Java at all.

R is a language mainly for statisticians, so the problems this language helps to solve are different. It may be well possible that it uses some special libraries in your mentioned algorithm which don't exist in Java - that means you couldn't just simply by literal take and convert R code to Java.

Might there is a reason why algorithm was written in R and not in Java. Basically I don't know what else to suggest to you - might somebody else will do.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setwd("C:\\Users\\ts93856\\Desktop\\Taxi")
data <- read.csv("Bigbasket.csv")
dim(data)
#250*7
summary(data)
# This is the initial value of the increment vector - all zeros
increment <- array(0,250)

flag = 0
increment_i <- increment
#flag = 1 is a condition when the increment vector remains the same
while (flag == 0) {
print(find_rev(increment_i))
increment_iplus1 <- incremental_new(increment_i)
if (min(increment_iplus1 == increment_i) == 1) {flag = 1}
increment_i <- increment_iplus1
}
increment_i
find_rev(increment_i)
/find_rev(increment)
price <- increment_i
write.csv(price,"price.csv")

#This function tries to get the next best increment vector
incremental_new <- function(initial_increments){
initial_rev <- find_rev(initial_increments)
intermediate_rev <- 0
for(i in 1:250){
increments <- initial_increments
if(increments[i] > -0.099) {increments[i] <- increments[i] - 0.01}
rev <- find_rev(increments)
if (rev > initial_rev) {final_increments <- increments
intermediate_rev <- rev
}
if(increments[i] < 0.19) {increments[i] <- initial_increments[i] + 0.01}
rev <- find_rev(increments)
if (rev > max(initial_rev,intermediate_rev)) {final_increments <- increments}
}
return(final_increments)
}
# This function will get us the overall revenue for the given increment vector
find_rev <- function(increment){
price <- data$Avg_Price_per_unit*(1+increment)
volumes <- data$Average_units_sold*(1-(data$Increase_sale_volume*increment*10))
multiplier <- (1-(data$Incremental_acquisition*increment*10))
total_multiplier <- prod(multiplier)
profit_wo_multiplier <- 0.05*(sum(price*volumes) - sum(volumes*data$Cost_per_unit))
profit_w_multiplier <- profit_wo_multiplier*total_multiplier
net_profit <- sum(profit_w_multiplier)
return(net_profit)}
 
Marshal
Posts: 79956
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Is that different code? Do you have a question? Would it have been better for you to start a new thread? Are you supposed to indent R code? What you showed is pretty difficult to read.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FA <- function(x){
return <- x^3-x-1}
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a <- -3
b <- 3
ErrorTolerance = 0.00000001
n <- 100
for(i in 1:n) {
p = a+(b-a)/2
print(p)
if(abs(FA(a) - FA(b)) < ErrorTolerance){
print(" Error Tolerance is passed")
break}
if((FA(a) * FA(p)) > 0 ){
a = p} else if ((FA(b) * FA(p))> 0){
b = p }else { break}
}
 
Men call me Jim. Women look past me to this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic