Why is 3log8(n) the dominant term in 3log8(n) + log2log2log2(n)?
I thought it was log2log2log2(n) since it is larger is it not?
Assuming that
log2log2log2(n) == log(log(log(n, 2), 2), 2)
3log8(n) == 3 * log(n, 8)
we can compute limit to compare asymptotics:
lim log(log(log(n, 2), 2), 2) / (3 * log(n, 8))
n -> inf
since
3 * log(n, 8) = 3 * log(n, 2) / log(8, 2) = log(n, 2)
the limit is
lim log(log(log(n, 2), 2), 2) / log(n, 2) =
n -> inf
Let's use l'Hôpital's rule:
= lim const * n / (n * log(n, 2) * log(log(n, 2), 2)) =
n -> inf
= lim const / (log(n, 2) * log(log(n, 2), 2)) =
n -> inf
= 0
Since limit is 0 3 * log(n, 8) grows faster then log(log(log(n, 2), 2), 2), i.e.
3 * log(n, 8) dominates
No, log2(log2(log2(n))) grows much more slowly than log2(n) as n gets larger.
As dmitry noted, 3log8(n) = log2(n)
Related
I'm trying to find multiple solutions (TXs[1],TXs[2],TXs[3],TXs[4],TXs[5],TZs) that respect the following conditions:
# Variables :
TXs <- Variable(5)
TZs <- Variable(1)
# Objectif :
obj = abs(TXs[1] + TXs[2] + TXs[3] + TXs[4] + TXs[5] + TZs - 100)
# Conditions :
abs(TXs[1] - 2) <=1
abs(TXs[2] - 55) <= 2
abs(TXs[3] - 25) <= 0.5
abs(TXs[4] - 8) <= 1
abs(TXs[5] - 7) <= 1
abs(TZs[1] - 1.5) <= 1
cor(TXs[1], TXs[2]) = 0.77
cor(TXs[3], TXs[2]) = 0.85
cor(TXs[4], TXs[2]) = 0.88
cor(TXs[5], TXs[2]) = 0.99
cor(TZs, TXs[2]) = 0.4
abs(TXs[1] + TXs[2] + TXs[3] + TXs[4] + TXs[5] + TZs[1] - 100) <= 0.001)
I've written the following code that tries to find k solutions but it fails as I always get the same result:
library(CVXR)
# k solutions
k <- 10
solutions <- matrix(NA, nrow = k, ncol = 6)
# Variables
TXs <- Variable(5)
TZs <- Variable(1)
# Objectif
obj = abs(TXs[1] + TXs[2] + TXs[3] + TXs[4] + TXs[5] + TZs - 100)
for (i in 1:k) {
print(i)
# Problem
prob = Problem(Minimize(obj),
list(abs(TXs[1] - 2) <= 1, ((TXs[1] - 2)/ 1) == (0.77 * (TXs[2] - 55)/ 2),
abs(TXs[3] - 25) <= 2, ((TXs[3] - 25)/ 2) == (0.85 * (TXs[2] - 55)/ 2),
abs(TXs[4] - 8) <= 0.5, ((TXs[4] - 8)/ 0.5) == (0.88 * (TXs[2] - 55)/ 2),
abs(TXs[5] - 7) <= 1, ((TXs[5] - 7)/ 1) == (0.99 * (TXs[2] - 55)/ 2),
abs(TZs[1] - 1.5) <= 1.2, ((TZs - 1.5)/ 1.2) == (0.4 * (TXs[2] - 55)/ 2),
abs(TXs[1] + TXs[2] + TXs[3] + TXs[4] + TXs[5] + TZs[1] - 100) <= 0.001))
result = solve(prob, verbose = TRUE )
solutions[i,] <- c(result$getValue(TXs[1]),
result$getValue(TXs[2]),#TXs[2],
result$getValue(TXs[3]),
result$getValue(TXs[4]),
result$getValue(TXs[5]),
result$getValue(TZs[1]))
}
solutions = as.data.frame(solutions)
colnames(solutions) = c("TXs[1]","TXs[2]","TXs[3]","TXs[4]","TXs[5]","TZs" )
solutions$Somme = rowSums(solutions)
Is there a way to modify my code to get multiple solutions? I am also open to other alternatives to "CVXR".
I receive an error from nls function in R. I search some similar questions, but do not solve this problem. For example, I try to use nlsLM from library 'minpack.lm', it also fails. So I have to ask for help here. Following is the code:
tt = c(10, 30, 50, 90, 180, 360, 720, 1440, 2880, 4320, 8640, 12960)
x = c(
1.53901e-06,
1.22765e-06,
1.11200e-06,
9.25185e-07,
8.71809e-07,
8.80705e-07,
8.36225e-07,
7.82849e-07,
8.18433e-07,
6.04928e-07,
3.46944e-07,
4.44800e-07
)
y = c(
3.81639e-06,
5.00623e-06,
4.62815e-06,
5.10631e-06,
4.48359e-06,
3.30487e-06,
2.64879e-06,
2.13727e-06,
8.02865e-07,
1.91487e-06,
3.73855e-06,
2.32631e-06
)
nt = length(tt)
L0 = 0.005
y0 = 0.000267681
model = function(K, Kd, k1) {
eta = 5 / (4 * Kd + 40)
eta1 = 1 - eta
eta1_seq = eta1 ^ c(0:(nt - 1))
Lt = L0 * eta * cumsum(eta1_seq)
b = K * x - K * Lt + 1
L = (-b + sqrt(b ^ 2.0 + 4 * K * Lt)) / (2 * K)
cx = x * K * L / (K * L + 1)
qx = Kd * cx
q1 = y0 * (1 - k1 * sqrt(tt))
y = qx + q1
return(y)
}
fit <- nls(
y ~ model(K, Kd, k1),
start = list(K = 1e+15,
Kd = 10,
k1 = 1e-5),
lower = c(1e+13, 1, 1e-10),
upper = c(1e+20, 200, 1e-3),
algorithm = "port"
)
Thanks in advance for your help!
Have a problem with data generating and I have no idea how to solve this. All information provided in photo: Problem.
I think that X_i(t) in both cases should be 200 x 100 if we say that t is from 0 to 1 (length = 100). Furthermore, coefficients for polynomial should contain 200 x 4 and coefficients for fourier should contain 200 x 5. Bu I have no idea how to start to solve this problem.
Here is some code. So, I have already defined my beta's, but I can't defeat generating of X_i(t).
t <- seq(0, 1, length = 100)
beta_1t <- rep(0, 100)
plot(t, beta_1t, type = "l")
beta_2t <- (t >= 0 & t < 0.342) * ((t - 0.5)^2 - 0.025) +
(t >= 0.342 & t <= 0.658) * 0 +
(t > 0.658 & t <= 1) * (-(t - 0.5)^2 + 0.025)
plot(t, beta_2t, type = "l")
beta_3t <- t^3 - 1.6 * t^2 + 0.76 * t + 1
plot(t, beta_3t, type = "l")
poly_c <- matrix(rnorm(n = 800, mean = 0, sd = 1), ncol = 4)
four_c <- matrix(rnorm(n = 1000, mean = 0, sd = 1), ncol = 5)
As I mentioned before, there should be (X_i(t), Y_i(t)) samples. Here i = 1, 2, ..., 200; t from [0, 1] (length = 100).
I am trying to implement the following formula in R where r0, t, theta0 and alpha are constants. Also, I is a Modified Bessel function of the first kind. My issue, I suppose, is from the Sum term to the end of the formula. I set n = 150 given that the function converges to zero fast so there is no need to go beyond 150. I am using the "Bessel" package.
Formula1
Formula2
Results to reproduce first row = t, second row = Defaultcorr in %
Here is what I have thus far. I can't seem to find my mistake. Defaultcorr should be 0.04 % when t = 1 (according to the image "Results to reproduce").
To obtain this result " m " should be equal to 6.234611709.
V1 = 5
V2 = 5
K1 = 1
K2 = 1
sigma1 = 0.3
sigma2 = 0.3
Z1 = log((V1/K1)/sigma1)
Z2 = log((V2/K2)/sigma2)
t = 1
rho = 0.4
#One firm default -> Firm #1 when lambda = mu
PD_asset1 = 2 * pnorm(-(Z1/sqrt(t)))
PD_asset1
PD_asset2 = 2 * pnorm(-(Z2/sqrt(t)))
PD_asset2
#Results assuming that lambda = mu
#Conditions for alpha, theta0, r0
if (rho < 0) { #alpha
alpha = atan(-(sqrt(1-rho^2)) / rho)
} else {
alpha = pi + atan(-(sqrt(1-rho^2)) / rho)
}
if (rho > 0) { #theta0
theta0 = atan((Z2 * sqrt(1 - rho^2)) / (Z1 - (rho * Z2)))
} else {
theta0 = pi + atan((Z2 * sqrt(1 - rho^2)) / (Z1 - (rho * Z2)))
}
r0 = (Z2 / sin(theta0)) #r0
#Simplified function
h = function(n) {
(sin((n * pi * theta0)/alpha)/n)
}
n = seq(1, 150, 2)
Bessel1 = (besselI(((r0^2)/(4*t)), (0.5*(((n*pi)/alpha) + 1)), FALSE))
Bessel2 = (besselI(((r0^2)/(4*t)), (0.5*(((n*pi)/alpha) - 1)), FALSE))
l = matrix(data = n, ncol = n)
m = apply((h(l)*(Bessel1 + Bessel2)), 2, FUN = sum)
PD_asset1_or_asset2 = 1 - (((2 * r0)/(sqrt(2*pi*t))) * (exp(-(r0^2)/(4*t))) * m)
PD_asset1_or_asset2
Var_asset1 = PD_asset1 * (1 - PD_asset1)
Var_asset1
Var_asset2 = PD_asset2 * (1 - PD_asset2)
Var_asset2
PD_asset1_and_asset2 = PD_asset1 + PD_asset2 - PD_asset1_or_asset2
PD_asset1_and_asset2
Defaultcorr = (PD_asset1_and_asset2 - (PD_asset1 * PD_asset2)) / (sqrt(Var_asset1 * Var_asset2))
Defaultcorr
Any help would be appreciated. Thank you
How can I scale a set of values to fit a new range if they include negative numbers?
For example, I have a set of numbers (-10, -9, 1, 4, 10) which have to scaled to a range [0 1], such that -10 maps to 0, and 10 maps to 1.
The regular method for an arbitrary number 'x' would be:
(x - from_min) * (to_max - to_min) / (from_max - from_min) + to_min
but this does not work for negative numbers. Any help is appreciated. Thanks!!
I believe id does; in your example,
from_min = -10,
from_max = 10,
to_max = 1,
to_min = 0.
This yields
to_max - to_min = 1,
from_max - from_min = 20;
So using the formula
x -> (x - from_min) * (to_max - to_min) / (from_max - from_min) + to_min
= (x - from_min) * 1 / 20 + 0
= (x - from_min) / 20
yields
-10 -> (-10 + 10) / 20 = 0 / 20,
-9 -> (-9 + 10) / 20 = 1 / 20,
1 -> (1 + 10) / 20 = 11 / 20,
4 -> (4 + 10) / 20 = 14 / 20,
10 -> (10 + 10) / 20 = 20 / 20,
so all the resulting values are nonnegative. Furthermore, the original minimum -10 maps to to_min = 0 and the original maximum 10 maps to to_max = 1. If this doesn't work in your implementation, check if you mixed up integral types and floating-point types.
Your formula works fine for negative numbers.
You have:
from_min = -10
from_max = 10
to_min = 0
to_max = 1
Substituting these into your formula:
(x - (-10)) * (1 - 0) / (10 - (-10)) + 0
Which simplifies to:
(x + 10) / 20