Modeling an exponential distribution in R

I have the following graph:

enter image description here

I was told the following information:

(1) the vertex A to the vertex X is described by an exponential distribution with lambda = 4;

(2) the vertex A to the vertex Y is described by an exponential distribution with lambda = 2.5;

(3) the vertex X to the vertex Y, identical to the vertex Y, to the vertex X, and it is described by an exponential distribution with lambda = 10;

(4) the vertex X to the vertex B is described by an exponential distribution with lambda = 3; and finally

(5) the vertex Y to the vertex B is described by an exponential distribution with lambda = 5.

Suppose I use the fastest path between the vertices of each simulation.

Now I want to find out the average time needed to go from vertex A to vertex B.

My R code is as follows:

# Generate/simulate 1000 random numbers for each of the internode paths.

            AtoX <- rexp(1000, 4)
            AtoY <- rexp(1000, 2.5)
            XtoY <- rexp(1000, 10)
            XtoB <- rexp(1000, 3)
            YtoB <- rexp(1000, 5)

    # Length of path from A to X to Y and A to Y to X.

            AYX = AtoY + XtoY
            AXY = AtoX + XtoY

    # Total time of paths from A to B. 

            AXB = AtoX + XtoB
            AYB = AtoY + YtoB
            AXYB = AtoX + XtoY + YtoB
            AYXB = AtoY + XtoY + XtoB

    # Taking the fastest path of all paths. 

            minAXB = min(AXB)
            minAYB = min(AYB)
            minAXYB = min(AXYB)
            minAYXB = min(AYXB)

    # Taking an average of the fastest paths.

            averageTravelTime = 
              mean(minAXB + minAYB + minAXYB + minAYXB)

? , .

+4
1
  • , , X Y Y X , . , , , , X Y, .

  • AYX <- AtoY + XtoY
    AXY <- AtoX + XtoY
    

    .

  • minAXB <- min(AXB) . 1000 , AXB - 1000 AXB, .

  • , averageTravelTime , minAXB + minAYB + minAXYB + minAYXB - , .

, ,

set.seed(1)
AtoX <- rexp(1000, 4)
AtoY <- rexp(1000, 2.5)
XtoY <- rexp(1000, 10)
YtoX <- rexp(1000, 10) # added
XtoB <- rexp(1000, 3)
YtoB <- rexp(1000, 5)

AXB <- AtoX + XtoB
AYB <- AtoY + YtoB
AXYB <- AtoX + XtoY + YtoB
AYXB <- AtoY + YtoX + XtoB # changed XtoY to YtoX

TravelTimes <- pmin(AXB, AYB, AXYB, AYXB)
averageTravelTime <- mean(TravelTimes)

. ?pmin. 1000.

,

table(apply(cbind(AXB, AYB, AXYB, AYXB), 1, which.min))
#   1   2   3   4 
# 317 370 240  73 
+3

Source: https://habr.com/ru/post/1695101/


All Articles