Categories
Mastering Development

python pulp: How do I create LpMaximize and LpMinimize problem?

How do I go about creating an optimization that LpMaximize profits and LpMinimize the variance? I tried making var negative than using LpMaximize. The code below just the max of var and not the min of var and the max of profit. prob += lpSum([profits[i]*x[i] for i in N] and [var[v]*x[v] for v in N]) […]

Categories
Ask Mathematics

Question regarding combinatorics formula

I was solving this math problem: If we roll three standard dices what is the possibility that the sum of eyes will be equal to 7? So I tried to approach this problem in two different ways: 1) The order in every sequence IS IMPORTANT (a,a,b) and (a,b,a) sequences are counted as different. In this […]

Categories
Mastering Development

Divide data by the preceding row and create new dataframe

I have a data set and I’m trying to calculate the rate of change between the rows. My input looks like this: foo = structure(list(date = structure(c(5L, 1L, 2L, 3L, 4L), .Label = c(“10/03/2020”, “11/03/2020”, “12/03/2020”, “13/03/2020”, “9/03/2020”), class = “factor”), A = c(0.60256322, 0.634543306, 0.022976661, 0.009839044, 0.319456765), B = c(45.42320826, 57.32689951, 32.49487759, 29.40804164, 54.33691346), […]

Categories
Mastering Development

Backpropagation giving strange values in C++ neural network

I am trying to solve the iris data set with a neural network I wrote in C++ from scratch, which has 150 rows divided up into 3 different flowers with 4 columns and then a fifth for the flower type which I converted to a 0, 1 or 2. Problem: Whenever I run the network […]

Categories
Development

jq convert json to a different json

I am working with a JSON file similar to this, and I am looking to flatten it and after some calculations: { “Response” : { “TimeUnit” : [ 1583443380000, 1583443390000 ], “metaData” : { “errors” : [ ], “notices” : [ “” ] }, “resultTruncated” : false, “stats” : { “data” : [ { “identifier” […]

Categories
Development

R Creating a p-value matrix with missing values

I have a dataframe with many missing NAs. I want to create a correlation matrix with a p-value matrix as shown in this link: Link I created the correlation matrix like this: as.data.frame(round(cor(df, use = “pairwise.complete.obs”, method = c(“spearman”)), 1)) Now I am trying to create a matrix that shows the p-values for each correlation. […]

Categories
Development

How to identify a range of data points between a minimum and a maximum in a dataframe in R?

My measured variable V1 follows cycles: it goes up to reach a maximum and down to reach a minimum. I call “cycle” the range of data points between 2 consecutive maxima (cycle 1 is maximum 1 – minimum 1 – maximum 2, cycle 2 is maximum 2 – minimum 2 – maximum 3). The minima […]

Categories
Development

How to plot a median value of a continuous parameter using dplyr or ggplot?

Being complete new to tidyverse and trying to learn, I am trying to plot a median time denoted ee$rfs per ee$Ki67, which is marker of many cells that proliferates in a tumor sample, ie. a continuous covariate too. I have attached my data ee below. I am searching for a solution in either dplyr or […]

Categories
Development

Best way to bin all x values within a range and then take the mean of all y values in each bin?

I have a list of x,y coordinates. The x values are close together but are not the same. I would like to bin x values together within a range and then take the mean value of the y values in each bin. I want the end results to be two 1-D arrays – one of […]

Categories
Development

dplyr – recode several columns at once

Suppose you have a dataframe with variables named X1 – X30 and Y1 – Y30. Each of these variables holds integers 1 – 5. We wish to recode some of the variables starting with X like this: df %<>% mutate_at(vars(starts_with(“X”) & ends_with(“5”, “8”, “16”, “22”, “28”)), recode, “1” = 5, “2” = 4, “4” = […]